diff --git a/resources/js/components/demographic-evidence.tsx b/resources/js/components/demographic-evidence.tsx index 3082722b..a75d1cc2 100644 --- a/resources/js/components/demographic-evidence.tsx +++ b/resources/js/components/demographic-evidence.tsx @@ -280,17 +280,35 @@ export default function DemographicEvidence({

Diferenças entre localizações

- {Array.from( - new Set(evidence.comparisons.map((c) => c.year)), - ) - .sort((a, b) => a - b) - .map((year) => ( -
-

{year}

- {evidence.comparisons - .filter((c) => c.year === year) +
+ + + + + {[ + 'Ano', + 'Localização', + 'População', + 'Comparada com', + 'População', + 'Diferença', + ].map((h, index) => ( + + ))} + + + + {[...evidence.comparisons] + .sort((a, b) => a.year - b.year) .map((c) => ( -

- {c.left} ( - {populationValueLabel(c.left_value)} - ) / {c.right} ( - {populationValueLabel( - c.right_value, - )} - ). Diferença:{' '} - {c.difference === null - ? 'não comparável: âmbitos ou metadados distintos' - : populationValueLabel( - c.difference, - )} - {c.difference !== null && - ' pessoas'} - . -

+ + + + + + + ))} - - ))} + +
+ População total por ano (pessoas). A diferença + compara os totais do mesmo ano e da mesma + edição; não mede procura efectiva. +
+ {h} +
{c.year}{c.left} + {populationValueLabel( + c.left_value, + )} + {c.right} + {populationValueLabel( + c.right_value, + )} + + {c.difference === null + ? 'Não comparável: âmbitos ou metadados distintos' + : populationValueLabel( + c.difference, + )} +
+
)} {evidence.differences.some( diff --git a/resources/js/components/next-actions.tsx b/resources/js/components/next-actions.tsx new file mode 100644 index 00000000..e4cd7a84 --- /dev/null +++ b/resources/js/components/next-actions.tsx @@ -0,0 +1,39 @@ +import { Link } from '@inertiajs/react'; + +export type NextAction = { label: string; href: string; description?: string }; + +/** + * Next steps grouped in one place, one per line, apart from the surrounding text + * (mapa de erros 4.5: options mixed into a line of text are hard to find). + */ +export default function NextActions({ + title = 'Próximos passos', + actions, +}: { + title?: string; + actions: NextAction[]; +}) { + if (!actions.length) return null; + return ( + + ); +} diff --git a/resources/js/pages/portfolio/index.tsx b/resources/js/pages/portfolio/index.tsx index daabe751..fb282201 100644 --- a/resources/js/pages/portfolio/index.tsx +++ b/resources/js/pages/portfolio/index.tsx @@ -1,4 +1,5 @@ import { Link, useForm, usePage } from '@inertiajs/react'; +import NextActions from '@/components/next-actions'; import { publicPortfolioText } from '@/lib/public-presentation'; import { searchTerritoryHref } from '@/lib/search-territory'; import { catalogueDetailHref } from '@/lib/catalogue-context'; @@ -221,26 +222,26 @@ export default function Index({ não representa concursos abertos nem confirma disponibilidade de infra-estruturas ou incentivos.

- + )} diff --git a/tests/frontend/demographic-reading.test.mjs b/tests/frontend/demographic-reading.test.mjs index ed30ea20..b720c8c2 100644 --- a/tests/frontend/demographic-reading.test.mjs +++ b/tests/frontend/demographic-reading.test.mjs @@ -276,7 +276,7 @@ test('annual comparisons format all populations and do not repeat technical expl assert.match(html, /157\s983/); assert.match(html, /46\s657/); assert.match(html, /111\s326/); - assert.match(html, /]*>2027<\/h3>/); + assert.match(html, /]*>2027<\/td>/); assert.doesNotMatch(html, /111326\.479|INTERNAL REPEATED/); assert.equal( ( diff --git a/tests/frontend/portfolio-embedded-opportunities.test.mjs b/tests/frontend/portfolio-embedded-opportunities.test.mjs index d8d22592..162b5c03 100644 --- a/tests/frontend/portfolio-embedded-opportunities.test.mjs +++ b/tests/frontend/portfolio-embedded-opportunities.test.mjs @@ -41,6 +41,25 @@ compileFunction( useForm: (data) => ({ data, setData() {}, get() {} }), usePage: () => ({ url: '/carteira?q=Soja' }), }; + if (name === '@/components/next-actions') + return { + default: ({ actions }) => + React.createElement( + 'ul', + null, + actions.map((action) => + React.createElement( + 'li', + { key: action.href }, + React.createElement( + 'a', + { href: action.href }, + action.label, + ), + ), + ), + ), + }; if (name === '@/lib/catalogue-context') return catalogue; if (name === '@/lib/search-territory') return territory; if (name === '@/components/investment-territory') diff --git a/tests/frontend/presentation-error-map.test.mjs b/tests/frontend/presentation-error-map.test.mjs new file mode 100644 index 00000000..c4782881 --- /dev/null +++ b/tests/frontend/presentation-error-map.test.mjs @@ -0,0 +1,119 @@ +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: '/x', props: {} }), + }; + if (id.startsWith('.') || id.startsWith('@/')) { + const base = id.startsWith('@/') + ? path.resolve(root, id.slice(2)) + : path.resolve(path.dirname(absolute), id); + const found = [base + '.tsx', base + '.ts'].find((p) => + fs.existsSync(p), + ); + if (found) return load(path.relative(root, found)); + } + return require(id); + }, + module, + module.exports, + ); + return module.exports; +} + +test('differences between places are a yearly table of whole people with the warning once (mapa de erros 4.1)', () => { + const { default: DemographicEvidence } = load( + 'components/demographic-evidence.tsx', + ); + const comparison = (year, left, right, difference) => ({ + year, + left: 'BILENE', + right: 'FUNHALOURO', + left_value: left, + right_value: right, + left_import: 'a', + right_import: 'b', + difference, + explanation: + 'Diferença dos totais de população no mesmo ano, nível, tipo de dado, unidade e identificação de edição. Não mede procura efectiva.', + }); + const html = renderToStaticMarkup( + React.createElement(DemographicEvidence, { + evidence: { + state: 'available', + start_year: 2026, + end_year: 2028, + limitations: [], + territories: [], + differences: [], + comparisons: [ + comparison( + 2028, + '161636.2', + '47040.1', + '114596.1', + ), + comparison( + 2026, + '157982.9857834139', + '46656.505898723823', + '111326.479884690077', + ), + ], + }, + }), + ); + assert.match(html, /2026<') < html.indexOf('>2028<')); +}); + +test('next actions are a list of separate, easy-to-find links (mapa de erros 4.5)', () => { + const { default: NextActions } = load('components/next-actions.tsx'); + const html = renderToStaticMarkup( + React.createElement(NextActions, { + title: 'Alternativas de exploração', + actions: [ + { label: 'Ver oportunidades publicadas', href: '/oportunidades' }, + { label: 'Consultar ZEE, ZFI e parques', href: '/zonas' }, + { label: 'Transformar uma ideia num projecto', href: '/Simulador' }, + ], + }), + ); + assert.equal(html.split(']*>Alternativas de exploração<\/h3>/); + assert.equal( + renderToStaticMarkup( + React.createElement(NextActions, { actions: [] }), + ), + '', + ); +});