Translation files, step 0: typed text helper, checks and the baseline of the pages
Adds src/i18n (t, tList, tPlural over typed Dutch JSON, key and parameter checks), the first text (back to top) as proof, a baseline tool for the prerendered pages (pnpm baseline:save and baseline:check), a lint warning for text typed straight into JSX, and docs/translations.md. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { firstDifferences, normalizeHtml } from './htmlBaseline.ts';
|
||||
|
||||
describe('normalizeHtml', () => {
|
||||
it('keeps text, links, labels, meta and structured data', () => {
|
||||
const html =
|
||||
'<html><head><title>Titel</title><meta name="description" content="Tekst"/>' +
|
||||
'<link rel="canonical" href="https://a.nl/"/></head><body>' +
|
||||
'<a href="/over-mij" aria-label="Naar over mij">Over mij</a>' +
|
||||
'<script type="application/ld+json">{"a":1}</script></body></html>';
|
||||
const out = normalizeHtml(html);
|
||||
for (const part of [
|
||||
'<title>Titel</title>',
|
||||
'content="Tekst"',
|
||||
'rel="canonical"',
|
||||
'aria-label="Naar over mij"',
|
||||
'Over mij',
|
||||
'{"a":1}',
|
||||
]) {
|
||||
expect(out).toContain(part);
|
||||
}
|
||||
});
|
||||
|
||||
it('leaves out look and build details', () => {
|
||||
const html =
|
||||
'<style data-emotion="css">.a{}</style><script src="/assets/x-AbCd1234.js"></script>' +
|
||||
'<link rel="stylesheet" href="/assets/y-AbCd1234.css"/><!-- opmerking -->' +
|
||||
'<div class="css-1abc" style="color:red" data-reveal="hidden" id="x">tekst</div>' +
|
||||
'<img src="/assets/foto-AbCd1234.jpg"/><noscript><style>.b{}</style></noscript>';
|
||||
const out = normalizeHtml(html);
|
||||
expect(out).not.toMatch(
|
||||
/css-1abc|color:red|data-reveal|opmerking|\.a\{|stylesheet|AbCd1234.js/,
|
||||
);
|
||||
expect(out).toContain('<div id="x">');
|
||||
expect(out).toContain('/assets/foto.jpg');
|
||||
expect(out).toContain(
|
||||
'<noscript>' + String.fromCharCode(10) + '</noscript>',
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps the CMS markers and the data block', () => {
|
||||
const html =
|
||||
'<!--CMS:DATA--><script type="application/json" id="cms-data">{"x":1}</script>' +
|
||||
'<!--CMS:OFFERINGS-HTML-->a<!--/CMS:OFFERINGS-HTML-->';
|
||||
const out = normalizeHtml(html);
|
||||
expect(out).toContain('<!--CMS:DATA-->');
|
||||
expect(out).toContain('{"x":1}');
|
||||
expect(out).toContain('<!--/CMS:OFFERINGS-HTML-->');
|
||||
});
|
||||
|
||||
it('notices a changed word', () => {
|
||||
expect(normalizeHtml('<p>een</p>')).not.toBe(
|
||||
normalizeHtml('<p>twee</p>'),
|
||||
);
|
||||
});
|
||||
|
||||
it('puts one tag per line and ends with a newline', () => {
|
||||
expect(normalizeHtml('<ul> <li>a</li> <li>b</li> </ul>')).toBe(
|
||||
'<ul>\n<li>a</li>\n<li>b</li>\n</ul>\n',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('firstDifferences', () => {
|
||||
it('shows the lines that differ, at most a few', () => {
|
||||
const out = firstDifferences('a\nb\nc', 'a\nB\nc\nd');
|
||||
expect(out.join('\n')).toContain('regel 2');
|
||||
expect(out.join('\n')).toContain('basislijn: b');
|
||||
expect(out.join('\n')).toContain('nu: B');
|
||||
expect(out.join('\n')).toContain('(geen)');
|
||||
expect(firstDifferences('a', 'a')).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user