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:
@@ -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' }),
|
||||
|
||||
@@ -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),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
)}
|
||||
</Box>
|
||||
<Box textAlign={{ base: 'start', md: 'center' }}>
|
||||
<Text
|
||||
fontFamily="heading"
|
||||
fontSize="1.75rem"
|
||||
lineHeight="1.1"
|
||||
color="white"
|
||||
>
|
||||
{banner.priceText}
|
||||
</Text>
|
||||
{banner.priceText && (
|
||||
<Text
|
||||
fontFamily="heading"
|
||||
fontSize="1.75rem"
|
||||
lineHeight="1.1"
|
||||
color="white"
|
||||
>
|
||||
{banner.priceText}
|
||||
</Text>
|
||||
)}
|
||||
{banner.priceNote && (
|
||||
<Text fontSize="sm" opacity={0.85} mb={4}>
|
||||
<Text fontSize="sm" opacity={0.85}>
|
||||
{banner.priceNote}
|
||||
</Text>
|
||||
)}
|
||||
<Box
|
||||
asChild
|
||||
css={linkButton({ variant: 'light', size: 'fit' })}
|
||||
mt={banner.priceNote ? 0 : 4}
|
||||
mt={banner.priceText || banner.priceNote ? 4 : 0}
|
||||
>
|
||||
<Link to="/" hash="contact" data-testid="price-banner-cta">
|
||||
{banner.ctaLabel ?? 'Neem contact op'}
|
||||
|
||||
@@ -63,6 +63,27 @@ describe('Pricing', () => {
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('hides every empty field of the banner', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<Pricing
|
||||
content={content}
|
||||
packages={packages}
|
||||
banner={{ title: 'Past er niets bij?', features: [] }}
|
||||
/>,
|
||||
);
|
||||
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(
|
||||
<Pricing content={content} packages={packages} banner={null} />,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user