Adds a slim top bar above the packages and centres the last row of cards

The CMS serves a second banner at /api/v1/offerings/banner?position=top. The
site bakes it into the HTML at build time and replaces it live after
hydration, like the banner under the cards, and both may show at once.
The cards now sit in a wrapping flex row so an incomplete last row is centred
for any number of cards on desktop; phone and tablet stay one column.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 12:42:07 +01:00
co-authored by Claude Sonnet 5.5
parent e28188c997
commit 6f1be2f7f5
14 changed files with 474 additions and 20 deletions
+97
View File
@@ -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<number, typeof found>();
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);
});
});