Files
compras/tests/frontend/procurement-search.test.tsx
T
nala 36dcfdf00c
tests / ci (push) Canceled after 0s
commit melhorias compras4
2026-11-22 16:28:03 +02:00

116 lines
4.4 KiB
TypeScript

import { App } from '@inertiajs/react';
import { renderToStaticMarkup } from 'react-dom/server';
import { expect, test } from 'vitest';
import Search from '@/pages/search/procurement';
test('process search separates result groups escapes text and retains page links', () => {
const html = renderToStaticMarkup(
<App
initialComponent={Search}
initialPage={{
component: 'search/procurement',
url: '/compras/pesquisa?q=QA',
version: null,
clearHistory: false,
encryptHistory: true,
props: {
errors: {},
term: 'QA',
groups: [
{
key: 'requests',
title: 'Requisições',
records: {
total: 16,
current_page: 1,
last_page: 2,
prev_page_url: null,
next_page_url:
'/compras/pesquisa?q=QA&requests_page=2',
data: [
{
id: 7,
title: 'QA <original>',
detail: 'draft',
href: '/requisicoes/7',
},
],
},
},
],
},
}}
/>,
);
expect(html).toContain('QA &lt;original&gt;');
expect(html).toContain('Rascunho');
expect(html).toContain('q=QA&amp;requests_page=2');
expect(html).toContain('/requisicoes/7');
expect(html).toContain('A pesquisa não inclui Pessoas');
expect(html).not.toContain('acesso financeiro');
});
test('financial search explains references and states only when available', () => {
const html = renderToStaticMarkup(
<App
initialComponent={Search}
initialPage={{
component: 'search/procurement',
url: '/compras/pesquisa?q=FT',
version: null,
clearHistory: false,
encryptHistory: true,
props: {
errors: {},
term: 'FT',
invoiceSearchAvailable: true,
groups: [
{
key: 'invoices',
title: 'Facturas de fornecedor',
records: {
total: 1,
current_page: 1,
last_page: 1,
prev_page_url: null,
next_page_url: null,
data: [
{
id: 9,
title: 'FT <QA>',
detail: 'confirmed',
href: '/facturas?invoice_id=9',
},
],
},
},
],
},
}}
/>,
);
expect(html).toContain('pelo número, dentro do seu acesso financeiro');
expect(html).toContain('mostram a referência e o estado');
expect(html).toContain('FT &lt;QA&gt;');
expect(html).toContain('Confirmada');
expect(html).toContain('/facturas?invoice_id=9');
});
test('empty search explains the minimum input rather than implying that the database is empty', () => {
const html = renderToStaticMarkup(
<App
initialComponent={Search}
initialPage={{
component: 'search/procurement',
url: '/compras/pesquisa',
version: null,
clearHistory: false,
encryptHistory: true,
props: { errors: {}, term: '', groups: [] },
}}
/>,
);
expect(html).toContain('Introduza pelo menos dois caracteres');
expect(html).not.toContain('Nenhum resultado no seu âmbito');
});