cms-client: hero uit het datablok #cms-data (parseHero, doelcontrole, titelregels en afgeleide kop, useCmsHero) met tests

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 16:48:55 +01:00
co-authored by Claude Sonnet 5.5
parent 02f3d9e931
commit 72dd381cf9
11 changed files with 364 additions and 0 deletions
@@ -0,0 +1,47 @@
import fc from 'fast-check';
import { describe, expect, it } from 'vitest';
import { headingFromLines, titleLines } from '../title';
describe('titleLines', () => {
it('splits on line breaks and trims', () => {
expect(titleLines('Websites,\napps\n& meer.')).toEqual(['Websites,', 'apps', '& meer.']);
expect(titleLines(' a \r\n b\r c ')).toEqual(['a', 'b', 'c']);
});
it('drops empty lines', () => {
expect(titleLines('\n\na\n\n b \n')).toEqual(['a', 'b']);
expect(titleLines(' \n ')).toEqual([]);
});
it('property: no line is empty, has line breaks or has outer spaces', () => {
fc.assert(
fc.property(fc.string(), (title) =>
titleLines(title).every(
(line) => line !== '' && line === line.trim() && !/[\r\n]/.test(line),
),
),
);
});
});
describe('headingFromLines (screen-reader and search-engine heading)', () => {
it('puts the brand prefix before the lines joined with single spaces (the seed title)', () => {
expect(headingFromLines(['Websites,', 'apps', '& meer.'], 'SLP Software:')).toBe(
'SLP Software: Websites, apps & meer.',
);
});
it('works without a prefix and with a single line', () => {
expect(headingFromLines(['Alleen'])).toBe('Alleen');
expect(headingFromLines(['Alleen'], ' ')).toBe('Alleen');
});
it('property: the heading is the prefix, a space and the lines joined by spaces', () => {
fc.assert(
fc.property(
fc.array(fc.string({ minLength: 1 }), { minLength: 1 }),
(lines) => headingFromLines(lines, 'SLP Software:') === `SLP Software: ${lines.join(' ')}`,
),
);
});
});