import assert from 'node:assert/strict'; import { readFile } from 'node:fs/promises'; import test from 'node:test'; const readProjectFile = (path) => readFile(new URL(`../../${path}`, import.meta.url), 'utf8'); test('theme toggle metadata is dynamic, localized, and frontend-only', async () => { const metadata = JSON.parse(await readProjectFile('blocks/theme-toggle/block.json')); assert.equal(metadata.apiVersion, 3); assert.equal(metadata.name, 'chrnx/theme-toggle'); assert.equal(metadata.textdomain, 'chrnx'); assert.equal(metadata.render, 'file:./render.php'); assert.equal(metadata.viewScript, 'file:../../assets/js/theme-toggle.js'); assert.equal(metadata.script, undefined); }); test('header controls use one progressive shell script and retain panel markup', async () => { const headerToolsMetadata = JSON.parse(await readProjectFile('blocks/header-tools/block.json')); const mobileMenuMetadata = JSON.parse(await readProjectFile('blocks/mobile-menu-toggle/block.json')); const headerToolsRender = await readProjectFile('blocks/header-tools/render.php'); const themeToggleRender = await readProjectFile('blocks/theme-toggle/render.php'); assert.equal(headerToolsMetadata.viewScript, undefined); assert.equal(mobileMenuMetadata.viewScript, 'file:../../assets/js/navigation.js'); assert.match(headerToolsRender, /data-chrnx-search-panel/); assert.match(headerToolsRender, /data-chrnx-search-button[\s\S]+aria-controls=/); assert.match(headerToolsRender, /data-chrnx-search-button[\s\S]+aria-expanded="true"/); assert.match(themeToggleRender, /data-chrnx-theme-button/); assert.match(themeToggleRender, /data-chrnx-theme-panel/); assert.match(themeToggleRender, /'Choose color theme', 'chrnx'/); assert.match(themeToggleRender, /wp_unique_id\( 'chrnx-theme-panel-'/); }); for (const asset of ['chrnx-cat.svg', 'chrnx-wordmark.svg']) { test(`${asset} is an inert, local, vector-only asset`, async () => { const svg = await readProjectFile(`assets/icons/${asset}`); assert.match(svg, /^ { const cat = await readProjectFile('assets/icons/chrnx-cat.svg'); const wordmark = await readProjectFile('assets/icons/chrnx-wordmark.svg'); const geometry = cat.match(/]*>([\s\S]*?)<\/g>/)?.[1].trim(); assert.ok(geometry, 'standalone cat must expose its canonical geometry group'); assert.ok(wordmark.includes(geometry), 'wordmark must contain the exact canonical cat geometry'); assert.match(wordmark, /]*>CHRNX<\/text>/); assert.match(wordmark, /Zen Maru Gothic/); }); test('footer user-facing copy lives in an extractable PHP render block', async () => { const part = await readProjectFile('parts/footer.html'); const render = await readProjectFile('blocks/footer-content/render.php'); assert.match(part, //); assert.doesNotMatch(part, /Made in Sinaloa|Journal|Footer navigation/); const navHelper = await readProjectFile('inc/blocks.php'); for (const text of ['Footer navigation', 'Made in Sinaloa, shared from home.']) { assert.ok(render.includes(`'${text}', 'chrnx'`), `${text} must use the chrnx text domain`); } // The link labels moved to the shared navigation helper, still translatable. for (const text of ['Journal', 'Projects', 'Music', 'Podcasts', 'About']) { assert.ok(navHelper.includes(`'${text}', 'chrnx'`), `${text} must use the chrnx text domain`); } }); test('header navigation and search copy lives in one extractable PHP render block', async () => { const part = await readProjectFile('parts/header.html'); const render = await readProjectFile('blocks/header-tools/render.php'); assert.match(part, //); assert.doesNotMatch(part, /wp:navigation|wp:navigation-link|wp:search|Journal|Primary navigation/); const navHelper = await readProjectFile('inc/blocks.php'); for (const text of ['Primary navigation', 'Search', 'Open search']) { assert.ok(render.includes(`'${text}', 'chrnx'`), `${text} must use the chrnx text domain`); } for (const text of ['Journal', 'Projects', 'Music', 'Podcasts', 'About']) { assert.ok(navHelper.includes(`'${text}', 'chrnx'`), `${text} must use the chrnx text domain`); } // The built-in destinations remain the fallback when no menu is assigned. assert.match(navHelper, /home_url\( '\/' \. \$slug \. '\/' \)/); assert.match(navHelper, /get_nav_menu_locations\(\)/); assert.match(render, /home_url\( '\/' \)/); });