From eada56aa186390ee40adeb2f9b2ab4394c699985 Mon Sep 17 00:00:00 2001 From: nala Date: Sun, 22 Nov 2026 08:59:38 +0200 Subject: [PATCH] test: align deployment checks with accepted diagnostics and public presentation --- .../frontend/business-financial-plan.test.mjs | 14 ++--- tests/frontend/business-plan-editing.test.mjs | 15 +++++ .../business-point-publication.test.mjs | 7 ++- .../business-proximity-catalogue.test.mjs | 7 ++- tests/frontend/catalogue-map-layers.test.mjs | 7 ++- .../financial-issue-presentation.test.mjs | 12 +++- tests/frontend/fiscal-form-entry.test.mjs | 60 ++++++++++++++++--- tests/frontend/fixtures/funding-b03-b06.json | 16 +++++ .../funding-journey-coherence.test.mjs | 5 +- .../frontend/portal-horizontal-shell.test.mjs | 5 ++ .../portfolio-embedded-opportunities.test.mjs | 5 +- tests/frontend/public-information.test.mjs | 15 +++-- tests/frontend/similar-businesses.test.mjs | 5 +- tests/frontend/v12-diagnostics.test.mjs | 20 ++++++- 14 files changed, 158 insertions(+), 35 deletions(-) create mode 100644 tests/frontend/fixtures/funding-b03-b06.json diff --git a/tests/frontend/business-financial-plan.test.mjs b/tests/frontend/business-financial-plan.test.mjs index cda2fd41..50970108 100644 --- a/tests/frontend/business-financial-plan.test.mjs +++ b/tests/frontend/business-financial-plan.test.mjs @@ -313,7 +313,7 @@ void test('monthly unit schedules must match the horizon and contain valid quant }, ], }), - /Quantidade/, + /Previs\u00e3o de Vendas \/ Unidades do produto 1, m\u00eas 1: .*tr\u00eas casas decimais/, ); assert.throws( () => @@ -327,7 +327,7 @@ void test('monthly unit schedules must match the horizon and contain valid quant }, ], }), - /Quantidade/, + /Previs\u00e3o de Vendas \/ Unidades do produto 1, m\u00eas 1: .*tr\u00eas casas decimais/, ); }); @@ -412,7 +412,7 @@ void test('monthly money schedules cover the horizon and reject invalid amounts' }, ], }), - /não negativo/, + /Este valor n\u00e3o pode ser negativo\./, ); assert.throws( () => @@ -503,7 +503,7 @@ void test('monthly operating schedules require full horizon, exact cents and cur periods: 1, monthlyPayrollExpenseByPeriod: ['-1'], }), - /não negativo/, + /Este valor n\u00e3o pode ser negativo\./, ); const restored = restoreBusinessPlanSnapshot( serializeBusinessPlanSnapshot({ @@ -611,7 +611,7 @@ void test('missing currency, products, invalid numbers and invalid horizons are assert.throws( () => forecastBusinessPlan({ ...assumptions, monthlyCollections: '-10' }), - /não negativo/, + /Este valor n\u00e3o pode ser negativo\./, ); assert.throws( () => forecastBusinessPlan({ ...assumptions, periods: 61 }), @@ -1067,7 +1067,7 @@ void test('scheduled collection percentage keeps unpaid invoices in receivables salesCollectionLagMonths: 0, salesCollectionPercent: '100.01', }), - /entre 0 e 100/, + /Introduza uma percentagem entre 0% e 100%\./, ); }); @@ -1126,7 +1126,7 @@ void test('sales recovery applies only to overdue invoices and never exceeds ope salesCollectionLagMonths: 0, salesRecoverySchedule: [{ month: 1, percent: '100.01' }], }), - /entre 0 e 100/, + /Introduza uma percentagem entre 0% e 100%\./, ); assert.throws( () => diff --git a/tests/frontend/business-plan-editing.test.mjs b/tests/frontend/business-plan-editing.test.mjs index 482657cb..1ffda193 100644 --- a/tests/frontend/business-plan-editing.test.mjs +++ b/tests/frontend/business-plan-editing.test.mjs @@ -1,3 +1,4 @@ +import * as issuePresentation from '../../resources/js/lib/financial-issue-presentation.ts'; import assert from 'node:assert/strict'; import test from 'node:test'; import fs from 'node:fs'; @@ -78,6 +79,20 @@ function editor(initialSnapshot) { ? { SimulationAnnualExample: () => null } : undefined) ?? { + './warning-limits-editor': { WarningLimitsEditor: () => null }, + '@/components/supplier-advances': { + SupplierAdvancesEditor: () => null, + }, + '@/components/period-investments': { + PeriodInvestmentsEditor: () => null, + }, + '@/components/financial-day-terms': { + FinancialDayTerms: () => null, + }, + '@/components/startup-asset-requirements': { + StartupAssetRequirements: () => null, + }, + '@/lib/financial-issue-presentation': issuePresentation, react: hooks, '@/components/currency-select': { CurrencySelect: () => null }, '@/lib/business-financial-plan': business, diff --git a/tests/frontend/business-point-publication.test.mjs b/tests/frontend/business-point-publication.test.mjs index 56712515..b4f0e3f4 100644 --- a/tests/frontend/business-point-publication.test.mjs +++ b/tests/frontend/business-point-publication.test.mjs @@ -1,3 +1,4 @@ +import * as publicPresentation from '../../resources/js/lib/public-presentation.ts'; import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; @@ -21,7 +22,11 @@ function load(file, mocks = {}) { ).outputText; const module = { exports: {} }; compileFunction(output, ['require', 'module', 'exports'])( - (name) => mocks[name] ?? require(name), + (name) => + mocks[name] ?? + (name === '@/lib/public-presentation' + ? publicPresentation + : require(name)), module, module.exports, ); diff --git a/tests/frontend/business-proximity-catalogue.test.mjs b/tests/frontend/business-proximity-catalogue.test.mjs index 71915888..db7fb4c7 100644 --- a/tests/frontend/business-proximity-catalogue.test.mjs +++ b/tests/frontend/business-proximity-catalogue.test.mjs @@ -1,3 +1,4 @@ +import * as publicPresentation from '../../resources/js/lib/public-presentation.ts'; import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; @@ -20,7 +21,11 @@ function load(file, mocks) { ).outputText; const module = { exports: {} }; compileFunction(output, ['require', 'module', 'exports'])( - (name) => mocks[name] ?? require(name), + (name) => + mocks[name] ?? + (name === '@/lib/public-presentation' + ? publicPresentation + : require(name)), module, module.exports, ); diff --git a/tests/frontend/catalogue-map-layers.test.mjs b/tests/frontend/catalogue-map-layers.test.mjs index 7b8015d4..a6f956b1 100644 --- a/tests/frontend/catalogue-map-layers.test.mjs +++ b/tests/frontend/catalogue-map-layers.test.mjs @@ -1,3 +1,4 @@ +import * as publicPresentation from '../../resources/js/lib/public-presentation.ts'; import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; @@ -28,7 +29,11 @@ function load(file, mocks) { ).outputText; const module = { exports: {} }; compileFunction(output, ['require', 'module', 'exports'])( - (name) => mocks[name] ?? require(name), + (name) => + mocks[name] ?? + (name === '@/lib/public-presentation' + ? publicPresentation + : require(name)), module, module.exports, ); diff --git a/tests/frontend/financial-issue-presentation.test.mjs b/tests/frontend/financial-issue-presentation.test.mjs index 00c2bfe8..dc58ce17 100644 --- a/tests/frontend/financial-issue-presentation.test.mjs +++ b/tests/frontend/financial-issue-presentation.test.mjs @@ -165,7 +165,11 @@ void test('real table component presents one issue panel while retaining every t const html = renderToStaticMarkup( React.createElement(module.exports.InvestmentReportTables, { tables }), ); - assert.equal(html.split(message).length - 1, 1); + assert.equal( + html.replace(/ data-correction-message="[^"]*"/g, '').split(message) + .length - 1, + 1, + ); assert.equal( (html.match(/aria-label="Dados financeiros a corrigir"/g) ?? []).length, 1, @@ -199,7 +203,11 @@ void test('print and Word present the same capital correction only once, without report.sections.find((s) => s.id === 'finance').tables, )[0].message; const html = await createProjectDossierPrintHtml(report, []); - assert.equal(html.split(message).length - 1, 1); + assert.equal( + html.replace(/ data-correction-message="[^"]*"/g, '').split(message) + .length - 1, + 1, + ); const blob = await generateProjectDossierDocx(report, []), zip = await JSZip.loadAsync( blob instanceof Blob ? await blob.arrayBuffer() : blob, diff --git a/tests/frontend/fiscal-form-entry.test.mjs b/tests/frontend/fiscal-form-entry.test.mjs index 42b4fe3d..f6b0d9ba 100644 --- a/tests/frontend/fiscal-form-entry.test.mjs +++ b/tests/frontend/fiscal-form-entry.test.mjs @@ -7,14 +7,53 @@ import React from 'react'; import { renderToStaticMarkup } from 'react-dom/server'; import ts from 'typescript'; import * as forms from '../../resources/js/lib/fiscal-form-preparation.ts'; -const require=createRequire(import.meta.url); -const source=fs.readFileSync(new URL('../../resources/js/pages/portal/fiscal-forms.tsx',import.meta.url),'utf8'); -const compiled=ts.transpileModule(source,{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2022,jsx:ts.JsxEmit.ReactJSX}}).outputText; -const module={exports:{}}; -new Function('require','module','exports',compiled)(name=>name==='@inertiajs/react'?{Head:()=>null,Link:({href,children,...props})=>React.createElement('a',{href,...props},children),router:{on:()=>()=>{}}}:name==='@/components/portal-menu'?{PortalMenu:()=>null}:name==='@/lib/fiscal-form-preparation'?forms:require(name),module,module.exports); -test('fiscal entry renders labelled editable fields and a guided preparation rather than legislation',()=>{ - const html=renderToStaticMarkup(React.createElement(module.exports.default)); - for(const label of ['Identificação e período','Nome ou designação social','NUIT','Período — ano e mês','Conferir e guardar','Guardar ficheiro para continuar','Recuperar ficheiro guardado','Confirmar recuperação']) { +const require = createRequire(import.meta.url); +const source = fs.readFileSync( + new URL( + '../../resources/js/pages/portal/fiscal-forms.tsx', + import.meta.url, + ), + 'utf8', +); +const compiled = ts.transpileModule(source, { + compilerOptions: { + module: ts.ModuleKind.CommonJS, + target: ts.ScriptTarget.ES2022, + jsx: ts.JsxEmit.ReactJSX, + }, +}).outputText; +const module = { exports: {} }; +new Function('require', 'module', 'exports', compiled)( + (name) => + name === '@inertiajs/react' + ? { + Head: () => null, + Link: ({ href, children, ...props }) => + React.createElement('a', { href, ...props }, children), + router: { on: () => () => {} }, + } + : name === '@/components/portal-menu' + ? { PortalMenu: () => null } + : name === '@/lib/fiscal-form-preparation' + ? forms + : require(name), + module, + module.exports, +); +test('fiscal entry renders labelled editable fields and a guided preparation rather than legislation', () => { + const html = renderToStaticMarkup( + React.createElement(module.exports.default), + ); + for (const label of [ + 'Identificação e período', + 'Nome ou designação social', + 'NUIT', + 'Período — ano e mês', + 'Conferir e guardar', + 'Guardar ficheiro para continuar', + 'Recuperar ficheiro guardado', + 'Confirmar recuperação', + ]) { // Confirmation appears only after a compatible file is selected. if (label !== 'Confirmar recuperação') assert.ok(html.includes(label), label); @@ -29,7 +68,10 @@ void test('IRPC entry opens the requested form directly and keeps its partial co React.createElement(module.exports.default, { initialTax: 'irpc' }), ); assert.match(html, /IRPC — Modelo 22/); - assert.match(html, /L8 permanece parcial/); + assert.match( + html, + /não há apuramento automático nem confirmação de elegibilidade/, + ); assert.match(html, /303 — Dupla tributação económica/); assert.match(html, /304 — Dupla tributação internacional/); assert.match(html, /Não utilize a mesma parcela/); diff --git a/tests/frontend/fixtures/funding-b03-b06.json b/tests/frontend/fixtures/funding-b03-b06.json new file mode 100644 index 00000000..ee25f70e --- /dev/null +++ b/tests/frontend/fixtures/funding-b03-b06.json @@ -0,0 +1,16 @@ +{ + "records": { + "moza": { + "id": "53119370-3dcc-4488-b469-80ffcd24ece2" + }, + "bci": { + "id": "9ba03e9c-850a-415b-8caa-a7092aa8db25" + }, + "standard-bank": { + "id": "1b5f6e6b-4c3e-477a-a847-74803719f8fd" + }, + "ac-microbanco": { + "id": "e6c7c1b7-cbf0-4c69-ad4e-0d02f18fa136" + } + } +} diff --git a/tests/frontend/funding-journey-coherence.test.mjs b/tests/frontend/funding-journey-coherence.test.mjs index 8731e467..6b67bc92 100644 --- a/tests/frontend/funding-journey-coherence.test.mjs +++ b/tests/frontend/funding-journey-coherence.test.mjs @@ -182,10 +182,7 @@ test('B06 empty results omit institution alternatives and real result links keep 0, ); const fixture = JSON.parse( - fs.readFileSync( - 'outputs/funding-b03-b06-20261120/fixture.json', - 'utf8', - ), + fs.readFileSync('tests/frontend/fixtures/funding-b03-b06.json', 'utf8'), ); const originals = JSON.parse( fs.readFileSync( diff --git a/tests/frontend/portal-horizontal-shell.test.mjs b/tests/frontend/portal-horizontal-shell.test.mjs index 38077507..565c8bdc 100644 --- a/tests/frontend/portal-horizontal-shell.test.mjs +++ b/tests/frontend/portal-horizontal-shell.test.mjs @@ -1,3 +1,4 @@ +import * as fieldCorrections from '../../resources/js/lib/field-corrections.ts'; import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; @@ -72,6 +73,10 @@ function load(name) { ); return module.exports.default; } +mocks['@/lib/field-corrections'] = fieldCorrections; +mocks['@/components/portal-corrections'] = { + default: load('components/portal-corrections.tsx'), +}; const PortalNavigation = load('layouts/portal-navigation.tsx'), AppHeaderLayout = load('layouts/app/app-header-layout.tsx'); mocks['@/layouts/app/app-header-layout'] = { default: AppHeaderLayout }; diff --git a/tests/frontend/portfolio-embedded-opportunities.test.mjs b/tests/frontend/portfolio-embedded-opportunities.test.mjs index fc955366..d8d22592 100644 --- a/tests/frontend/portfolio-embedded-opportunities.test.mjs +++ b/tests/frontend/portfolio-embedded-opportunities.test.mjs @@ -1,3 +1,4 @@ +import * as publicPresentation from '../../resources/js/lib/public-presentation.ts'; import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; @@ -46,7 +47,9 @@ compileFunction( return { TerritoryFields: () => null }; if (name === '../management/shared' || name === './shared') return shared; - return require(name); + return name === '@/lib/public-presentation' + ? publicPresentation + : require(name); }, module, module.exports, diff --git a/tests/frontend/public-information.test.mjs b/tests/frontend/public-information.test.mjs index abf4634e..36757e39 100644 --- a/tests/frontend/public-information.test.mjs +++ b/tests/frontend/public-information.test.mjs @@ -27,7 +27,10 @@ function load(file, mocks = {}) { return { Link: ({ children, ...props }) => React.createElement('a', props, children), - usePage: () => ({ url: '/sectores/test', props: { auth: { user: { id: 1 } } } }), + usePage: () => ({ + url: '/sectores/test', + props: { auth: { user: { id: 1 } } }, + }), }; if (id.startsWith('.') || id.startsWith('@/')) { const base = id.startsWith('@/') @@ -111,7 +114,10 @@ test('demographic comparison retains four saved places and requires a province b test('the real preparation editor opens an own idea with its budget and no mandatory advert or duplicate reference selector', () => { const Empty = () => null; const Editor = load('pages/investor-path/context.tsx', { - '@/components/investment-step-help': { HelpAtStep: Empty, InvestmentHelpGuide: ({ children }) => children }, + '@/components/investment-step-help': { + HelpAtStep: Empty, + InvestmentHelpGuide: ({ children }) => children, + }, '@/pages/investment/shared': { Frame: ({ children }) => React.createElement('main', null, children), @@ -413,11 +419,10 @@ test('demography shows original latest total, period, projection and decision wa ], }; const html = render('components/demographic-evidence.tsx', { evidence }); - assert.match(html, /1 234/); + assert.match(html, /1[\u00a0\u202f ]234/); assert.match(html, /não demonstram procura ou rentabilidade/); assert.match(html, /Projecção/); - assert.match(html, /SHA256/); - assert.ok(html.indexOf('SHA256') > html.indexOf(']*\bopen/); }); test('cluster analysis omits empty field blocks but keeps documented evidence and uncertainty', () => { diff --git a/tests/frontend/similar-businesses.test.mjs b/tests/frontend/similar-businesses.test.mjs index d30b44b4..228358e7 100644 --- a/tests/frontend/similar-businesses.test.mjs +++ b/tests/frontend/similar-businesses.test.mjs @@ -1,3 +1,4 @@ +import * as publicPresentation from '../../resources/js/lib/public-presentation.ts'; import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; @@ -65,7 +66,9 @@ function harness() { }), ), } - : require(name), + : name === '@/lib/public-presentation' + ? publicPresentation + : require(name), module, module.exports, ); diff --git a/tests/frontend/v12-diagnostics.test.mjs b/tests/frontend/v12-diagnostics.test.mjs index 72449d84..a4bc8d88 100644 --- a/tests/frontend/v12-diagnostics.test.mjs +++ b/tests/frontend/v12-diagnostics.test.mjs @@ -88,18 +88,32 @@ test('D1: one startup diagnostic across real local and report components; standa ), ); assert.ok(error.includes('caixa requerida')); - assert.equal(render().split(error).length - 1, 1); + assert.equal( + render() + .replace(/ data-correction-message="[^"]*"/g, '') + .replace(/ data-correction-message="[^"]*"/g, '') + .split(error).length - 1, + 1, + ); assert.equal( renderToStaticMarkup( React.createElement(StartupAssetRequirements, { plan, onChange() {}, }), - ).split(error).length - 1, + ) + .replace(/ data-correction-message="[^"]*"/g, '') + .split(error).length - 1, 1, ); plan.reportAssumptions.startupExpenses = 'invalid'; - assert.equal(render().split(error).length - 1, 1); + assert.equal( + render() + .replace(/ data-correction-message="[^"]*"/g, '') + .replace(/ data-correction-message="[^"]*"/g, '') + .split(error).length - 1, + 1, + ); plan.reportSource = 'annual_example'; assert.equal(presentation.forecastErrorShownInReport(plan, error), false); plan.startupAssetRequirements.cashRequired = '0';