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,101 @@
|
||||
import { cleanup, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import fc from 'fast-check';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import type { FaqItem } from '@/content/types';
|
||||
import { faqItems } from '@/test/arbitraries';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import FaqList from './FaqList';
|
||||
|
||||
const items: FaqItem[] = [
|
||||
{
|
||||
id: 'een',
|
||||
question: 'Wanneer boek ik?',
|
||||
answer: [
|
||||
'Zo vroeg mogelijk, zie ',
|
||||
{ text: 'de prijzen', to: '/', hash: 'prijzen' },
|
||||
'.',
|
||||
],
|
||||
},
|
||||
{ id: 'twee', question: 'Waar?', answer: ['Bij jullie thuis.'] },
|
||||
{ id: 'drie', question: 'Hoe lang?', answer: ['Twee uur.'] },
|
||||
];
|
||||
|
||||
describe('FaqList', () => {
|
||||
it('shows every question closed, with the answers in the page', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<FaqList items={items} data-testid="faq" />,
|
||||
);
|
||||
const details = container.querySelectorAll('details');
|
||||
expect(details).toHaveLength(3);
|
||||
for (const item of details) expect(item).not.toHaveAttribute('open');
|
||||
for (const item of items) {
|
||||
expect(screen.getByText(item.question).tagName).toBe('SUMMARY');
|
||||
}
|
||||
expect(
|
||||
screen.getByText('Bij jullie thuis.', { exact: false }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole('link', { name: 'de prijzen' }),
|
||||
).toHaveAttribute('href', '/#prijzen');
|
||||
// The questions are labels, not headings
|
||||
expect(screen.queryByRole('heading')).toBeNull();
|
||||
expect(
|
||||
container.querySelectorAll('summary svg[aria-hidden="true"]'),
|
||||
).toHaveLength(3);
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
// jsdom does not turn Enter or Space on a summary into the click that
|
||||
// opens the details (browsers do, for any summary that is the first
|
||||
// child of its details), and user-event only does so for buttons and
|
||||
// links. So the test checks what the page controls: the summary is
|
||||
// focusable and is the first child of its details, and activating it
|
||||
// (the click a browser sends) toggles the item.
|
||||
it('has a focusable summary as first child, which toggles the item when activated', async () => {
|
||||
const user = userEvent.setup();
|
||||
const { container } = await renderWithProviders(
|
||||
<FaqList items={items} />,
|
||||
);
|
||||
const first = container.querySelector('details')!;
|
||||
const summary = first.firstElementChild as HTMLElement;
|
||||
expect(summary.tagName).toBe('SUMMARY');
|
||||
expect(summary).toHaveTextContent('Wanneer boek ik?');
|
||||
expect(summary.getAttribute('tabindex')).not.toBe('-1');
|
||||
await user.tab();
|
||||
expect(summary).toHaveFocus();
|
||||
await user.click(summary);
|
||||
expect(first).toHaveAttribute('open');
|
||||
await user.click(summary);
|
||||
expect(first).not.toHaveAttribute('open');
|
||||
});
|
||||
|
||||
it('renders nothing without questions', async () => {
|
||||
const { container } = await renderWithProviders(<FaqList items={[]} />);
|
||||
expect(container.querySelector('details')).toBeNull();
|
||||
});
|
||||
|
||||
it('has one closed details per item, with every answer in the page (invariant)', async () => {
|
||||
for (const sample of fc.sample(faqItems, { numRuns: 6 })) {
|
||||
const { container } = await renderWithProviders(
|
||||
<FaqList items={sample} />,
|
||||
);
|
||||
const details = container.querySelectorAll('details');
|
||||
expect(details).toHaveLength(sample.length);
|
||||
details.forEach((item, index) => {
|
||||
expect(item.hasAttribute('open')).toBe(false);
|
||||
expect(item.querySelector('summary')!.textContent).toBe(
|
||||
sample[index].question,
|
||||
);
|
||||
const answer = sample[index].answer
|
||||
.map((piece) =>
|
||||
typeof piece === 'string' ? piece : piece.text,
|
||||
)
|
||||
.join('');
|
||||
expect(item.querySelector('p')!.textContent).toBe(answer);
|
||||
});
|
||||
cleanup();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,82 @@
|
||||
import { Box, chakra } from '@chakra-ui/react';
|
||||
import RichParagraph from '@/components/RichParagraph/RichParagraph';
|
||||
import type { FaqItem } from '@/content/types';
|
||||
|
||||
type FaqListProps = {
|
||||
items: readonly FaqItem[];
|
||||
'data-testid'?: string;
|
||||
};
|
||||
|
||||
// The plus that turns into a minus while its item is open: the vertical
|
||||
// stroke is hidden by CSS under details[open]. Decoration only.
|
||||
function ToggleIcon() {
|
||||
return (
|
||||
<chakra.svg
|
||||
aria-hidden="true"
|
||||
focusable="false"
|
||||
viewBox="0 0 24 24"
|
||||
w="1.25rem"
|
||||
h="1.25rem"
|
||||
flexShrink={0}
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
>
|
||||
<path d="M5 12h14" />
|
||||
<path data-faq-vertical d="M12 5v14" />
|
||||
</chakra.svg>
|
||||
);
|
||||
}
|
||||
|
||||
// The questions of a shoot page (FR-ST-06, BR-SP-50..52): one native
|
||||
// details element per question, so it works without JavaScript and by
|
||||
// keyboard. All items start closed; the answers are in the page either way.
|
||||
// The browser keeps track of what is open, there is no state here.
|
||||
export default function FaqList({
|
||||
items,
|
||||
'data-testid': testId,
|
||||
}: FaqListProps) {
|
||||
if (items.length === 0) return null;
|
||||
|
||||
return (
|
||||
<Box borderTopWidth="1px" borderColor="sand" data-testid={testId}>
|
||||
{items.map((item) => (
|
||||
<Box
|
||||
as="details"
|
||||
key={item.id}
|
||||
borderBottomWidth="1px"
|
||||
borderColor="sand"
|
||||
css={{
|
||||
'&[open] [data-faq-vertical]': { display: 'none' },
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
as="summary"
|
||||
display="flex"
|
||||
alignItems="center"
|
||||
justifyContent="space-between"
|
||||
gap={4}
|
||||
minH="2.75rem"
|
||||
py={5}
|
||||
fontFamily="heading"
|
||||
fontSize="1.25rem"
|
||||
color="ink"
|
||||
cursor="pointer"
|
||||
listStyle="none"
|
||||
css={{
|
||||
'&::-webkit-details-marker': { display: 'none' },
|
||||
}}
|
||||
_focusVisible={{ outlineOffset: '2px' }}
|
||||
>
|
||||
{item.question}
|
||||
<ToggleIcon />
|
||||
</Box>
|
||||
<Box mb={6} maxW="680px" color="ink.soft">
|
||||
<RichParagraph paragraph={item.answer} />
|
||||
</Box>
|
||||
</Box>
|
||||
))}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user