import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import {createRequire} from 'node:module'; import {compileFunction} from 'node:vm'; import ts from 'typescript'; import React from 'react'; import {renderToStaticMarkup} from 'react-dom/server'; import * as annual from '../../resources/js/lib/irpc-annual-settlement.ts'; import {combinedCase} from './helpers/irpc-investment-combination-case.mjs'; import {plan as ppc} from './helpers/irpc-ppc-obligation-case.mjs'; import {plan as pec} from './helpers/irpc-pec-obligation-case.mjs'; import {newPecPlan} from '../../resources/js/lib/irpc-pec-plan.ts'; const require=createRequire(import.meta.url),module={exports:{}}; const source=fs.readFileSync(new URL('../../resources/js/components/simulation-irpc-annual.tsx',import.meta.url),'utf8'); const code=ts.transpileModule(source,{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2022,jsx:ts.JsxEmit.ReactJSX}}).outputText; compileFunction(code,['require','module','exports'])(name=>name==='@/lib/irpc-annual-settlement'?annual:name.startsWith('./')?new Proxy({},{get:()=>()=>null}):require(name),module,module.exports); const Summary=module.exports.SimulationIrpcAdvanceCashflow; const book=()=>({...combinedCase().b,ppcObligation:ppc(),pecObligation:{...pec(),plan:{...newPecPlan(),mode:'single',singleMonth:'2026-05',reference:'SYNTHETIC cash choice'}}}); const render=b=>renderToStaticMarkup(React.createElement(Summary,{book:b})); test('joint view labels monthly contributions and distinguishes a partial subtotal from a complete forecast',()=>{ const b=book(),html=render(b);assert.match(html,/Saídas previstas PPC\/PEC por mês/);assert.match(html,/112000\.00/);assert.match(html,/64000\.00/);assert.match(html,/não acrescenta outra saída/);assert.match(html,/prazo legal/); delete b.pecObligation;const partial=render(b);assert.match(partial,/Projecção parcial/);assert.match(partial,/Subtotal conhecido/);assert.match(partial,/Por determinar/);assert.ok(!partial.includes('Total da projecção:')); }); test('explicit zero has a complete zero forecast and legacy absence does not create a forecast',()=>{ const b=book();b.ppcObligation.previousTax='0';b.ppcObligation.previousWithholdings='0';b.pecObligation.previousPpcPaid='60000';const html=render(b);assert.match(html,/Total da projecção: 0\.00 MZN/);assert.match(html,/Sem saída PPC\/PEC estimada/); delete b.ppcObligation;delete b.pecObligation;assert.equal(render(b),'');const {d}=combinedCase(),prepared=book();d.modelo_a_snapshot=annual.saveAnnualBook(d,annual.recordAnnual(d,prepared,'2026-11-13T21:45:00Z')); const full=renderToStaticMarkup(React.createElement(module.exports.SimulationIrpcAnnual,{draft:d,onChange:()=>{}})); const estimation=full.indexOf('Estimativas PPC e PEC para a viabilidade'),paid=full.indexOf('PPC documentados como pagos'); assert.ok(estimation>=0 && paid>estimation);const between=full.slice(estimation,paid);assert.match(between,/Saídas previstas PPC\/PEC por mês/);assert.match(between,/<\/fieldset>/); });