4 lines
3.6 KiB
JavaScript
4 lines
3.6 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';
|
|
const require=createRequire(import.meta.url),root=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json')).root+'/private/receipt-composition-cc50a276c10c',samples=JSON.parse(fs.readFileSync(root+'/accounting-reports-samples-private.json'));const load=async name=>{let source=fs.readFileSync('resources/js/'+name,'utf8').replace("from 'react'",'from '+JSON.stringify(pathToFileURL(require.resolve('react')).href));for(const file of ['ledger-report-view.js','accounting-menu.js'])source=source.replace("from './"+file+"'",'from '+JSON.stringify(pathToFileURL(process.cwd()+'/resources/js/'+file).href));const compiled=await transformWithOxc(source,name,{jsx:{runtime:'classic'}});return import('data:text/javascript;base64,'+Buffer.from(compiled.code).toString('base64'));};const {default:Reports,LedgerReportTable}=await load('LedgerReportsWorkspace.jsx'),{default:Workspace}=await load('ComposedAccountingWorkspace.jsx'),checks=[],ok=(v,n)=>{assert(v,n);checks.push(n);};for(const [kind,data]of Object.entries(samples)){const html=renderToStaticMarkup(React.createElement(LedgerReportTable,{data,onAccount(){}}));ok(data.rows.every(r=>html.includes(String(kind==='trial'?r.code:r.journal_id))),kind+' actual rows rendered');ok(!html.includes('NaN')&&!html.includes('undefined'),kind+' exact present values');ok(kind==='trial'?html.includes('Abrir razão desta conta'):html.includes('revisão #'),kind+' explicit source continuation');}const form=renderToStaticMarkup(React.createElement(Reports,{context:{token:'test'},api(){throw Error('No automatic query');}}));ok(form.includes('data-sgf-read-filters="true"'),'read filter not business editor');ok(!form.includes('2026-01-01')&&form.includes('type="date" required="" value=""'),'no fixed or implicit reporting dates');ok(form.includes('Todas as contas do balancete')&&!form.includes('type="number"'),'account selected from rows without ID typing');
|
|
const context={token:'scope',company:{name:'Empresa QA'},unit:{id:2,name:'Unidade QA'},fiscal_qa_enabled:true,fiscal_rules_qa_enabled:true,bank_qa_enabled:true};const outputs={};for(const section of ['accounting_panel','accounting_daily','accounting_review','accounting_closing','accounting_configuration'])outputs[section]=renderToStaticMarkup(React.createElement(Workspace,{section,context,can:()=>true,navigate(){}}));ok(new Set(Object.values(outputs)).size===5,'five sections distinct instead of duplicated panel');ok(outputs.accounting_closing.includes('não fecha nem reabre'),'closing consultation no implicit command');ok(outputs.accounting_review.includes('conferir extracto')&&outputs.accounting_configuration.includes('Fontes e regras'),'authorized cross-module existing functions exposed');const restricted=renderToStaticMarkup(React.createElement(Workspace,{section:'accounting_review',context,can:()=>false,navigate(){}}));ok(!restricted.includes('conferir extracto')&&!restricted.includes('Livro e mapa'),'restricted fiscal and bank links hidden');const escaped=structuredClone(samples.trial);escaped.rows[0].label='<script>bad</script>';ok(!renderToStaticMarkup(React.createElement(LedgerReportTable,{data:escaped})).includes('<script>'),'account label escaped');const file=root+'/accounting-reports-ui-20261110.json';fs.writeFileSync(file,JSON.stringify({passed:true,checks,business_commands:0,browser_visual_review:false},null,2));console.log(JSON.stringify({passed:true,checks:checks.length,proof:file}));
|