- Diferenças entre localizações em tabela por ano, população inteira com separador de milhares e a advertência uma só vez (legenda da tabela). - Componente NextActions: opções seguintes agrupadas numa lista com título, separadas do texto; aplicado às alternativas de exploração da carteira. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jm
120 lines
4.3 KiB
JavaScript
120 lines
4.3 KiB
JavaScript
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, /<table/);
|
|
assert.match(html, /157\s983/);
|
|
assert.match(html, /111\s326/);
|
|
assert.doesNotMatch(html, /\d+\.\d{3,}/);
|
|
assert.equal(html.split('não mede procura efectiva').length - 1, 1);
|
|
assert.ok(html.indexOf('>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('<li').length - 1, 3);
|
|
assert.match(html, /<nav aria-label="Alternativas de exploração"/);
|
|
assert.match(html, /<h3[^>]*>Alternativas de exploração<\/h3>/);
|
|
assert.equal(
|
|
renderToStaticMarkup(
|
|
React.createElement(NextActions, { actions: [] }),
|
|
),
|
|
'',
|
|
);
|
|
});
|