diff --git a/web/config/offerings.test.ts b/web/config/offerings.test.ts index 521f19c..739d3e0 100644 --- a/web/config/offerings.test.ts +++ b/web/config/offerings.test.ts @@ -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' }), diff --git a/web/config/offerings.ts b/web/config/offerings.ts index ed46f24..f65ebd5 100644 --- a/web/config/offerings.ts +++ b/web/config/offerings.ts @@ -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), }; } diff --git a/web/src/components/home/Pricing/PriceBanner.tsx b/web/src/components/home/Pricing/PriceBanner.tsx index 71fe0a1..157f700 100644 --- a/web/src/components/home/Pricing/PriceBanner.tsx +++ b/web/src/components/home/Pricing/PriceBanner.tsx @@ -10,6 +10,8 @@ type PriceBannerProps = { // layout=banner in the CMS), for an offer or an announcement. It is not a // bookable package: the button only leads to the contact form, without a // chosen package. The price is free text from the CMS ("€ 99 i.p.v. € 150"). +// Only the title is required; whatever is empty is left out. Without a button +// label the button says "Neem contact op". export default function PriceBanner({ banner }: PriceBannerProps) { const linkButton = useRecipe({ key: 'linkButton' }); @@ -60,23 +62,25 @@ export default function PriceBanner({ banner }: PriceBannerProps) { )} - - {banner.priceText} - + {banner.priceText && ( + + {banner.priceText} + + )} {banner.priceNote && ( - + {banner.priceNote} )} {banner.ctaLabel ?? 'Neem contact op'} diff --git a/web/src/components/home/Pricing/Pricing.test.tsx b/web/src/components/home/Pricing/Pricing.test.tsx index 56a4bf6..6344547 100644 --- a/web/src/components/home/Pricing/Pricing.test.tsx +++ b/web/src/components/home/Pricing/Pricing.test.tsx @@ -63,6 +63,27 @@ describe('Pricing', () => { expect(await axeResults(container)).toHaveNoViolations(); }); + it('hides every empty field of the banner', async () => { + const { container } = await renderWithProviders( + , + ); + const shown = screen.getByTestId('price-banner'); + expect( + within(shown).getByRole('heading', { level: 3 }), + ).toHaveTextContent('Past er niets bij?'); + expect(shown.querySelectorAll('ul, li')).toHaveLength(0); + // Only the heading and the button have text + expect(shown.querySelectorAll('p')).toHaveLength(0); + expect( + within(shown).getByRole('link', { name: 'Neem contact op' }), + ).toBeInTheDocument(); + expect(await axeResults(container)).toHaveNoViolations(); + }); + it('shows no banner without one', async () => { await renderWithProviders( , diff --git a/web/src/content/types.ts b/web/src/content/types.ts index 33ef3c2..95ce0f2 100644 --- a/web/src/content/types.ts +++ b/web/src/content/types.ts @@ -103,11 +103,12 @@ export interface PricingPackage { // The one optional banner under the price cards (an offering with // layout=banner in the CMS). It is not a bookable package: it is not in the -// form's choices and not in the package count. The price is free text. +// form's choices and not in the package count. The price is free text. Only +// the title is required; the banner hides what is empty. export interface PricingBanner { title: string; - description: string; - priceText: string; + description?: string; + priceText?: string; priceNote?: string; features: string[]; ctaLabel?: string;