mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-30 20:06:22 -05:00
app: handle form fetch failures without unhandled rejection
Catch useForm fetcher errors and surface them so DomainEditPage can show a not-found message instead of hanging on the loader (and so the webpack overlay no longer flakes Cypress).
This commit is contained in:
parent
f5615440e5
commit
0850b6a7fe
5 changed files with 104 additions and 10 deletions
|
|
@ -630,6 +630,15 @@ export function DomainEditPage() {
|
|||
};
|
||||
|
||||
if (!form.ready) {
|
||||
if (form.error) {
|
||||
return <>
|
||||
<BackButton/>
|
||||
<Message error>
|
||||
<Message.Header>Domain not found</Message.Header>
|
||||
<p>{form.error}</p>
|
||||
</Message>
|
||||
</>;
|
||||
}
|
||||
return <Loader active>Loading domain...</Loader>;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -154,10 +154,13 @@ describe('DomainEditPage', () => {
|
|||
});
|
||||
|
||||
describe('Error States', () => {
|
||||
it('shows loader when form is not ready (fetch fails)', () => {
|
||||
// When form.ready is false (e.g., fetch failed), show loader
|
||||
it('shows error message when domain fetch fails', () => {
|
||||
const form = createTestForm({}, {
|
||||
overrides: {ready: false, loading: false, error: new Error('Domain not found')}
|
||||
overrides: {
|
||||
ready: false,
|
||||
loading: false,
|
||||
error: 'Domain collection with ID 999 not found',
|
||||
}
|
||||
});
|
||||
|
||||
mockUseDomain.mockReturnValue({
|
||||
|
|
@ -168,10 +171,26 @@ describe('DomainEditPage', () => {
|
|||
|
||||
render(<DomainEditPage/>);
|
||||
|
||||
// Should show loading screen when not ready
|
||||
expect(screen.getByText(/loading domain/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/domain not found/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/Domain collection with ID 999 not found/i)).toBeInTheDocument();
|
||||
expect(screen.queryByText(/loading domain/i)).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('collection-edit-form')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
// Form should not be rendered
|
||||
it('shows loader when form is not ready and there is no error', () => {
|
||||
const form = createTestForm({}, {
|
||||
overrides: {ready: false, loading: false, error: null}
|
||||
});
|
||||
|
||||
mockUseDomain.mockReturnValue({
|
||||
domain: null,
|
||||
form,
|
||||
fetchDomain: jest.fn(),
|
||||
});
|
||||
|
||||
render(<DomainEditPage/>);
|
||||
|
||||
expect(screen.getByText(/loading domain/i)).toBeInTheDocument();
|
||||
expect(screen.queryByTestId('collection-edit-form')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
|
|
@ -182,7 +201,7 @@ describe('DomainEditPage', () => {
|
|||
});
|
||||
|
||||
const form = createTestForm(mockDomain, {
|
||||
overrides: {ready: true, loading: false, error: new Error('Update failed')}
|
||||
overrides: {ready: true, loading: false, error: 'Update failed'}
|
||||
});
|
||||
|
||||
mockUseDomain.mockReturnValue({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue