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); const source = fs.readFileSync( new URL( '../../resources/js/components/investment-map-indicators.tsx', import.meta.url, ), 'utf8', ); const compiled = ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022, jsx: ts.JsxEmit.ReactJSX, }, }).outputText; const module = { exports: {} }; compileFunction(compiled, ['require', 'module', 'exports'])( require, module, module.exports, ); const Component = module.exports.default; const filterIndicators = module.exports.filterMapIndicators; const row = { id: '1', zone_id: 'park-a', zone_name: 'Synthetic park', zone_version: 3, url: '/zonas/park-a', theme: 'workforce', indicator: 'employment', label: 'Synthetic declared jobs', value: '0', unit: 'pessoas', period_start: '2025-01-01', period_end: '2025-12-31', scope: 'Park A only', population: 'Declared establishments', methodology: 'Documentary register', source_reference: '', source_date: '2026-01-15', knowledge: 'documented', missing_metadata: [], }; const context = { state: 'available', records: [ row, { ...row, id: '2', theme: 'economic_potential', indicator: 'production', label: 'Synthetic production', value: '12.3400', unit: 'toneladas', period_start: '2024-01-01', period_end: '2024-12-31', }, ], zones_consulted: 1, zone_limit: 30, record_limit: 200, truncated: false, }; const render = (data, theme = 'all') => renderToStaticMarkup( React.createElement(Component, { context: data, theme }), ); test('quantitative observations keep zero, decimal precision, units, periods, scope, methodology and public source', () => { const html = render(context); for (const value of [ '0', '12.3400', 'pessoas', 'toneladas', '2025-01-01', '2024-01-01', 'Park A only', 'Declared establishments', 'Documentary register', '2026-01-15', 'Versão pública 3', ]) assert.ok(html.includes(value), value); assert.match(html, /Sem somas, conversões de unidade ou moeda/); assert.match(html, /Emprego não mede trabalhadores disponíveis/); assert.match(html, /não constituem um índice de potencial/); assert.doesNotMatch(html, /