diff --git a/aidlc-docs/features/asf-packages-cms/requirements.md b/aidlc-docs/features/asf-packages-cms/requirements.md index ab72d3b..ed7a6f8 100644 --- a/aidlc-docs/features/asf-packages-cms/requirements.md +++ b/aidlc-docs/features/asf-packages-cms/requirements.md @@ -8,6 +8,8 @@ Decided by Bryan via SLP Software - SLS - Main, 2026-11-12. Source of truth: the - FR-PK-03 One source: the price cards, the "welke shoot" choices of the contact form and the `?pakket=` check use the same list (`content/packages.ts`). - FR-PK-04 Mapping: `slug` is the package id (kept `zwangerschap`, `newborn`, `gezin`: they appear in `?pakket=` and the form), `title` the name, the price text is read as whole euros ("€ 175", "€ 1.250", "175,-"); a card with an unreadable price, no features or a bad slug is skipped; order by `displayOrder`. - FR-PK-05 Banner: the first usable offering with `layout=banner` becomes an optional dark band under the cards (own block, price as free text). It is not a package: not in the form choices, not in the package count, no booking link with a package. +- FR-PK-07 Last row of cards (desktop): rows of three, an incomplete last row is centred, for any number of cards, with no styling per number. Phone and tablet stay one column. Done with a wrapping flex and card width `calc((100% - 2 * gap) / 3)`. +- FR-PK-08 Slim top bar (2026-11-14, Bryan via SLS-Main): a second banner ABOVE the cards, next to the one under them; both may show at once. One line (title and text on one line, optional small text link), a slim bar in the ASF style that matches the white bottom banner. Contract: `GET /api/v1/offerings/banner?position=top|bottom` (no parameter is bottom), 204 is none, fields title/text/linkLabel/linkUrl, the title may be empty for top (title or text required). Built in like the bottom banner: baked in the HTML, replaced live after hydration, 204 hides it, errors keep what was baked, empty fields hidden. - FR-PK-06 The rebuild trigger (CMS change leads to a new build) is separate from the build; decision for Bryan (webhook to workflow_dispatch or a nightly build). Until then a change shows after the next build. - NFR-PK-01 Tests use the snapshot only (no dependence on a build or network). diff --git a/web/config/fetchOfferings.ts b/web/config/fetchOfferings.ts index 28903d7..e898d41 100644 --- a/web/config/fetchOfferings.ts +++ b/web/config/fetchOfferings.ts @@ -11,6 +11,7 @@ import { fileURLToPath } from 'node:url'; import { mapBanner, mapOfferings, + mapTopBanner, type SiteOfferings, } from '../src/lib/offerings.ts'; @@ -81,6 +82,25 @@ async function main() { `[offerings] banner not available (${String(error)}): none`, ); } + // The slim top bar, same rules + try { + const top = mapTopBanner( + await fetchAnswer( + base, + '/api/v1/offerings/banner?position=top', + ), + ); + result.topBanner = top; + console.log( + top + ? `[offerings] top bar "${top.title ?? top.text}"` + : '[offerings] no active top bar', + ); + } catch (error) { + console.warn( + `[offerings] top bar not available (${String(error)}): none`, + ); + } } else { console.warn( `[offerings] answer of ${base} has no valid package: using the snapshot`, diff --git a/web/e2e/packagesLive.e2e.ts b/web/e2e/packagesLive.e2e.ts index c498cc3..34b7a17 100644 --- a/web/e2e/packagesLive.e2e.ts +++ b/web/e2e/packagesLive.e2e.ts @@ -76,4 +76,101 @@ describe('pakketten live uit het CMS', () => { expect(await cards(page).count()).toBe(3); expect(messages.filter((m) => !m.includes('500'))).toEqual([]); }); + + // De kaartenrij: op desktop rijen van drie, een onvolledige laatste rij + // staat in het midden, voor elk aantal. Op tablet en mobiel één kolom. + const many = (count: number) => + Array.from({ length: count }, (_, index) => ({ + slug: `pakket-${index + 1}`, + title: `Pakket ${index + 1}`, + price: '€ 100', + features: ['Een kenmerk'], + displayOrder: index, + })); + + const boxes = (page: OpenedPage['page']) => + cards(page).evaluateAll((nodes) => + nodes.map((node) => { + const { x, y, width } = node.getBoundingClientRect(); + return { x, y: Math.round(y + window.scrollY), width }; + }), + ); + + it.each([4, 5, 7, 8, 10])( + 'zet de laatste, onvolledige rij van %i kaarten in het midden', + async (count) => { + const { page } = await openPage(server.origin + '/', { + prepare: mock(200, many(count)), + }); + await waitForHydration(page); + await eventually(() => cards(page).count()).toBe(count); + const found = await boxes(page); + const rows = new Map(); + for (const box of found) { + rows.set(box.y, [...(rows.get(box.y) ?? []), box]); + } + const list = [...rows.values()]; + expect(list.length).toBe(Math.ceil(count / 3)); + const first = list[0]; + // Alle kaarten even breed; de volle rij vult de breedte + const width = first[0].width; + const left = first[0].x; + const right = first[2].x + width; + for (const box of found) expect(box.width).toBeCloseTo(width, 0); + for (const row of list.slice(0, -1)) expect(row).toHaveLength(3); + // De laatste rij ligt in het midden van de volle rij + const last = list[list.length - 1]; + const rowLeft = last[0].x; + const rowRight = last[last.length - 1].x + width; + expect((rowLeft + rowRight) / 2).toBeCloseTo((left + right) / 2, 0); + }, + ); + + it.each([800, 390])( + 'houdt de kaarten onder elkaar bij %ipx breed', + async (width) => { + const { page } = await openPage(server.origin + '/', { + width, + prepare: mock(200, many(4)), + }); + await waitForHydration(page); + await eventually(() => cards(page).count()).toBe(4); + const found = await boxes(page); + expect(new Set(found.map((box) => box.x)).size).toBe(1); + expect(new Set(found.map((box) => box.y)).size).toBe(4); + }, + ); + + const topBar = + (status: number, body?: unknown) => + async (page: OpenedPage['page']) => { + await page.route( + /\/api\/v1\/offerings\/banner\?position=top/, + (route) => + route.fulfill({ + status, + contentType: 'application/json', + body: body === undefined ? '' : JSON.stringify(body), + }), + ); + }; + + it('toont de slanke balk boven de kaarten, op één regel op desktop', async () => { + const { page } = await openPage(server.origin + '/', { + prepare: topBar(200, { + title: 'Nieuw', + text: 'Nog twee plekken in december', + linkLabel: 'Boek nu', + linkUrl: '/contact', + }), + }); + await waitForHydration(page); + const bar = page.getByTestId('price-top-bar'); + await eventually(() => bar.count()).toBe(1); + const barBox = await bar.boundingBox(); + const cardBox = await cards(page).first().boundingBox(); + expect(barBox!.y + barBox!.height).toBeLessThan(cardBox!.y); + // Slank: een regel tekst plus opvulling + expect(barBox!.height).toBeLessThan(70); + }); }); diff --git a/web/src/components/PackagesProvider/PackagesProvider.test.tsx b/web/src/components/PackagesProvider/PackagesProvider.test.tsx index fa9cc36..080b50b 100644 --- a/web/src/components/PackagesProvider/PackagesProvider.test.tsx +++ b/web/src/components/PackagesProvider/PackagesProvider.test.tsx @@ -5,11 +5,13 @@ import { renderWithProviders } from '@/test/renderWithProviders'; import PackagesProvider, { useBanner, usePackages, + useTopBanner, type LoadJson, } from './PackagesProvider'; function Shown() { const banner = useBanner(); + const top = useTopBanner(); return ( <>

