Lets the price banner work with empty fields

Only the banner title is required; description, price, price note, features
and the button label are left out when empty (the button then says Neem contact
op).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-12 09:42:35 +01:00
co-authored by Claude Sonnet 5.5
parent 4cae76b21d
commit f9180f231f
5 changed files with 74 additions and 21 deletions
+28
View File
@@ -97,6 +97,34 @@ describe('mapOfferings', () => {
});
});
it('neemt een banner met alleen een titel; lege velden blijven leeg', () => {
const result = mapOfferings([
card(),
card({
slug: 'actie',
title: 'Past er niets bij?',
description: '',
price: '',
priceNote: '',
ctaLabel: '',
features: [],
layout: 'banner',
}),
]);
expect(result?.banner).toEqual({
title: 'Past er niets bij?',
description: undefined,
priceText: undefined,
priceNote: undefined,
features: [],
ctaLabel: undefined,
});
expect(
mapOfferings([card(), card({ title: ' ', layout: 'banner' })])
?.banner,
).toBeNull();
});
it('slaat ongeldige kaarten over en behoudt de rest', () => {
const result = mapOfferings([
card({ slug: 'Slecht Id' }),
+7 -8
View File
@@ -19,10 +19,11 @@ export interface OfferingPackage {
featured?: boolean;
}
// Only the title is required: the banner hides every field that is empty
export interface OfferingBanner {
title: string;
description: string;
priceText: string;
description?: string;
priceText?: string;
priceNote?: string;
features: string[];
ctaLabel?: string;
@@ -87,15 +88,13 @@ function toPackage(raw: RawOffering): OfferingPackage | null {
function toBanner(raw: RawOffering): OfferingBanner | null {
const title = asText(raw.title);
const priceText = asText(raw.price);
const features = asFeatures(raw.features);
if (!title || !priceText || !features) return null;
if (!title) return null;
return {
title,
description: asText(raw.description) ?? '',
priceText,
description: asText(raw.description),
priceText: asText(raw.price),
priceNote: asText(raw.priceNote),
features,
features: asFeatures(raw.features) ?? [],
ctaLabel: asText(raw.ctaLabel),
};
}