MC/website/tests/cp-v2-design-batch.test.mjs

9 lines
3.4 KiB
JavaScript

import test from 'node:test';import assert from 'node:assert/strict';import {readFile} from 'node:fs/promises';
import {DESIGN_PAGES} from '../control-panel/public/cp-v2/cp-v2-design-catalog.mjs';
import {DesignSession,designInput,designRows} from '../control-panel/public/cp-v2/cp-v2-design-pages.mjs';
import {auditDesign,designAliases} from '../scripts/audit-cp-v2-design.mjs';
test('every new unimplemented menu has an authored design and existing integrations stay separate',()=>{const audit=auditDesign();assert.ok(audit.length>80);assert.equal(audit.filter(r=>r.classification==='needs-design-spec').length,0);assert.equal(audit.filter(r=>r.classification==='new-design-only').length,35);assert.equal(Object.keys(designAliases).length,9);});
test('every feature tab has a complete, valid task-specific form and register',()=>{for(const [key,page]of Object.entries(DESIGN_PAGES)){assert.ok(page.title&&page.lore);assert.match(page.artwork,/^[a-z0-9/-]+\.(png|webp)$/);assert.ok(page.tabs.length>=3);assert.equal(new Set(page.tabs.map(t=>t.id)).size,page.tabs.length);for(const tab of page.tabs){assert.ok(tab.columns.length>=2,key);assert.ok(tab.fields.length>=3,key);assert.equal(new Set(tab.fields.map(f=>f.key)).size,tab.fields.length);const values=Object.fromEntries(tab.fields.map(f=>[f.key,f.type==='select'?f.options[0]:f.type==='checkbox'?false:f.type==='file'?null:f.type==='email'?'preview@example.com':f.type==='url'?'https://example.com':f.type==='money'?'25.00':f.type==='number'?'1':f.type==='date'?'2026-11-12':f.type==='month'?'2026-11':f.type==='datetime-local'?'2026-11-12T10:00':'Preview sample']));assert.doesNotThrow(()=>designInput(tab.fields,values),key+'/'+tab.id);}}});
test('preview records can be created, revised, filtered, sorted, transitioned and removed without leaking between sessions',()=>{const session=new DesignSession(),other=new DesignSession();const a=session.save('companies',{name:'Company A',sector:'Trade',amount:20});const b=session.save('companies',{name:'Company B',amount:10});session.save('companies',{name:'Updated'},a._id);assert.equal(session.rows('companies').find(r=>r._id===a._id).sector,'Trade');session.transition('companies',a._id,'Approved');assert.equal(designRows(session.rows('companies'),'updated','Approved').length,1);assert.equal(designRows(session.rows('companies'),'','','amount')[0]._id,b._id);session.remove('companies',[a._id]);assert.equal(session.rows('companies').length,1);assert.equal(other.rows('companies').length,0);assert.match(b._id,/^PREVIEW-/);});
test('design validation rejects invalid quantities, choices, addresses, ranges and oversized attachment metadata',()=>{assert.throws(()=>designInput([{key:'quantity',label:'Quantity',type:'number',required:true}],{quantity:0}));assert.throws(()=>designInput([{key:'status',label:'Status',type:'select',options:['Draft'],required:true}],{status:'Actual payment'}));assert.throws(()=>designInput([{key:'email',label:'Email',type:'email',required:true}],{email:'bad'}));assert.throws(()=>designInput([{key:'file',label:'File',type:'file'}],{file:{name:'x',size:21*1024*1024}}));});
test('new-page renderer has no integration or persistent-storage calls',async()=>{const source=await readFile(new URL('../control-panel/public/cp-v2/cp-v2-design-pages.mjs',import.meta.url),'utf8');assert.doesNotMatch(source,/\b(?:fetch|XMLHttpRequest|WebSocket|EventSource|localStorage|sessionStorage)\b/);assert.match(source,/shellHost:host/);});