Mediabibliotheek en Hero: definitief verwijderen en prullenbak legen, kiezen uit bibliotheek per slide, uitsnede direct zonder opslaan, teller per batch; aannamelijst
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -216,6 +216,79 @@ describe('MediaLibraryPage', () => {
|
||||
expect(window.sessionStorage.getItem('cms-hero-tab')).toBe('images');
|
||||
});
|
||||
|
||||
const trashed = (n: number) => ({ ...seedPhotos()[1]!, id: `hero:2222222${n}-2222-2222-2222-222222222222`, bytes: 1_000_000, deletedAt: new Date().toISOString() });
|
||||
|
||||
it('removes selected photos from the trash for good after a clear, irreversible confirmation that names the number', async () => {
|
||||
let body: { ids?: string[]; all?: boolean } | null = null;
|
||||
server.use(
|
||||
http.get('*/media-library/trash', () => HttpResponse.json({ photos: [trashed(1), trashed(2)], modules: ['hero'] })),
|
||||
http.post('*/media-library/purge', async ({ request }) => {
|
||||
body = (await request.json()) as { ids?: string[]; all?: boolean };
|
||||
return HttpResponse.json({ results: (body.ids ?? []).map((id) => ({ id, status: 'purged', uses: [] })) });
|
||||
}),
|
||||
);
|
||||
renderPage();
|
||||
await screen.findByTestId('photo-selection-list');
|
||||
await userEvent.click(screen.getByTestId('view-trash'));
|
||||
await userEvent.click(await screen.findByTestId('photo-select-hero:22222221-2222-2222-2222-222222222222'));
|
||||
await userEvent.click(await screen.findByTestId('photo-select-hero:22222222-2222-2222-2222-222222222222'));
|
||||
|
||||
expect(screen.getByTestId('bulk-action-restore')).toBeInTheDocument();
|
||||
await userEvent.click(screen.getByTestId('bulk-action-purge'));
|
||||
|
||||
expect(await screen.findByTestId('purge-text')).toHaveTextContent('2 foto');
|
||||
expect(screen.getByTestId('purge-warning')).toHaveTextContent('niet ongedaan');
|
||||
await userEvent.click(screen.getByTestId('purge-confirm'));
|
||||
await waitFor(() => expect(body).toEqual({ ids: ['hero:22222221-2222-2222-2222-222222222222', 'hero:22222222-2222-2222-2222-222222222222'] }));
|
||||
});
|
||||
|
||||
it('empties the whole trash with one button: the confirmation names the total number and size, and the server is asked for all', async () => {
|
||||
let body: { ids?: string[]; all?: boolean } | null = null;
|
||||
server.use(
|
||||
http.get('*/media-library/trash', () => HttpResponse.json({ photos: [trashed(1), trashed(2), trashed(3)], modules: ['hero'] })),
|
||||
http.post('*/media-library/purge', async ({ request }) => {
|
||||
body = (await request.json()) as { ids?: string[]; all?: boolean };
|
||||
return HttpResponse.json({ results: [{ id: 'a', status: 'purged', uses: [] }] });
|
||||
}),
|
||||
);
|
||||
renderPage();
|
||||
await screen.findByTestId('photo-selection-list');
|
||||
await userEvent.click(screen.getByTestId('view-trash'));
|
||||
await waitFor(() => expect(screen.getByTestId('trash-empty')).toBeEnabled());
|
||||
|
||||
await userEvent.click(screen.getByTestId('trash-empty'));
|
||||
|
||||
expect(await screen.findByTestId('purge-text')).toHaveTextContent(/3 foto's.*2,9 MB|3 foto's \(2,9 MB\)/);
|
||||
expect(screen.getByTestId('purge-warning')).toHaveTextContent('niet ongedaan');
|
||||
await userEvent.click(screen.getByTestId('purge-confirm'));
|
||||
await waitFor(() => expect(body).toEqual({ all: true }));
|
||||
});
|
||||
|
||||
it('disables Empty the trash when the trash is empty', async () => {
|
||||
server.use(http.get('*/media-library/trash', () => HttpResponse.json({ photos: [], modules: ['hero'] })));
|
||||
renderPage();
|
||||
await screen.findByTestId('photo-selection-list');
|
||||
|
||||
await userEvent.click(screen.getByTestId('view-trash'));
|
||||
|
||||
await waitFor(() => expect(screen.getByTestId('trash-empty')).toBeDisabled());
|
||||
});
|
||||
|
||||
it('reports photos that could not be removed for good', async () => {
|
||||
server.use(
|
||||
http.get('*/media-library/trash', () => HttpResponse.json({ photos: [trashed(1)], modules: ['hero'] })),
|
||||
http.post('*/media-library/purge', () => HttpResponse.json({ results: [{ id: 'x', status: 'inUse', uses: [] }] })),
|
||||
);
|
||||
renderPage();
|
||||
await screen.findByTestId('photo-selection-list');
|
||||
await userEvent.click(screen.getByTestId('view-trash'));
|
||||
await userEvent.click(await screen.findByTestId('photo-select-hero:22222221-2222-2222-2222-222222222222'));
|
||||
await userEvent.click(screen.getByTestId('bulk-action-purge'));
|
||||
await userEvent.click(await screen.findByTestId('purge-confirm'));
|
||||
|
||||
expect(await screen.findByTestId('purge-partial')).toHaveTextContent('1 foto kon niet worden verwijderd');
|
||||
});
|
||||
|
||||
it('shows an error when the library cannot be loaded', async () => {
|
||||
server.use(http.get('*/media-library/photos', () => new HttpResponse(null, { status: 500 })));
|
||||
renderPage();
|
||||
|
||||
Reference in New Issue
Block a user