68 lines
3.5 KiB
JavaScript
68 lines
3.5 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import {
|
|
getAutosaveSnapshot,
|
|
partitionSimulationDraft,
|
|
replaceSimulationValue,
|
|
restoreSimulationDraft,
|
|
simulationDraftFingerprint,
|
|
validateSimulationDraft,
|
|
} from "../../resources/js/lib/simulation-form.ts";
|
|
|
|
test("changing territorial or sector parents clears every dependent value", () => {
|
|
assert.deepEqual(
|
|
replaceSimulationValue({
|
|
province_id: "p1", district_id: "d1", admin_post_id: "a1", locality_id: "l1",
|
|
}, "province_id", "p2"),
|
|
{ province_id: "p2" },
|
|
);
|
|
assert.deepEqual(
|
|
replaceSimulationValue({ sector_id: "s1", activity_id: "a1", activity_id_label: "A" }, "sector_id", "s2"),
|
|
{ sector_id: "s2" },
|
|
);
|
|
});
|
|
|
|
test("switching to anonymous simulation clears formal identity and project data", () => {
|
|
const next = replaceSimulationValue({
|
|
purpose: "own_investment", legal_name: "Empresa", email: "a@b.co", project_title: "Projecto",
|
|
total_investment: "10", total_investment_label: "10",
|
|
}, "purpose", "simulate_only");
|
|
assert.deepEqual(next, { purpose: "simulate_only" });
|
|
});
|
|
|
|
test("client validation rejects absent arithmetic inputs and out-of-range rates", () => {
|
|
assert.deepEqual(validateSimulationDraft({ purpose: "simulate_only", tax_calculation: "yes" }, "tax"), {
|
|
base: "Este campo é obrigatório.",
|
|
rate: "Este campo é obrigatório.",
|
|
reduction: "Este campo é obrigatório.",
|
|
});
|
|
assert.equal(validateSimulationDraft({ purpose: "simulate_only", tax_calculation: "yes", base: "0", rate: "101", reduction: "0" }, "tax").rate,
|
|
"O valor não pode exceder 100.");
|
|
});
|
|
|
|
test("financial reconciliation reports a mismatch without inventing a fiscal value", () => {
|
|
const errors = validateSimulationDraft({
|
|
currency: "USD", total_investment: "100", own_capital: "20", domestic_debt: "20", foreign_debt: "20", grants: "20",
|
|
}, "financial");
|
|
assert.match(errors.total_investment, /corresponder ao investimento total/);
|
|
assert.equal(validateSimulationDraft({}, "financial").currency, "Este campo é obrigatório.");
|
|
});
|
|
|
|
test("autosave omits identity and contact fields from browser storage", () => {
|
|
assert.deepEqual(getAutosaveSnapshot({
|
|
total_investment: "50", legal_name: "Nome", email: "person@example.com", nuit: "123",
|
|
project_title: "Projecto", legal_name_label: "Nome",
|
|
}), { total_investment: "50", project_title: "Projecto" });
|
|
});
|
|
|
|
test("server draft snapshots split private identity from economic values", () => {
|
|
assert.deepEqual(partitionSimulationDraft({ purpose: "simulate_only", legal_name: "Nome", base: "10", rate: "2", province_id_label: "Tete", person_type: "collective", person_type_label: "Pessoa colectiva" }), {
|
|
personal_snapshot: { legal_name: "Nome", person_type: "collective", selection_labels: { person_type: "Pessoa colectiva" } },
|
|
economic_snapshot: { purpose: "simulate_only", base: "10", rate: "2", selection_labels: { province_id: "Tete" } },
|
|
});
|
|
assert.deepEqual(restoreSimulationDraft({ activity_id: "uuid", infrastructure_needs: ["energia", "água"], selection_labels: { activity_id: "Energia", infrastructure_needs: ["Energia", "Água"] } }, {}), {
|
|
activity_id: "uuid", activity_id_label: "Energia", infrastructure_needs: ["energia", "água"], infrastructure_needs_label: ["Energia", "Água"],
|
|
});
|
|
assert.equal(simulationDraftFingerprint({ base: "10", purpose: "simulate_only" }), simulationDraftFingerprint({ purpose: "simulate_only", base: "10" }));
|
|
});
|