Updates the packages and the banner live in the browser

The build still bakes the current packages and the active banner into the HTML.
After hydration the page asks /api/v1/offerings and /api/v1/offerings/banner
once and replaces what differs; errors and time-outs keep what was baked, and
a 204 from the banner route hides the banner. The banner is now the
OfferingBanner contract (title, text, optional link) instead of layout=banner.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-12 11:19:50 +01:00
co-authored by Claude Sonnet 5.5
parent f9180f231f
commit 12319bb841
22 changed files with 584 additions and 180 deletions
+5
View File
@@ -40,6 +40,11 @@ function mockApi(options: {
await page.route('**/api/v1/**', async (route) => {
const request = route.request();
const path = new URL(request.url()).pathname;
// The live packages call of every page: no live data, and
// not part of what these tests count
if (path.startsWith('/api/v1/offerings')) {
return route.fulfill({ status: 204 });
}
requests.push(`${request.method()} ${path}`);
if (path.endsWith('/token')) {
const { status, body } = options.token ?? {
+79
View File
@@ -0,0 +1,79 @@
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import {
eventually,
openPage,
waitForHydration,
type OpenedPage,
} from './support/browser.ts';
import { startServer } from './support/server.ts';
// De pakketten staan gebakken in de HTML. Na het laden vraagt de pagina het
// CMS (/api/v1/offerings); een afwijkend antwoord vervangt de lijst, een
// fout laat de gebakken lijst staan.
let server: Awaited<ReturnType<typeof startServer>>;
beforeAll(async () => {
server = await startServer();
});
afterAll(() => server.close());
const answer = (price: string) => [
{
slug: 'newborn',
title: 'Newborn',
price,
features: ['Een kenmerk'],
displayOrder: 0,
layout: 'card',
},
];
const mock =
(status: number, body?: unknown) => async (page: OpenedPage['page']) => {
await page.route('**/api/v1/offerings', (route) =>
route.fulfill({
status,
contentType: 'application/json',
body: body === undefined ? '' : JSON.stringify(body),
}),
);
};
const cards = (page: OpenedPage['page']) =>
page.locator('[data-testid^="price-card-"]:not([data-testid$="-book"])');
describe('pakketten live uit het CMS', () => {
it('toont eerst de gebakken pakketten en daarna het antwoord van het CMS', async () => {
const { page } = await openPage(server.origin + '/', {
prepare: mock(200, answer('€ 200')),
});
await waitForHydration(page);
await eventually(() => cards(page).count()).toBe(1);
expect(await cards(page).first().textContent()).toContain('€\u00a0200');
});
it('past ook de keuze in het formulier aan', async () => {
const { page } = await openPage(
server.origin + '/contact?pakket=newborn',
{ prepare: mock(200, answer('€ 200')) },
);
await waitForHydration(page);
await eventually(() =>
page.getByTestId('contact-form-shoot').locator('option').count(),
).toBe(3); // Kies een optie, Newborn, Overig
});
it.each([
['een fout', mock(500)],
['geen gegevens (204)', mock(204)],
['een ongeldig antwoord', mock(200, { error: 'x' })],
['een lijst zonder geldig pakket', mock(200, answer('op aanvraag'))],
])('houdt de gebakken pakketten bij %s', async (_name, prepare) => {
const { page, messages } = await openPage(server.origin + '/', {
prepare,
});
await waitForHydration(page);
await page.waitForTimeout(800);
expect(await cards(page).count()).toBe(3);
expect(messages.filter((m) => !m.includes('500'))).toEqual([]);
});
});