commit de menus
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-05 08:36:28 +02:00
41 changed files with 1878 additions and 143 deletions
+8 -47
View File
@@ -7,53 +7,14 @@ import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import ts from 'typescript';
import * as forms from '../../resources/js/lib/fiscal-form-preparation.ts';
const require = createRequire(import.meta.url);
const source = fs.readFileSync(
new URL(
'../../resources/js/pages/portal/fiscal-forms.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'])(
(name) =>
name === '@inertiajs/react'
? {
Head: () => null,
Link: ({ href, children, ...props }) =>
React.createElement('a', { href, ...props }, children),
router: { on: () => () => {} },
}
: name === '@/layouts/portal-navigation'
? { PortalMenu: () => null }
: name === '@/lib/fiscal-form-preparation'
? forms
: require(name),
module,
module.exports,
);
void test('fiscal entry renders labelled editable fields and a guided preparation rather than legislation', () => {
const html = renderToStaticMarkup(
React.createElement(module.exports.default),
);
for (const label of [
'Identificação e período',
'Nome ou designação social',
'NUIT',
'Período — ano e mês',
'Conferir e guardar',
'Guardar ficheiro para continuar',
'Recuperar ficheiro guardado',
'Confirmar recuperação',
]) {
const require=createRequire(import.meta.url);
const source=fs.readFileSync(new URL('../../resources/js/pages/portal/fiscal-forms.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:{}};
new Function('require','module','exports',compiled)(name=>name==='@inertiajs/react'?{Head:()=>null,Link:({href,children,...props})=>React.createElement('a',{href,...props},children),router:{on:()=>()=>{}}}:name==='@/layouts/portal-navigation'?{PortalMenu:()=>null}:name==='@/lib/fiscal-form-preparation'?forms:require(name),module,module.exports);
test('fiscal entry renders labelled editable fields and a guided preparation rather than legislation',()=>{
const html=renderToStaticMarkup(React.createElement(module.exports.default));
for(const label of ['Identificação e período','Nome ou designação social','NUIT','Período — ano e mês','Conferir e guardar','Guardar ficheiro para continuar','Recuperar ficheiro guardado','Confirmar recuperação']) {
// Confirmation appears only after a compatible file is selected.
if (label !== 'Confirmar recuperação')
assert.ok(html.includes(label), label);
+36
View File
@@ -0,0 +1,36 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
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/pages/portal/search.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: {} };
new Function('require', 'module', 'exports', compiled)(name => name === '@inertiajs/react' ? {
Head: () => null,
Link: ({ href, children, ...props }) => React.createElement('a', { href, ...props }, children),
} : name === 'lucide-react' ? { Search: () => null } : require(name), module, module.exports);
const Search = module.exports.default;
test('shows five results in one sequence with numbered pagination and the query preserved', () => {
const results = { data: [{ title: 'Energia em Nampula', description: 'Projecto público', url: '/oportunidades/energia', category: 'Oportunidades' }], total: 12, current_page: 1, last_page: 3, per_page: 5, unavailable: [] };
const html = renderToStaticMarkup(React.createElement(Search, { query: 'energia', results }));
assert.match(html, /Oportunidades/);
assert.match(html, /Resultados 1–1 de 12/);
assert.match(html, /href="\/oportunidades\/energia"/);
assert.match(html, /q=energia&page=2/);
assert.match(html, /aria-current="page"/);
assert.doesNotMatch(html, /emerald/);
});
test('makes source failures explicit without hiding other results', () => {
const results = { data: [], total: 0, current_page: 1, last_page: 1, per_page: 5, unavailable: ['Documentos e legislação'] };
const html = renderToStaticMarkup(React.createElement(Search, { query: 'terra', results }));
assert.match(html, /role="alert"/);
assert.match(html, /Não foi possível consultar: Documentos e legislação/);
assert.match(html, /Nenhum resultado nas fontes consultadas/);
});
@@ -55,7 +55,7 @@ await test('the quick search has a native GET destination and submits the actual
const input = nodes(tree).find(
(node) => node.type === 'input' && node.props.name === 'q',
);
assert.equal(form.props.action, '/oportunidades');
assert.equal(form.props.action, '/pesquisa');
assert.equal(form.props.method, 'get');
assert.equal(input.props.maxLength, 120);
input.props.onChange({ target: { value: 'plantio de algodao' } });
@@ -80,15 +80,15 @@ await test('the quick search has a native GET destination and submits the actual
});
assert.equal(prevented, true);
assert.deepEqual(sent, {
url: '/oportunidades',
url: '/pesquisa',
data: { q: 'plantio de algodao' },
});
} finally {
globalThis.FormData = original;
}
const html = renderToStaticMarkup(tree);
assert.ok(html.includes('Pesquisa rápida de oportunidades'));
assert.ok(html.includes('action="/oportunidades"'));
assert.ok(html.includes('Pesquisa rápida no InvesteMoz'));
assert.ok(html.includes('action="/pesquisa"'));
assert.ok(html.includes('Pesquisar'));
});