8 lines
4.0 KiB
JavaScript
8 lines
4.0 KiB
JavaScript
import fs from 'node:fs';import assert from 'node:assert/strict';import {createRequire} from 'node:module';import {pathToFileURL} from 'node:url';import {transformWithOxc} from 'vite';import React from 'react';import {renderToStaticMarkup} from 'react-dom/server';import {overviewPage} from '../resources/js/workspace-overview.js';
|
|
const require=createRequire(import.meta.url),run=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json')),root=run.root+'/private/receipt-composition-cc50a276c10c',samples=JSON.parse(fs.readFileSync(root+'/overview-samples-private.json'));let code=fs.readFileSync('resources/js/WorkspaceHome.jsx','utf8').replace("from 'react'",'from '+JSON.stringify(pathToFileURL(require.resolve('react')).href)).replace("from './workspace-overview.js'",'from '+JSON.stringify(pathToFileURL(process.cwd()+'/resources/js/workspace-overview.js').href));const compiled=await transformWithOxc(code,'WorkspaceHome.jsx',{jsx:{runtime:'classic'}}),{default:Home,OverviewRecords}=await import('data:text/javascript;base64,'+Buffer.from(compiled.code).toString('base64'));const checks=[],ok=(v,n)=>{assert(v,n);checks.push(n);};
|
|
for(const [key,sample]of Object.entries(samples)){const html=renderToStaticMarkup(React.createElement(OverviewRecords,{source:sample.source,result:sample.page,navigate(){}}));ok(html.includes('Evidência')&&html.includes('Abrir consulta completa'),key+' evidence and continuation visible');ok(!html.includes('NaN')&&!html.includes('undefined'),key+' no undefined amounts');}
|
|
const context={token:'c1',module_id:'commercial',company:{name:'Empresa <script>QA</script>'},unit:{id:2,name:'Unidade QA'},modules:[{id:'commercial',label:'Comercial'}],single_installation:true};const html=renderToStaticMarkup(React.createElement(Home,{context,groups:[{id:'billing',label:'Facturação',items:[{id:'billing_all',label:'Todos os documentos'}]}]}));ok(html.includes('Do primeiro registo')&&html.includes('Orçamento e rascunho não são receita'),'meaning and interpretation shown');ok(html.includes('Todos os documentos')&&!html.includes('Diário integrado'),'only supplied authorized functions shown');ok(!html.includes('<script>QA')&&html.includes('<script>'),'entity names escaped');ok(!html.includes('registo(s) nesta fonte'),'no invented initial metrics before reading');
|
|
const empty=renderToStaticMarkup(React.createElement(Home,{context:{...context,unit:null,module_id:null,modules:[]}}));ok(empty.includes('Seleccione uma unidade')&&!empty.includes('Informação existente neste módulo'),'no unit/source no query controls');
|
|
const cash=samples['finance:cash'].source,live=overviewPage(cash,{basis:{closed:true,balance_minor:95000},events:{total:0,current_page:1,last_page:1,data:[]}});const cashHtml=renderToStaticMarkup(React.createElement(OverviewRecords,{source:cash,result:live}));ok(cashHtml.includes('950,00 MZN')&&cashHtml.includes('Fechada'),'cash balance and state supplied by basis');assert.throws(()=>overviewPage(cash,{basis:{balance_minor:Number.MAX_SAFE_INTEGER+2},events:{total:0,current_page:1,last_page:1,data:[]}}));ok(true,'unsafe numeric amount refused');
|
|
let nav=fs.readFileSync('resources/js/ModuleNavigation.jsx','utf8').replace("from 'react'",'from '+JSON.stringify(pathToFileURL(require.resolve('react')).href));const transformed=await transformWithOxc(nav,'ModuleNavigation.jsx',{jsx:{runtime:'classic'}}),{moduleFunctionAllowed}=await import('data:text/javascript;base64,'+Buffer.from(transformed.code).toString('base64'));ok(moduleFunctionAllowed(context,[],'commercial','home'),'authorized module home available');ok(!moduleFunctionAllowed(context,[],'accounting','home'),'unauthorized module home refused');ok(!moduleFunctionAllowed(context,[],'commercial','cash'),'home exception does not authorize another function');const file=root+'/overview-ui-20261110.json';fs.writeFileSync(file,JSON.stringify({passed:true,checks,browser_visual_review:false,business_commands:0},null,2));console.log(JSON.stringify({passed:true,checks:checks.length,proof:file}));
|