Files
Investidor-V2/tests/frontend/territory-boundaries-once.test.mjs
T
Claude aff4ccea6c Mapa de erros: limites administrativos e complementos sem repetição
- Limites administrativos (4.3, 4.4, 4.5): quando o mapa já lista os limites,
  a pré-visualização territorial deixa de repetir a lista e a contagem; a data
  de cada limite passa a chamar-se sempre «Edição» e a advertência fica uma vez.
- Complementos da ficha da carteira (4.3, 4.9): a origem e a descrição dos
  complementos aparecem uma vez por investimento de origem; a referência interna
  ao documento de requisitos (.docx, secção) deixa de ser mostrada ao investidor,
  também na lista de complementos escolhidos do dossier.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jm
2026-12-04 17:30:39 +02:00

109 lines
3.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import * as publicPresentation from '../../resources/js/lib/public-presentation.ts';
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 { renderToStaticMarkup } from 'react-dom/server';
import ts from 'typescript';
const require = createRequire(import.meta.url);
function load(file, mocks = {}) {
const output = ts.transpileModule(
fs
.readFileSync(
new URL('../../resources/js/components/' + file, import.meta.url),
'utf8',
)
.replaceAll('import.meta.env.VITE_MAP_TILE_URL', 'undefined'),
{
compilerOptions: {
module: ts.ModuleKind.CommonJS,
target: ts.ScriptTarget.ES2022,
jsx: ts.JsxEmit.ReactJSX,
},
},
).outputText;
const module = { exports: {} };
compileFunction(output, ['require', 'module', 'exports'])(
(name) => {
if (name in mocks) return mocks[name];
if (name === '@/lib/public-presentation') return publicPresentation;
if (name.startsWith('./'))
return load(
name.slice(2) +
(fs.existsSync(
new URL(
'../../resources/js/components/' +
name.slice(2) +
'.tsx',
import.meta.url,
),
)
? '.tsx'
: '.ts'),
mocks,
);
return require(name);
},
module,
module.exports,
);
return module.exports;
}
const polygon = (x, y) => ({
type: 'Polygon',
coordinates: [[[x, y], [x + 1, y], [x + 1, y + 1], [x, y + 1], [x, y]]],
});
const area = (title, selected) => ({
geometry: polygon(selected ? 39 : 38, -13),
title,
purpose: 'administrative_boundary',
selected_territory: selected,
location_type: selected ? 'district' : 'province',
url: '/territorio',
source_reference: 'Mozambique INE - Instituto Nacional de Estatistica',
source_date: '2019-06-07',
});
test('each administrative boundary is listed once, with its edition, and the count is not repeated (mapa de erros 4.3–4.5)', () => {
const mocks = { leaflet: {}, 'leaflet/dist/leaflet.css': {} };
const { TerritoryGeometryDetails } = load(
'territory-geometry-preview.tsx',
mocks,
);
const context = {
selected_geometry_available: true,
context_geometry_count: 2,
areas: [area('ANCUABE', true), area('Cabo Delgado', false)],
truncated: false,
child_coverage: null,
};
const html = renderToStaticMarkup(
React.createElement(TerritoryGeometryDetails, {
context,
error: '',
renderMap: true,
}),
);
assert.equal(html.split('>ANCUABE<').length - 1, 1);
assert.equal(html.split('>Cabo Delgado<').length - 1, 1);
assert.doesNotMatch(html, /Data: 2019/);
assert.equal(html.split('Edição: 2019-06-07').length - 1, 2);
assert.doesNotMatch(html, /limites disponíveis na hierarquia/);
assert.equal(html.split('limites administrativos disponíveis').length - 1, 1);
assert.equal(
html.split('não representa um local de investimento').length - 1,
0,
);
assert.match(html, /São contexto administrativo/);
// Without a map the textual list remains the only list, with the count.
const textOnly = renderToStaticMarkup(
React.createElement(TerritoryGeometryDetails, { context, error: '' }),
);
assert.match(textOnly, /2 limites disponíveis na hierarquia consultada/);
assert.equal(textOnly.split('Edição: 2019-06-07').length - 1, 2);
});