fix: persist annual demonstration through existing simulation drafts
This commit is contained in:
@@ -6,6 +6,10 @@ import { compileFunction } from 'node:vm';
|
||||
import ts from 'typescript';
|
||||
import React from 'react';
|
||||
import * as business from '../../resources/js/lib/business-financial-plan.ts';
|
||||
import {
|
||||
newAnnualReferencePlan,
|
||||
serializeAnnualExampleSnapshot,
|
||||
} from '../../resources/js/lib/business-plan-guidance.ts';
|
||||
import * as contract from '../../resources/js/lib/simulation-contract.ts';
|
||||
import * as bridge from '../../resources/js/lib/financial-fiscal-bridge.ts';
|
||||
import { validateSimulationDraft } from '../../resources/js/lib/simulation-form.ts';
|
||||
@@ -140,9 +144,40 @@ function editor(initialSnapshot) {
|
||||
render();
|
||||
},
|
||||
snapshot: () => snapshot,
|
||||
example() {
|
||||
const toggle = walk(
|
||||
tree,
|
||||
(node) =>
|
||||
node.type === 'button' &&
|
||||
React.Children.toArray(node.props.children).some(
|
||||
(child) =>
|
||||
child === 'Carregar cenário anual de exemplo',
|
||||
),
|
||||
);
|
||||
if (toggle) {
|
||||
toggle.props.onClick();
|
||||
render();
|
||||
}
|
||||
return walk(
|
||||
tree,
|
||||
(node) => typeof node.props?.onSnapshotChange === 'function',
|
||||
)?.props;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
void test('annual example snapshot is saved through the existing parent callback and recovered by a fresh editor', () => {
|
||||
const form = editor();
|
||||
const exampleSnapshot = serializeAnnualExampleSnapshot(
|
||||
newAnnualReferencePlan(),
|
||||
);
|
||||
form.example().onSnapshotChange(exampleSnapshot);
|
||||
const recovered = editor(form.snapshot());
|
||||
assert.equal(recovered.example().snapshot, exampleSnapshot);
|
||||
recovered.edit('Preço por unidade', '250.50');
|
||||
assert.equal(recovered.example().snapshot, exampleSnapshot);
|
||||
});
|
||||
|
||||
void test('monthly units, unit price, variable cost and operating expenses remain editable after snapshot echo', () => {
|
||||
const form = editor();
|
||||
for (const label of [
|
||||
|
||||
Reference in New Issue
Block a user