fix: retain editable investment plans and record partial QA continuity evidence
This commit is contained in:
@@ -1,26 +1,26 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import { createRequire } from "node:module";
|
||||
import { compileFunction } from "node:vm";
|
||||
import React from "react";
|
||||
import ts from "typescript";
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import { createRequire } from 'node:module';
|
||||
import { compileFunction } from 'node:vm';
|
||||
import React from 'react';
|
||||
import ts from 'typescript';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const nodes = (tree) =>
|
||||
Array.isArray(tree)
|
||||
? tree.flatMap(nodes)
|
||||
: tree && typeof tree === "object"
|
||||
: tree && typeof tree === 'object'
|
||||
? [tree, ...nodes(tree.props?.children)]
|
||||
: [];
|
||||
const text = (tree) =>
|
||||
Array.isArray(tree)
|
||||
? tree.map(text).join("")
|
||||
? tree.map(text).join('')
|
||||
: tree?.props
|
||||
? text(tree.props.children)
|
||||
: typeof tree === "string"
|
||||
: typeof tree === 'string'
|
||||
? tree
|
||||
: "";
|
||||
: '';
|
||||
|
||||
// Real page event handlers, simulated Inertia transport. Not a browser or visual acceptance.
|
||||
function harness(filters, errors = {}) {
|
||||
@@ -32,7 +32,8 @@ function harness(filters, errors = {}) {
|
||||
return [
|
||||
memory[id],
|
||||
(next) => {
|
||||
memory[id] = typeof next === "function" ? next(memory[id]) : next;
|
||||
memory[id] =
|
||||
typeof next === 'function' ? next(memory[id]) : next;
|
||||
},
|
||||
];
|
||||
};
|
||||
@@ -40,7 +41,10 @@ function harness(filters, errors = {}) {
|
||||
let form;
|
||||
const TerritoryFields = () => null;
|
||||
const module = { exports: {} };
|
||||
const source = fs.readFileSync("resources/js/pages/funding/index.tsx", "utf8");
|
||||
const source = fs.readFileSync(
|
||||
'resources/js/pages/funding/index.tsx',
|
||||
'utf8',
|
||||
);
|
||||
compileFunction(
|
||||
ts.transpileModule(source, {
|
||||
compilerOptions: {
|
||||
@@ -48,10 +52,10 @@ function harness(filters, errors = {}) {
|
||||
jsx: ts.JsxEmit.ReactJSX,
|
||||
},
|
||||
}).outputText,
|
||||
["require", "module", "exports"],
|
||||
['require', 'module', 'exports'],
|
||||
)(
|
||||
(id) => {
|
||||
if (id === "react")
|
||||
if (id === 'react')
|
||||
return {
|
||||
...React,
|
||||
useState: state,
|
||||
@@ -60,9 +64,9 @@ function harness(filters, errors = {}) {
|
||||
return value;
|
||||
},
|
||||
};
|
||||
if (id === "@inertiajs/react")
|
||||
if (id === '@inertiajs/react')
|
||||
return {
|
||||
Link: "a",
|
||||
Link: 'a',
|
||||
useForm(initial) {
|
||||
const [data, set] = state(initial);
|
||||
form = {
|
||||
@@ -70,7 +74,11 @@ function harness(filters, errors = {}) {
|
||||
errors: {},
|
||||
processing: false,
|
||||
setData(key, value) {
|
||||
set(typeof key === "string" ? { ...data, [key]: value } : key);
|
||||
set(
|
||||
typeof key === 'string'
|
||||
? { ...data, [key]: value }
|
||||
: key,
|
||||
);
|
||||
},
|
||||
get(url) {
|
||||
submitted = { url, data };
|
||||
@@ -79,22 +87,25 @@ function harness(filters, errors = {}) {
|
||||
return form;
|
||||
},
|
||||
};
|
||||
if (id === "@/pages/investment/shared") return { Frame: "main", card: "", button: "" };
|
||||
if (id === "@/components/funding-classification")
|
||||
if (id === '@/pages/investment/shared')
|
||||
return { Frame: 'main', card: '', button: '' };
|
||||
if (id === '@/components/funding-classification')
|
||||
return {
|
||||
financialCategories: {
|
||||
banking: "Banca",
|
||||
insurance_intermediation: "Mediação de seguros",
|
||||
banking: 'Banca',
|
||||
insurance_intermediation: 'Mediação de seguros',
|
||||
},
|
||||
financialTypes: {
|
||||
commercial_bank: "Banco comercial",
|
||||
broker: "Corretora",
|
||||
other: "Outro",
|
||||
commercial_bank: 'Banco comercial',
|
||||
broker: 'Corretora',
|
||||
other: 'Outro',
|
||||
},
|
||||
};
|
||||
if (id === "@/components/investment-territory") return { TerritoryFields };
|
||||
if (id === "@/components/funding-institution") return { InstitutionView: "article" };
|
||||
if (id === "./shared") return { windowLabels: {} };
|
||||
if (id === '@/components/investment-territory')
|
||||
return { TerritoryFields };
|
||||
if (id === '@/components/funding-institution')
|
||||
return { InstitutionView: 'article' };
|
||||
if (id === './shared') return { windowLabels: {} };
|
||||
return require(id);
|
||||
},
|
||||
module,
|
||||
@@ -105,11 +116,11 @@ function harness(filters, errors = {}) {
|
||||
criteriaErrors: errors,
|
||||
items: { data: [], links: [] },
|
||||
options: { sectors: [], territories: [] },
|
||||
kinds: { institution: "Instituição", fund: "Fundo" },
|
||||
kinds: { institution: 'Instituição', fund: 'Fundo' },
|
||||
management: false,
|
||||
categoryTypes: {
|
||||
banking: ["commercial_bank"],
|
||||
insurance_intermediation: ["broker"],
|
||||
banking: ['commercial_bank'],
|
||||
insurance_intermediation: ['broker'],
|
||||
},
|
||||
};
|
||||
let tree;
|
||||
@@ -120,9 +131,11 @@ function harness(filters, errors = {}) {
|
||||
return tree;
|
||||
}
|
||||
const select = (label) =>
|
||||
nodes(nodes(tree).find((n) => n.type === "label" && text(n).startsWith(label))).find(
|
||||
(n) => n.type === "select",
|
||||
);
|
||||
nodes(
|
||||
nodes(tree).find(
|
||||
(n) => n.type === 'label' && text(n).startsWith(label),
|
||||
),
|
||||
).find((n) => n.type === 'select');
|
||||
render();
|
||||
return {
|
||||
render,
|
||||
@@ -134,92 +147,150 @@ function harness(filters, errors = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
test("institution category restricts types and removes only an incompatible dependent choice", () => {
|
||||
void test('searching another province resets only the search location and preserves the investment scope', () => {
|
||||
const filters = {
|
||||
category: 'banking',
|
||||
institution_type: 'commercial_bank',
|
||||
need: 'investment',
|
||||
context: 'case-qa',
|
||||
opportunity: 'opportunity-qa',
|
||||
province_id: 'province-qa',
|
||||
district_id: 'district-qa',
|
||||
territory: 'district-qa',
|
||||
location_mode: 'physical',
|
||||
certainty: 'documented',
|
||||
};
|
||||
const h = harness(filters);
|
||||
const action = nodes(h.tree()).find(
|
||||
(n) =>
|
||||
n.type === 'button' &&
|
||||
text(n) === 'Procurar instituição noutra província',
|
||||
);
|
||||
assert.ok(action);
|
||||
action.props.onClick();
|
||||
h.render();
|
||||
for (const key of [
|
||||
'territory',
|
||||
'province_id',
|
||||
'district_id',
|
||||
'admin_post_id',
|
||||
'locality_id',
|
||||
])
|
||||
assert.equal(h.form().data[key], '');
|
||||
for (const key of [
|
||||
'category',
|
||||
'institution_type',
|
||||
'need',
|
||||
'context',
|
||||
'opportunity',
|
||||
'location_mode',
|
||||
'certainty',
|
||||
])
|
||||
assert.equal(h.form().data[key], filters[key]);
|
||||
assert.deepEqual(h.territory().props.initial, []);
|
||||
assert.equal(h.submitted(), undefined);
|
||||
assert.match(
|
||||
text(h.tree()),
|
||||
/a localização do investimento no dossier mantém-se/,
|
||||
);
|
||||
});
|
||||
|
||||
void test('institution category restricts types and removes only an incompatible dependent choice', () => {
|
||||
const h = harness({
|
||||
category: "insurance_intermediation",
|
||||
institution_type: "broker",
|
||||
sector: "7",
|
||||
need: "investment",
|
||||
territory: "district-qa",
|
||||
category: 'insurance_intermediation',
|
||||
institution_type: 'broker',
|
||||
sector: '7',
|
||||
need: 'investment',
|
||||
territory: 'district-qa',
|
||||
});
|
||||
h.select("Categoria da instituição").props.onChange({
|
||||
target: { value: "banking" },
|
||||
h.select('Categoria da instituição').props.onChange({
|
||||
target: { value: 'banking' },
|
||||
});
|
||||
h.render();
|
||||
assert.equal(h.form().data.institution_type, "");
|
||||
assert.equal(h.form().data.institution_type, '');
|
||||
for (const [key, value] of Object.entries({
|
||||
sector: "7",
|
||||
need: "investment",
|
||||
territory: "district-qa",
|
||||
sector: '7',
|
||||
need: 'investment',
|
||||
territory: 'district-qa',
|
||||
}))
|
||||
assert.equal(h.form().data[key], value);
|
||||
assert.deepEqual(
|
||||
nodes(h.select("Tipo de instituição"))
|
||||
.filter((n) => n.type === "option")
|
||||
nodes(h.select('Tipo de instituição'))
|
||||
.filter((n) => n.type === 'option')
|
||||
.map((n) => n.props.value),
|
||||
["", "commercial_bank", "other"],
|
||||
['', 'commercial_bank', 'other'],
|
||||
);
|
||||
assert.match(text(h.tree()), /tipo anterior não pertence/);
|
||||
const results = nodes(h.tree()).find((n) => n.type === "details");
|
||||
const results = nodes(h.tree()).find((n) => n.type === 'details');
|
||||
assert.equal(results.props.open, false);
|
||||
assert.match(text(results), /pesquisa anterior/);
|
||||
});
|
||||
|
||||
test("contradictory record criteria remain explicit until the user chooses a correction", () => {
|
||||
void test('contradictory record criteria remain explicit until the user chooses a correction', () => {
|
||||
const h = harness(
|
||||
{
|
||||
kind: "fund",
|
||||
category: "banking",
|
||||
institution_type: "commercial_bank",
|
||||
location_mode: "physical",
|
||||
province_id: "province-qa",
|
||||
sector: "8",
|
||||
state: "closed",
|
||||
certainty: "documented",
|
||||
kind: 'fund',
|
||||
category: 'banking',
|
||||
institution_type: 'commercial_bank',
|
||||
location_mode: 'physical',
|
||||
province_id: 'province-qa',
|
||||
sector: '8',
|
||||
state: 'closed',
|
||||
certainty: 'documented',
|
||||
},
|
||||
{ kind: ["Combinação incompatível."] },
|
||||
{ kind: ['Combinação incompatível.'] },
|
||||
);
|
||||
assert.match(text(h.tree()), /A pesquisa não foi executada/);
|
||||
assert.equal(h.form().data.kind, "fund");
|
||||
assert.equal(h.form().data.kind, 'fund');
|
||||
const action = nodes(h.tree()).find(
|
||||
(n) => n.type === "button" && /Manter o fundo/.test(text(n)),
|
||||
(n) => n.type === 'button' && /Manter o fundo/.test(text(n)),
|
||||
);
|
||||
action.props.onClick();
|
||||
h.render();
|
||||
assert.equal(h.form().data.category, "");
|
||||
assert.equal(h.form().data.institution_type, "");
|
||||
assert.equal(h.form().data.location_mode, "coverage");
|
||||
assert.equal(h.form().data.category, '');
|
||||
assert.equal(h.form().data.institution_type, '');
|
||||
assert.equal(h.form().data.location_mode, 'coverage');
|
||||
for (const [key, value] of Object.entries({
|
||||
kind: "fund",
|
||||
province_id: "province-qa",
|
||||
sector: "8",
|
||||
state: "closed",
|
||||
certainty: "documented",
|
||||
kind: 'fund',
|
||||
province_id: 'province-qa',
|
||||
sector: '8',
|
||||
state: 'closed',
|
||||
certainty: 'documented',
|
||||
}))
|
||||
assert.equal(h.form().data[key], value);
|
||||
nodes(h.tree())
|
||||
.find((n) => n.type === "form")
|
||||
.find((n) => n.type === 'form')
|
||||
.props.onSubmit({ preventDefault() {} });
|
||||
assert.equal(h.submitted().url, "/fundos");
|
||||
assert.equal(h.submitted().data.province_id, "province-qa");
|
||||
assert.ok(h.territory(), "the catalogue consumes the common hierarchical location control");
|
||||
assert.equal(h.submitted().url, '/fundos');
|
||||
assert.equal(h.submitted().data.province_id, 'province-qa');
|
||||
assert.ok(
|
||||
h.territory(),
|
||||
'the catalogue consumes the common hierarchical location control',
|
||||
);
|
||||
});
|
||||
|
||||
test("local search defaults to documented presence and keeps the explicit unknown option and chosen territory", () => {
|
||||
const h = harness({ territory: "district-qa", sector: "7" });
|
||||
h.select("Localização a pesquisar").props.onChange({ target: { value: "physical" } });
|
||||
h.render();
|
||||
assert.equal(h.form().data.certainty, "documented");
|
||||
assert.equal(h.form().data.territory, "district-qa");
|
||||
assert.equal(h.form().data.sector, "7");
|
||||
h.select("Informação por confirmar").props.onChange({ target: { value: "include_unknown" } });
|
||||
h.render();
|
||||
assert.equal(h.form().data.certainty, "include_unknown");
|
||||
const resumed = harness({
|
||||
location_mode: "physical",
|
||||
territory: "district-qa",
|
||||
certainty: "include_unknown",
|
||||
void test('local search defaults to documented presence and keeps the explicit unknown option and chosen territory', () => {
|
||||
const h = harness({ territory: 'district-qa', sector: '7' });
|
||||
h.select('Localização a pesquisar').props.onChange({
|
||||
target: { value: 'physical' },
|
||||
});
|
||||
assert.equal(resumed.form().data.certainty, "include_unknown");
|
||||
assert.equal(harness({ location_mode: "physical" }).form().data.certainty, "documented");
|
||||
h.render();
|
||||
assert.equal(h.form().data.certainty, 'documented');
|
||||
assert.equal(h.form().data.territory, 'district-qa');
|
||||
assert.equal(h.form().data.sector, '7');
|
||||
h.select('Informação por confirmar').props.onChange({
|
||||
target: { value: 'include_unknown' },
|
||||
});
|
||||
h.render();
|
||||
assert.equal(h.form().data.certainty, 'include_unknown');
|
||||
const resumed = harness({
|
||||
location_mode: 'physical',
|
||||
territory: 'district-qa',
|
||||
certainty: 'include_unknown',
|
||||
});
|
||||
assert.equal(resumed.form().data.certainty, 'include_unknown');
|
||||
assert.equal(
|
||||
harness({ location_mode: 'physical' }).form().data.certainty,
|
||||
'documented',
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user