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>
399 lines
14 KiB
TypeScript
399 lines
14 KiB
TypeScript
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);
|
|
});
|
|
});
|