import test from 'node:test'; import assert from 'node:assert/strict'; import {readFileSync,readdirSync} from 'node:fs'; import {applySharedHeader,applySharedFooter,SHARED_FOOTER,assertSharedChrome} from '../scripts/site-chrome.mjs'; import {SHARED_HEADER} from '../scripts/portal-navigation.mjs'; import {homepageHeaderTemplate,sharedHomepageHeaderScript,sharedHomepageHeaderFallback} from '../scripts/homepage-header.mjs'; test('shared chrome replaces legacy navigation without changing page forms or dialogs',()=>{ const content='
'; const old='
'+content+''; const next=applySharedFooter(applySharedHeader(old,SHARED_HEADER)); assert(next.includes(content));assert(next.includes(SHARED_HEADER));assert(next.includes(SHARED_FOOTER));assert(!next.includes('Old footer')); assert.equal(applySharedFooter(applySharedHeader(next,SHARED_HEADER)),next); }); test('homepage retains its original header and dropdowns while sharing the footer',()=>{ const source=readFileSync(new URL('../web/index.html',import.meta.url),'utf8'); const next=applySharedFooter(applySharedHeader(source,SHARED_HEADER,'index.html')); assert(next.includes(SHARED_HEADER)); assert.equal(SHARED_HEADER,sharedHomepageHeaderFallback(source)); assert(SHARED_HEADER.includes(homepageHeaderTemplate(source).replace('
','
').replace('
',''))); assert(sharedHomepageHeaderScript(source).includes(JSON.stringify(homepageHeaderTemplate(source)))); assert(next.includes('id="portal-navigation"'));assert(next.includes('data-play'));assert(next.includes('id="play-dialog"'));assert(next.includes('id="world-dialog"')); assert.equal(assertSharedChrome(next,SHARED_HEADER,'index.html'),next); assert.throws(()=>assertSharedChrome(next.replace('assertSharedChrome(next.replace('{ const memorial='',legal=''; const next=applySharedFooter(''+legal+'
'+memorial+'
Old links'+memorial+'
'); assert(next.includes(memorial));assert(next.includes(legal));assert.equal((next.match(/class="dune-memorial"/g)||[]).length,1); }); test('all authored public pages can be normalised to one shared footer',()=>{ const web=new URL('../web/',import.meta.url);for(const name of readdirSync(web).filter(n=>n.endsWith('.html'))){const old=readFileSync(new URL(name,web),'utf8');const next=applySharedFooter(old);assert.equal((next.match(/data-shared-chrome="3"/g)||[]).length,1,name);} }); test('publication refuses duplicate or divergent chrome instead of silently keeping a page-specific variant',()=>{const valid=''+SHARED_HEADER+SHARED_FOOTER+'';assert.equal(assertSharedChrome(valid,SHARED_HEADER),valid);assert.throws(()=>assertSharedChrome(valid.replace('',SHARED_HEADER+''),SHARED_HEADER));assert.throws(()=>assertSharedChrome(valid.replace('Play now','Different header'),SHARED_HEADER));assert.throws(()=>assertSharedChrome(valid.replace('','
'),SHARED_HEADER));});