Files
SlpSoftware/src/cms-client/hero/__tests__/title.test.ts
T

48 lines
1.6 KiB
TypeScript

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(' ')}`,
),
);
});
});