Files
SGF/scripts/sgf-workshop-period-ui.mjs
2026-11-11 09:00:17 +02:00

5 lines
3.5 KiB
JavaScript

import fs from 'node:fs';import assert from 'node:assert/strict';import {createRequire} from 'node:module';import {pathToFileURL} from 'node:url';import React from 'react';import {renderToStaticMarkup} from 'react-dom/server';import {transformWithOxc} from 'vite';import {checkedWorkshopReport,workshopPageCsv} from '../resources/js/workshop-report-view.js';
const root=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json')).root+'/private/receipt-composition-cc50a276c10c',sample=JSON.parse(fs.readFileSync(root+'/workshop-orders-sample-private.json')),checks=[],ok=(v,n)=>{assert(v,n);checks.push(n);},query={page:1,per_page:25,from:'2026-11-10',to:'2026-11-10'};sample.opening_period={from:query.from,to:query.to,zone:'Africa/Johannesburg',basis:'order_created_at_current_records'};sample.orders.current_page=1;ok(checkedWorkshopReport(sample,query)===sample,'matching period accepted');for(const change of [{from:'2026-11-11'},{zone:'UTC'},{basis:'historical'}]){assert.throws(()=>checkedWorkshopReport({...sample,opening_period:{...sample.opening_period,...change}},query));ok(true,'changed period refused '+JSON.stringify(change));}assert.throws(()=>checkedWorkshopReport({...sample,orders:{...sample.orders,current_page:2}},query));ok(true,'wrong page refused');const csv=workshopPageCsv(sample,query);ok(csv.includes('APENAS ESTA PAGINA')&&csv.includes('NAO E FECHO DIARIO')&&csv.includes('Africa/Johannesburg'),'CSV declares page temporal and timezone limits');ok(sample.orders.data.every(r=>csv.includes(r.reference)),'CSV actual source rows');const danger=structuredClone(sample);danger.orders.data=[{...danger.orders.data[0],reference:' =FORMULA()',client:'Cliente "QA"\nLinha2'}];const escaped=workshopPageCsv(danger,query);ok(escaped.includes("' =FORMULA()")&&escaped.includes('Cliente ""QA""\nLinha2'),'formula-like free text quotes and multiline escaped');ok(escaped.includes('Minutos verificados')&&!escaped.includes('Margem'),'time evidence no invented financial total');
const require=createRequire(import.meta.url);let source=fs.readFileSync('resources/js/WorkshopOrderList.jsx','utf8').replace("from 'react'",'from '+JSON.stringify(pathToFileURL(require.resolve('react')).href));for(const f of ['workshop-menu.js','workshop-report-view.js'])source=source.replace("from './"+f+"'",'from '+JSON.stringify(pathToFileURL(process.cwd()+'/resources/js/'+f).href));const c=await transformWithOxc(source,'WorkshopOrderList.jsx',{jsx:{runtime:'classic'}}),{default:View}=await import('data:text/javascript;base64,'+Buffer.from(c.code).toString('base64'));const props={context:{token:'qa'},api(){throw Error('SSR no network');},navigate(){}};const report=renderToStaticMarkup(React.createElement(View,{...props,report:true})),list=renderToStaticMarkup(React.createElement(View,props));ok(report.includes('Relatório de ordens por período de abertura')&&report.includes('não é um fecho diário'),'report title and scope');ok((report.match(/required=""/g)??[]).length===2&&report.includes('value=""'),'report requires both explicit dates');ok(!report.includes('Exportar apenas')&&!report.includes('ordem(ns) para os filtros'),'no empty-state invented report or export');ok(!list.includes('required=""'),'normal list retains optional period');
const file=root+'/workshop-period-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}));