Mediabibliotheek: gebruik-link via de router (blijft onder /admin) en opent de Hero op het tabblad Afbeeldingen
Continuous Integration / config-asf (pull_request) Successful in 7s
Continuous Integration / config-sls (pull_request) Successful in 8s
Continuous Integration / changes (pull_request) Successful in 12s
Continuous Integration / compile-sites (pull_request) Successful in 1m53s
Continuous Integration / backend-build (pull_request) Successful in 1m54s
Continuous Integration / vulnerability-scan (pull_request) Successful in 2m22s
Continuous Integration / frontend-prepare (pull_request) Successful in 2m46s
Continuous Integration / frontend-build (pull_request) Successful in 1m8s
Continuous Integration / backend-test (pull_request) Successful in 3m8s
Continuous Integration / frontend-test (pull_request) Successful in 2m48s
Continuous Integration / frontend-lint (pull_request) Successful in 3m26s
Continuous Integration / publish-sls-test (pull_request) Skipped
Continuous Integration / publish-sls-production (pull_request) Skipped
Continuous Integration / deploy-sls-test (pull_request) Skipped
Continuous Integration / deploy-sls-production (pull_request) Skipped
Continuous Integration / publish-asf-test (pull_request) Skipped
Continuous Integration / deploy-asf-test (pull_request) Skipped
Continuous Integration / smoke-sls-test (pull_request) Skipped
Continuous Integration / smoke-asf-test (pull_request) Skipped

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 16:38:28 +01:00
co-authored by Claude Sonnet 5.5
parent 4ae1789575
commit 8ad071da1c
4 changed files with 82 additions and 33 deletions
@@ -5,16 +5,30 @@ import userEvent from '@testing-library/user-event';
import i18n from '@/i18n/config';
import { server } from '@/mocks/server';
import { renderWithProviders } from '@/test/utils';
import { createMemoryHistory, createRootRoute, createRoute, createRouter, RouterProvider } from '@tanstack/react-router';
import { seedPhotos, seedStorage } from '../mocks/handlers';
import { MediaLibraryPage } from './MediaLibraryPage';
/** The page inside a router with the same base path as the real admin app (/admin), and a stub hero route to land on. */
function renderPage() {
const root = createRootRoute();
const media = createRoute({ getParentRoute: () => root, path: '/media', component: MediaLibraryPage });
const hero = createRoute({ getParentRoute: () => root, path: '/hero', component: () => <p data-testid="hero-stub">hero</p> });
const router = createRouter({
routeTree: root.addChildren([media, hero]),
basepath: '/admin',
history: createMemoryHistory({ initialEntries: ['/admin/media'] }),
});
return renderWithProviders(<RouterProvider router={router} />);
}
beforeEach(async () => {
await i18n.changeLanguage('nl');
});
describe('MediaLibraryPage', () => {
it('lists the photos newest first with where each is used, and the storage', async () => {
renderWithProviders(<MediaLibraryPage />);
renderPage();
const list = await screen.findByTestId('photo-selection-list');
const rows = within(list).getAllByRole('listitem');
@@ -28,17 +42,17 @@ describe('MediaLibraryPage', () => {
it('warns when the storage is nearly full and says so when it is full', async () => {
server.use(http.get('*/media-library/storage', () => HttpResponse.json({ ...seedStorage(), usedBytes: 1_800_000_000, level: 'warning' })));
const { unmount } = renderWithProviders(<MediaLibraryPage />);
const { unmount } = renderPage();
expect(await screen.findByTestId('storage-warning')).toHaveTextContent('80%');
unmount();
server.use(http.get('*/media-library/storage', () => HttpResponse.json({ ...seedStorage(), usedBytes: 2_147_483_648, level: 'full' })));
renderWithProviders(<MediaLibraryPage />);
renderPage();
expect(await screen.findByTestId('storage-warning')).toHaveTextContent('vol');
});
it('selects photos and shows the bulk bar with the delete action', async () => {
renderWithProviders(<MediaLibraryPage />);
renderPage();
await screen.findByTestId('photo-selection-list');
await userEvent.click(screen.getByRole('checkbox', { name: 'zomer.jpg' }));
@@ -48,7 +62,7 @@ describe('MediaLibraryPage', () => {
});
it('opens the clean-up: older than 7 days, only unused, all selected, newest first, and nothing is deleted', async () => {
renderWithProviders(<MediaLibraryPage />);
renderPage();
await screen.findByTestId('photo-selection-list');
await userEvent.click(screen.getByTestId('cleanup-open'));
@@ -63,7 +77,7 @@ describe('MediaLibraryPage', () => {
});
it('includes photos in use when "only unused" is switched off', async () => {
renderWithProviders(<MediaLibraryPage />);
renderPage();
await screen.findByTestId('photo-selection-list');
await userEvent.click(screen.getByTestId('cleanup-open'));
const dialog = await screen.findByTestId('cleanup-dialog');
@@ -83,7 +97,7 @@ describe('MediaLibraryPage', () => {
return HttpResponse.json({ results: body.ids.map((id) => ({ id, status: 'trashed', uses: [] })) });
}),
);
renderWithProviders(<MediaLibraryPage />);
renderPage();
await screen.findByTestId('photo-selection-list');
await userEvent.click(screen.getByTestId('photo-select-hero:22222222-2222-2222-2222-222222222222'));
@@ -103,7 +117,7 @@ describe('MediaLibraryPage', () => {
return HttpResponse.json({ results: body.ids.map((id) => ({ id, status: 'trashed', uses: [] })) });
}),
);
renderWithProviders(<MediaLibraryPage />);
renderPage();
await screen.findByTestId('photo-selection-list');
await userEvent.click(screen.getByTestId('photo-select-hero:11111111-1111-1111-1111-111111111111'));
@@ -125,7 +139,7 @@ describe('MediaLibraryPage', () => {
return HttpResponse.json({ results: ids.map((id, i) => ({ id, status: i === 0 ? 'failed' : 'trashed', uses: [] })) });
}),
);
renderWithProviders(<MediaLibraryPage />);
renderPage();
await screen.findByTestId('photo-selection-list');
await userEvent.click(screen.getByTestId('photo-select-hero:22222222-2222-2222-2222-222222222222'));
@@ -146,7 +160,7 @@ describe('MediaLibraryPage', () => {
return HttpResponse.json({ results: restored.map((id) => ({ id, status: 'restored', uses: [] })) });
}),
);
renderWithProviders(<MediaLibraryPage />);
renderPage();
await screen.findByTestId('photo-selection-list');
await userEvent.click(screen.getByTestId('view-trash'));
@@ -165,7 +179,7 @@ describe('MediaLibraryPage', () => {
return HttpResponse.json({ results: body.ids.map((id) => ({ id, status: 'trashed', uses: [] })) });
}),
);
renderWithProviders(<MediaLibraryPage />);
renderPage();
await screen.findByTestId('photo-selection-list');
await userEvent.click(screen.getByTestId('cleanup-open'));
const dialog = await screen.findByTestId('cleanup-dialog');
@@ -177,8 +191,8 @@ describe('MediaLibraryPage', () => {
await waitFor(() => expect(body).toEqual({ ids: ['hero:22222222-2222-2222-2222-222222222222'], confirmedInUse: false }));
});
it('filters the library on used and unused photos and links a use to its module', async () => {
renderWithProviders(<MediaLibraryPage />);
it('filters the library on used and unused photos', async () => {
renderPage();
const list = await screen.findByTestId('photo-selection-list');
expect(within(list).getAllByRole('listitem')).toHaveLength(3);
@@ -186,14 +200,25 @@ describe('MediaLibraryPage', () => {
expect(within(screen.getByTestId('photo-selection-list')).getAllByRole('listitem')).toHaveLength(1);
await userEvent.click(screen.getByTestId('filter-used'));
const used = within(screen.getByTestId('photo-selection-list')).getAllByRole('listitem');
expect(used).toHaveLength(2);
expect(within(used[0]!).getByRole('link', { name: 'Hero, slide 1' })).toHaveAttribute('href', '/hero');
expect(within(screen.getByTestId('photo-selection-list')).getAllByRole('listitem')).toHaveLength(2);
});
it('links a use to the hero under the admin base path (/admin/hero, not /hero) and opens its images tab', async () => {
window.sessionStorage.removeItem('cms-hero-tab');
renderPage();
const list = await screen.findByTestId('photo-selection-list');
const link = within(within(list).getAllByRole('listitem')[0]!).getByRole('link', { name: 'Hero, slide 1' });
expect(link).toHaveAttribute('href', '/admin/hero');
await userEvent.click(link);
expect(await screen.findByTestId('hero-stub')).toBeInTheDocument();
expect(window.sessionStorage.getItem('cms-hero-tab')).toBe('images');
});
it('shows an error when the library cannot be loaded', async () => {
server.use(http.get('*/media-library/photos', () => new HttpResponse(null, { status: 500 })));
renderWithProviders(<MediaLibraryPage />);
renderPage();
expect(await screen.findByTestId('media-error')).toBeInTheDocument();
});