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', () => {
|
it('slaat ongeldige kaarten over en behoudt de rest', () => {
|
||||||
const result = mapOfferings([
|
const result = mapOfferings([
|
||||||
card({ slug: 'Slecht Id' }),
|
card({ slug: 'Slecht Id' }),
|
||||||
|
|||||||
@@ -19,10 +19,11 @@ export interface OfferingPackage {
|
|||||||
featured?: boolean;
|
featured?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only the title is required: the banner hides every field that is empty
|
||||||
export interface OfferingBanner {
|
export interface OfferingBanner {
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description?: string;
|
||||||
priceText: string;
|
priceText?: string;
|
||||||
priceNote?: string;
|
priceNote?: string;
|
||||||
features: string[];
|
features: string[];
|
||||||
ctaLabel?: string;
|
ctaLabel?: string;
|
||||||
@@ -87,15 +88,13 @@ function toPackage(raw: RawOffering): OfferingPackage | null {
|
|||||||
|
|
||||||
function toBanner(raw: RawOffering): OfferingBanner | null {
|
function toBanner(raw: RawOffering): OfferingBanner | null {
|
||||||
const title = asText(raw.title);
|
const title = asText(raw.title);
|
||||||
const priceText = asText(raw.price);
|
if (!title) return null;
|
||||||
const features = asFeatures(raw.features);
|
|
||||||
if (!title || !priceText || !features) return null;
|
|
||||||
return {
|
return {
|
||||||
title,
|
title,
|
||||||
description: asText(raw.description) ?? '',
|
description: asText(raw.description),
|
||||||
priceText,
|
priceText: asText(raw.price),
|
||||||
priceNote: asText(raw.priceNote),
|
priceNote: asText(raw.priceNote),
|
||||||
features,
|
features: asFeatures(raw.features) ?? [],
|
||||||
ctaLabel: asText(raw.ctaLabel),
|
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
|
// 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
|
// 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").
|
// 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) {
|
export default function PriceBanner({ banner }: PriceBannerProps) {
|
||||||
const linkButton = useRecipe({ key: 'linkButton' });
|
const linkButton = useRecipe({ key: 'linkButton' });
|
||||||
|
|
||||||
@@ -60,23 +62,25 @@ export default function PriceBanner({ banner }: PriceBannerProps) {
|
|||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
<Box textAlign={{ base: 'start', md: 'center' }}>
|
<Box textAlign={{ base: 'start', md: 'center' }}>
|
||||||
<Text
|
{banner.priceText && (
|
||||||
fontFamily="heading"
|
<Text
|
||||||
fontSize="1.75rem"
|
fontFamily="heading"
|
||||||
lineHeight="1.1"
|
fontSize="1.75rem"
|
||||||
color="white"
|
lineHeight="1.1"
|
||||||
>
|
color="white"
|
||||||
{banner.priceText}
|
>
|
||||||
</Text>
|
{banner.priceText}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
{banner.priceNote && (
|
{banner.priceNote && (
|
||||||
<Text fontSize="sm" opacity={0.85} mb={4}>
|
<Text fontSize="sm" opacity={0.85}>
|
||||||
{banner.priceNote}
|
{banner.priceNote}
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
<Box
|
<Box
|
||||||
asChild
|
asChild
|
||||||
css={linkButton({ variant: 'light', size: 'fit' })}
|
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">
|
<Link to="/" hash="contact" data-testid="price-banner-cta">
|
||||||
{banner.ctaLabel ?? 'Neem contact op'}
|
{banner.ctaLabel ?? 'Neem contact op'}
|
||||||
|
|||||||
@@ -63,6 +63,27 @@ describe('Pricing', () => {
|
|||||||
expect(await axeResults(container)).toHaveNoViolations();
|
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 () => {
|
it('shows no banner without one', async () => {
|
||||||
await renderWithProviders(
|
await renderWithProviders(
|
||||||
<Pricing content={content} packages={packages} banner={null} />,
|
<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
|
// 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
|
// 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 {
|
export interface PricingBanner {
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description?: string;
|
||||||
priceText: string;
|
priceText?: string;
|
||||||
priceNote?: string;
|
priceNote?: string;
|
||||||
features: string[];
|
features: string[];
|
||||||
ctaLabel?: string;
|
ctaLabel?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user