fix(qa): remove duplicate startup editor pending acceptance
This commit is contained in:
@@ -198,70 +198,6 @@ export function IntegralFinancialPlan({
|
|||||||
novos activos no saldo anterior, nem os novos capitais nos
|
novos activos no saldo anterior, nem os novos capitais nos
|
||||||
resultados anteriores.
|
resultados anteriores.
|
||||||
</p>
|
</p>
|
||||||
<h5 className="font-semibold">
|
|
||||||
Despesas de arranque (reconhecidas e pagas na abertura)
|
|
||||||
</h5>
|
|
||||||
{a.startupExpenses.map((row, index) => (
|
|
||||||
<div className="my-2 grid gap-2 sm:grid-cols-3" key={index}>
|
|
||||||
<label className="grid gap-1 text-sm">
|
|
||||||
Despesa
|
|
||||||
<input
|
|
||||||
className="min-w-0 rounded border p-2"
|
|
||||||
maxLength={160}
|
|
||||||
value={row.label}
|
|
||||||
onChange={(event) =>
|
|
||||||
update({
|
|
||||||
startupExpenses: a.startupExpenses.map(
|
|
||||||
(entry, i) =>
|
|
||||||
i === index
|
|
||||||
? {
|
|
||||||
...entry,
|
|
||||||
label: event.target.value,
|
|
||||||
}
|
|
||||||
: entry,
|
|
||||||
),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
{numeric('Montante de arranque', row.amount, (amount) =>
|
|
||||||
update({
|
|
||||||
startupExpenses: a.startupExpenses.map(
|
|
||||||
(entry, i) =>
|
|
||||||
i === index ? { ...entry, amount } : entry,
|
|
||||||
),
|
|
||||||
}),
|
|
||||||
)}
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className="rounded border p-2"
|
|
||||||
onClick={() =>
|
|
||||||
update({
|
|
||||||
startupExpenses: a.startupExpenses.filter(
|
|
||||||
(_, i) => i !== index,
|
|
||||||
),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
>
|
|
||||||
Remover despesa
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className="my-2 rounded border px-3 py-2"
|
|
||||||
disabled={a.startupExpenses.length >= 40}
|
|
||||||
onClick={() =>
|
|
||||||
update({
|
|
||||||
startupExpenses: [
|
|
||||||
...a.startupExpenses,
|
|
||||||
{ label: '', amount: '' },
|
|
||||||
],
|
|
||||||
})
|
|
||||||
}
|
|
||||||
>
|
|
||||||
Adicionar despesa de arranque
|
|
||||||
</button>
|
|
||||||
<p className="text-sm">
|
<p className="text-sm">
|
||||||
Sem linhas significa que não declarou despesas de arranque; para
|
Sem linhas significa que não declarou despesas de arranque; para
|
||||||
confirmar a inexistência, registe uma linha «Sem despesas de
|
confirmar a inexistência, registe uma linha «Sem despesas de
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import test from 'node:test';
|
||||||
|
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 { financialReportFixture } from './fixtures/integral-financial-plan.mjs';
|
||||||
|
import * as report from '../../resources/js/lib/integral-financial-report.ts';
|
||||||
|
import {
|
||||||
|
serializeBusinessPlanSnapshot,
|
||||||
|
restoreBusinessPlanSnapshot,
|
||||||
|
} from '../../resources/js/lib/business-financial-plan.ts';
|
||||||
|
|
||||||
|
void test('one startup editor retains all rows and persists an edit without duplicating controls or changing reconciliation', () => {
|
||||||
|
const source = fs.readFileSync(
|
||||||
|
new URL(
|
||||||
|
'../../resources/js/components/integral-financial-plan.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: {} },
|
||||||
|
require = createRequire(import.meta.url);
|
||||||
|
compileFunction(code, ['require', 'module', 'exports'])(
|
||||||
|
(name) =>
|
||||||
|
name === '@/lib/integral-financial-report'
|
||||||
|
? report
|
||||||
|
: name === './investment-report-tables'
|
||||||
|
? { InvestmentReportTables: () => null }
|
||||||
|
: require(name),
|
||||||
|
module,
|
||||||
|
module.exports,
|
||||||
|
);
|
||||||
|
let plan = financialReportFixture(12);
|
||||||
|
const render = () =>
|
||||||
|
module.exports.IntegralFinancialPlan({
|
||||||
|
plan,
|
||||||
|
onChange: (next) => {
|
||||||
|
plan = next;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const html = renderToStaticMarkup(render());
|
||||||
|
assert.equal(
|
||||||
|
(html.match(/Adicionar despesa de arranque/g) ?? []).length,
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
assert.equal((html.match(/Remover despesa/g) ?? []).length, 1);
|
||||||
|
const nodes = (node) =>
|
||||||
|
Array.isArray(node)
|
||||||
|
? node.flatMap(nodes)
|
||||||
|
: node && typeof node === 'object'
|
||||||
|
? [node, ...nodes(node.props?.children)]
|
||||||
|
: [];
|
||||||
|
const label = nodes(render()).find(
|
||||||
|
(node) =>
|
||||||
|
node.type === 'label' &&
|
||||||
|
React.Children.toArray(node.props.children).includes(
|
||||||
|
'Montante de arranque 1',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
nodes(label)
|
||||||
|
.find((node) => node.type === 'input')
|
||||||
|
.props.onChange({ target: { value: '100.25' } });
|
||||||
|
plan = restoreBusinessPlanSnapshot(serializeBusinessPlanSnapshot(plan));
|
||||||
|
assert.equal(plan.reportAssumptions.startupExpenses[0].amount, '100.25');
|
||||||
|
assert.match(renderToStaticMarkup(render()), /value="100.25"/);
|
||||||
|
const balance = report
|
||||||
|
.buildIntegralFinancialTables(plan)
|
||||||
|
.find((table) => table.id === 'balance');
|
||||||
|
assert.ok(
|
||||||
|
balance.rows
|
||||||
|
.find((row) => row[0] === 'Diferença do balanço')
|
||||||
|
.slice(1)
|
||||||
|
.every((value) => value === '0.00'),
|
||||||
|
);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user