web/website/tests/template-fix-6000.test.mjs

46 lines
2.9 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {readFileSync} from 'node:fs';
import {sharedHomepageHeaderFallback,sharedHomepageHeaderScript,homepageHeaderTemplate} from '../scripts/homepage-header.mjs';
import {SHARED_HEADER} from '../scripts/portal-navigation.mjs';
import {MAIN_MENU_GROUPS} from '../scripts/main-menu.mjs';
const read=path=>readFileSync(new URL('../'+path,import.meta.url),'utf8');
test('Template Fix 6000 generates one shared header from the original homepage and retains PR602 menu destinations',()=>{
const original=read('web/index.html'),runtime=sharedHomepageHeaderScript(original);
assert.equal(SHARED_HEADER,sharedHomepageHeaderFallback(original));
assert(runtime.includes(JSON.stringify(homepageHeaderTemplate(original))));
assert(runtime.includes(JSON.stringify(MAIN_MENU_GROUPS)));
assert.doesNotThrow(()=>new Function(runtime));
assert.match(runtime,/window\.top!==window\.self/);
assert.match(runtime,/context\.staffAccess!==true/);
assert.match(runtime,/dialog\.showModal\(\)/);
});
test('native support keeps the authored workspace intro and native themes do not target unrelated sites',()=>{
assert.match(read('web/realm-design.js'),/\.arrival-grid,\.dune-support-workspace-hero/);
const support=read('scripts/osticket-presentation.css');
for(const selector of ['#ticketTable','#ticketForm','.thread-entry','.redactor-editor','.ui-dialog','.queue'])assert(support.includes(selector));
assert.match(support,/body:is\(\.dune-support,\.dr-native-support\)/);
assert.doesNotMatch(support,/display:\s*none/);
});
test('native forum status artwork maps every actual MyBB state and board shortcuts are only a no-row fallback',()=>{
const css=read('scripts/mybb-presentation.css'),sections=read('integrations/mybb/inc/plugins/dune_sections.php');
for(const [state,icon]of [['forum_on','new'],['forum_off','read'],['forum_offclose','locked'],['forum_offlink','link']]){
assert(css.includes('.'+state));
assert(css.includes('forum-status-'+icon+'.svg'));
assert.match(read('web/assets/forum-status-'+icon+'.svg'),/^<svg /);
}
assert(!sections.includes('Subcategories</span>'));
assert.match(sections,/if\(\$rows&&!empty\(\$rows\['forum_list'\]\)\)/);
assert.match(sections,/else if\(\$children\).*dune_sections_links\(\$children\)/);
assert.match(sections,/forum_permissions/);
assert.match(sections,/forum_password_validated/);
});
test('native publisher and website build publish the same header and both presentation styles',()=>{
const build=read('scripts/build.mjs'),pub=read('ops/publish-realm-design.py');
for(const name of ['homepage-header.css','osticket-presentation.css','mybb-presentation.css']){
assert(build.includes(name));assert(pub.includes(name));
}
assert(build.includes('sharedHomepageHeaderScript()'));
assert(pub.includes('data-shared-header-source="homepage"'));
assert(pub.includes('mybb/inc/plugins/dune_sections.php'));
});