Preserve documented turnover corrections in PEC viability estimates
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import { compileFunction } from 'node:vm';
|
||||
import { createRequire } from 'node:module';
|
||||
import React from 'react';
|
||||
import ts from 'typescript';
|
||||
import * as annual from '../../resources/js/lib/irpc-annual-settlement.ts';
|
||||
import * as investment from '../../resources/js/lib/irpc-pec-correction.ts';
|
||||
import * as rational from '../../resources/js/lib/fiscal-rational.ts';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
|
||||
const require = createRequire(import.meta.url),
|
||||
module = { exports: {} };
|
||||
const source = fs.readFileSync(
|
||||
new URL(
|
||||
'../../resources/js/components/simulation-irpc-pec-correction.tsx',
|
||||
import.meta.url,
|
||||
),
|
||||
'utf8',
|
||||
);
|
||||
const output = ts.transpileModule(source, {
|
||||
compilerOptions: {
|
||||
module: ts.ModuleKind.CommonJS,
|
||||
target: ts.ScriptTarget.ES2022,
|
||||
jsx: ts.JsxEmit.ReactJSX,
|
||||
},
|
||||
}).outputText;
|
||||
compileFunction(output, ['require', 'module', 'exports'])(
|
||||
(name) =>
|
||||
name === './simulation-irpc-pec-plan'
|
||||
? { SimulationIrpcPecPlan: () => null }
|
||||
: name === '@/lib/irpc-annual-settlement'
|
||||
? annual
|
||||
: name === '@/lib/irpc-pec-correction'
|
||||
? investment
|
||||
: name === '@/lib/fiscal-rational'
|
||||
? rational
|
||||
: name === './simulation-irpc-special'
|
||||
? { QualificationFields: () => null }
|
||||
: name === './fiscal-proof-parcel'
|
||||
? { FiscalProofParcelFields: () => null }
|
||||
: require(name),
|
||||
module,
|
||||
module.exports,
|
||||
);
|
||||
const Component = module.exports.SimulationIrpcPecCorrection;
|
||||
const text = (node) =>
|
||||
typeof node === 'string' || typeof node === 'number'
|
||||
? String(node)
|
||||
: React.isValidElement(node)
|
||||
? React.Children.toArray(node.props.children).map(text).join('')
|
||||
: '';
|
||||
const all = (node) =>
|
||||
React.isValidElement(node)
|
||||
? [node, ...React.Children.toArray(node.props.children).flatMap(all)]
|
||||
: [];
|
||||
test('actual correction form preserves original and revised values when retaining baseline', () => {
|
||||
let value;
|
||||
const render = () =>
|
||||
Component({
|
||||
value,
|
||||
original: '10000000',
|
||||
subjectNuit: '123456789',
|
||||
onChange: (next) => (value = next),
|
||||
});
|
||||
const click = (label) => {
|
||||
const n = all(render()).find(
|
||||
(x) => x.type === 'button' && text(x) === label,
|
||||
);
|
||||
assert.ok(n, label);
|
||||
n.props.onClick();
|
||||
};
|
||||
const change = (label, v) => {
|
||||
const n = all(render()).find((x) => x.props['aria-label'] === label);
|
||||
assert.ok(n, label);
|
||||
n.props.onChange({ target: { value: v } });
|
||||
};
|
||||
click('Rectificar volume na simulação PEC');
|
||||
assert.equal(value.originalTurnover, '10000000');
|
||||
assert.equal(value.subjectNuit, '123456789');
|
||||
change('Volume corrigido — PEC', '50000000');
|
||||
change(
|
||||
'Fonte e fundamento da rectificação PEC',
|
||||
'SYNTHETIC correction2025',
|
||||
);
|
||||
change('Aplicar rectificação PEC', 'yes');
|
||||
change('Aplicar rectificação PEC', 'no');
|
||||
assert.equal(value.revisedTurnover, '50000000');
|
||||
assert.equal(value.originalTurnover, '10000000');
|
||||
change('Aplicar rectificação PEC', 'yes');
|
||||
assert.match(renderToStaticMarkup(render()), /não submete declaração/);
|
||||
assert.match(text(render()), /original permanece/);
|
||||
});
|
||||
Reference in New Issue
Block a user