Adds the shoot page layout and the shoot-type submenu
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>
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
import { screen, within } from '@testing-library/react';
|
||||
import fc from 'fast-check';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { cleanup } from '@testing-library/react';
|
||||
import type { BreadcrumbItem } from '@/lib/shootPageView';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { knownRoutePath } from '@/test/arbitraries';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import Breadcrumb from './Breadcrumb';
|
||||
|
||||
const three: BreadcrumbItem[] = [
|
||||
{ label: 'Home', to: '/' },
|
||||
{ label: 'Soorten fotoshoots', to: '/soorten-fotoshoots' },
|
||||
{ label: 'Newborn', to: '/soorten-fotoshoots/newborn' },
|
||||
];
|
||||
|
||||
describe('Breadcrumb', () => {
|
||||
it('shows links for all but the last item, which is the current page', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<Breadcrumb label="Kruimelpad" items={three} data-testid="crumb" />,
|
||||
{ path: '/soorten-fotoshoots/newborn' },
|
||||
);
|
||||
const nav = screen.getByRole('navigation', { name: 'Kruimelpad' });
|
||||
expect(nav).toBe(screen.getByTestId('crumb'));
|
||||
expect(within(nav).getAllByRole('link')).toHaveLength(2);
|
||||
expect(screen.getByRole('link', { name: 'Home' })).toHaveAttribute(
|
||||
'href',
|
||||
'/',
|
||||
);
|
||||
expect(
|
||||
screen.getByRole('link', { name: 'Soorten fotoshoots' }),
|
||||
).toHaveAttribute('href', '/soorten-fotoshoots');
|
||||
const current = screen.getByText('Newborn');
|
||||
expect(current.tagName).toBe('SPAN');
|
||||
expect(current).toHaveAttribute('aria-current', 'page');
|
||||
expect(nav.querySelectorAll('[aria-current]')).toHaveLength(1);
|
||||
expect(nav.querySelectorAll('li[aria-hidden="true"]')).toHaveLength(2);
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('shows only the current page for one item', async () => {
|
||||
await renderWithProviders(
|
||||
<Breadcrumb label="Kruimelpad" items={three.slice(2)} />,
|
||||
);
|
||||
expect(screen.queryByRole('link')).toBeNull();
|
||||
expect(screen.getByText('Newborn')).toHaveAttribute(
|
||||
'aria-current',
|
||||
'page',
|
||||
);
|
||||
expect(
|
||||
document.querySelectorAll('li[aria-hidden="true"]'),
|
||||
).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('renders nothing without items', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<Breadcrumb label="Kruimelpad" items={[]} />,
|
||||
);
|
||||
expect(screen.queryByRole('navigation')).toBeNull();
|
||||
expect(container.querySelector('ol')).toBeNull();
|
||||
});
|
||||
|
||||
it('marks only the last item as current, and the links are not current on their own page (invariant)', async () => {
|
||||
const items = fc.uniqueArray(
|
||||
fc.record({
|
||||
label: fc
|
||||
.string({ minLength: 1, maxLength: 12 })
|
||||
.filter((text) => text.trim() !== ''),
|
||||
to: knownRoutePath,
|
||||
}),
|
||||
{ selector: (item) => item.to, minLength: 1, maxLength: 5 },
|
||||
);
|
||||
const samples = fc.sample(items, { numRuns: 8 });
|
||||
for (const sample of samples) {
|
||||
const { container } = await renderWithProviders(
|
||||
<Breadcrumb label="Kruimelpad" items={sample} />,
|
||||
{ path: sample[sample.length - 1].to },
|
||||
);
|
||||
const entries = [...container.querySelectorAll('ol > li')].filter(
|
||||
(li) => li.getAttribute('aria-hidden') !== 'true',
|
||||
);
|
||||
expect(entries).toHaveLength(sample.length);
|
||||
entries.forEach((li, index) => {
|
||||
const last = index === sample.length - 1;
|
||||
expect(li.querySelectorAll('a')).toHaveLength(last ? 0 : 1);
|
||||
expect(
|
||||
li.querySelectorAll('[aria-current="page"]').length,
|
||||
).toBe(last ? 1 : 0);
|
||||
expect(li.textContent).toBe(sample[index].label);
|
||||
});
|
||||
expect(
|
||||
container.querySelectorAll('li[aria-hidden="true"]'),
|
||||
).toHaveLength(sample.length - 1);
|
||||
cleanup();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,80 @@
|
||||
import { Fragment } from 'react';
|
||||
import { Box, Flex, Text } from '@chakra-ui/react';
|
||||
import RouterLink from '@/components/RouterLink';
|
||||
import type { BreadcrumbItem } from '@/lib/shootPageView';
|
||||
|
||||
type BreadcrumbProps = {
|
||||
// The name of the navigation landmark, e.g. "Kruimelpad"
|
||||
label: string;
|
||||
// The last item is the page itself
|
||||
items: readonly BreadcrumbItem[];
|
||||
'data-testid'?: string;
|
||||
};
|
||||
|
||||
// The path to the current page (BR-SP-01..04): links for every item but the
|
||||
// last, which is plain text marked as the current page. The links match
|
||||
// exactly, so only the page itself can ever be "current".
|
||||
export default function Breadcrumb({
|
||||
label,
|
||||
items,
|
||||
'data-testid': testId,
|
||||
}: BreadcrumbProps) {
|
||||
if (items.length === 0) return null;
|
||||
|
||||
return (
|
||||
<Box as="nav" aria-label={label} data-testid={testId}>
|
||||
<Flex
|
||||
as="ol"
|
||||
wrap="wrap"
|
||||
justify="center"
|
||||
align="center"
|
||||
gap={2}
|
||||
fontSize="0.875rem"
|
||||
color="ink.soft"
|
||||
listStyle="none"
|
||||
m={0}
|
||||
p={0}
|
||||
>
|
||||
{items.map((item, index) => {
|
||||
const last = index === items.length - 1;
|
||||
// The list is static, so the index is a stable key
|
||||
return (
|
||||
<Fragment key={index}>
|
||||
<Box as="li">
|
||||
{last ? (
|
||||
<Text
|
||||
as="span"
|
||||
aria-current="page"
|
||||
color="ink"
|
||||
minH="2.75rem"
|
||||
display="inline-flex"
|
||||
alignItems="center"
|
||||
>
|
||||
{item.label}
|
||||
</Text>
|
||||
) : (
|
||||
<RouterLink
|
||||
to={item.to}
|
||||
activeOptions={{ exact: true }}
|
||||
color="accent.deep"
|
||||
textDecoration="underline"
|
||||
minH="2.75rem"
|
||||
display="inline-flex"
|
||||
alignItems="center"
|
||||
>
|
||||
{item.label}
|
||||
</RouterLink>
|
||||
)}
|
||||
</Box>
|
||||
{!last && (
|
||||
<Box as="li" aria-hidden="true">
|
||||
/
|
||||
</Box>
|
||||
)}
|
||||
</Fragment>
|
||||
);
|
||||
})}
|
||||
</Flex>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user