Merge branch 'front' of https://git.tempo.co.mz/nala/Investidor-V2
tests / ci (push) Waiting to run
tests / ci (push) Waiting to run
This commit is contained in:
@@ -7,18 +7,53 @@ 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 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);
|
||||
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'
|
||||
? new Proxy({}, { get: () => () => 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 }));
|
||||
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"/);
|
||||
@@ -28,8 +63,17 @@ test('shows five results in one sequence with numbered pagination and the query
|
||||
});
|
||||
|
||||
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 }));
|
||||
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/);
|
||||
|
||||
Reference in New Issue
Block a user