feat: display precise public labour and economic observations in map context
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
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 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: '<script>synthetic source</script>',
|
||||
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, /<script>/);
|
||||
assert.match(html, /href="\/zonas\/park-a"/);
|
||||
});
|
||||
|
||||
test('themes separate labour and economic observations without inventing totals or losing metadata', () => {
|
||||
assert.match(render(context, 'workforce'), /pessoas/);
|
||||
assert.doesNotMatch(render(context, 'workforce'), /toneladas/);
|
||||
assert.match(render(context, 'economic_potential'), /12.3400/);
|
||||
assert.doesNotMatch(
|
||||
render(context, 'economic_potential'),
|
||||
/Synthetic declared jobs/,
|
||||
);
|
||||
assert.equal(render(context, 'resource'), '');
|
||||
});
|
||||
|
||||
test('unknown values, disputes, missing metadata, incomplete coverage and excluded scope remain explicit', () => {
|
||||
const html = render({
|
||||
...context,
|
||||
truncated: true,
|
||||
records: [
|
||||
{
|
||||
...row,
|
||||
value: null,
|
||||
unit: null,
|
||||
knowledge: 'unknown',
|
||||
missing_metadata: ['unit', 'population'],
|
||||
},
|
||||
{ ...row, id: '3', knowledge: 'disputed' },
|
||||
],
|
||||
});
|
||||
assert.match(html, /Por determinar/);
|
||||
assert.match(html, /Em divergência/);
|
||||
assert.match(html, /Informação em falta: unidade, população\/base/);
|
||||
assert.match(html, /limitada a 30 fichas e 200 observações/);
|
||||
assert.match(
|
||||
render({ ...context, records: [] }),
|
||||
/Valor desconhecido não equivale a zero/,
|
||||
);
|
||||
assert.match(
|
||||
render({ ...context, state: 'not_included' }),
|
||||
/Não foi feita uma medição quantitativa/,
|
||||
);
|
||||
assert.match(
|
||||
render({ ...context, state: 'unavailable' }),
|
||||
/indisponíveis nesta versão/,
|
||||
);
|
||||
assert.match(render(null), /A carregar indicadores/);
|
||||
assert.match(
|
||||
render({ ...context, state: 'error' }),
|
||||
/Não foi possível consultar os indicadores/,
|
||||
);
|
||||
});
|
||||
@@ -51,9 +51,11 @@ function setup() {
|
||||
];
|
||||
},
|
||||
}
|
||||
: name === './catalogue-investment-map'
|
||||
? { default: Map }
|
||||
: require(name),
|
||||
: name === './investment-map-indicators'
|
||||
? { default: () => null }
|
||||
: name === './catalogue-investment-map'
|
||||
? { default: Map }
|
||||
: require(name),
|
||||
module,
|
||||
module.exports,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user