From aff4ccea6ce8b4d124436e1081ff6532c27d3c8b Mon Sep 17 00:00:00 2001
From: Claude
Date: Fri, 4 Dec 2026 14:58:18 +0200
Subject: [PATCH] =?UTF-8?q?Mapa=20de=20erros:=20limites=20administrativos?=
=?UTF-8?q?=20e=20complementos=20sem=20repeti=C3=A7=C3=A3o?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 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
Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jm
---
.../components/interactive-investment-map.tsx | 19 +-
.../js/components/investment-complements.tsx | 192 +++++++++++-------
.../components/territory-geometry-preview.tsx | 13 +-
...vestment-complements-presentation.test.mjs | 117 +++++++++++
.../territory-boundaries-once.test.mjs | 108 ++++++++++
5 files changed, 369 insertions(+), 80 deletions(-)
create mode 100644 tests/frontend/investment-complements-presentation.test.mjs
create mode 100644 tests/frontend/territory-boundaries-once.test.mjs
diff --git a/resources/js/components/interactive-investment-map.tsx b/resources/js/components/interactive-investment-map.tsx
index d6d70321..64f9f30c 100644
--- a/resources/js/components/interactive-investment-map.tsx
+++ b/resources/js/components/interactive-investment-map.tsx
@@ -68,6 +68,12 @@ export default function InteractiveInvestmentMap({
documented_locations: 'Mapa dos locais documentados',
declared_parcel: 'Perímetro declarado pelo Promotor',
}[mapKind];
+ const administrativeRole = (area: InvestmentMapArea) =>
+ area.selected_territory
+ ? 'Território seleccionado'
+ : area.child_territory
+ ? 'Subdivisão do território seleccionado'
+ : 'Contexto de nível superior';
const areaDescription = (area: InvestmentMapArea) =>
area.purpose === 'administrative_boundary'
? `${area.selected_territory ? 'Território seleccionado' : area.child_territory ? 'Subdivisão do território seleccionado' : 'Contexto de nível superior'} · Limite administrativo da edição indicada; não representa um local de investimento`
@@ -512,10 +518,19 @@ export default function InteractiveInvestmentMap({
{area.title}
{' '}
- · {areaDescription(area)} · Fonte:{' '}
+ ·{' '}
+ {mapKind === 'administrative' &&
+ area.purpose === 'administrative_boundary'
+ ? administrativeRole(area)
+ : areaDescription(area)}{' '}
+ · Fonte:{' '}
{publicReference(area.source_reference) ??
'Não indicada'}{' '}
- · Data: {area.source_date ?? 'Não documentada'}
+ ·{' '}
+ {area.purpose === 'administrative_boundary'
+ ? 'Edição'
+ : 'Data'}
+ : {area.source_date ?? 'Não documentada'}
))}
diff --git a/resources/js/components/investment-complements.tsx b/resources/js/components/investment-complements.tsx
index 472c0b2a..6cbaff63 100644
--- a/resources/js/components/investment-complements.tsx
+++ b/resources/js/components/investment-complements.tsx
@@ -90,9 +90,6 @@ export function SelectedComplements({
antes de a utilizar.
)}
-
- Fonte: {item.source} · Trecho: {item.excerpt}
-
{onRemove && (
candidate.key === key);
+ if (group) group.items.push(item);
+ else
+ groups.push({
+ key,
+ origin: item.origin,
+ territory,
+ excerpt: item.excerpt.trim(),
+ items: [item],
+ });
+ }
+ return groups;
+}
+
export default function InvestmentComplements({
items,
dossierId,
@@ -159,79 +182,102 @@ export default function InvestmentComplements({
Escolha os complementos relevantes para o seu investimento. A
localização e as condições de cada ficha conservam-se.
- {items.map((item) => (
-
- {item.title}
+ {complementGroups(items).map((group) => (
+
- Investimento de origem: {item.origin.title} ·{' '}
- {item.territory?.title ?? 'Localização por definir'}
+ Investimento de origem: {group.origin.title} ·{' '}
+ {group.territory ?? 'Localização por definir'}
-
- Referência: {item.source} · Trecho: {item.excerpt}
-
- {[...item.opportunities, ...item.services].map((offer) => (
-
-
- {
- if (onNavigate) {
- event.preventDefault();
- onNavigate(consult(item, offer));
- }
- }}
- >
- {offer.title}
- {' '}
- · {offer.location}
-
-
{
- if (onNavigate) {
- event.preventDefault();
- onNavigate(prepare(item, offer));
- }
- }}
- >
- Seleccionar esta{' '}
- {offer.key.startsWith('opportunity:')
- ? 'oportunidade'
- : 'oferta'}{' '}
- para o dossier
-
-
- ))}
- {!item.opportunities.length && !item.services.length && (
- <>
-
- Necessidade complementar referida; sem oferta
- cadastrada identificada nas relações deste
- contexto.
-
- {
- if (onNavigate) {
- event.preventDefault();
- onNavigate(prepare(item));
- }
- }}
- >
- Iniciar preparação de uma ideia de{' '}
- {item.title.toLocaleLowerCase('pt-MZ')}
-
- >
+ {group.excerpt && (
+
+ Complementos habitualmente associados:{' '}
+ {group.excerpt}
+
)}
-
+ {group.items.map((item) => (
+
+ {item.title}
+ {[...item.opportunities, ...item.services].map(
+ (offer) => (
+
+
+ {
+ if (onNavigate) {
+ event.preventDefault();
+ onNavigate(
+ consult(
+ item,
+ offer,
+ ),
+ );
+ }
+ }}
+ >
+ {offer.title}
+ {' '}
+ · {offer.location}
+
+
{
+ if (onNavigate) {
+ event.preventDefault();
+ onNavigate(
+ prepare(item, offer),
+ );
+ }
+ }}
+ >
+ Seleccionar esta{' '}
+ {offer.key.startsWith(
+ 'opportunity:',
+ )
+ ? 'oportunidade'
+ : 'oferta'}{' '}
+ para o dossier
+
+
+ ),
+ )}
+ {!item.opportunities.length &&
+ !item.services.length && (
+ <>
+
+ Necessidade complementar referida;
+ sem oferta cadastrada identificada
+ nas relações deste contexto.
+
+ {
+ if (onNavigate) {
+ event.preventDefault();
+ onNavigate(prepare(item));
+ }
+ }}
+ >
+ Iniciar preparação de uma ideia de{' '}
+ {item.title.toLocaleLowerCase(
+ 'pt-MZ',
+ )}
+
+ >
+ )}
+
+ ))}
+
))}
);
diff --git a/resources/js/components/territory-geometry-preview.tsx b/resources/js/components/territory-geometry-preview.tsx
index 7734f59a..998b1c95 100644
--- a/resources/js/components/territory-geometry-preview.tsx
+++ b/resources/js/components/territory-geometry-preview.tsx
@@ -47,6 +47,8 @@ export function TerritoryGeometryDetails({
renderMap?: boolean;
showSources?: boolean;
}) {
+ // The map lists each boundary and its count itself; a second list repeated every limit.
+ const mapLists = Boolean(renderMap && context && context.areas.length > 0);
return (
Território selecionado no cadastro.
@@ -68,10 +70,11 @@ export function TerritoryGeometryDetails({
)}
- {context.context_geometry_count} limites disponíveis na
- hierarquia consultada. São contexto administrativo, não
- perímetro nem disponibilidade de investimento. A edição
- e a atualidade jurídica são informações distintas.
+ {!mapLists &&
+ `${context.context_geometry_count} limites disponíveis na hierarquia consultada. `}
+ São contexto administrativo, não perímetro nem
+ disponibilidade de investimento. A edição e a
+ actualidade jurídica são informações distintas.
{context.child_coverage?.location_type && (
@@ -97,7 +100,7 @@ export function TerritoryGeometryDetails({
contextOnly
/>
)}
- {showSources && (
+ {showSources && !mapLists && (
{context.areas.map((area, index) => (
diff --git a/tests/frontend/investment-complements-presentation.test.mjs b/tests/frontend/investment-complements-presentation.test.mjs
new file mode 100644
index 00000000..c97f00eb
--- /dev/null
+++ b/tests/frontend/investment-complements-presentation.test.mjs
@@ -0,0 +1,117 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import fs from 'node:fs';
+import path from 'node:path';
+import { createRequire } from 'node:module';
+import { compileFunction } from 'node:vm';
+import React from 'react';
+import { renderToStaticMarkup } from 'react-dom/server';
+import ts from 'typescript';
+
+const require = createRequire(import.meta.url);
+const root = path.resolve('resources/js');
+function load(file) {
+ const absolute = path.resolve(root, file);
+ const module = { exports: {} };
+ const code = ts.transpileModule(fs.readFileSync(absolute, 'utf8'), {
+ compilerOptions: {
+ module: ts.ModuleKind.CommonJS,
+ target: ts.ScriptTarget.ES2022,
+ jsx: ts.JsxEmit.ReactJSX,
+ },
+ }).outputText;
+ compileFunction(code, ['require', 'module', 'exports'])(
+ (id) => {
+ if (id === '@inertiajs/react')
+ return {
+ Link: ({ children, ...props }) =>
+ React.createElement('a', props, children),
+ usePage: () => ({ url: '/carteira/x', props: {} }),
+ };
+ if (id.startsWith('@/')) {
+ const base = path.resolve(root, id.slice(2));
+ const found = [base + '.ts', base + '.tsx'].find((p) =>
+ fs.existsSync(p),
+ );
+ if (found) return load(path.relative(root, found));
+ }
+ return require(id);
+ },
+ module,
+ module.exports,
+ );
+ return module.exports;
+}
+
+const source = 'upgrade do portal de investimentos v4 programacao.docx — 4.5.2';
+const excerpt =
+ 'Irrigação, sementes, mecanização, frio, silos, embalagem, certificação, financiamento e compradores.';
+const origin = {
+ key: 'opportunity:1',
+ title: 'Agro-indústria e segurança alimentar',
+ href: '/carteira/1',
+};
+const option = (code, title) => ({
+ code,
+ title,
+ origin,
+ territory_id: null,
+ territory: null,
+ source,
+ excerpt,
+ source_sha256: 'a'.repeat(64),
+ opportunities: [],
+ services: [],
+});
+
+test('complements show the origin and excerpt once, without the internal requirements reference (mapa de erros 4.3)', () => {
+ const { default: InvestmentComplements } = load(
+ 'components/investment-complements.tsx',
+ );
+ const html = renderToStaticMarkup(
+ React.createElement(InvestmentComplements, {
+ items: [
+ option('irrigation', 'Regadio'),
+ option('storage', 'Silos e armazenagem'),
+ option('cold', 'Cadeia de frio'),
+ ],
+ }),
+ );
+ assert.doesNotMatch(html, /programacao|\.docx|Referência:|Trecho:/);
+ assert.doesNotMatch(html, /a{64}/);
+ assert.equal(html.split('Investimento de origem:').length - 1, 1);
+ assert.equal(html.split('Irrigação, sementes').length - 1, 1);
+ for (const title of ['Regadio', 'Silos e armazenagem', 'Cadeia de frio'])
+ assert.match(html, new RegExp(title));
+ assert.equal(
+ html.split('Iniciar preparação de uma ideia de').length - 1,
+ 3,
+ );
+});
+
+test('selected complements in the dossier do not expose the internal source either', () => {
+ const { SelectedComplements } = load(
+ 'components/investment-complements.tsx',
+ );
+ const html = renderToStaticMarkup(
+ React.createElement(SelectedComplements, {
+ items: [
+ {
+ key: 'k',
+ code: 'irrigation',
+ title: 'Regadio',
+ kind: 'need',
+ origin,
+ target: null,
+ territory_id: null,
+ territory: null,
+ source,
+ excerpt,
+ source_sha256: 'a'.repeat(64),
+ },
+ ],
+ }),
+ );
+ assert.doesNotMatch(html, /programacao|\.docx|Fonte:|Trecho:/);
+ assert.match(html, /Regadio/);
+});
diff --git a/tests/frontend/territory-boundaries-once.test.mjs b/tests/frontend/territory-boundaries-once.test.mjs
new file mode 100644
index 00000000..7822ac5b
--- /dev/null
+++ b/tests/frontend/territory-boundaries-once.test.mjs
@@ -0,0 +1,108 @@
+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);
+});