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:
@@ -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;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user