66 lines
4.6 KiB
JavaScript
66 lines
4.6 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { businessPlanWarnings } from '../../resources/js/lib/business-plan-guidance.ts';
|
|
void test('V14 optional narratives emit the exact requested guidance once, without altering inputs or existing financial warnings', () => {
|
|
const metrics = {
|
|
optionalTexts: [
|
|
{ label: 'Concorrência', value: ' ' },
|
|
{ label: 'SWOT', value: '' },
|
|
],
|
|
netProfit: -1,
|
|
};
|
|
const before = JSON.stringify(metrics);
|
|
const warnings = businessPlanWarnings(metrics);
|
|
assert.equal(warnings.filter((w) => w.id === 'optional-texts').length, 1);
|
|
assert.equal(
|
|
warnings.find((w) => w.id === 'optional-texts').message,
|
|
'Pode completar estas secções para um relatório mais convincente.',
|
|
);
|
|
assert.ok(warnings.some((w) => w.id === 'loss'));
|
|
assert.equal(JSON.stringify(metrics), before);
|
|
assert.deepEqual(businessPlanWarnings({}), []);
|
|
assert.deepEqual(
|
|
businessPlanWarnings({
|
|
optionalTexts: [
|
|
{
|
|
label: 'Concorrência',
|
|
value: 'Existem alternativas identificadas.',
|
|
},
|
|
{ label: 'SWOT', value: 'Risco descrito pelo investidor.' },
|
|
],
|
|
}),
|
|
[],
|
|
);
|
|
});
|
|
import fs from 'node:fs';
|
|
import { createRequire } from 'node:module';
|
|
import { compileFunction } from 'node:vm';
|
|
import React from 'react';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import ts from 'typescript';
|
|
import * as guidance from '../../resources/js/lib/business-plan-guidance.ts';
|
|
const require = createRequire(import.meta.url);
|
|
void test('V14 real notice lists missing optional sections once and disappears when completed', () => {
|
|
const source=fs.readFileSync(new URL('../../resources/js/components/business-plan-warnings.tsx',import.meta.url),'utf8');
|
|
const code=ts.transpileModule(source,{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2022,jsx:ts.JsxEmit.ReactJSX}}).outputText;
|
|
const module={exports:{}};
|
|
compileFunction(code,['require','module','exports'])(key=>key==='@/lib/business-plan-guidance'?guidance:require(key),module,module.exports);
|
|
const render=optionalTexts=>renderToStaticMarkup(React.createElement(module.exports.BusinessPlanWarnings,{metrics:{optionalTexts}}));
|
|
const html=render([{label:'SWOT',value:''},{label:'Marketing',value:'definido'}]);
|
|
assert.equal((html.match(/role="status"/g)||[]).length,1);assert.match(html,/SWOT/);assert.doesNotMatch(html,/Marketing/);
|
|
assert.match(html,/type="button"/);assert.doesNotMatch(html,/aria-invalid|required=/);
|
|
assert.equal(render([{label:'SWOT',value:'Forcas e riscos descritos.'}]),'');
|
|
});
|
|
import * as investorReports from '../../resources/js/lib/investor-dossier-report.ts';
|
|
import * as projectReports from '../../resources/js/lib/project-dossier-report.ts';
|
|
void test('V14 dossier SWOT notice uses the selected context, removes when text exists, and does not leak across ambiguous contexts', () => {
|
|
function load(name){const module={exports:{}};const code=ts.transpileModule(fs.readFileSync(new URL('../../resources/js/components/'+name+'.tsx',import.meta.url),'utf8'),{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2022,jsx:ts.JsxEmit.ReactJSX}}).outputText;compileFunction(code,['require','module','exports'])(id=>id==='@/lib/business-plan-guidance'?guidance:id==='@/lib/investor-dossier-report'?investorReports:id==='@/lib/project-dossier-report'?projectReports:id==='./business-plan-warnings'?load('business-plan-warnings'):id==='./dossier-report-preview'?{DossierReportPreview:()=>null}:require(id),module,module.exports);return module.exports;}
|
|
const Component=load('investor-dossier-reports').InvestorDossierReports;
|
|
const dossier={case:{id:'synthetic',title:'SYNTHETIC',version:1},context_opportunity:null,opportunity_options:[],investment_context:null,phases:{},steps:[],results:[],documents:[]};
|
|
const render=()=>renderToStaticMarkup(React.createElement(Component,{dossier}));
|
|
assert.match(render(),/Pode completar/);
|
|
dossier.preparation_report={case_id:'synthetic',opportunity:null,version:1,context_revision:1,href:'/synthetic',api_state:'not_started',api_issues:[],exports:[],external:[],swot_review_required:false,swot:{object_key:'synthetic',scope:null,source_fingerprint:'',actions:[],rows:[{id:'r',dimension:'strength',text:'SYNTHETIC documented capability',reference:'',source_key:null,date:null,classification:'hypothesis'}]}};
|
|
assert.doesNotMatch(render(),/Pode completar/);
|
|
dossier.opportunity_options=['one','two'];dossier.preparation_report=null;assert.doesNotMatch(render(),/Pode completar/);
|
|
});
|