H5: duidelijke meldingen bij een te groot bestand, een 413 van de proxy, een afgebroken of te vaak herhaalde upload

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 16:40:57 +01:00
co-authored by Claude Sonnet 5.5
parent d597faf86a
commit d26720ee75
4 changed files with 79 additions and 2 deletions
@@ -1,6 +1,9 @@
import { beforeEach, describe, expect, it } from 'vitest';
import { fireEvent, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { http, HttpResponse } from 'msw';
import { server } from '@/mocks/server';
import { API_BASE } from '@/features/auth/mocks/fixtures';
import { renderApp, mockAuthenticated } from '@/test/utils';
import { emptyHero, failNextUpload, getSavedHeroRequests, resetMockHero, setMockHero, slide } from '@/features/hero/mocks/handlers';
import { _resetSetupStatusCache } from '@/router';
@@ -271,3 +274,43 @@ describe('Focus dialog', () => {
await waitFor(() => expect(screen.queryByTestId('focus-dialog')).not.toBeInTheDocument());
});
});
describe('Upload problems', () => {
it('refuses a file over 10 MB without sending it', async () => {
await openPage();
const big = new File(['x'], 'groot.jpg', { type: 'image/jpeg' });
Object.defineProperty(big, 'size', { value: 11 * 1024 * 1024 });
await userEvent.upload(screen.getByTestId('hero-upload'), big);
expect(await screen.findByTestId('hero-upload-error')).toHaveTextContent(/maximaal 10 MB|at most 10 MB/);
expect(screen.getByTestId('hero-slides-empty')).toBeInTheDocument();
});
it('explains a 413 of the proxy (no JSON body)', async () => {
await openPage();
server.use(http.post(`${API_BASE}/api/v1/hero/images`, () => new HttpResponse('<html>413 Request Entity Too Large</html>', { status: 413 })));
await userEvent.upload(screen.getByTestId('hero-upload'), new File(['x'], 'x.jpg', { type: 'image/jpeg' }));
expect(await screen.findByTestId('hero-upload-error')).toHaveTextContent(/maximaal 10 MB|at most 10 MB/);
});
it('asks to try again when the connection breaks off', async () => {
await openPage();
server.use(http.post(`${API_BASE}/api/v1/hero/images`, () => HttpResponse.error()));
await userEvent.upload(screen.getByTestId('hero-upload'), new File(['x'], 'x.jpg', { type: 'image/jpeg' }));
expect(await screen.findByTestId('hero-upload-error')).toHaveTextContent(/afgebroken|interrupted/);
});
it('says when there are too many uploads in a row', async () => {
await openPage();
server.use(http.post(`${API_BASE}/api/v1/hero/images`, () => new HttpResponse(null, { status: 429 })));
await userEvent.upload(screen.getByTestId('hero-upload'), new File(['x'], 'x.jpg', { type: 'image/jpeg' }));
expect(await screen.findByTestId('hero-upload-error')).toHaveTextContent(/te veel uploads|Too many uploads/);
});
});