Build central Political CP with campaign cards and imperial artwork

This commit is contained in:
unimatrixgit 2026-11-15 21:43:04 +01:00
commit 84edcf31e7

View file

@ -9,8 +9,8 @@ import {governmentRoute,politicalFrameMessage} from '../web/government-cp.js';
import {workspacesForSurface} from '../control-panel/public/cp-v2/cp-v2-surface.mjs';
import {politicsCPDocument} from '../control-panel/politics-cp-shell.mjs';
test('Political CP exposes exactly Elections, Offices and Tools with every existing chamber',()=>{
assert.deepEqual(POLITICAL_TABS.map(t=>t.label),['Elections','Offices','Tools']);
test('Political CP exposes central Elections, Voting Directory, Offices and Tools menus with every existing chamber',()=>{
assert.deepEqual(POLITICAL_TABS.map(t=>t.label),['Elections','Voting Directory','Offices','Tools']);
const pages=POLITICAL_TABS.flatMap(t=>t.pages.map(([id])=>id));assert.equal(new Set(pages).size,pages.length);
for(const tab of POLITICAL_TABS)for(const [page]of tab.pages){const route=tab.id+'/'+page;assert.deepEqual(politicalRoute('#'+route),{tab:tab.id,page});assert.equal(governmentRoute(route),route);assert.equal(governmentRoute('politics/'+page),route);assert.equal(politicsDestination('politics',page),'https://www.dunerealms.com/government.html#'+route);assert.equal(politicsDestination(page),'https://www.dunerealms.com/government.html#'+route);}
assert.equal(politicalRoute('elections').page,'house-elections');assert.equal(politicalRoute('offices').page,'office-register');assert.equal(politicalRoute('tools').page,'council-motd');
@ -27,16 +27,17 @@ test('the real server serves an independent Political CP and styles without the
const response=await app(new Request('https://cp.dunerealms.com/politics-cp'));assert.equal(response.status,200);assert.match(response.headers.get('content-type'),/text\/html/);const html=await response.text();assert.match(html,/data-cp-mode="politics"/);assert.match(html,/cp-v2-politics-shell.mjs/);assert.match(html,/class="command-banner"/);assert.match(html,/id="sidebar-right"/);assert.doesNotMatch(html,/src="\/v2\/v2.js|class="dune-site-header"/);
assert.equal((await app(new Request('https://cp.dunerealms.com/politics-cp',{method:'HEAD'}))).status,200);assert.equal((await app(new Request('https://cp.dunerealms.com/politics-cp',{method:'POST'}))).status,405);
for(const file of ['cp-v2-politics-shell.mjs','cp-v2-politics-shell.css','cp-v2-politics-navigation.mjs','cp-v2-politics-native.css'])assert.equal((await app(new Request('https://cp.dunerealms.com/v2/'+file))).status,200,file);
assert.equal((await app(new Request('https://cp.dunerealms.com/political-catalog.mjs'))).status,200);
assert.equal((await app(new Request('https://cp.dunerealms.com/api/public/government?user=other'))).status,400);assert.equal((await app(new Request('https://cp.dunerealms.com/api/public/government',{method:'POST'}))).status,405);
}finally{db.close();}
});
test('Political CP reuses the authored CP layout and normal CP remains a valid classic script',async()=>{
const template=await readFile(new URL('../control-panel/public/cp-v2/index.html',import.meta.url),'utf8'),html=politicsCPDocument(template);
const layout=template.slice(template.indexOf('<div class="layout"'),template.indexOf('<footer'));assert(html.includes(layout));assert.match(html,/class="portals" role="tablist"/);assert.match(html,/type="module" src="\/v2\/cp-v2-politics-shell.mjs"/);
const layout=template.slice(template.indexOf('<div class="layout"'),template.indexOf('<footer'));assert(html.includes(layout));assert.match(html,/class="portals" hidden aria-hidden="true"/);assert.match(html,/type="module" src="\/v2\/cp-v2-politics-shell.mjs"/);
const source=await readFile(new URL('../control-panel/public/cp-v2/v2.js',import.meta.url),'utf8');assert.doesNotThrow(()=>new Script(source));
const redirect=runInNewContext(source.slice(source.indexOf('function politicsDestination('),source.indexOf('const requestedPolitics='))+';politicsDestination');
for(const tab of POLITICAL_TABS)for(const [page]of tab.pages)assert.equal(redirect('politics',page),politicsDestination('politics',page));
for(const page of ['house-elections','imperial-elections','landsraad','council-motd'])assert.equal(redirect('politics',page),politicsDestination('politics',page));
});
test('Government hosts the Political CP while retaining the public office directory',async()=>{