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

97 lines
5.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';
import {updateReleaseBadge} from '../scripts/release-branding.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('the emitted shared header reads release authority and falls back to release.json',async()=>{
const runtime=sharedHomepageHeaderScript(read('web/index.html'));
const api='https://cp.dunerealms.com/api/menu-badges';
assert(runtime.includes(api));
assert.match(runtime,/update\(releaseBadge,releaseApi,release\)/);
assert(runtime.includes(updateReleaseBadge.toString()));
const built={stage:'alpha',version:'1.0.1.0'};
const release=JSON.parse(read('web/release.json'));
const badge={};
const requested=[];
const run=async responses=>{
requested.length=0;
await updateReleaseBadge(badge,api,built,async(url,options)=>{
requested.push(url);
assert.deepEqual(options,{cache:'no-store'});
return {ok:responses.has(url),json:async()=>responses.get(url)};
});
};
await run(new Map([[api,{stage:'beta',releaseVersion:'1.0.1.7'}]]));
assert.deepEqual(requested,[api]);
assert.equal(badge.textContent,'Beta 1.0.1.7');
await run(new Map([[api,{stage:'beta',releaseVersion:'1.0.1'}],['/release.json',release]]));
assert.deepEqual(requested,[api,'/release.json']);
assert.equal(badge.textContent,(release.stage==='beta'?'Beta':'Alpha')+' '+release.version);
await run(new Map());
assert.deepEqual(requested,[api,'/release.json']);
assert.equal(badge.textContent,'Alpha 1.0.1.0');
});
test('footer sponsors use the approved existing logos and native fallback avatars never force replacement',()=>{
const chrome=read('scripts/site-chrome.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(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/);
});