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,114 @@
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { useRef } from 'react';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import useDismiss, { type DismissReason } from './useDismiss';
|
||||
|
||||
function Harness({
|
||||
active,
|
||||
onDismiss,
|
||||
}: {
|
||||
active: boolean;
|
||||
onDismiss: (reason: DismissReason) => void;
|
||||
}) {
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
useDismiss(ref, active, onDismiss);
|
||||
return (
|
||||
<>
|
||||
<div ref={ref}>
|
||||
<button>inside</button>
|
||||
</div>
|
||||
<button>outside</button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
describe('useDismiss', () => {
|
||||
it('reports Escape while active', async () => {
|
||||
const onDismiss = vi.fn();
|
||||
render(<Harness active onDismiss={onDismiss} />);
|
||||
await userEvent.keyboard('{Escape}');
|
||||
expect(onDismiss).toHaveBeenCalledExactlyOnceWith('escape');
|
||||
});
|
||||
|
||||
it('ignores other keys', async () => {
|
||||
const onDismiss = vi.fn();
|
||||
render(<Harness active onDismiss={onDismiss} />);
|
||||
await userEvent.keyboard('a{Enter}{Tab}');
|
||||
expect(onDismiss).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('reports a pointer down outside, not inside', async () => {
|
||||
const onDismiss = vi.fn();
|
||||
render(<Harness active onDismiss={onDismiss} />);
|
||||
await userEvent.click(screen.getByRole('button', { name: 'inside' }));
|
||||
expect(onDismiss).not.toHaveBeenCalled();
|
||||
await userEvent.click(screen.getByRole('button', { name: 'outside' }));
|
||||
expect(onDismiss).toHaveBeenCalledExactlyOnceWith('outside');
|
||||
});
|
||||
|
||||
it('reports nothing while inactive', async () => {
|
||||
const onDismiss = vi.fn();
|
||||
render(<Harness active={false} onDismiss={onDismiss} />);
|
||||
await userEvent.keyboard('{Escape}');
|
||||
await userEvent.click(screen.getByRole('button', { name: 'outside' }));
|
||||
expect(onDismiss).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('starts and stops listening when active changes', async () => {
|
||||
const onDismiss = vi.fn();
|
||||
const { rerender } = render(
|
||||
<Harness active={false} onDismiss={onDismiss} />,
|
||||
);
|
||||
rerender(<Harness active onDismiss={onDismiss} />);
|
||||
await userEvent.keyboard('{Escape}');
|
||||
expect(onDismiss).toHaveBeenCalledTimes(1);
|
||||
rerender(<Harness active={false} onDismiss={onDismiss} />);
|
||||
await userEvent.keyboard('{Escape}');
|
||||
expect(onDismiss).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('removes its listeners on unmount', async () => {
|
||||
const onDismiss = vi.fn();
|
||||
const { unmount } = render(<Harness active onDismiss={onDismiss} />);
|
||||
const remove = vi.spyOn(document, 'removeEventListener');
|
||||
unmount();
|
||||
expect(remove.mock.calls.map(([type]) => type).sort()).toEqual([
|
||||
'keydown',
|
||||
'pointerdown',
|
||||
]);
|
||||
await userEvent.keyboard('{Escape}');
|
||||
fireEvent.pointerDown(document.body);
|
||||
expect(onDismiss).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('calls the latest callback once without re-subscribing', async () => {
|
||||
const first = vi.fn();
|
||||
const second = vi.fn();
|
||||
const { rerender } = render(<Harness active onDismiss={first} />);
|
||||
const add = vi.spyOn(document, 'addEventListener');
|
||||
rerender(<Harness active onDismiss={second} />);
|
||||
expect(add).not.toHaveBeenCalled();
|
||||
await userEvent.keyboard('{Escape}');
|
||||
expect(first).not.toHaveBeenCalled();
|
||||
expect(second).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('ignores a pointer down whose target is not a Node', () => {
|
||||
const onDismiss = vi.fn();
|
||||
render(<Harness active onDismiss={onDismiss} />);
|
||||
fireEvent.pointerDown(window);
|
||||
expect(onDismiss).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('ignores a pointer down when the ref is empty', () => {
|
||||
const onDismiss = vi.fn();
|
||||
function Detached() {
|
||||
useDismiss({ current: null }, true, onDismiss);
|
||||
return null;
|
||||
}
|
||||
render(<Detached />);
|
||||
fireEvent.pointerDown(document.body);
|
||||
expect(onDismiss).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
import { useEffect, useRef, type RefObject } from 'react';
|
||||
|
||||
export type DismissReason = 'escape' | 'outside';
|
||||
|
||||
// Reports Escape and a pointer down outside `ref` while `active` is true.
|
||||
// It only listens: what a dismissal means is up to the caller (FR-ST-10).
|
||||
// The listeners exist only while active and are removed on deactivation and
|
||||
// unmount. A missing element or a target that is no Node is ignored.
|
||||
export default function useDismiss(
|
||||
ref: RefObject<HTMLElement | null>,
|
||||
active: boolean,
|
||||
onDismiss: (reason: DismissReason) => void,
|
||||
) {
|
||||
// The latest callback, so a new function identity does not re-subscribe
|
||||
const callback = useRef(onDismiss);
|
||||
useEffect(() => {
|
||||
callback.current = onDismiss;
|
||||
}, [onDismiss]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!active) return;
|
||||
|
||||
const onKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Escape') callback.current('escape');
|
||||
};
|
||||
const onPointerDown = (event: PointerEvent) => {
|
||||
const element = ref.current;
|
||||
if (!element || !(event.target instanceof Node)) return;
|
||||
if (!element.contains(event.target)) callback.current('outside');
|
||||
};
|
||||
|
||||
document.addEventListener('keydown', onKeyDown);
|
||||
document.addEventListener('pointerdown', onPointerDown);
|
||||
return () => {
|
||||
document.removeEventListener('keydown', onKeyDown);
|
||||
document.removeEventListener('pointerdown', onPointerDown);
|
||||
};
|
||||
}, [active, ref]);
|
||||
}
|
||||
Reference in New Issue
Block a user