Adds the Prijzen section to the homepage
Shows the three live packages as cards with their price and what is included. Each card links to the contact section with ?pakket=<id>, so the contact form can preselect it. Invalid packages from the CMS are skipped and the pakket value is only accepted when it names a package. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -132,6 +132,7 @@ describe('homepage', () => {
|
||||
screen.getByRole('region', {
|
||||
name: 'Lifestyle fotograaf met een passie voor storytelling',
|
||||
}),
|
||||
screen.getByRole('region', { name: 'Prijzen' }),
|
||||
];
|
||||
|
||||
let previous: Element = hero;
|
||||
@@ -147,6 +148,19 @@ describe('homepage', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('homepage ?pakket=', () => {
|
||||
it.each(['/?pakket=newborn', '/?pakket=123', '/?pakket=%3Cscript%3E'])(
|
||||
'%s renders the homepage without errors',
|
||||
async (path) => {
|
||||
await renderApp(path);
|
||||
expect(
|
||||
await screen.findByRole('region', { name: 'Prijzen' }),
|
||||
).toBeInTheDocument();
|
||||
expect(document.body).not.toHaveTextContent('<script>');
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe('pagina-register', () => {
|
||||
it('bevat precies de routes van de route tree', async () => {
|
||||
const { router } = await renderApp('/');
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 42 KiB |
@@ -0,0 +1,45 @@
|
||||
import { screen, within } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import packages from '@/content/packages';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import PriceCard from './PriceCard';
|
||||
|
||||
const newborn = packages[1];
|
||||
|
||||
describe('PriceCard', () => {
|
||||
it('shows the name, price, features and a booking link with the package', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<PriceCard pkg={newborn} />,
|
||||
);
|
||||
const card = screen.getByTestId('price-card-newborn');
|
||||
expect(
|
||||
within(card).getByRole('heading', { level: 3 }),
|
||||
).toHaveTextContent('Newborn');
|
||||
// Raw text: Testing Library's matchers would turn the non-breaking
|
||||
// space into a normal one
|
||||
expect(card.textContent).toContain('€\u00a0185');
|
||||
expect(
|
||||
within(card)
|
||||
.getAllByRole('listitem')
|
||||
.map((item) => item.textContent),
|
||||
).toEqual(newborn.features);
|
||||
|
||||
const link = within(card).getByRole('link', { name: 'Boek Newborn' });
|
||||
expect(link).toHaveAttribute('href', '/?pakket=newborn#contact');
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('uses "Boek je shoot" with the name for screen readers when the name is long', async () => {
|
||||
await renderWithProviders(
|
||||
<PriceCard
|
||||
pkg={{ ...newborn, id: 'bruiloft', name: 'Bruiloft en feest' }}
|
||||
/>,
|
||||
);
|
||||
const link = screen.getByRole('link', {
|
||||
name: 'Boek je shoot: Bruiloft en feest',
|
||||
});
|
||||
expect(link).toHaveTextContent('Boek je shoot');
|
||||
expect(link).toHaveAttribute('href', '/?pakket=bruiloft#contact');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,98 @@
|
||||
import {
|
||||
Box,
|
||||
Heading,
|
||||
List,
|
||||
Text,
|
||||
useRecipe,
|
||||
VisuallyHidden,
|
||||
} from '@chakra-ui/react';
|
||||
import { Link } from '@tanstack/react-router';
|
||||
import type { PricingPackage } from '@/content/types';
|
||||
import { bookLabel } from '@/lib/bookLabel';
|
||||
import { formatPrice } from '@/lib/formatPrice';
|
||||
|
||||
type PriceCardProps = {
|
||||
pkg: PricingPackage;
|
||||
};
|
||||
|
||||
// One package (design .price-card): name, price, what is included and a
|
||||
// link that takes the visitor to the contact form with this package chosen.
|
||||
export default function PriceCard({ pkg }: PriceCardProps) {
|
||||
const label = bookLabel(pkg.name);
|
||||
const linkButton = useRecipe({ key: 'linkButton' });
|
||||
|
||||
return (
|
||||
<Box
|
||||
as="article"
|
||||
data-testid={`price-card-${pkg.id}`}
|
||||
display="flex"
|
||||
flexDirection="column"
|
||||
h="100%"
|
||||
px="clamp(1.5rem, 3vw, 2.5rem)"
|
||||
py="clamp(2rem, 3.5vw, 3rem)"
|
||||
bg="white"
|
||||
borderWidth="1px"
|
||||
borderColor="line"
|
||||
textAlign="center"
|
||||
transitionProperty="transform, box-shadow, border-color"
|
||||
transitionDuration="interaction"
|
||||
transitionTimingFunction="smooth"
|
||||
_hover={{
|
||||
transform: 'translateY(-6px)',
|
||||
borderColor: 'accent',
|
||||
boxShadow: 'lift',
|
||||
}}
|
||||
_motionReduce={{ _hover: { transform: 'none' } }}
|
||||
>
|
||||
<Heading as="h3" fontSize="1.75rem" mb={3}>
|
||||
{pkg.name}
|
||||
</Heading>
|
||||
{/* accent.deep instead of the design's accent: meets 4.5:1 (NFR-HP-01) */}
|
||||
<Text
|
||||
fontFamily="heading"
|
||||
fontSize="2.25rem"
|
||||
lineHeight="1"
|
||||
color="accent.deep"
|
||||
mb={6}
|
||||
>
|
||||
{formatPrice(pkg.price)}
|
||||
</Text>
|
||||
<List.Root
|
||||
listStyleType="none"
|
||||
display="grid"
|
||||
gap={3}
|
||||
mb={8}
|
||||
py={6}
|
||||
borderBlockWidth="1px"
|
||||
borderColor="line"
|
||||
color="ink.soft"
|
||||
fontSize="sm"
|
||||
>
|
||||
{pkg.features.map((feature) => (
|
||||
<List.Item key={feature}>{feature}</List.Item>
|
||||
))}
|
||||
</List.Root>
|
||||
{/* The router's own Link keeps the route types, so search is
|
||||
checked against the homepage's ?pakket=; the button style
|
||||
goes on via asChild */}
|
||||
<Box
|
||||
asChild
|
||||
css={linkButton({ size: 'fit' })}
|
||||
alignSelf="center"
|
||||
mt="auto"
|
||||
>
|
||||
<Link
|
||||
to="/"
|
||||
search={{ pakket: pkg.id }}
|
||||
hash="contact"
|
||||
data-testid={`price-card-${pkg.id}-book`}
|
||||
>
|
||||
{label.visible}
|
||||
{label.hidden && (
|
||||
<VisuallyHidden>{label.hidden}</VisuallyHidden>
|
||||
)}
|
||||
</Link>
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import { screen, within } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import homeContent from '@/content/homeContent';
|
||||
import packages from '@/content/packages';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import Pricing from './Pricing';
|
||||
|
||||
const content = homeContent.pricing;
|
||||
|
||||
describe('Pricing', () => {
|
||||
it('shows the heading and one card per package, in order', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<Pricing content={content} packages={packages} />,
|
||||
);
|
||||
const section = screen.getByRole('region', { name: 'Prijzen' });
|
||||
expect(within(section).getByText('Pakketten')).toBeInTheDocument();
|
||||
expect(
|
||||
within(section)
|
||||
.getAllByRole('heading', { level: 3 })
|
||||
.map((heading) => heading.textContent),
|
||||
).toEqual(['Zwangerschap', 'Newborn', 'Gezin']);
|
||||
expect(
|
||||
within(section)
|
||||
.getAllByRole('link')
|
||||
.map((link) => link.getAttribute('href')),
|
||||
).toEqual([
|
||||
'/?pakket=zwangerschap#contact',
|
||||
'/?pakket=newborn#contact',
|
||||
'/?pakket=gezin#contact',
|
||||
]);
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('keeps the decorations away from assistive technology', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<Pricing content={content} packages={packages} />,
|
||||
);
|
||||
// The only images here are the decorations: empty alt and aria-hidden
|
||||
expect(screen.queryAllByRole('img')).toHaveLength(0);
|
||||
const images = container.querySelectorAll('img');
|
||||
expect(images).toHaveLength(content.decorations.length);
|
||||
images.forEach((image) => {
|
||||
expect(image).toHaveAttribute('alt', '');
|
||||
expect(image).toHaveAttribute('aria-hidden', 'true');
|
||||
});
|
||||
});
|
||||
|
||||
it('skips invalid packages', async () => {
|
||||
await renderWithProviders(
|
||||
<Pricing
|
||||
content={content}
|
||||
packages={[{ ...packages[0], price: 0 }, packages[1]]}
|
||||
/>,
|
||||
);
|
||||
expect(
|
||||
screen
|
||||
.getAllByRole('heading', { level: 3 })
|
||||
.map((h) => h.textContent),
|
||||
).toEqual(['Newborn']);
|
||||
});
|
||||
|
||||
it('leaves the section out when no package is valid', async () => {
|
||||
await renderWithProviders(<Pricing content={content} packages={[]} />);
|
||||
expect(screen.queryByRole('region', { name: 'Prijzen' })).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,73 @@
|
||||
import { Box, Grid } from '@chakra-ui/react';
|
||||
import DeferredImage from '@/components/DeferredImage/DeferredImage';
|
||||
import HomeSection from '@/components/HomeSection/HomeSection';
|
||||
import Reveal from '@/components/Reveal/Reveal';
|
||||
import SectionHeading from '@/components/SectionHeading/SectionHeading';
|
||||
import type { HomeContent, PricingPackage } from '@/content/types';
|
||||
import { visiblePackages } from '@/lib/visiblePackages';
|
||||
import PriceCard from './PriceCard';
|
||||
|
||||
const TITLE_ID = 'pricing-title';
|
||||
const STAGGER = 0.08;
|
||||
|
||||
// Where the two decorations sit (design .pricing__deco--1 and --2). The
|
||||
// design measures from the whole section; here they sit in the content box,
|
||||
// so the second one moves down into the section's bottom padding, or the
|
||||
// last card would cover it.
|
||||
const decorationPositions = [
|
||||
{ top: '8%', left: '2%' },
|
||||
{ bottom: 'calc(-0.6 * {spacing.sectionY})', right: '2%' },
|
||||
];
|
||||
|
||||
type PricingProps = {
|
||||
content: HomeContent['pricing'];
|
||||
packages: PricingPackage[];
|
||||
};
|
||||
|
||||
// "Prijzen": the shoot packages as cards (design .pricing). One column on
|
||||
// phones and tablets, three from `lg`. Without a valid package the section
|
||||
// is left out entirely.
|
||||
export default function Pricing({ content, packages }: PricingProps) {
|
||||
const shown = visiblePackages(packages);
|
||||
if (shown.length === 0) return null;
|
||||
|
||||
return (
|
||||
<HomeSection labelledBy={TITLE_ID} data-testid="pricing">
|
||||
<Box position="relative" isolation="isolate">
|
||||
{content.decorations.map((decoration, index) => (
|
||||
<DeferredImage
|
||||
key={decoration.src}
|
||||
image={decoration}
|
||||
aria-hidden="true"
|
||||
position="absolute"
|
||||
zIndex={-1}
|
||||
w="clamp(90px, 10vw, 160px)"
|
||||
h="auto"
|
||||
opacity={0.55}
|
||||
pointerEvents="none"
|
||||
{...decorationPositions[index % 2]}
|
||||
/>
|
||||
))}
|
||||
<Reveal>
|
||||
<SectionHeading
|
||||
id={TITLE_ID}
|
||||
title={content.title}
|
||||
lead={content.lead}
|
||||
/>
|
||||
</Reveal>
|
||||
<Grid
|
||||
templateColumns={{ base: '1fr', lg: 'repeat(3, 1fr)' }}
|
||||
gap="gridGap"
|
||||
maxW={{ base: '460px', lg: 'none' }}
|
||||
mx="auto"
|
||||
>
|
||||
{shown.map((pkg, index) => (
|
||||
<Reveal key={pkg.id} delay={index * STAGGER} h="100%">
|
||||
<PriceCard pkg={pkg} />
|
||||
</Reveal>
|
||||
))}
|
||||
</Grid>
|
||||
</Box>
|
||||
</HomeSection>
|
||||
);
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import intro2 from '../assets/home/intro-2.jpg';
|
||||
import intro3 from '../assets/home/intro-3.jpg';
|
||||
import intro4 from '../assets/home/intro-4.jpg';
|
||||
import andrea from '../assets/home/andrea.jpg';
|
||||
import deco1 from '../assets/home/deco-1.png';
|
||||
import deco2 from '../assets/home/deco-2.png';
|
||||
|
||||
// Static content of the homepage sections until the CMS API exists; the API
|
||||
// will then deliver this object.
|
||||
@@ -56,6 +58,14 @@ const homeContent: HomeContent = {
|
||||
},
|
||||
link: { label: 'Lees mijn verhaal', to: '/over-mij' },
|
||||
},
|
||||
pricing: {
|
||||
title: 'Prijzen',
|
||||
lead: 'Pakketten',
|
||||
decorations: [
|
||||
{ src: deco1, alt: '', width: 143, height: 112 },
|
||||
{ src: deco2, alt: '', width: 239, height: 224 },
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
export default homeContent;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import type { PricingPackage } from './types';
|
||||
|
||||
// The shoot packages until the CMS API exists (live site, October 2026), in
|
||||
// display order. Andrea uses the small business scheme (KOR): no VAT.
|
||||
const packages: PricingPackage[] = [
|
||||
{
|
||||
id: 'zwangerschap',
|
||||
name: 'Zwangerschap',
|
||||
price: 175,
|
||||
features: [
|
||||
'1 uur fotografie',
|
||||
"Minstens 30 zorgvuldig nabewerkte foto's",
|
||||
'Persoonlijke online fotogalerij',
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'newborn',
|
||||
name: 'Newborn',
|
||||
price: 185,
|
||||
features: [
|
||||
'1-2 uur fotografie',
|
||||
"Minstens 40 zorgvuldig nabewerkte foto's",
|
||||
'Persoonlijke online fotogalerij',
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'gezin',
|
||||
name: 'Gezin',
|
||||
price: 175,
|
||||
features: [
|
||||
'1 uur fotografie',
|
||||
"Minstens 30 zorgvuldig nabewerkte foto's",
|
||||
'Persoonlijke online fotogalerij',
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export default packages;
|
||||
@@ -31,6 +31,15 @@ export interface ContentImage {
|
||||
height: number;
|
||||
}
|
||||
|
||||
// A priced shoot offer. id is a stable slug: it goes into ?pakket= and is
|
||||
// the shoot value the contact form sends.
|
||||
export interface PricingPackage {
|
||||
id: string;
|
||||
name: string;
|
||||
price: number; // whole euros
|
||||
features: string[];
|
||||
}
|
||||
|
||||
// Content of the homepage sections below the hero
|
||||
export interface HomeContent {
|
||||
intro: {
|
||||
@@ -46,6 +55,12 @@ export interface HomeContent {
|
||||
// A route, so a wrong link is a type error
|
||||
link: { label: string; to: RoutePath };
|
||||
};
|
||||
pricing: {
|
||||
title: string;
|
||||
lead: string;
|
||||
// Purely decorative illustrations, alt=""
|
||||
decorations: ContentImage[];
|
||||
};
|
||||
}
|
||||
|
||||
export interface HeroSlide {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import fc from 'fast-check';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { BOOK_LABEL_MAX_NAME, bookLabel } from './bookLabel';
|
||||
|
||||
describe('bookLabel', () => {
|
||||
it('puts short names in the visible text', () => {
|
||||
expect(bookLabel('Newborn')).toEqual({ visible: 'Boek Newborn' });
|
||||
expect(bookLabel('Zwangerschap')).toEqual({
|
||||
visible: 'Boek Zwangerschap',
|
||||
});
|
||||
});
|
||||
|
||||
it('falls back to "Boek je shoot" with a hidden name for long names', () => {
|
||||
expect(bookLabel('Bruiloft en feest')).toEqual({
|
||||
visible: 'Boek je shoot',
|
||||
hidden: ': Bruiloft en feest',
|
||||
});
|
||||
});
|
||||
|
||||
it('always names the package and follows the length rule (invariant)', () => {
|
||||
fc.assert(
|
||||
fc.property(fc.string({ maxLength: 40 }), (name) => {
|
||||
const label = bookLabel(name);
|
||||
expect(`${label.visible}${label.hidden ?? ''}`).toContain(name);
|
||||
if (name.length <= BOOK_LABEL_MAX_NAME) {
|
||||
expect(label).toEqual({ visible: `Boek ${name}` });
|
||||
} else {
|
||||
expect(label.visible).toBe('Boek je shoot');
|
||||
}
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
// Longest package name that still fits as "Boek <name>" on one line in the
|
||||
// card's button down to a 320px phone (BR-BOOK-02, BR-BOOK-03)
|
||||
export const BOOK_LABEL_MAX_NAME = 14;
|
||||
|
||||
export interface BookLabel {
|
||||
visible: string;
|
||||
// Extra text for screen readers only
|
||||
hidden?: string;
|
||||
}
|
||||
|
||||
// Text of a card's booking link. Short names go in the visible text; for
|
||||
// longer ones the button says "Boek je shoot" and the name is added for
|
||||
// screen readers, so every link still names its package.
|
||||
export function bookLabel(name: string): BookLabel {
|
||||
if (name.length <= BOOK_LABEL_MAX_NAME) {
|
||||
return { visible: `Boek ${name}` };
|
||||
}
|
||||
return { visible: 'Boek je shoot', hidden: `: ${name}` };
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import fc from 'fast-check';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { formatPrice } from './formatPrice';
|
||||
|
||||
const NBSP = '\u00a0';
|
||||
|
||||
describe('formatPrice', () => {
|
||||
it('formats whole euros the Dutch way', () => {
|
||||
expect(formatPrice(175)).toBe(`€${NBSP}175`);
|
||||
expect(formatPrice(1250)).toBe(`€${NBSP}1.250`);
|
||||
});
|
||||
|
||||
it('gives back the amount from its digits (round-trip)', () => {
|
||||
fc.assert(
|
||||
fc.property(fc.integer({ min: 1, max: 1_000_000 }), (price) => {
|
||||
expect(Number(formatPrice(price).replace(/\D/g, ''))).toBe(
|
||||
price,
|
||||
);
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('starts with the euro sign and a non-breaking space, and has no breaking space (invariant)', () => {
|
||||
fc.assert(
|
||||
fc.property(fc.integer({ min: 1, max: 1_000_000 }), (price) => {
|
||||
const text = formatPrice(price);
|
||||
expect(text.startsWith(`€${NBSP}`)).toBe(true);
|
||||
expect(/[ \t\n\u202f]/.test(text)).toBe(false);
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
const euros = new Intl.NumberFormat('nl-NL', {
|
||||
style: 'currency',
|
||||
currency: 'EUR',
|
||||
maximumFractionDigits: 0,
|
||||
});
|
||||
|
||||
// A price in whole euros as shown on the cards: "€ 175", "€ 1.250". Any space
|
||||
// the browser puts in (some use a narrow one) becomes a non-breaking space,
|
||||
// so the price never wraps (BR-PRICE-01).
|
||||
export function formatPrice(price: number): string {
|
||||
return euros.format(price).replace(/\s/g, '\u00a0');
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import fc from 'fast-check';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import packages from '../content/packages';
|
||||
import { uniquePackages } from '../test/arbitraries';
|
||||
import { packageFromSearch } from './packageFromSearch';
|
||||
|
||||
// Random upper/lower case per letter, plus spaces around
|
||||
const mangled = (id: string) =>
|
||||
fc
|
||||
.tuple(
|
||||
fc.array(fc.boolean(), {
|
||||
minLength: id.length,
|
||||
maxLength: id.length,
|
||||
}),
|
||||
fc.constantFrom('', ' ', ' '),
|
||||
fc.constantFrom('', ' ', '\t'),
|
||||
)
|
||||
.map(
|
||||
([upper, before, after]) =>
|
||||
before +
|
||||
[...id]
|
||||
.map((char, i) => (upper[i] ? char.toUpperCase() : char))
|
||||
.join('') +
|
||||
after,
|
||||
);
|
||||
|
||||
describe('packageFromSearch', () => {
|
||||
it('finds a package by id, ignoring case and spaces', () => {
|
||||
expect(packageFromSearch('newborn', packages)).toBe('newborn');
|
||||
expect(packageFromSearch(' Gezin ', packages)).toBe('gezin');
|
||||
});
|
||||
|
||||
it('ignores unknown or non-text values', () => {
|
||||
expect(packageFromSearch('bruiloft', packages)).toBeUndefined();
|
||||
expect(packageFromSearch('', packages)).toBeUndefined();
|
||||
expect(packageFromSearch(123, packages)).toBeUndefined();
|
||||
expect(packageFromSearch(['newborn'], packages)).toBeUndefined();
|
||||
expect(packageFromSearch(undefined, packages)).toBeUndefined();
|
||||
});
|
||||
|
||||
it('only returns undefined or one of the given ids (invariant)', () => {
|
||||
fc.assert(
|
||||
fc.property(fc.anything(), uniquePackages, (value, list) => {
|
||||
const result = packageFromSearch(value, list);
|
||||
expect(
|
||||
result === undefined ||
|
||||
list.some((pkg) => pkg.id === result),
|
||||
).toBe(true);
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('finds every package in any letter case with spaces around (oracle)', () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
uniquePackages
|
||||
.filter((list) => list.length > 0)
|
||||
.chain((list) =>
|
||||
fc
|
||||
.integer({ min: 0, max: list.length - 1 })
|
||||
.chain((i) =>
|
||||
mangled(list[i].id).map(
|
||||
(value) =>
|
||||
[list, list[i].id, value] as const,
|
||||
),
|
||||
),
|
||||
),
|
||||
([list, id, value]) => {
|
||||
expect(packageFromSearch(value, list)).toBe(id);
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it('never matches a value that is not text (invariant)', () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.anything().filter((value) => typeof value !== 'string'),
|
||||
uniquePackages,
|
||||
(value, list) => {
|
||||
expect(packageFromSearch(value, list)).toBeUndefined();
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it('gives the same id when its result is fed back in (idempotent)', () => {
|
||||
fc.assert(
|
||||
fc.property(fc.string(), uniquePackages, (value, list) => {
|
||||
const once = packageFromSearch(value, list);
|
||||
expect(packageFromSearch(once, list)).toBe(once);
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
import type { PricingPackage } from '../content/types.ts';
|
||||
|
||||
// The package id from ?pakket=, if it names one of the given packages.
|
||||
// Letter case and surrounding spaces do not matter; anything else (unknown
|
||||
// id, number, array, missing) is ignored. Only our own ids can come out, so
|
||||
// the value from the URL is never reflected on the page (BR-PARAM-01).
|
||||
export function packageFromSearch(
|
||||
value: unknown,
|
||||
packages: readonly PricingPackage[],
|
||||
): string | undefined {
|
||||
if (typeof value !== 'string') return undefined;
|
||||
const wanted = value.trim().toLowerCase();
|
||||
return packages.find((pkg) => pkg.id === wanted)?.id;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import fc from 'fast-check';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import packages from '../content/packages';
|
||||
import { anyPackage, uniquePackages } from '../test/arbitraries';
|
||||
import { isValidPackage, visiblePackages } from './visiblePackages';
|
||||
|
||||
const valid = packages[0];
|
||||
|
||||
describe('visiblePackages', () => {
|
||||
it('keeps the live packages as they are', () => {
|
||||
expect(visiblePackages(packages)).toEqual(packages);
|
||||
});
|
||||
|
||||
it('skips packages that break an invariant', () => {
|
||||
const broken = [
|
||||
{ ...valid, id: 'Hoofdletters' },
|
||||
{ ...valid, id: 'leeg-naam', name: ' ' },
|
||||
{ ...valid, id: 'gratis', price: 0 },
|
||||
{ ...valid, id: 'negatief', price: -10 },
|
||||
{ ...valid, id: 'centen', price: 12.5 },
|
||||
{ ...valid, id: 'geen-getal', price: Number.NaN },
|
||||
{ ...valid, id: 'niets', features: [] },
|
||||
{ ...valid, id: 'lege-regel', features: ['1 uur', ' '] },
|
||||
];
|
||||
expect(visiblePackages([...broken, valid])).toEqual([valid]);
|
||||
});
|
||||
|
||||
it('keeps the first of two packages with the same id', () => {
|
||||
const second = { ...valid, name: 'Dubbel' };
|
||||
expect(visiblePackages([valid, second])).toEqual([valid]);
|
||||
});
|
||||
|
||||
it('only returns valid packages with unique ids (invariant)', () => {
|
||||
fc.assert(
|
||||
fc.property(fc.array(anyPackage), (input) => {
|
||||
const result = visiblePackages(input);
|
||||
expect(result.every(isValidPackage)).toBe(true);
|
||||
const ids = result.map((pkg) => pkg.id);
|
||||
expect(new Set(ids).size).toBe(ids.length);
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('is a subsequence of the input in the same order (invariant)', () => {
|
||||
fc.assert(
|
||||
fc.property(fc.array(anyPackage), (input) => {
|
||||
const result = visiblePackages(input);
|
||||
let i = 0;
|
||||
for (const item of input) {
|
||||
if (item === result[i]) i++;
|
||||
}
|
||||
return i === result.length;
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('is idempotent', () => {
|
||||
fc.assert(
|
||||
fc.property(fc.array(anyPackage), (input) => {
|
||||
const once = visiblePackages(input);
|
||||
expect(visiblePackages(once)).toEqual(once);
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('returns valid, unique packages unchanged (oracle)', () => {
|
||||
fc.assert(
|
||||
fc.property(uniquePackages, (input) => {
|
||||
expect(visiblePackages(input)).toEqual(input);
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
import type { PricingPackage } from '../content/types.ts';
|
||||
|
||||
const SLUG = /^[a-z0-9-]+$/;
|
||||
|
||||
// Whether a package meets the invariants in domain-entities.md
|
||||
export function isValidPackage(pkg: PricingPackage): boolean {
|
||||
return (
|
||||
SLUG.test(pkg.id) &&
|
||||
pkg.name.trim() !== '' &&
|
||||
Number.isInteger(pkg.price) &&
|
||||
pkg.price > 0 &&
|
||||
pkg.features.length > 0 &&
|
||||
pkg.features.every((feature) => feature.trim() !== '')
|
||||
);
|
||||
}
|
||||
|
||||
// The packages that can be shown: invalid ones from the CMS are skipped
|
||||
// rather than breaking the page, and of two packages with the same id the
|
||||
// first wins. The order stays the same (BR-PRICE-02).
|
||||
export function visiblePackages(
|
||||
packages: readonly PricingPackage[],
|
||||
): PricingPackage[] {
|
||||
const seen = new Set<string>();
|
||||
return packages.filter((pkg) => {
|
||||
if (!isValidPackage(pkg) || seen.has(pkg.id)) return false;
|
||||
seen.add(pkg.id);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
@@ -51,9 +51,19 @@ const linkButtonRecipe = defineRecipe({
|
||||
},
|
||||
},
|
||||
},
|
||||
size: {
|
||||
default: {},
|
||||
// Never wraps; less side padding on phones so a longer label
|
||||
// still fits inside a card (BR-BOOK-03)
|
||||
fit: {
|
||||
whiteSpace: 'nowrap',
|
||||
px: { base: '1.25rem', sm: '2.4rem' },
|
||||
},
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: 'outline',
|
||||
size: 'default',
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -1,13 +1,21 @@
|
||||
import { createFileRoute } from '@tanstack/react-router';
|
||||
import Hero from '../components/Hero/Hero';
|
||||
import AboutBlock from '../components/home/AboutBlock/AboutBlock';
|
||||
import Pricing from '../components/home/Pricing/Pricing';
|
||||
import IntroGallery from '../components/home/IntroGallery/IntroGallery';
|
||||
import heroContent from '../content/heroContent';
|
||||
import homeContent from '../content/homeContent';
|
||||
import packages from '../content/packages';
|
||||
import siteContent from '../content/siteContent';
|
||||
import { pageHead } from '../seo';
|
||||
|
||||
// ?pakket= from a "Boek" link on a price card. Only text is kept; whether it
|
||||
// names a real package is checked against the shown packages (BR-PARAM-01).
|
||||
type HomeSearch = { pakket?: string };
|
||||
|
||||
export const Route = createFileRoute('/')({
|
||||
validateSearch: (search: Record<string, unknown>): HomeSearch =>
|
||||
typeof search.pakket === 'string' ? { pakket: search.pakket } : {},
|
||||
head: () => pageHead('/'),
|
||||
component: Index,
|
||||
});
|
||||
@@ -19,6 +27,7 @@ function Index() {
|
||||
<Hero content={heroContent} socials={siteContent.socials} />
|
||||
<IntroGallery content={homeContent.intro} />
|
||||
<AboutBlock content={homeContent.about} />
|
||||
<Pricing content={homeContent.pricing} packages={packages} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import fc from 'fast-check';
|
||||
import type { EmailAddress, SocialLink } from '../content/types';
|
||||
import type {
|
||||
EmailAddress,
|
||||
PricingPackage,
|
||||
SocialLink,
|
||||
} from '../content/types';
|
||||
|
||||
// Gedeelde generators voor de property-based tests (fast-check)
|
||||
|
||||
@@ -47,3 +51,47 @@ export const anyEmail: fc.Arbitrary<EmailAddress> = fc.oneof(
|
||||
validEmail,
|
||||
fc.record({ user: fc.string(), domain: fc.string() }),
|
||||
);
|
||||
|
||||
// Package ids: a few fixed ones so lists contain duplicates, plus random slugs
|
||||
const packageId = fc.oneof(
|
||||
fc.constantFrom('newborn', 'gezin', 'zwangerschap'),
|
||||
fc.stringMatching(/^[a-z0-9-]{1,16}$/),
|
||||
);
|
||||
const nonBlank = fc
|
||||
.string({ minLength: 1, maxLength: 30 })
|
||||
.filter((text) => text.trim() !== '');
|
||||
|
||||
// A package that meets every invariant
|
||||
export const pricingPackage: fc.Arbitrary<PricingPackage> = fc.record({
|
||||
id: packageId,
|
||||
name: nonBlank,
|
||||
price: fc.integer({ min: 1, max: 5000 }),
|
||||
features: fc.array(nonBlank, { minLength: 1, maxLength: 5 }),
|
||||
});
|
||||
|
||||
// Valid packages with unique ids, as a well-behaved CMS would deliver them
|
||||
export const uniquePackages = fc.uniqueArray(pricingPackage, {
|
||||
selector: (pkg) => pkg.id,
|
||||
maxLength: 6,
|
||||
});
|
||||
|
||||
// Valid and broken packages mixed, as a CMS might deliver them
|
||||
export const anyPackage: fc.Arbitrary<PricingPackage> = fc.oneof(
|
||||
pricingPackage,
|
||||
fc.record({
|
||||
id: fc.oneof(
|
||||
packageId,
|
||||
fc.constantFrom('', 'Newborn', 'met spatie', 'a/b'),
|
||||
fc.string(),
|
||||
),
|
||||
name: fc.oneof(nonBlank, fc.constantFrom('', ' ')),
|
||||
price: fc.oneof(
|
||||
fc.integer({ min: 1, max: 5000 }),
|
||||
fc.constantFrom(0, -5, 12.5, Number.NaN, Infinity),
|
||||
),
|
||||
features: fc.oneof(
|
||||
fc.array(nonBlank, { maxLength: 3 }),
|
||||
fc.constant<string[]>(['', 'x']),
|
||||
),
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -95,6 +95,12 @@ const config = defineConfig({
|
||||
// Binnen de header: de hamburger boven het logo en menu
|
||||
menuToggle: { value: 1 },
|
||||
},
|
||||
shadows: {
|
||||
// Soft shadow under a lifted card on hover (design --shadow-md)
|
||||
lift: {
|
||||
value: '0 12px 40px color-mix(in srgb, {colors.ink} 12%, transparent)',
|
||||
},
|
||||
},
|
||||
gradients: {
|
||||
// Donker verloop over hero-foto's, zodat witte tekst leesbaar blijft
|
||||
scrim: {
|
||||
|
||||
Reference in New Issue
Block a user