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:
2026-10-30 14:43:43 +01:00
co-authored by Claude Opus 5.5
parent e5f4348178
commit 7af2069959
84 changed files with 6090 additions and 128 deletions
+52
View File
@@ -0,0 +1,52 @@
import fc from 'fast-check';
import { describe, expect, it } from 'vitest';
import { shootTypeId } from '@/test/arbitraries';
import { headingId } from './headingId';
describe('headingId', () => {
it.each([
['story', 'verwachten', 'story-verwachten'],
['story', 'Met Spatie', 'story-met-spatie'],
['story', 'UPPER', 'story-upper'],
['story', '</script>', 'story---script-'],
['story', '', 'story-'],
['story', 'één', 'story---n'],
['Story', 'a_b-c', 'story-a_b-c'],
])('maps (%s, %s) to %s', (prefix, id, expected) => {
expect(headingId(prefix, id)).toBe(expected);
});
it('keeps the five real shoot ids readable', () => {
for (const id of [
'newborn',
'zwangerschap',
'gezin',
'loveshoot',
'portret',
]) {
expect(headingId('shoot', id)).toBe(`shoot-${id}`);
}
});
it('only produces a-z, 0-9, - and _, and is deterministic (invariant)', () => {
fc.assert(
fc.property(
fc.oneof(
fc.string(),
fc.string({ unit: 'binary' }),
shootTypeId,
),
fc.oneof(
fc.string(),
fc.string({ unit: 'binary' }),
fc.constantFrom('</script>', ' ', '"', "'", '\u0130'),
),
(prefix, id) => {
const result = headingId(prefix, id);
expect(result).toMatch(/^[a-z0-9\-_]*$/);
expect(headingId(prefix, id)).toBe(result);
},
),
);
});
});
+7
View File
@@ -0,0 +1,7 @@
// An id for a heading that aria-labelledby can always point at: lower-case
// letters, digits, '-' and '_' only. Anything else, such as a space in a
// story id from the content, becomes '-' (BR-SP-72). The caller adds
// '-title' where the id belongs to a heading.
export function headingId(prefix: string, id: string): string {
return `${prefix}-${id}`.toLowerCase().replace(/[^a-z0-9\-_]/g, '-');
}
+52
View File
@@ -0,0 +1,52 @@
import fc from 'fast-check';
import { describe, expect, it } from 'vitest';
import { isShootSectionPath } from './isShootSectionPath';
// Het prefix in willekeurige hoofd- en kleine letters
const prefixInRandomCase = fc
.array(fc.boolean(), { minLength: 20, maxLength: 20 })
.map((flags) =>
[...'/soorten-fotoshoots/']
.map((ch, i) => (flags[i] ? ch.toUpperCase() : ch))
.join(''),
);
describe('isShootSectionPath', () => {
it.each([
['/soorten-fotoshoots/niet-bestaande-shoot', true],
['/Soorten-Fotoshoots/x', true],
['/soorten-fotoshoots/', true],
['/soorten-fotoshoots', false],
['/soorten-fotoshootsx/abc', false],
['/bestaat-niet', false],
['/', false],
])('%s geeft %s', (path, expected) => {
expect(isShootSectionPath(path)).toBe(expected);
});
it('is true voor elk pad met het prefix, in elke schrijfwijze (property)', () => {
fc.assert(
fc.property(prefixInRandomCase, fc.string(), (prefix, rest) => {
expect(isShootSectionPath(prefix + rest)).toBe(true);
}),
);
});
it('is false voor paden zonder het prefix (property)', () => {
fc.assert(
fc.property(
fc
.string()
.filter(
(path) =>
!path
.toLowerCase()
.startsWith('/soorten-fotoshoots/'),
),
(path) => {
expect(isShootSectionPath(path)).toBe(false);
},
),
);
});
});
+7
View File
@@ -0,0 +1,7 @@
const SHOOT_SECTION_PREFIX = '/soorten-fotoshoots/';
// Staat het pad onder /soorten-fotoshoots/ (FR-ST-14)? Hoofdletterongevoelig,
// net als de router. Het overzicht zelf (zonder slash) hoort er niet bij.
export function isShootSectionPath(pathname: string): boolean {
return pathname.toLowerCase().startsWith(SHOOT_SECTION_PREFIX);
}
+96
View File
@@ -0,0 +1,96 @@
import fc from 'fast-check';
import { describe, expect, it } from 'vitest';
import { mosaicCount } from '@/test/arbitraries';
import {
MOSAIC_MAX_PHOTOS,
mosaicLayout,
type MosaicTile,
} from './mosaicLayout';
// The grid cells ("column,row") a tile covers, from its 'start / end' strings
function cells(tile: MosaicTile): string[] {
const [c0, c1] = tile.column.split(' / ').map(Number);
const [r0, r1] = tile.row.split(' / ').map(Number);
const result: string[] = [];
for (let c = c0; c < c1; c++) {
for (let r = r0; r < r1; r++) result.push(`${c},${r}`);
}
return result;
}
describe('mosaicLayout', () => {
it('gives nothing for 0, a negative or a fractional count', () => {
expect(mosaicLayout(0)).toEqual([]);
expect(mosaicLayout(-1)).toEqual([]);
expect(mosaicLayout(1.5)).toEqual([]);
expect(mosaicLayout(Number.NaN)).toEqual([]);
});
it('gives one wide tile for 1', () => {
expect(mosaicLayout(1)).toEqual([
{ column: '1 / 5', row: '1 / 3', wide: true, phoneRatio: '4 / 3' },
]);
});
it('gives two equal tiles for 2', () => {
expect(mosaicLayout(2)).toEqual([
{ column: '1 / 3', row: '1 / 3', wide: true, phoneRatio: '4 / 3' },
{ column: '3 / 5', row: '1 / 3', wide: true, phoneRatio: '4 / 3' },
]);
});
it('gives a large and two wide tiles for 3', () => {
expect(mosaicLayout(3).map((tile) => tile.phoneRatio)).toEqual([
'4 / 3',
'3 / 2',
'3 / 2',
]);
expect(mosaicLayout(3)[2]).toMatchObject({
column: '3 / 5',
row: '2 / 3',
});
});
it('gives design E for 4, and the same for 5 or more', () => {
expect(mosaicLayout(4)).toEqual([
{ column: '1 / 3', row: '1 / 3', wide: true, phoneRatio: '4 / 3' },
{ column: '3 / 5', row: '1 / 2', wide: true, phoneRatio: '3 / 2' },
{ column: '3 / 4', row: '2 / 3', wide: false, phoneRatio: '1 / 1' },
{ column: '4 / 5', row: '2 / 3', wide: false, phoneRatio: '1 / 1' },
]);
expect(mosaicLayout(5)).toEqual(mosaicLayout(4));
expect(mosaicLayout(12)).toEqual(mosaicLayout(4));
});
it('returns fresh objects, so a caller cannot change the layout', () => {
mosaicLayout(4)[0].column = 'x';
expect(mosaicLayout(4)[0].column).toBe('1 / 3');
});
it('fills the 4 x 2 grid without overlap and stays well formed (invariant)', () => {
fc.assert(
fc.property(mosaicCount, (count) => {
const tiles = mosaicLayout(count);
expect(mosaicLayout(count)).toEqual(tiles);
if (count <= 0) {
expect(tiles).toEqual([]);
return;
}
expect(tiles).toHaveLength(Math.min(count, MOSAIC_MAX_PHOTOS));
const covered = tiles.flatMap(cells);
expect(new Set(covered).size).toBe(covered.length);
if (count >= 2) expect(covered).toHaveLength(8);
if (count >= 2) {
// (A single photo, never shown, spans the whole grid)
expect(tiles[0]).toMatchObject({
column: '1 / 3',
row: '1 / 3',
});
expect(tiles.filter((tile) => !tile.wide).length % 2).toBe(
0,
);
}
}),
);
});
});
+50
View File
@@ -0,0 +1,50 @@
// The photo mosaic of a shoot page: a 4 x 2 grid from `md`, two columns on
// phones (FR-ST-05). Each tile says where it sits; the component only
// draws them.
// The most photos the mosaic shows; more stay in the content
export const MOSAIC_MAX_PHOTOS = 4;
export interface MosaicTile {
// CSS grid-column from `md`, e.g. '1 / 3'
column: string;
// CSS grid-row from `md`
row: string;
// Spans both columns below `md`
wide: boolean;
// Aspect ratio of the tile below `md`
phoneRatio: '4 / 3' | '3 / 2' | '1 / 1';
}
const large: MosaicTile = {
column: '1 / 3',
row: '1 / 3',
wide: true,
phoneRatio: '4 / 3',
};
const layouts: Record<1 | 2 | 3 | 4, readonly MosaicTile[]> = {
// Never shown (the view needs at least two photos), kept so that the
// function is total
1: [{ column: '1 / 5', row: '1 / 3', wide: true, phoneRatio: '4 / 3' }],
2: [large, { ...large, column: '3 / 5' }],
3: [
large,
{ column: '3 / 5', row: '1 / 2', wide: true, phoneRatio: '3 / 2' },
{ column: '3 / 5', row: '2 / 3', wide: true, phoneRatio: '3 / 2' },
],
4: [
large,
{ column: '3 / 5', row: '1 / 2', wide: true, phoneRatio: '3 / 2' },
{ column: '3 / 4', row: '2 / 3', wide: false, phoneRatio: '1 / 1' },
{ column: '4 / 5', row: '2 / 3', wide: false, phoneRatio: '1 / 1' },
],
};
// The tiles for `count` photos. Nothing for a count below 1 or one that is
// not a whole number (fail safe); five or more get the layout for four.
export function mosaicLayout(count: number): MosaicTile[] {
if (!Number.isInteger(count) || count < 1) return [];
const key = Math.min(count, MOSAIC_MAX_PHOTOS) as 1 | 2 | 3 | 4;
return layouts[key].map((tile) => ({ ...tile }));
}
+200
View File
@@ -0,0 +1,200 @@
import fc from 'fast-check';
import { describe, expect, it } from 'vitest';
import type { NavItem } from '../navigation';
import { knownRoutePath, uniqueShootTypes } from '../test/arbitraries';
import { pathname } from '../test/navArbitraries';
import { isItemCurrent, isSectionCurrent } from './navCurrent';
import { shootNavItems } from './shootNavItems';
// The comparison rule written out once more: lower case, one trailing slash
const normalise = (path: string) => {
const lower = path.toLowerCase();
return lower.length > 1 && lower.endsWith('/') ? lower.slice(0, -1) : lower;
};
const item = fc.record({ to: knownRoutePath, label: fc.string() });
// The overview with a random set of shoot pages as children
const parent = uniqueShootTypes.map((shoots): NavItem => ({
to: '/soorten-fotoshoots',
label: 'Soorten fotoshoots',
children: shootNavItems(shoots),
}));
describe('isItemCurrent', () => {
it('is true exactly when the normalised paths are equal (invariant)', () => {
fc.assert(
fc.property(item, pathname, (nav, path) => {
expect(isItemCurrent(nav, path)).toBe(
normalise(nav.to) === normalise(path),
);
}),
);
});
it('is true for its own path in every spelling (invariant)', () => {
fc.assert(
fc.property(item, (nav) => {
for (const spelling of [
nav.to,
`${nav.to}/`,
nav.to.toUpperCase(),
`${nav.to.toUpperCase()}/`,
]) {
expect(isItemCurrent(nav, spelling)).toBe(true);
}
}),
);
});
it('is not changed by letter case or one added trailing slash (idempotency)', () => {
fc.assert(
fc.property(item, pathname, (nav, path) => {
// '' and '/' have no "added slash" twin that means the same
fc.pre(path.length > 0 && path !== '/');
const result = isItemCurrent(nav, path);
expect(isItemCurrent(nav, path.toUpperCase())).toBe(
isItemCurrent(nav, path.toLowerCase()),
);
// Adding a slash to a path without one gives the same answer
fc.pre(!path.endsWith('/'));
expect(isItemCurrent(nav, `${path}/`)).toBe(result);
}),
);
});
it('is false for a path that normalises differently (invariant)', () => {
fc.assert(
fc.property(item, pathname, (nav, path) => {
fc.pre(normalise(nav.to) !== normalise(path));
expect(isItemCurrent(nav, path)).toBe(false);
}),
);
});
it('accepts the item path with a trailing slash and other case', () => {
const nav: NavItem = { to: '/portfolio', label: 'Portfolio' };
expect(isItemCurrent(nav, '/portfolio')).toBe(true);
expect(isItemCurrent(nav, '/portfolio/')).toBe(true);
expect(isItemCurrent(nav, '/Portfolio')).toBe(true);
expect(isItemCurrent(nav, '/')).toBe(false);
});
it('keeps the home page apart from every other path', () => {
const home: NavItem = { to: '/', label: 'Home' };
expect(isItemCurrent(home, '/')).toBe(true);
expect(isItemCurrent(home, '')).toBe(false);
expect(isItemCurrent(home, '/portfolio')).toBe(false);
});
});
describe('isSectionCurrent', () => {
it('is implied by isItemCurrent (invariant)', () => {
fc.assert(
fc.property(parent, pathname, (nav, path) => {
fc.pre(isItemCurrent(nav, path));
expect(isSectionCurrent(nav, path)).toBe(true);
}),
);
});
it('is implied by any child being current (invariant)', () => {
fc.assert(
fc.property(parent, fc.nat(), (nav, index) => {
const children = nav.children ?? [];
fc.pre(children.length > 0);
const child = children[index % children.length];
expect(isSectionCurrent(nav, child.to)).toBe(true);
expect(isSectionCurrent(nav, `${child.to}/`)).toBe(true);
expect(isSectionCurrent(nav, child.to.toUpperCase())).toBe(
true,
);
}),
);
});
it('is true only for the item or a child (invariant)', () => {
fc.assert(
fc.property(parent, pathname, (nav, path) => {
const expected =
isItemCurrent(nav, path) ||
(nav.children ?? []).some((child) =>
isItemCurrent(child, path),
);
expect(isSectionCurrent(nav, path)).toBe(expected);
}),
);
});
it('is false for unrelated paths and prefix look-alikes (invariant)', () => {
fc.assert(
fc.property(
parent,
fc.constantFrom(
'/',
'/portfolio',
'/contact',
'/soorten-fotoshoots-extra',
'/soorten-fotoshootsX',
'/soorten-fotoshoots/newborn/extra',
'/soorten-fotoshoots/onbekend',
),
(nav, path) => {
expect(isSectionCurrent(nav, path)).toBe(false);
},
),
);
});
it('is false on the home page for the overview', () => {
const nav: NavItem = {
to: '/soorten-fotoshoots',
label: 'Soorten fotoshoots',
children: shootNavItems([]),
};
expect(isSectionCurrent(nav, '/')).toBe(false);
});
it('marks the parent as section and the child as item on a shoot page', () => {
const child: NavItem = {
to: '/soorten-fotoshoots/newborn',
label: 'Newborn',
};
const nav: NavItem = {
to: '/soorten-fotoshoots',
label: 'Soorten fotoshoots',
children: [child],
};
expect(isSectionCurrent(nav, '/soorten-fotoshoots/newborn/')).toBe(
true,
);
expect(isItemCurrent(child, '/soorten-fotoshoots/newborn/')).toBe(true);
expect(isItemCurrent(nav, '/soorten-fotoshoots/newborn/')).toBe(false);
});
it('works for an item without children', () => {
const nav: NavItem = { to: '/contact', label: 'Contact' };
expect(isSectionCurrent(nav, '/contact')).toBe(true);
expect(isSectionCurrent(nav, '/portfolio')).toBe(false);
});
});
describe('hostile pathnames', () => {
it('always gives a boolean and does not throw (invariant)', () => {
fc.assert(
fc.property(parent, fc.string(), (nav, path) => {
expect(typeof isItemCurrent(nav, path)).toBe('boolean');
expect(typeof isSectionCurrent(nav, path)).toBe('boolean');
}),
);
});
it.each(['', '//', ' ', '%2F', '/%2F', 'a'.repeat(100_000)])(
'handles %j without throwing',
(path) => {
const nav: NavItem = { to: '/', label: 'Home' };
expect(() => isItemCurrent(nav, path)).not.toThrow();
expect(() => isSectionCurrent(nav, path)).not.toThrow();
},
);
});
+24
View File
@@ -0,0 +1,24 @@
import type { NavItem } from '../navigation.ts';
// Lower case and without one trailing slash (not for "/"), the way the
// router matches a path (BR-NAV-04)
function normalise(path: string): string {
const lower = path.toLowerCase();
return lower.length > 1 && lower.endsWith('/') ? lower.slice(0, -1) : lower;
}
// Whether the item is the page at `pathname`. Pure string comparison: never
// throws and never renders the pathname (SECURITY-05, SECURITY-15).
export function isItemCurrent(item: NavItem, pathname: string): boolean {
return normalise(item.to) === normalise(pathname);
}
// Whether the item or one of its children is the page at `pathname`; marks
// the parent while a page below it is open (D4)
export function isSectionCurrent(item: NavItem, pathname: string): boolean {
return (
isItemCurrent(item, pathname) ||
(item.children?.some((child) => isItemCurrent(child, pathname)) ??
false)
);
}
+398
View File
@@ -0,0 +1,398 @@
import fc from 'fast-check';
import { describe, expect, it } from 'vitest';
import {
navMenuEvent,
navMenuEvents,
navMenuState,
navMenuStateOn,
} from '../test/navArbitraries';
import {
initialNavMenuState,
navMenuReducer,
type NavMenuEvent,
type NavMenuState,
} from './navMenuState';
const reduce = (events: readonly NavMenuEvent[], start = initialNavMenuState) =>
events.reduce(navMenuReducer, start);
const closed: NavMenuState = { ...initialNavMenuState };
const mobile: NavMenuState = { ...closed, isDesktop: false };
const desktop: NavMenuState = { ...closed, isDesktop: true };
const mobileOpen: NavMenuState = { ...mobile, menuOpen: true };
const mobileGroup: NavMenuState = { ...mobileOpen, groupOpen: true };
const desktopOpen: NavMenuState = { ...desktop, submenuOpen: true };
// The invariants I1-I4 of the domain model
function expectInvariants(state: NavMenuState) {
if (state.submenuOpen) expect(state.isDesktop).toBe(true);
if (state.menuOpen) expect(state.isDesktop).toBe(false);
if (state.groupOpen) expect(state.menuOpen).toBe(true);
if (state.focusRequest === 'menuToggle') {
expect(state.isDesktop).toBe(false);
}
if (state.focusRequest === 'submenuToggle') {
expect(state.isDesktop).toBe(true);
}
}
// An independent, deliberately plain model of the transition table, written
// per field instead of per event as the reducer does
function model(state: NavMenuState, event: NavMenuEvent) {
const next = { ...state };
const everythingClosed = () => {
next.menuOpen = false;
next.groupOpen = false;
next.submenuOpen = false;
};
if (event.type === 'viewport') {
next.isDesktop = event.isDesktop;
if (event.isDesktop) {
next.menuOpen = false;
next.groupOpen = false;
} else {
next.submenuOpen = false;
}
if (event.isDesktop && next.focusRequest === 'menuToggle') {
next.focusRequest = null;
}
if (!event.isDesktop && next.focusRequest === 'submenuToggle') {
next.focusRequest = null;
}
} else if (event.type === 'toggleMenu' && !state.isDesktop) {
next.menuOpen = !state.menuOpen;
next.groupOpen = next.menuOpen ? event.inSection : false;
} else if (event.type === 'toggleGroup' && state.menuOpen) {
next.groupOpen = !state.groupOpen;
} else if (event.type === 'toggleSubmenu' && state.isDesktop) {
next.submenuOpen = !state.submenuOpen;
} else if (event.type === 'escape' && state.menuOpen) {
next.menuOpen = false;
next.groupOpen = false;
next.focusRequest = event.focusInside ? 'menuToggle' : null;
} else if (event.type === 'escape' && state.submenuOpen) {
next.submenuOpen = false;
next.focusRequest = event.focusInside ? 'submenuToggle' : null;
} else if (
(event.type === 'outside' || event.type === 'focusLeave') &&
state.submenuOpen
) {
next.submenuOpen = false;
} else if (event.type === 'linkChosen' || event.type === 'routeChanged') {
everythingClosed();
next.focusRequest = null;
} else if (event.type === 'focusHandled') {
next.focusRequest = null;
}
return next;
}
describe('navMenuReducer (stateful)', () => {
it('keeps I1-I4 and follows the model after every event (stateful)', () => {
fc.assert(
fc.property(navMenuEvents, (events) => {
let state = initialNavMenuState;
for (const event of events) {
const expected = model(state, event);
state = navMenuReducer(state, event);
expect(state).toEqual(expected);
expectInvariants(state);
}
}),
);
});
it('starts all closed and keeps the invariants for any reached state', () => {
expectInvariants(initialNavMenuState);
fc.assert(
fc.property(navMenuState, (state) => {
expectInvariants(state);
}),
);
});
it('returns the same object when an event does not apply (invariant)', () => {
fc.assert(
fc.property(navMenuState, navMenuEvent, (state, event) => {
const next = navMenuReducer(state, event);
if (JSON.stringify(next) === JSON.stringify(state)) {
expect(next).toBe(state);
}
}),
);
});
});
describe('navMenuReducer (idempotency)', () => {
it('ends all closed after routeChanged or linkChosen, twice as once (idempotency)', () => {
fc.assert(
fc.property(
navMenuState,
fc.constantFrom('routeChanged', 'linkChosen'),
(state, type) => {
const once = navMenuReducer(state, { type });
expect(once.menuOpen).toBe(false);
expect(once.groupOpen).toBe(false);
expect(once.submenuOpen).toBe(false);
expect(once.focusRequest).toBeNull();
expect(once.isDesktop).toBe(state.isDesktop);
expect(navMenuReducer(once, { type })).toEqual(once);
},
),
);
});
it('closes the same on escape twice as once, apart from the focus request (idempotency)', () => {
fc.assert(
fc.property(navMenuState, fc.boolean(), (state, focusInside) => {
const event = { type: 'escape', focusInside } as const;
const once = navMenuReducer(state, event);
const twice = navMenuReducer(once, event);
expect({ ...twice, focusRequest: null }).toEqual({
...once,
focusRequest: null,
});
}),
);
});
it('closes the submenu on outside or focusLeave without touching the rest (invariant)', () => {
fc.assert(
fc.property(
navMenuState,
fc.constantFrom('outside', 'focusLeave'),
(state, type) => {
const once = navMenuReducer(state, { type });
expect(once.menuOpen).toBe(state.menuOpen);
expect(once.groupOpen).toBe(state.groupOpen);
expect(once.focusRequest).toBe(state.focusRequest);
expect(once.submenuOpen).toBe(false);
expect(navMenuReducer(once, { type })).toBe(once);
},
),
);
});
});
describe('navMenuReducer (invariant)', () => {
it('gives back the original state after two submenu toggles on desktop (invariant)', () => {
fc.assert(
fc.property(navMenuStateOn(true), (state) => {
const twice = reduce(
[{ type: 'toggleSubmenu' }, { type: 'toggleSubmenu' }],
state,
);
expect(twice).toEqual(state);
}),
);
});
it('leaves no mobile state open after viewport(true) (invariant)', () => {
fc.assert(
fc.property(navMenuState, (state) => {
const next = navMenuReducer(state, {
type: 'viewport',
isDesktop: true,
});
expect(next.isDesktop).toBe(true);
expect(next.menuOpen).toBe(false);
expect(next.groupOpen).toBe(false);
}),
);
});
it('leaves no submenu open after viewport(false) (invariant)', () => {
fc.assert(
fc.property(navMenuState, (state) => {
const next = navMenuReducer(state, {
type: 'viewport',
isDesktop: false,
});
expect(next.isDesktop).toBe(false);
expect(next.submenuOpen).toBe(false);
}),
);
});
it('opens the menu with the group set to inSection and closes both (invariant)', () => {
fc.assert(
fc.property(fc.boolean(), (inSection) => {
const open = navMenuReducer(mobile, {
type: 'toggleMenu',
inSection,
});
expect(open.menuOpen).toBe(true);
expect(open.groupOpen).toBe(inSection);
const shut = navMenuReducer(open, {
type: 'toggleMenu',
inSection,
});
expect(shut.menuOpen).toBe(false);
expect(shut.groupOpen).toBe(false);
}),
);
});
});
describe('navMenuReducer (examples)', () => {
it('viewport sets the width and closes what no longer exists', () => {
expect(
navMenuReducer(initialNavMenuState, {
type: 'viewport',
isDesktop: true,
}),
).toEqual(desktop);
expect(
navMenuReducer(mobileGroup, { type: 'viewport', isDesktop: true }),
).toEqual(desktop);
expect(
navMenuReducer(desktopOpen, { type: 'viewport', isDesktop: false }),
).toEqual(mobile);
});
it('viewport drops a focus request that no longer fits', () => {
expect(
navMenuReducer(
{ ...desktop, focusRequest: 'submenuToggle' },
{ type: 'viewport', isDesktop: false },
).focusRequest,
).toBeNull();
expect(
navMenuReducer(
{ ...mobile, focusRequest: 'menuToggle' },
{ type: 'viewport', isDesktop: true },
).focusRequest,
).toBeNull();
expect(
navMenuReducer(
{ ...mobile, focusRequest: 'menuToggle' },
{ type: 'viewport', isDesktop: false },
).focusRequest,
).toBe('menuToggle');
});
it('viewport to the same width changes nothing and returns the same object', () => {
expect(
navMenuReducer(mobile, { type: 'viewport', isDesktop: false }),
).toBe(mobile);
expect(
navMenuReducer(desktopOpen, { type: 'viewport', isDesktop: true }),
).toBe(desktopOpen);
});
it('toggleMenu opens with the group expanded in the section, collapsed outside it', () => {
expect(
navMenuReducer(mobile, { type: 'toggleMenu', inSection: true }),
).toEqual(mobileGroup);
expect(
navMenuReducer(mobile, { type: 'toggleMenu', inSection: false }),
).toEqual(mobileOpen);
expect(
navMenuReducer(mobileGroup, {
type: 'toggleMenu',
inSection: true,
}),
).toEqual(mobile);
});
it('toggleMenu on desktop is ignored', () => {
expect(
navMenuReducer(desktop, { type: 'toggleMenu', inSection: true }),
).toBe(desktop);
});
it('toggleGroup flips the group while the menu is open', () => {
expect(navMenuReducer(mobileOpen, { type: 'toggleGroup' })).toEqual(
mobileGroup,
);
expect(navMenuReducer(mobileGroup, { type: 'toggleGroup' })).toEqual(
mobileOpen,
);
});
it('toggleGroup while the menu is closed is ignored', () => {
expect(navMenuReducer(mobile, { type: 'toggleGroup' })).toBe(mobile);
});
it('toggleSubmenu flips the submenu on desktop', () => {
expect(navMenuReducer(desktop, { type: 'toggleSubmenu' })).toEqual(
desktopOpen,
);
expect(navMenuReducer(desktopOpen, { type: 'toggleSubmenu' })).toEqual(
desktop,
);
});
it('toggleSubmenu on mobile is ignored', () => {
expect(navMenuReducer(mobile, { type: 'toggleSubmenu' })).toBe(mobile);
});
it('escape closes the mobile menu and asks for focus on the hamburger when focus is inside', () => {
expect(
navMenuReducer(mobileGroup, { type: 'escape', focusInside: true }),
).toEqual({ ...mobile, focusRequest: 'menuToggle' });
expect(
navMenuReducer(mobileGroup, { type: 'escape', focusInside: false }),
).toEqual(mobile);
});
it('escape closes the submenu and asks for focus on its toggle when focus is inside', () => {
expect(
navMenuReducer(desktopOpen, { type: 'escape', focusInside: true }),
).toEqual({ ...desktop, focusRequest: 'submenuToggle' });
expect(
navMenuReducer(desktopOpen, { type: 'escape', focusInside: false }),
).toEqual(desktop);
});
it('escape with nothing open is ignored', () => {
expect(
navMenuReducer(desktop, { type: 'escape', focusInside: true }),
).toBe(desktop);
expect(
navMenuReducer(mobile, { type: 'escape', focusInside: true }),
).toBe(mobile);
});
it('outside and focusLeave close the submenu without a focus request', () => {
expect(navMenuReducer(desktopOpen, { type: 'outside' })).toEqual(
desktop,
);
expect(navMenuReducer(desktopOpen, { type: 'focusLeave' })).toEqual(
desktop,
);
});
it('outside and focusLeave with the submenu closed are ignored', () => {
expect(navMenuReducer(desktop, { type: 'outside' })).toBe(desktop);
expect(navMenuReducer(desktop, { type: 'focusLeave' })).toBe(desktop);
expect(navMenuReducer(mobileGroup, { type: 'outside' })).toBe(
mobileGroup,
);
});
it('linkChosen and routeChanged close everything', () => {
for (const type of ['linkChosen', 'routeChanged'] as const) {
expect(navMenuReducer(mobileGroup, { type })).toEqual(mobile);
expect(navMenuReducer(desktopOpen, { type })).toEqual(desktop);
expect(navMenuReducer(desktop, { type })).toBe(desktop);
}
});
it('focusHandled clears the request, or is ignored when there is none', () => {
const asked: NavMenuState = {
...desktop,
focusRequest: 'submenuToggle',
};
expect(navMenuReducer(asked, { type: 'focusHandled' })).toEqual(
desktop,
);
expect(navMenuReducer(desktop, { type: 'focusHandled' })).toBe(desktop);
});
it('ignores an unknown event instead of opening anything', () => {
const unknown = { type: 'explode' } as unknown as NavMenuEvent;
expect(navMenuReducer(desktop, unknown)).toBe(desktop);
expect(navMenuReducer(mobileOpen, unknown)).toBe(mobileOpen);
});
});
+140
View File
@@ -0,0 +1,140 @@
// The open/closed state of the navigation menus (FR-ST-10): the desktop
// submenu below "Soorten fotoshoots" and, below lg, the full-screen menu
// with its expandable group. One reducer, so the hamburger, the submenu,
// the group and the route listener cannot disagree.
// Where the focus must go after a state change; cleared by `focusHandled`
export type FocusRequest = 'menuToggle' | 'submenuToggle' | null;
// Invariants (checked by the property tests):
// I1 submenuOpen implies isDesktop
// I2 menuOpen implies !isDesktop
// I3 groupOpen implies menuOpen
// I4 focusRequest 'menuToggle' implies !isDesktop, 'submenuToggle' implies
// isDesktop
export interface NavMenuState {
// Viewport is at or above lg
isDesktop: boolean;
// The full-screen mobile menu
menuOpen: boolean;
// The "Soorten fotoshoots" sub-list inside the mobile menu
groupOpen: boolean;
// The desktop dropdown panel
submenuOpen: boolean;
focusRequest: FocusRequest;
}
export type NavMenuEvent =
| { type: 'viewport'; isDesktop: boolean }
| { type: 'toggleMenu'; inSection: boolean }
| { type: 'toggleGroup' }
| { type: 'toggleSubmenu' }
| { type: 'escape'; focusInside: boolean }
| { type: 'outside' }
| { type: 'focusLeave' }
| { type: 'linkChosen' }
| { type: 'routeChanged' }
| { type: 'focusHandled' };
// Everything closed; the width is unknown until the first `viewport` event
export const initialNavMenuState: NavMenuState = {
isDesktop: false,
menuOpen: false,
groupOpen: false,
submenuOpen: false,
focusRequest: null,
};
// A focus request that cannot be met at this width is dropped (I4)
function fittingRequest(request: FocusRequest, isDesktop: boolean) {
if (request === 'menuToggle' && isDesktop) return null;
if (request === 'submenuToggle' && !isDesktop) return null;
return request;
}
// The transition table of the navigation menus. An event that does not apply
// returns the same state object, so useReducer skips the re-render. Nothing
// is ever opened by a fallback (SECURITY-15).
export function navMenuReducer(
state: NavMenuState,
event: NavMenuEvent,
): NavMenuState {
switch (event.type) {
case 'viewport': {
const { isDesktop } = event;
const next: NavMenuState = {
isDesktop,
menuOpen: isDesktop ? false : state.menuOpen,
groupOpen: isDesktop ? false : state.groupOpen,
submenuOpen: isDesktop ? state.submenuOpen : false,
focusRequest: fittingRequest(state.focusRequest, isDesktop),
};
return sameState(state, next) ? state : next;
}
case 'toggleMenu':
if (state.isDesktop) return state;
return state.menuOpen
? { ...state, menuOpen: false, groupOpen: false }
: { ...state, menuOpen: true, groupOpen: event.inSection };
case 'toggleGroup':
if (!state.menuOpen) return state;
return { ...state, groupOpen: !state.groupOpen };
case 'toggleSubmenu':
if (!state.isDesktop) return state;
return { ...state, submenuOpen: !state.submenuOpen };
case 'escape':
if (state.menuOpen) {
return {
...state,
menuOpen: false,
groupOpen: false,
focusRequest: event.focusInside ? 'menuToggle' : null,
};
}
if (state.submenuOpen) {
return {
...state,
submenuOpen: false,
focusRequest: event.focusInside ? 'submenuToggle' : null,
};
}
return state;
case 'outside':
case 'focusLeave':
if (!state.submenuOpen) return state;
return { ...state, submenuOpen: false };
case 'linkChosen':
case 'routeChanged': {
const closed: NavMenuState = {
...state,
menuOpen: false,
groupOpen: false,
submenuOpen: false,
focusRequest: null,
};
return sameState(state, closed) ? state : closed;
}
case 'focusHandled':
if (state.focusRequest === null) return state;
return { ...state, focusRequest: null };
default:
// A new event type without a case is a type error here (never);
// at run time an unknown event changes nothing
return ignore(state, event);
}
}
function sameState(a: NavMenuState, b: NavMenuState) {
return (
a.isDesktop === b.isDesktop &&
a.menuOpen === b.menuOpen &&
a.groupOpen === b.groupOpen &&
a.submenuOpen === b.submenuOpen &&
a.focusRequest === b.focusRequest
);
}
function ignore(state: NavMenuState, event: never): NavMenuState {
void event;
return state;
}
+38
View File
@@ -0,0 +1,38 @@
import fc from 'fast-check';
import { describe, expect, it } from 'vitest';
import shootTypes from '@/content/shootTypes';
import { uniqueShootTypes } from '@/test/arbitraries';
import { readMoreLabel } from './readMoreLabel';
describe('readMoreLabel', () => {
it('names each of the five real shoots', () => {
expect(shootTypes.map(readMoreLabel)).toEqual([
'Lees meer over de newbornshoot',
'Lees meer over de zwangerschapsshoot',
'Lees meer over de gezinsshoot',
'Lees meer over de loveshoot',
'Lees meer over de portretshoot',
]);
expect(new Set(shootTypes.map(readMoreLabel)).size).toBe(5);
});
it('starts with the fixed words and is unique for unique shoot labels (invariant)', () => {
fc.assert(
fc.property(uniqueShootTypes, (shoots) => {
const unique = shoots.filter(
(shoot, index) =>
shoots.findIndex(
(other) =>
other.shootLabel.toLowerCase() ===
shoot.shootLabel.toLowerCase(),
) === index,
);
const labels = unique.map(readMoreLabel);
for (const label of labels) {
expect(label.startsWith('Lees meer over de ')).toBe(true);
}
expect(new Set(labels).size).toBe(labels.length);
}),
);
});
});
+7
View File
@@ -0,0 +1,7 @@
import type { ShootType } from '../content/types.ts';
// The text of the link from the overview to a shoot page (FR-ST-09). It
// differs per shoot, so no aria-label is needed to tell the links apart.
export function readMoreLabel(shoot: ShootType): string {
return `Lees meer over de ${shoot.shootLabel.toLowerCase()}`;
}
+75
View File
@@ -0,0 +1,75 @@
import fc from 'fast-check';
import { describe, expect, it } from 'vitest';
import shootTypes from '../content/shootTypes';
import { uniqueShootTypes } from '../test/arbitraries';
import { shootNavItems } from './shootNavItems';
import { SHOOT_TYPES_PATH, shootIdFromPath, shootPagePath } from './shootPages';
describe('shootNavItems', () => {
it('gives one item per shoot (invariant)', () => {
fc.assert(
fc.property(uniqueShootTypes, (shoots) => {
expect(shootNavItems(shoots)).toHaveLength(shoots.length);
}),
);
});
it('keeps the order and uses the name as label (invariant)', () => {
fc.assert(
fc.property(uniqueShootTypes, (shoots) => {
const items = shootNavItems(shoots);
expect(items.map((item) => item.label)).toEqual(
shoots.map((shoot) => shoot.name),
);
}),
);
});
it('links to the page of the same shoot (round trip)', () => {
fc.assert(
fc.property(uniqueShootTypes, (shoots) => {
const items = shootNavItems(shoots);
items.forEach((item, index) => {
expect(shootIdFromPath(item.to)).toBe(shoots[index].id);
});
}),
);
});
it('links to a page below the overview (invariant)', () => {
fc.assert(
fc.property(uniqueShootTypes, (shoots) => {
shootNavItems(shoots).forEach((item, index) => {
expect(item.to).toBe(shootPagePath(shoots[index].id));
expect(item.to.startsWith(`${SHOOT_TYPES_PATH}/`)).toBe(
true,
);
});
}),
);
});
it('has no other fields than to and label (invariant)', () => {
fc.assert(
fc.property(uniqueShootTypes, (shoots) => {
for (const item of shootNavItems(shoots)) {
expect(Object.keys(item).sort()).toEqual(['label', 'to']);
}
}),
);
});
it('gives the five names of the real shoot types in order', () => {
expect(shootNavItems(shootTypes).map((item) => item.label)).toEqual([
'Newborn',
'Zwangerschap',
'Gezin',
'Loveshoot',
'Portretten',
]);
});
it('gives an empty list for no shoots', () => {
expect(shootNavItems([])).toEqual([]);
});
});
+12
View File
@@ -0,0 +1,12 @@
import type { ShootType } from '../content/types.ts';
import type { NavItem } from '../navigation.ts';
import { shootPagePath } from './shootPages.ts';
// The submenu items of the shoot types, one per shoot in the given order:
// the label is the shoot name, the target its page (FR-ST-10, BR-NAV-10)
export function shootNavItems(shoots: readonly ShootType[]): NavItem[] {
return shoots.map((shoot) => ({
to: shootPagePath(shoot.id),
label: shoot.name,
}));
}
+95
View File
@@ -0,0 +1,95 @@
import fc from 'fast-check';
import { describe, expect, it } from 'vitest';
import shootPageShared from '@/content/shootPageShared';
import newbornPage from '@/content/shootPages/newborn';
import loveshootPage from '@/content/shootPages/loveshoot';
import packages from '@/content/packages';
import shootTypes from '@/content/shootTypes';
import siteContent from '@/content/siteContent';
import { shootPageViewArb } from '@/test/arbitraries';
import { shootPageBands } from './shootPageBands';
import { shootPageView } from './shootPageView';
import { storyLayout } from './storyLayout';
const sources = {
shootTypes,
packages,
shared: shootPageShared,
site: siteContent,
portfolioShoots: [],
};
describe('shootPageBands', () => {
it('gives the newborn page nine bands', () => {
const view = shootPageView('newborn', newbornPage, sources)!;
const bands = shootPageBands(view);
expect(bands).toHaveLength(9);
expect(bands.map((band) => band.id)).toEqual([
...view.stories.map((story) => `story-${story.id}`),
'process',
'photos',
'faq',
'offer',
'closing',
]);
expect(bands.map((band) => band.position)).toEqual([
0, 1, 2, 3, 4, 5, 6, 7, 8,
]);
expect(bands[0].tone).toBe('paper');
expect(bands[1].tone).toBe('alt');
});
it('leaves out the photos for loveshoot', () => {
const view = shootPageView('loveshoot', loveshootPage, sources)!;
const bands = shootPageBands(view);
expect(bands).toHaveLength(8);
expect(bands.map((band) => band.id)).not.toContain('photos');
});
it('leaves out the FAQ of a view without questions', () => {
const view = shootPageView(
'newborn',
{ ...newbornPage, faq: { ...newbornPage.faq, items: [] } },
sources,
)!;
const ids = shootPageBands(view).map((band) => band.id);
expect(ids).not.toContain('faq');
expect(ids).toContain('photos');
});
it('keeps the order, the alternation and the story tones for any view (invariant)', () => {
fc.assert(
fc.property(shootPageViewArb, (view) => {
const bands = shootPageBands(view);
expect(bands).toHaveLength(
view.stories.length +
1 +
(view.photos ? 1 : 0) +
(view.faq ? 1 : 0) +
2,
);
bands.forEach((band, index) => {
expect(band.position).toBe(index);
expect(band.tone).toBe(index % 2 === 0 ? 'paper' : 'alt');
});
const tail = bands.slice(view.stories.length).map((b) => b.id);
expect(tail).toEqual([
'process',
...(view.photos ? ['photos'] : []),
...(view.faq ? ['faq'] : []),
'offer',
'closing',
]);
expect(
bands.slice(0, view.stories.length).map((b) => b.id),
).toEqual(view.stories.map((story) => `story-${story.id}`));
const layout = storyLayout(view.stories);
layout.forEach((item, index) => {
expect(bands[index].tone).toBe(item.tone);
});
// Story ids are unique in the generated content
expect(new Set(bands.map((b) => b.id)).size).toBe(bands.length);
}),
);
});
});
+29
View File
@@ -0,0 +1,29 @@
import type { ShootPageView } from './shootPageView.ts';
export interface SectionBand {
id: `story-${string}` | 'process' | 'photos' | 'faq' | 'offer' | 'closing';
// The band colour: paper at even positions, alt at odd ones
tone: 'paper' | 'alt';
// 0 for the first story; the intro above it is not a band
position: number;
}
// The bands of a shoot page in page order (BR-SP-70): the stories, the
// timeline, the photos and the FAQ when the view has them, the offer and
// the closing block. Tones alternate, so two bands never touch in the same
// colour; the intro above is always paper.
export function shootPageBands(view: ShootPageView): SectionBand[] {
const ids: SectionBand['id'][] = [
...view.stories.map((story) => `story-${story.id}` as const),
'process',
...(view.photos ? (['photos'] as const) : []),
...(view.faq ? (['faq'] as const) : []),
'offer',
'closing',
];
return ids.map((id, position) => ({
id,
tone: position % 2 === 0 ? 'paper' : 'alt',
position,
}));
}
+119
View File
@@ -0,0 +1,119 @@
import fc from 'fast-check';
import { describe, expect, it } from 'vitest';
import newbornPage from '@/content/shootPages/newborn';
import loveshootPage from '@/content/shootPages/loveshoot';
import type { StoryBlock } from '@/content/types';
import { imageWithOrientation, storyBlock } from '@/test/arbitraries';
import { LANDSCAPE_RATIO, storyLayout } from './storyLayout';
const story = (width?: number, height?: number): StoryBlock => ({
id: 's',
eyebrow: 'e',
title: 't',
paragraphs: [['p']],
...(width === undefined || height === undefined
? {}
: { image: { src: '/a.jpg', alt: 'a', width, height } }),
});
describe('storyLayout', () => {
it('lays out the four real newborn stories', () => {
const layout = storyLayout(newbornPage.stories);
expect(layout.map((item) => item.media)).toEqual([
{ aspectRatio: '4 / 5', mediaSize: 'medium' },
{ aspectRatio: '3 / 2', mediaSize: 'half' },
{ aspectRatio: '4 / 5', mediaSize: 'medium' },
{ aspectRatio: '4 / 5', mediaSize: 'medium' },
]);
expect(layout.map((item) => item.tone)).toEqual([
'paper',
'alt',
'paper',
'alt',
]);
expect(layout.map((item) => item.reverse)).toEqual([
false,
true,
false,
true,
]);
expect(layout.map((item) => item.priority)).toEqual([
true,
false,
false,
false,
]);
expect(layout[0].spacing).toBe('flushTop');
expect(layout[1].spacing).toBe('default');
});
it('gives text-only stories no media and no priority', () => {
const layout = storyLayout(loveshootPage.stories);
expect(layout[0].media).toBeDefined();
for (const item of layout.slice(1)) {
expect(item).not.toHaveProperty('media');
expect(item.priority).toBe(false);
}
expect(storyLayout([story()])[0].priority).toBe(false);
});
it('switches to landscape at exactly 1.2', () => {
expect(LANDSCAPE_RATIO).toBe(1.2);
expect(storyLayout([story(120, 100)])[0].media?.aspectRatio).toBe(
'3 / 2',
);
expect(storyLayout([story(119, 100)])[0].media?.aspectRatio).toBe(
'4 / 5',
);
});
it('gives nothing for no stories', () => {
expect(storyLayout([])).toEqual([]);
});
it('alternates, and decides ratio and width by the photo (invariant)', () => {
fc.assert(
fc.property(
fc.array(
fc.tuple(
storyBlock,
fc.option(imageWithOrientation, { nil: undefined }),
),
{ maxLength: 8 },
),
(pairs) => {
const stories = pairs.map(([block, image]) => ({
...block,
image,
}));
const layout = storyLayout(stories);
expect(layout).toHaveLength(stories.length);
layout.forEach((item, index) => {
const { image } = stories[index];
expect(item.tone).toBe(
index % 2 === 0 ? 'paper' : 'alt',
);
expect(item.reverse).toBe(index % 2 === 1);
expect(item.priority).toBe(
index === 0 && image !== undefined,
);
if (image === undefined) {
expect(item.media).toBeUndefined();
return;
}
const landscape =
image.width >= LANDSCAPE_RATIO * image.height;
expect(item.media).toEqual(
landscape
? { aspectRatio: '3 / 2', mediaSize: 'half' }
: {
aspectRatio: '4 / 5',
mediaSize: 'medium',
},
);
});
},
),
);
});
});
+44
View File
@@ -0,0 +1,44 @@
import type { StoryBlock } from '../content/types.ts';
// A photo is landscape when it is at least this much wider than it is high
export const LANDSCAPE_RATIO = 1.2;
export interface StoryLayout {
// Band colour; the same rule as shootPageBands gives the story bands
tone: 'paper' | 'alt';
// flushTop: no space above the first block, below the page head
spacing: 'flushTop' | 'default';
// Photo in the right-hand column from `lg`
reverse: boolean;
// Only the first story's photo may load with priority
priority: boolean;
// Absent for a story without a photo
media?: {
aspectRatio: '3 / 2' | '4 / 5';
mediaSize: 'half' | 'medium';
};
}
// How each story block is laid out (FR-ST-03): tone and side from the
// index, the photo's shape and column width from its proportions.
export function storyLayout(stories: readonly StoryBlock[]): StoryLayout[] {
return stories.map((story, index) => {
const { image } = story;
const landscape =
image !== undefined &&
image.width >= LANDSCAPE_RATIO * image.height;
return {
tone: index % 2 === 0 ? 'paper' : 'alt',
spacing: index === 0 ? 'flushTop' : 'default',
reverse: index % 2 === 1,
priority: index === 0 && image !== undefined,
...(image === undefined
? {}
: {
media: landscape
? { aspectRatio: '3 / 2', mediaSize: 'half' }
: { aspectRatio: '4 / 5', mediaSize: 'medium' },
}),
};
});
}