Shoot pages follow design E: breadcrumb, story blocks, process timeline with icons, photo mosaic, FAQ, package block and booking call to action, with per-shoot OG images. The navigation gets a "Soorten fotoshoots" submenu (desktop panel, mobile group) built from shootTypes, with exact current-page matching in menu, footer and breadcrumb. A 404 under /soorten-fotoshoots/ also offers a link back to the overview. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
116 lines
4.4 KiB
TypeScript
116 lines
4.4 KiB
TypeScript
import { screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
import { axeResults } from '@/test/axe';
|
|
import { renderWithProviders } from '@/test/renderWithProviders';
|
|
import ErrorPage from './ErrorPage';
|
|
import NotFound from './NotFound';
|
|
|
|
describe('NotFound', () => {
|
|
it('toont de 404-tekst met een link naar home', async () => {
|
|
const { container } = await renderWithProviders(<NotFound />, {
|
|
path: '/bestaat-niet',
|
|
});
|
|
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent(
|
|
'Pagina niet gevonden',
|
|
);
|
|
expect(
|
|
screen.getByRole('link', { name: 'Terug naar home' }),
|
|
).toHaveAttribute('href', '/');
|
|
expect(await axeResults(container)).toHaveNoViolations();
|
|
});
|
|
|
|
it('zet een eigen titel en noindex in de head', async () => {
|
|
await renderWithProviders(<NotFound />, { path: '/bestaat-niet' });
|
|
expect(document.title).toBe(
|
|
'Pagina niet gevonden | Andrea Slop Fotografie',
|
|
);
|
|
expect(
|
|
document.head.querySelector('meta[name="robots"]'),
|
|
).toHaveAttribute('content', 'noindex');
|
|
});
|
|
|
|
it('toont onder /soorten-fotoshoots/ twee knoppen in vaste volgorde', async () => {
|
|
const { container } = await renderWithProviders(<NotFound />, {
|
|
path: '/soorten-fotoshoots/niet-bestaande-shoot',
|
|
});
|
|
const links = screen.getAllByRole('link');
|
|
expect(links.map((link) => link.textContent)).toEqual([
|
|
'Terug naar Soorten fotoshoots',
|
|
'Terug naar home',
|
|
]);
|
|
expect(links[0]).toHaveAttribute('href', '/soorten-fotoshoots');
|
|
expect(links[1]).toHaveAttribute('href', '/');
|
|
expect(await axeResults(container)).toHaveNoViolations();
|
|
});
|
|
|
|
it('herkent het prefix hoofdletterongevoelig', async () => {
|
|
await renderWithProviders(<NotFound />, {
|
|
path: '/Soorten-Fotoshoots/x',
|
|
});
|
|
expect(screen.getAllByRole('link')).toHaveLength(2);
|
|
expect(
|
|
screen.getByRole('link', { name: 'Terug naar Soorten fotoshoots' }),
|
|
).toHaveAttribute('href', '/soorten-fotoshoots');
|
|
});
|
|
|
|
it('houdt buiten de sectie één knop', async () => {
|
|
await renderWithProviders(<NotFound />, { path: '/bestaat-niet' });
|
|
expect(screen.getAllByRole('link')).toHaveLength(1);
|
|
});
|
|
});
|
|
|
|
describe('ErrorPage', () => {
|
|
const error = new Error('Geheime interne fout in de database');
|
|
|
|
const renderError = async () => {
|
|
const reset = vi.fn();
|
|
const consoleError = vi
|
|
.spyOn(console, 'error')
|
|
.mockImplementation(() => {});
|
|
const result = await renderWithProviders(
|
|
<ErrorPage error={error} reset={reset} />,
|
|
);
|
|
return { ...result, reset, consoleError };
|
|
};
|
|
|
|
it('toont een algemene melding zonder foutdetails', async () => {
|
|
const { container } = await renderError();
|
|
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent(
|
|
'Er ging iets mis',
|
|
);
|
|
expect(container).not.toHaveTextContent('Geheime interne fout');
|
|
expect(container.innerHTML).not.toContain('database');
|
|
expect(await axeResults(container)).toHaveNoViolations();
|
|
});
|
|
|
|
it('logt de fout precies een keer', async () => {
|
|
const { consoleError } = await renderError();
|
|
expect(consoleError).toHaveBeenCalledTimes(1);
|
|
expect(consoleError).toHaveBeenCalledWith(error);
|
|
});
|
|
|
|
it('opnieuw proberen reset de foutgrens en laadt de route opnieuw', async () => {
|
|
const { reset, router } = await renderError();
|
|
const invalidate = vi.spyOn(router, 'invalidate');
|
|
await userEvent.click(
|
|
screen.getByRole('button', { name: 'Opnieuw proberen' }),
|
|
);
|
|
expect(reset).toHaveBeenCalledTimes(1);
|
|
expect(invalidate).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('biedt een link naar home en zet noindex', async () => {
|
|
await renderError();
|
|
expect(
|
|
screen.getByRole('link', { name: 'Terug naar home' }),
|
|
).toHaveAttribute('href', '/');
|
|
expect(document.title).toBe(
|
|
'Er ging iets mis | Andrea Slop Fotografie',
|
|
);
|
|
expect(
|
|
document.head.querySelector('meta[name="robots"]'),
|
|
).toHaveAttribute('content', 'noindex');
|
|
});
|
|
});
|