Files
descrybe/apps/web/src/lib/category-prompt-examples.test.ts
T
2026-10-14 20:02:42 +02:00

50 lines
3.0 KiB
TypeScript

import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { CONTENT_LANGUAGES } from './content-languages.ts';
import { CATEGORY_FORMULA_RULES, localizedCategoryPromptExample } from './categories/prompt-examples.ts';
const sections = ['title', 'description', 'meta'] as const;
const expectedTagOrder = ['p', 'h2', 'p', 'h2', 'ul'];
describe('localized category prompt SEO formulas', () => {
it('covers every supported language with localized title, HTML description and SEO meta instructions', () => {
assert.equal(Object.keys(CATEGORY_FORMULA_RULES).length, CONTENT_LANGUAGES.length);
for (const { value: language } of CONTENT_LANGUAGES) {
for (const section of sections) {
const rule = localizedCategoryPromptExample(language, section);
assert.equal(rule, CATEGORY_FORMULA_RULES[language][section]);
assert.ok(rule.length > 90, `${language}/${section} incomplete`);
assert.ok(rule.includes('{') && rule.includes('}'), `${language}/${section} missing instruction braces`);
}
const description = CATEGORY_FORMULA_RULES[language].description;
assert.deepEqual([...description.matchAll(/<(p|h2|ul)(?=>)/g)].map((m) => m[1]), expectedTagOrder, `${language} wrong HTML order`);
assert.equal((description.match(/<ul><li>\{/g) ?? []).length, 1, `${language} needs one specs list`);
assert.ok(!description.includes('<h1>'), `${language} must not add another product H1`);
assert.ok(description.includes('{{name}}') && description.includes('{{attrs}}'), `${language} missing evidence tokens`);
assert.ok(CATEGORY_FORMULA_RULES[language].meta.includes('meta_title:'));
assert.ok(CATEGORY_FORMULA_RULES[language].meta.includes('meta_description:'));
assert.ok(!/five distinct H2|approximately 100 words below each|pet različitih naslova H2|pet različnih naslovov H2/i.test(description), `${language} old bloated SEO template`);
}
});
it('shows actual localized HTML when changing languages, not a one-line summary', () => {
const hr = localizedCategoryPromptExample('hr', 'description');
const en = localizedCategoryPromptExample('en', 'description');
assert.match(hr, /Tehničke specifikacije/);
assert.match(en, /Technical specifications/);
assert.ok(hr.includes('<h2>{') && hr.includes('<ul><li>{'));
assert.notEqual(hr, en);
});
});
describe('canonical default template across languages', () => {
it('never mixes the previous English five-benefit formula with localized SEO defaults', () => {
for (const { value: language } of CONTENT_LANGUAGES) {
const rule = CATEGORY_FORMULA_RULES[language];
assert.equal((rule.description.match(/<h2>/g) ?? []).length, 2, language);
assert.equal((rule.description.match(/<p>/g) ?? []).length, 2, language);
assert.equal((rule.description.match(/<ul>/g) ?? []).length, 1, language);
assert.doesNotMatch(rule.description, /first verified benefit|fifth verified benefit|Write five different H2/i);
}
});
});