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:
@@ -3,6 +3,7 @@ import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
isSafeBannerUrl,
|
||||
mapBanner,
|
||||
mapTopBanner,
|
||||
mapOfferings,
|
||||
parsePriceText,
|
||||
} from './offerings';
|
||||
@@ -164,6 +165,37 @@ describe('mapBanner', () => {
|
||||
});
|
||||
});
|
||||
|
||||
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',
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user