web/website/tests/realm-switch.test.mjs

5 lines
1.5 KiB
JavaScript

import test from 'node:test';import assert from 'node:assert/strict';import {realmSurface,renderRealmSwitch,withRealmSwitch} from '../scripts/realm-switch.mjs';import {MAIN_MENU} from '../scripts/main-menu.mjs';
test('realm switches are limited to the three organisation surfaces, never Boards or other public pages',()=>{for(const [url,expected]of [['https://clans.dunerealms.com/','clan'],['https://corp.dunerealms.com/','company'],['https://www.dunerealms.com/government.html','politics'],['https://forums.dunerealms.com/',null],['https://www.dunerealms.com/',null],['https://www.dunerealms.com/exchange.html',null],['https://support.dunerealms.com/',null],['https://www.dunerealms.com/realm-hub.html',null]])assert.equal(realmSurface(url),expected);const script=withRealmSwitch(withRealmSwitch('base'));assert.equal(script.split('/* Dune realm switch begin */').length,2);});
test('the canonical header uses the agreed names and keeps links for non-roleplay services',()=>{assert.deepEqual(MAIN_MENU.map(([name])=>name),['Home','Shop','Community','Starport','Realm Hub','My Account','Support','Wiki']);assert.equal(MAIN_MENU.find(([name])=>name==='Shop')[1],'https://shop.dunerealms.com/');});
test('the retired banner switch is removed without changing the banner or primary menu',()=>{let removed=0;const doc={querySelector(selector){assert.equal(selector,'[data-realm-switch]');return {remove(){removed++;}};}};renderRealmSwitch(doc,'https://clans.dunerealms.com/');assert.equal(removed,1);});