2026-10-14 18:18:54 +02:00
import assert from 'node:assert/strict' ;
import { describe , it } from 'node:test' ;
import { CONTENT_LANGUAGES } from './content-languages.ts' ;
2026-10-14 19:23:16 +02:00
import { CATEGORY_FORMULA_RULES , localizedCategoryPromptExample } from './categories/prompt-examples.ts' ;
2026-10-14 18:18:54 +02:00
const sections = [ 'title' , 'description' , 'meta' ] as const ;
2026-10-14 19:23:16 +02:00
const expectedTagOrder = [ 'p' , 'h2' , 'p' , 'h2' , 'ul' ];
2026-10-14 18:18:54 +02:00
2026-10-14 19:23:16 +02:00
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 ) {
2026-10-14 18:18:54 +02:00
for ( const section of sections ) {
2026-10-14 19:23:16 +02:00
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` );
2026-10-14 18:18:54 +02:00
}
2026-10-14 19:23:16 +02:00
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` );
2026-10-14 18:18:54 +02:00
}
});
2026-10-14 19:23:16 +02:00
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 );
2026-10-14 18:18:54 +02:00
});
});
2026-10-14 20:02:42 +02:00
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 );
}
});
});