forked from unimatrix/web
16 lines
2.8 KiB
JavaScript
16 lines
2.8 KiB
JavaScript
import test from 'node:test';import assert from 'node:assert/strict';import {readFileSync,readdirSync,existsSync} from 'node:fs';
|
|
import {applyRealmPageDesign,REALM_PAGE_DESIGNS} from '../scripts/realm-page-design.mjs';
|
|
const web=new URL('../web/',import.meta.url);
|
|
test('every public document opts into the common design and every legacy page owns a labelled illustrated banner',()=>{
|
|
const files=readdirSync(web).filter(f=>f.endsWith('.html'));assert.equal(files.length,38);
|
|
for(const file of files){const html=readFileSync(new URL(file,web),'utf8');assert.match(html,/data-realm-design/,file);assert.match(html,/realm-design\.css/,file);assert.match(html,/realm-design\.js/,file);if(REALM_PAGE_DESIGNS[file]){assert.match(html,/data-realm-layout="2"/,file);assert.equal((html.match(/class="dr-page-banner"/g)||[]).length,1,file);assert(html.indexOf('class="dr-page-banner"')<html.indexOf('<main'),file+' banner must precede nested content grids');}}
|
|
for(const d of Object.values(REALM_PAGE_DESIGNS))assert(existsSync(new URL('assets/'+d.icon,web)),d.icon);
|
|
});
|
|
test('page migration preserves functional element identities and keeps the banner outside a nested manual grid',()=>{
|
|
const source='<!doctype html><html lang="en"><head><title>Manual</title><script src="manual.js" defer></script></head><body><header><a>Old navigation</a></header><div class="manual-layout"><aside id="chapter-nav"></aside><main id="chapter-content" tabindex="-1"><form id="chapter-search"><input name="q"></form></main></div></body></html>',next=applyRealmPageDesign(source,'manual.html');
|
|
assert(next.indexOf('class="dr-page-banner"')<next.indexOf('class="manual-layout"'));assert.match(next,/<main id="chapter-content" tabindex="-1" class="dr-page-content">/);assert.match(next,/<form id="chapter-search"><input name="q"><\/form>/);assert.match(next,/<script src="manual.js" defer>/);assert.match(next,/href="\/realm-design\.css/);assert.match(next,/src="\/realm-design\.js/);assert.equal(applyRealmPageDesign(next,'manual.html'),next);assert.equal((next.match(/class="dune-site-header"/g)||[]).length,1);
|
|
});
|
|
test('all standalone CP documents load the same design without changing their feature scripts',()=>{
|
|
for(const name of ['user-service.html','clan-center.html','servers.html','cp-v2/index.html','cp-v2/cp-v2-mentat-embed.html','cp-v2/reserve-ledger.html','dmpaint/index.html']){const html=readFileSync(new URL('../control-panel/public/'+name,import.meta.url),'utf8');assert.match(html,/realm-design\.css/,name);assert.match(html,/src="\/v2\/cp-v2-realm-design\.mjs/,name);}
|
|
const terms=readFileSync(new URL('../control-panel/public/terms.html',import.meta.url),'utf8');assert.match(terms,/^<section class="terms-document"/);assert.doesNotMatch(terms,/<head|<script/); // This legal fragment inherits its host's design; its accepted text is unchanged.
|
|
});
|

Staff