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 { renderToStaticMarkup } from 'react-dom/server'; import ts from 'typescript'; import * as presentation from '../../resources/js/lib/public-presentation.ts'; const require = createRequire(import.meta.url); function load(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' ? presentation : id === '@inertiajs/react' ? { Link: ({ children, ...props }) => React.createElement('a', props, children), } : id === './public-reference' ? load('public-reference') : id.startsWith('./') ? { default: () => null } : require(id), module, module.exports, ); return module.exports; } const LocationList = load('structure-geography').LocationList; const base = () => ({ id: 'synthetic', name: 'SYNTHETIC province', role: 'primary', location_type: 'province', path: [{ id: 'p', name: 'SYNTHETIC province', location_type: 'province' }], coordinates: [], boundaries: [], source_reference: 'upgrade do portal de investimentos v4 programacao.docx — 6.1 / 6.6', }); void test('P16 shows every required unknown field without inventing territorial values or exposing internal source paths', () => { const row = base(), before = JSON.stringify(row); const html = renderToStaticMarkup( React.createElement(LocationList, { locations: [row] }), ); assert.match(html, /Posto administrativo<\/dt>
N\u00e3o documentado/); assert.match(html, /Localidade<\/dt>
N\u00e3o documentado/); assert.match(html, /Coordenadas n\u00e3o documentadas/); assert.match(html, /Pol\u00edgono n\u00e3o documentado/); assert.match(html, /Data da fonte: N\u00e3o documentada/); assert.ok(!html.includes('programacao.docx')); assert.equal(JSON.stringify(row), before); }); void test('P16 shows a confirmed source date once and treats empty dates as undocumented while preserving inputs', () => { for (const value of ['2026-11-01', '', ' ']) { const row = { ...base(), source_reference: 'https://example.gov.mz/reference.pdf', source_date: value, }; const html = renderToStaticMarkup( React.createElement(LocationList, { locations: [row] }), ); if (value.trim()) { assert.equal((html.match(/2026-11-01/g) || []).length, 1); assert.ok(!html.includes('Data da fonte: N\u00e3o documentada')); } else assert.match(html, /Data da fonte: N\u00e3o documentada/); assert.equal(row.source_date, value); } }); void test('P16 internal office filenames stay administrative while official document links and legal citations remain useful', () => { for (const v of [ 'upgrade do portal de investimentos v4 programacao.docx - 6.1', 'Anexo.xlsm', 'Mapa.xlsx', 'Captura.emf', ]) assert.equal(presentation.publicReference(v), null); assert.equal( presentation.publicReference('Decreto n. 70/2009'), 'Decreto n. 70/2009', ); const url = 'https://example.gov.mz/Decreto70.docx'; assert.equal(presentation.publicReference(url), url); });