{banner ? banner.title : 'geen banner'}

+

+ {top ? (top.title ?? top.text) : 'geen balk'} +

); } @@ -34,12 +39,18 @@ const card = (price: string) => [ // A fake CMS: one answer per path; a value, undefined (204) or an Error to // throw -type Answers = { offerings?: unknown; banner?: unknown }; +type Answers = { + offerings?: unknown; + banner?: unknown; + topBanner?: unknown; +}; const fake = (answers: Answers): LoadJson => vi.fn(async (path: string) => { - const answer = path.endsWith('/banner') - ? answers.banner - : answers.offerings; + const answer = path.endsWith('?position=top') + ? answers.topBanner + : path.endsWith('/banner') + ? answers.banner + : answers.offerings; if (answer instanceof Error) throw answer; return answer; }); @@ -125,6 +136,44 @@ describe('PackagesProvider', () => { expect(screen.getByTestId('banner')).toHaveTextContent('geen banner'); }); + it('shows the slim top bar from the CMS, asking for position=top', async () => { + const load = fake({ + topBanner: { title: '', text: 'Nog twee plekken', linkLabel: null }, + }); + await show(load); + await waitFor(() => + expect(screen.getByTestId('top')).toHaveTextContent( + 'Nog twee plekken', + ), + ); + expect(load).toHaveBeenCalledWith( + '/api/v1/offerings/banner?position=top', + expect.anything(), + ); + }); + + it('keeps the two banners apart', async () => { + await show( + fake({ + banner: { title: 'Onder' }, + topBanner: { title: 'Boven' }, + }), + ); + await waitFor(() => + expect(screen.getByTestId('top')).toHaveTextContent('Boven'), + ); + expect(screen.getByTestId('banner')).toHaveTextContent('Onder'); + }); + + it.each([ + ['a network error', new Error('offline')], + ['an answer without title and text', { title: '', text: ' ' }], + ['a 204 (no active bar)', undefined], + ])('shows no top bar on %s', async (_name, answer) => { + await show(fake({ topBanner: answer })); + expect(screen.getByTestId('top')).toHaveTextContent('geen balk'); + }); + it('passes an abort signal and aborts on unmount', async () => { const signals: AbortSignal[] = []; const load: LoadJson = (_path, signal) => { @@ -136,7 +185,7 @@ describe('PackagesProvider', () => { , ); - expect(signals).toHaveLength(2); + expect(signals).toHaveLength(3); expect(signals.every((signal) => !signal.aborted)).toBe(true); view.unmount(); expect(signals.every((signal) => signal.aborted)).toBe(true); diff --git a/web/src/components/PackagesProvider/PackagesProvider.tsx b/web/src/components/PackagesProvider/PackagesProvider.tsx index 74e90c4..3429e00 100644 --- a/web/src/components/PackagesProvider/PackagesProvider.tsx +++ b/web/src/components/PackagesProvider/PackagesProvider.tsx @@ -1,8 +1,15 @@ import { createContext, useContext, useEffect, useMemo, useState } from 'react'; import type { ReactNode } from 'react'; -import bakedPackages, { banner as bakedBanner } from '@/content/packages'; -import type { PricingBanner, PricingPackage } from '@/content/types'; -import { mapBanner, mapOfferings } from '@/lib/offerings'; +import bakedPackages, { + banner as bakedBanner, + topBanner as bakedTopBanner, +} from '@/content/packages'; +import type { + PricingBanner, + PricingPackage, + PricingTopBanner, +} from '@/content/types'; +import { mapBanner, mapOfferings, mapTopBanner } from '@/lib/offerings'; // The shoot packages and the announcement banner the pages show. The build // bakes the current ones into the HTML (prices for search engines, no layout @@ -13,10 +20,12 @@ import { mapBanner, mapOfferings } from '@/lib/offerings'; // Failing safe is the rule: a network error, a time-out, a bad status or an // answer that cannot be used leaves what was baked on screen. Nothing flashes // and no price ever becomes empty. The one exception is by design: a 204 from -// the banner route means "no active banner" and hides a baked banner. +// a banner route means "no active banner" and hides a baked banner (the one +// under the cards and the slim bar above them each on their own). const OFFERINGS_PATH = '/api/v1/offerings'; const BANNER_PATH = '/api/v1/offerings/banner'; +const TOP_BANNER_PATH = '/api/v1/offerings/banner?position=top'; const TIMEOUT_MS = 8000; // The JSON answer; undefined for 204; throws for anything else @@ -35,9 +44,14 @@ const loadFromApi: LoadJson = async (path, signal) => { interface Live { packages: PricingPackage[]; banner: PricingBanner | null; + topBanner: PricingTopBanner | null; } -const baked: Live = { packages: bakedPackages, banner: bakedBanner }; +const baked: Live = { + packages: bakedPackages, + banner: bakedBanner, + topBanner: bakedTopBanner, +}; const LiveContext = createContext(baked); @@ -49,6 +63,10 @@ export const usePackages = (): PricingPackage[] => export const useBanner = (): PricingBanner | null => useContext(LiveContext).banner; +// The slim bar above the cards, if any +export const useTopBanner = (): PricingTopBanner | null => + useContext(LiveContext).topBanner; + const same = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b); @@ -93,7 +111,19 @@ export default function PackagesProvider({ } }) .catch(() => undefined); - void Promise.all([packages, banner]).finally(() => clearTimeout(timer)); + const topBanner = load(TOP_BANNER_PATH, signal) + .then((answer) => { + if (signal.aborted) return; + if (answer === undefined) update({ topBanner: null }); + else { + const mapped = mapTopBanner(answer); + if (mapped) update({ topBanner: mapped }); + } + }) + .catch(() => undefined); + void Promise.all([packages, banner, topBanner]).finally(() => + clearTimeout(timer), + ); return () => { clearTimeout(timer); controller.abort(); diff --git a/web/src/components/home/Pricing/PriceTopBar.tsx b/web/src/components/home/Pricing/PriceTopBar.tsx new file mode 100644 index 0000000..8a43279 --- /dev/null +++ b/web/src/components/home/Pricing/PriceTopBar.tsx @@ -0,0 +1,85 @@ +import { Box, chakra, Text } from '@chakra-ui/react'; +import type { PricingTopBanner } from '@/content/types'; + +type PriceTopBarProps = { + banner: PricingTopBanner; +}; + +// The slim bar above the price cards: one line with a short announcement +// from the CMS, made to go with the white banner under the cards (same white, +// hairline border and thin heidegroen rule on top). The title is small +// spaced capitals in the heading font, the text is quiet ink, and a link is a +// small underlined deep-green text link, not a button. The title may be left +// out; the text may be too, but not both (mapTopBanner guarantees that). On +// a phone a long line wraps, which is the only time it is more than one. +export default function PriceTopBar({ banner }: PriceTopBarProps) { + const { title, text, link } = banner; + + return ( + + {title && ( + + {title} + + )} + {title && text && ( + + ); +} diff --git a/web/src/components/home/Pricing/Pricing.test.tsx b/web/src/components/home/Pricing/Pricing.test.tsx index fcb47da..b6b1a30 100644 --- a/web/src/components/home/Pricing/Pricing.test.tsx +++ b/web/src/components/home/Pricing/Pricing.test.tsx @@ -94,6 +94,75 @@ describe('Pricing', () => { expect(await axeResults(container)).toHaveNoViolations(); }); + it('shows a slim bar above the cards next to the banner under them', async () => { + const { container } = await renderWithProviders( + , + ); + const bar = screen.getByTestId('price-top-bar'); + expect(within(bar).getByText('Nieuw')).toBeInTheDocument(); + expect(within(bar).getByText('Nog twee plekken')).toBeInTheDocument(); + expect( + within(bar).getByRole('link', { name: 'Boek nu' }), + ).toHaveAttribute('rel', 'noopener'); + // The bar comes before the first card, the banner after the last + const first = screen.getByTestId('price-card-zwangerschap'); + expect( + bar.compareDocumentPosition(first) & + Node.DOCUMENT_POSITION_FOLLOWING, + ).toBeTruthy(); + expect( + first.compareDocumentPosition(screen.getByTestId('price-banner')) & + Node.DOCUMENT_POSITION_FOLLOWING, + ).toBeTruthy(); + expect(await axeResults(container)).toHaveNoViolations(); + }); + + it('leaves out what the slim bar does not have', async () => { + await renderWithProviders( + , + ); + const bar = screen.getByTestId('price-top-bar'); + expect(bar).toHaveTextContent('Alleen tekst'); + expect(within(bar).queryByRole('link')).not.toBeInTheDocument(); + expect(screen.queryByTestId('price-banner')).not.toBeInTheDocument(); + }); + + it('shows a slim bar with a title only and a site link', async () => { + await renderWithProviders( + , + ); + const bar = screen.getByTestId('price-top-bar'); + expect(bar).toHaveTextContent('Alleen titel'); + expect(within(bar).getByRole('link')).not.toHaveAttribute('rel'); + }); + + it('shows no slim bar without one', async () => { + await renderWithProviders( + , + ); + expect(screen.queryByTestId('price-top-bar')).not.toBeInTheDocument(); + }); + it('shows no banner without one', async () => { await renderWithProviders( , diff --git a/web/src/components/home/Pricing/Pricing.tsx b/web/src/components/home/Pricing/Pricing.tsx index 8e1c54b..d57343d 100644 --- a/web/src/components/home/Pricing/Pricing.tsx +++ b/web/src/components/home/Pricing/Pricing.tsx @@ -1,4 +1,4 @@ -import { Box, Grid } from '@chakra-ui/react'; +import { Box, Flex } from '@chakra-ui/react'; import DeferredImage from '@/components/DeferredImage/DeferredImage'; import PageSection from '@/components/PageSection/PageSection'; import Reveal from '@/components/Reveal/Reveal'; @@ -7,10 +7,12 @@ import type { HomeContent, PricingBanner, PricingPackage, + PricingTopBanner, } from '@/content/types'; import { visiblePackages } from '@/lib/visiblePackages'; import PriceBanner from './PriceBanner'; import PriceCard from './PriceCard'; +import PriceTopBar from './PriceTopBar'; const TITLE_ID = 'pricing-title'; const STAGGER = 0.08; @@ -29,12 +31,20 @@ type PricingProps = { packages: PricingPackage[]; // Optional band under the cards; not a package banner?: PricingBanner | null; + // Optional slim bar above the cards; both may show at the same time + topBanner?: PricingTopBanner | null; }; // "Prijzen": the shoot packages as cards (design .pricing). One column on -// phones and tablets, three from `lg`. Without a valid package the section +// phones and tablets, from `lg` rows of three where an incomplete last row is +// centred, for any number of cards (4, 5, 7, ...). Without a valid package the section // is left out entirely. -export default function Pricing({ content, packages, banner }: PricingProps) { +export default function Pricing({ + content, + packages, + banner, + topBanner, +}: PricingProps) { const shown = visiblePackages(packages); if (shown.length === 0) return null; @@ -67,18 +77,36 @@ export default function Pricing({ content, packages, banner }: PricingProps) { lead={content.lead} /> - + + + )} + {/* Wrapping flex, not a grid: a grid leaves the last row at + the left. Every card is exactly a third of the row minus + the gaps, so the cards of a full row line up and an + incomplete last row is centred. */} + {shown.map((pkg, index) => ( - + ))} - + {banner && ( { }); }); +describe('mapTopBanner', () => { + it('accepts a title, a text or both, and a complete safe link', () => { + expect(mapTopBanner({ title: 'T', text: 'x' })).toMatchObject({ + title: 'T', + text: 'x', + }); + expect(mapTopBanner({ title: '', text: 'x' })?.title).toBeUndefined(); + expect(mapTopBanner({ title: 'T', text: null })?.text).toBeUndefined(); + expect( + mapTopBanner({ + text: 'x', + linkLabel: 'Hier', + linkUrl: '/contact', + })?.link, + ).toEqual({ label: 'Hier', url: '/contact' }); + expect( + mapTopBanner({ + text: 'x', + linkLabel: 'Hier', + linkUrl: 'http://a.nl', + })?.link, + ).toBeUndefined(); + }); + + it('rejects an answer with neither title nor text', () => { + expect(mapTopBanner({ title: ' ', text: '' })).toBeNull(); + expect(mapTopBanner(null)).toBeNull(); + expect(mapTopBanner([{ title: 'T' }])).toBeNull(); + }); +}); + describe('isSafeBannerUrl', () => { it.each(['https://example.nl/x', '/contact', '/#contact', '/a?b=1'])( 'staat %s toe', diff --git a/web/src/lib/offerings.ts b/web/src/lib/offerings.ts index 53710e0..7a85fc1 100644 --- a/web/src/lib/offerings.ts +++ b/web/src/lib/offerings.ts @@ -27,9 +27,18 @@ export interface OfferingBanner { link?: { label: string; url: string }; } +// The slim bar above the cards (GET /api/v1/offerings/banner?position=top). +// The title may be empty here, but not both title and text. +export interface OfferingTopBanner { + title?: string; + text?: string; + link?: { label: string; url: string }; +} + export interface SiteOfferings { packages: OfferingPackage[]; banner: OfferingBanner | null; + topBanner: OfferingTopBanner | null; } const SLUG = /^[a-z0-9-]+$/; @@ -116,6 +125,22 @@ export function mapBanner(answer: unknown): OfferingBanner | null { }; } +// The 200 answer of /api/v1/offerings/banner?position=top: one line, so a +// title, a text or both; null when it has neither +export function mapTopBanner(answer: unknown): OfferingTopBanner | null { + if (!isObject(answer)) return null; + const title = asText(answer.title); + const text = asText(answer.text); + if (!title && !text) return null; + const label = asText(answer.linkLabel); + const url = asText(answer.linkUrl); + return { + title, + text, + link: label && url && isSafeBannerUrl(url) ? { label, url } : undefined, + }; +} + const orderOf = (raw: RawOffering) => typeof raw.displayOrder === 'number' ? raw.displayOrder : 0; diff --git a/web/src/routes/index.tsx b/web/src/routes/index.tsx index 62d4ec0..ae86676 100644 --- a/web/src/routes/index.tsx +++ b/web/src/routes/index.tsx @@ -11,6 +11,7 @@ import homeContent from '../content/homeContent'; import instagramContent from '../content/instagramContent'; import { useBanner, + useTopBanner, usePackages, } from '../components/PackagesProvider/PackagesProvider'; import testimonials from '../content/testimonials'; @@ -34,6 +35,7 @@ export const Route = createFileRoute('/')({ function Index() { const packages = usePackages(); const banner = useBanner(); + const topBanner = useTopBanner(); const { pakket: searched } = Route.useSearch(); // The search only counts after hydration, so the prerendered HTML and the // first browser render agree (BR-HYD-10) @@ -51,6 +53,7 @@ function Index() { content={homeContent.pricing} packages={packages} banner={banner} + topBanner={topBanner} />