fix: correct V13 and public presentation patterns in isolated QA

This commit is contained in:
2026-11-21 12:36:28 +02:00
parent 1950bb69ec
commit e239a31a76
66 changed files with 3977 additions and 278 deletions
@@ -0,0 +1,133 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {
correctionFieldHints,
fieldLabelMatches,
} from '../../resources/js/lib/field-corrections.ts';
import {
publicReference,
publicSourceHref,
publicLocation,
uniquePresentation,
publicPortfolioText,
} from '../../resources/js/lib/public-presentation.ts';
import {
catalogueFilterHref,
catalogueDetailHref,
catalogueReturnHref,
} from '../../resources/js/lib/catalogue-context.ts';
test('existing diagnostics point to matching labels without inventing fields for unknown messages', () => {
const hints = correctionFieldHints(
'O capital discriminado não coincide com o capital próprio.',
);
assert.ok(
hints.some((h) => fieldLabelMatches('Capital do proprietário', h)),
);
assert.ok(hints.some((h) => fieldLabelMatches('Capital próprio (MZN)', h)));
assert.ok(
correctionFieldHints(
'Confira «Preço por unidade»: valor em falta.',
).some((h) => fieldLabelMatches('Preço por unidade', h)),
);
assert.equal(
correctionFieldHints('Situação não prevista').some((h) =>
fieldLabelMatches('Capital próprio', h),
),
false,
);
assert.equal(
fieldLabelMatches('Capital do investidor', 'Capital do proprietário'),
false,
);
});
test('public sources retain legal references and official PHP links, excluding local paths and executable schemes', () => {
for (const value of [
'C:\\laragon\\www\\portal\\app.php',
'docs/auditoria/e25.json',
'QA-20261121',
'http://127.0.0.3:18724/private',
'javascript:alert(1)',
'https://example.org/resources/js/report.ts',
])
assert.equal(publicReference(value), null, value);
assert.equal(publicReference('Decreto n.º 70/2009'), 'Decreto n.º 70/2009');
assert.equal(
publicSourceHref('https://example.gov.mz/documento.php?id=70'),
'https://example.gov.mz/documento.php?id=70',
);
assert.equal(publicSourceHref('Decreto n.º 70/2009'), undefined);
});
test('presentation deduplicates identical editions and preserves source records and full location', () => {
const rows = Object.freeze([
Object.freeze({ ref: 'Lei', date: '2020' }),
Object.freeze({ ref: 'Lei', date: '2020' }),
Object.freeze({ ref: 'Lei', date: '2024' }),
]);
assert.equal(uniquePresentation(rows, (r) => r.ref + r.date).length, 2);
assert.equal(rows.length, 3);
assert.equal(
publicLocation([
{ name: 'Cabo Delgado' },
{ name: 'Balama' },
{ name: 'Balama' },
]),
'Cabo Delgado · Balama · Balama',
);
});
test('published names replace internal cross-reference codes without replacing a code inside a word or altering originals', () => {
const names = Object.freeze({
A06: 'Projecto de arroz',
'CLU-01': 'Cluster industrial',
'A.1': 'Nome pontuado',
});
assert.equal(
publicPortfolioText(
'A06 e CLU-01; A.1. CA06 e A060 permanecem.',
names,
),
'Projecto de arroz e Cluster industrial; Nome pontuado. CA06 e A060 permanecem.',
);
assert.equal(names.A06, 'Projecto de arroz');
});
test('filter removal clears actual indexed arrays and dependent geography without losing deliberate criteria', () => {
assert.equal(
catalogueFilterHref(
'/oportunidades?q=arroz&facets%5B0%5D=a&facets%5B1%5D=b&page=3',
['q', 'facets'],
'facets',
),
'/oportunidades?q=arroz',
);
assert.equal(
catalogueFilterHref(
'/zonas?category=zee&province_id=p&district_id=d&locality_id=l&activity=energia&page=2',
[],
'province_id',
),
'/zonas?category=zee&activity=energia',
);
assert.equal(
catalogueFilterHref('/zonas?category=zee&q=arroz&page=2', [
'category',
'q',
]),
'/zonas',
);
const detail = catalogueDetailHref(
'/zonas/zone',
'category=industrial_park&activity=energia&q=Balama&page=2',
);
const back = new URL(
catalogueReturnHref('/zonas', detail),
'https://portal.invalid',
);
assert.equal(back.searchParams.get('activity'), 'energia');
assert.equal(back.searchParams.get('category'), 'industrial_park');
assert.equal(back.searchParams.get('q'), 'Balama');
assert.equal(back.searchParams.get('page'), '2');
});
@@ -0,0 +1,216 @@
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 ts from 'typescript';
import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import * as publicPresentation from '../../resources/js/lib/public-presentation.ts';
import { displayReportMoney } from '../../resources/js/lib/integral-financial-report.ts';
const require = createRequire(import.meta.url);
function component(name) {
const module = { exports: {} };
const code = ts.transpileModule(
fs.readFileSync(
new URL(
`../../resources/js/components/${name}.tsx`,
import.meta.url,
),
'utf8',
),
{
compilerOptions: {
module: ts.ModuleKind.CommonJS,
target: ts.ScriptTarget.ES2022,
jsx: ts.JsxEmit.ReactJSX,
},
},
).outputText;
compileFunction(code, ['require', 'module', 'exports'])(
(id) =>
id === '@/lib/public-presentation'
? publicPresentation
: id.startsWith('./')
? component(id.slice(2))
: require(id),
module,
module.exports,
);
return module.exports;
}
test('real public source list separates links, merges duplicate notes, retains different editions and original data', () => {
const sources = [
{
title: 'Lei de investimento',
url: 'https://example.gov.mz/lei.php',
source_date: '2020-01-01',
supports: 'Âmbito territorial',
},
{
title: 'Lei de investimento',
url: 'https://example.gov.mz/lei.php',
source_date: '2020-01-01',
supports: 'Âmbito territorial',
},
{
title: 'Lei de investimento',
url: 'https://example.gov.mz/lei.php',
source_date: '2024-01-01',
supports: 'Edição posterior',
},
{
title: 'docs/interno.json',
url: 'C:\\portal\\app.php',
supports: 'QA-20261121',
},
];
const before = JSON.stringify(sources);
const html = renderToStaticMarkup(
React.createElement(component('public-source-list').default, {
sources,
}),
);
assert.equal((html.match(/<li>/g) || []).length, 2);
assert.equal((html.match(/Âmbito territorial/g) || []).length, 1);
assert.match(html, /2020-01-01/);
assert.match(html, /2024-01-01/);
assert.match(html, /href="https:\/\/example.gov.mz\/lei.php"/);
assert.doesNotMatch(html, /docs\/interno|QA-20261121|C:\\portal/);
assert.equal(JSON.stringify(sources), before);
});
test('real report tables expose existing message for navigation without changing their rows or values', () => {
const module = { exports: {} };
const code = ts.transpileModule(
fs.readFileSync(
new URL(
'../../resources/js/components/investment-report-tables.tsx',
import.meta.url,
),
'utf8',
),
{
compilerOptions: {
module: ts.ModuleKind.CommonJS,
target: ts.ScriptTarget.ES2022,
jsx: ts.JsxEmit.ReactJSX,
},
},
).outputText;
compileFunction(code, ['require', 'module', 'exports'])(
(id) =>
id === '@/lib/integral-financial-report'
? { displayReportMoney }
: id === '@/lib/financial-issue-presentation'
? {
financialIssuesForDisplay: () => [
{
message: 'Confira «Capital próprio».',
tables: ['Quadro'],
},
],
}
: require(id),
module,
module.exports,
);
const tables = [
{
id: 'synthetic',
title: 'Quadro',
headers: ['Rubrica', 'Janeiro'],
rows: [['Saldo declarado', '123.45']],
notes: [],
issues: ['Confira «Capital próprio».'],
},
];
const before = JSON.stringify(tables);
const html = renderToStaticMarkup(
React.createElement(module.exports.InvestmentReportTables, { tables }),
);
assert.match(html, /data-correction-message="Confira «Capital próprio»."/);
assert.doesNotMatch(html, /href="#portal-corrections"/); // Read-only report consumers need no dead editor link.
assert.match(html, /Saldo declarado/);
assert.equal(JSON.stringify(tables), before);
});
test('real territorial presentation removes identical geometry editions but preserves distinct dates and full hierarchy', () => {
const module = { exports: {} };
const code = ts.transpileModule(
fs.readFileSync(
new URL(
'../../resources/js/components/structure-geography.tsx',
import.meta.url,
),
'utf8',
),
{
compilerOptions: {
module: ts.ModuleKind.CommonJS,
target: ts.ScriptTarget.ES2022,
jsx: ts.JsxEmit.ReactJSX,
},
},
).outputText;
compileFunction(code, ['require', 'module', 'exports'])(
(id) =>
id === '@/lib/public-presentation'
? publicPresentation
: id === './public-reference'
? component('public-reference')
: id === '@inertiajs/react'
? {
Link: ({ children, ...p }) =>
React.createElement('a', p, children),
}
: id.startsWith('./')
? { default: () => null }
: require(id),
module,
module.exports,
);
const point = {
geometry_id: 'point-1',
source_reference: 'Decreto 70/2009',
source_date: '2020-01-01',
geometry: { coordinates: [32, -25] },
};
const boundary = {
geometry_id: 'boundary-1',
source_reference: 'Decreto 70/2009',
source_date: '2020-01-01',
geometry: { type: 'Polygon', coordinates: [] },
};
const locations = [
{
id: 'location',
name: 'Balama sintético',
role: 'primary',
location_type: 'district',
path: [
{ id: 'p', name: 'Cabo Delgado', location_type: 'province' },
{ id: 'd', name: 'Balama', location_type: 'district' },
],
coordinates: [
point,
{ ...point },
{ ...point, source_date: '2024-01-01' },
],
boundaries: [
boundary,
{ ...boundary },
{ ...boundary, source_date: '2024-01-01' },
],
},
];
const before = JSON.stringify(locations);
const html = renderToStaticMarkup(
React.createElement(module.exports.LocationList, { locations }),
);
assert.equal((html.match(/Coordenadas documentadas/g) || []).length, 2);
assert.equal((html.match(/Polígono cadastrado/g) || []).length, 2);
assert.match(html, /Cabo Delgado/);
assert.match(html, /Balama/);
assert.match(html, /2024-01-01/);
assert.equal(JSON.stringify(locations), before);
});