MC/website/tests/template-fix-6000.test.mjs
2026-11-27 23:43:05 +00:00

65 lines
4.8 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'));
});
test('shared footer canonical markers prevent legacy observers re-appending canonical links',()=>{
assert.match(read('scripts/site-chrome.mjs'),/data-dune-api-footer="1" href="https:\/\/www\.dunerealms\.com\/api\.html"/);
assert.match(read('scripts/site-chrome.mjs'),/data-bank-rates="1" href="https:\/\/www\.dunerealms\.com\/rates-and-charges\.html"/);
const runtime=read('web/realm-design.js'),css=read('scripts/shared-footer.css');
assert.match(runtime,/if\(embedded\)\{for\(const footer of footers\)footer\.hidden=true/);
assert.match(runtime,/footer\.querySelectorAll\('.dune-memorial'\)/);
assert.match(runtime,/keeper\.after\(notice\)/);
assert.match(css,/footer\.dune-shared-footer nav\{display:flex!important/);
assert.match(css,/html\.dune-embedded body\.dr-design footer\.dune-shared-footer/);
});
test('footer sponsors use the approved existing logos, version badge reads the authority, and native fallback avatars never force replacement',()=>{
const chrome=read('scripts/site-chrome.mjs'),header=read('scripts/homepage-header.mjs'),runtime=read('web/realm-design.js'),support=read('scripts/osticket-presentation.css'),footer=read('scripts/shared-footer.css');
assert.match(chrome,/corrino-group-v4\.png/);assert.match(chrome,/data:image\/svg\+xml;base64,/);
assert.match(header,/\/api\/menu-badges/);assert.match(header,/\/release\.json/);assert.match(header,/releaseBadge\.textContent='Alpha '\+version/);
assert.match(runtime,/\['mm','mp'\]\.includes\(fallback\)/);assert.match(runtime,/!u\.searchParams\.has\('forcedefault'\)/);assert.match(runtime,/support-avatar-default\.png/);
assert.match(support,/\.thread-body \.attachments\{background:#17372c/);
assert.match(footer,/\.dune-footer-sponsors\{flex-direction:row!important/);assert.match(footer,/a\.skip:not\(:focus-visible\)/);
assert.match(read('scripts/mybb-presentation.css'),/\.wrapper>\.navigation\+br\{display:none!important/);
});