Files
compras/tests/frontend/procurement-search.test.tsx
T
nala 448948a487
tests / ci (push) Waiting to run
commit compras1 2911
2026-11-29 05:28:30 +02:00

383 lines
15 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('operational search exposes the native selected-order destination and a registration state without private source bodies', () => {
const html = renderToStaticMarkup(
<App
initialComponent={Search}
initialPage={{
component: 'search/procurement',
url: '/compras/pesquisa?q=OP',
version: null,
clearHistory: false,
encryptHistory: true,
props: {
errors: {},
term: 'OP',
operationalOrderSearchAvailable: true,
groups: [
{
key: 'operational_orders',
title: 'Ordens de produção e manutenção',
records: {
total: 16,
current_page: 1,
last_page: 2,
prev_page_url: null,
next_page_url:
'/compras/pesquisa?q=OP&operational_orders_page=2',
data: [
{
id: 5,
title: 'Produção OP-QA · v1',
detail: 'recorded',
href: '/ordens-operacionais?order_id=5#op-order-5',
},
],
},
},
],
},
}}
/>,
);
expect(html).toContain('/ordens-operacionais?order_id=5#op-order-5');
expect(html).toContain('Registada');
expect(html).toContain('operational_orders_page=2');
expect(html).toContain('ordem de origem autorizada');
});
test.each([0, 1])(
'search places matching areas before collapsed empty areas and reports an entirely empty scope (%i)',
(total) => {
const empty = {
total: 0,
current_page: 1,
last_page: 1,
prev_page_url: null,
next_page_url: null,
data: [],
};
const html = renderToStaticMarkup(
<App
initialComponent={Search}
initialPage={{
component: 'search/procurement',
url: '/compras/pesquisa?q=CAP',
version: null,
clearHistory: false,
encryptHistory: true,
props: {
errors: {},
term: 'CAP',
groups: [
{
key: 'requests',
title: 'Requisições',
records: empty,
},
{
key: 'capital',
title: 'Projectos e imobilizado',
records: {
...empty,
total,
data: total
? [
{
id: 1,
title: 'PROJECT-HIT',
detail: 'active',
href: '/projectos-imobilizado?history=qa',
},
]
: [],
},
},
],
},
}}
/>,
);
expect(html).toContain('Áreas sem resultados');
expect(html).toContain('data-query-form="true"');
expect(html).not.toContain('<details open');
expect(
html.includes(
'Não foram encontrados resultados para esta pesquisa',
),
).toBe(total === 0);
if (total)
expect(html.indexOf('PROJECT-HIT')).toBeLessThan(
html.indexOf('Áreas sem resultados'),
);
expect(html).not.toContain('Requisições (0)');
},
);
test.each([false, true])(
'capital search presents only supplied register metadata and its native history destination (%s)',
(available) => {
const html = renderToStaticMarkup(
<App
initialComponent={Search}
initialPage={{
component: 'search/procurement',
url: '/compras/pesquisa?q=CAP',
version: null,
clearHistory: false,
encryptHistory: true,
props: {
errors: {},
term: 'CAP',
capitalSearchAvailable: available,
groups: available
? [
{
key: 'capital',
title: 'Projectos e imobilizado',
records: {
total: 16,
current_page: 1,
last_page: 2,
prev_page_url: null,
next_page_url:
'/compras/pesquisa?q=CAP&capital_page=2',
data: [
{
id: 8,
title: 'Projecto CAP <QA> · v2',
detail: 'archived',
href: '/projectos-imobilizado?history=qa-record',
},
],
},
},
]
: [],
},
}}
/>,
);
expect(html.includes('Projectos e imobilizado')).toBe(available);
expect(html.includes('próprios de Compras')).toBe(available);
expect(html.includes('/projectos-imobilizado?history=qa-record')).toBe(
available,
);
if (available) {
expect(html).toContain('Projecto CAP &lt;QA&gt; · v2');
expect(html).toContain('Arquivado');
expect(html).toContain('capital_page=2');
}
},
);
test('warehouse search preserves the distinct internal reference event state and result page', () => {
const html = renderToStaticMarkup(
<App
initialComponent={Search}
initialPage={{
component: 'search/procurement',
url: '/compras/pesquisa?q=RA-9',
version: null,
clearHistory: false,
encryptHistory: true,
props: {
errors: {},
term: 'RA-9',
warehouseRequestSearchAvailable: true,
groups: [
{
key: 'warehouse_requests',
title: 'Requisições internas de armazém',
records: {
total: 16,
current_page: 1,
last_page: 2,
prev_page_url: null,
next_page_url:
'/compras/pesquisa?q=RA&warehouse_requests_page=2',
data: [
{
id: 9,
title: 'RA-9',
detail: 'partial',
href: '/stock/requisicoes/9',
},
],
},
},
],
},
}}
/>,
);
expect(html).toContain('Requisições internas de armazém');
expect(html).toContain('RA-9');
expect(html).toContain('Entrega parcial');
expect(html).toContain('warehouse_requests_page=2');
expect(html).toContain('/stock/requisicoes/9');
expect(html).toContain('nome do requisitante preservado');
});
test('supply reference search shows current versions native targets and its own pagination', () => {
const html = renderToStaticMarkup(
<App
initialComponent={Search}
initialPage={{
component: 'search/procurement',
url: '/compras/pesquisa?q=AG',
version: null,
clearHistory: false,
encryptHistory: true,
props: {
errors: {},
term: 'AG',
supplySearchAvailable: true,
groups: [
{
key: 'agreements',
title: 'Acordos',
records: {
total: 16,
current_page: 1,
last_page: 2,
prev_page_url: null,
next_page_url:
'/compras/pesquisa?q=AG&agreements_page=2',
data: [
{
id: 5,
title: 'AG <QA> · v2',
detail: 'suspended',
href: '/compras/fornecimento?view=agreements&record_id=5#supply-record-5',
},
],
},
},
],
},
}}
/>,
);
expect(html).toContain('AG &lt;QA&gt; · v2');
expect(html).toContain('Suspenso');
expect(html).toContain('agreements_page=2');
expect(html).toContain('view=agreements&amp;record_id=5#supply-record-5');
expect(html).toContain('nome do fornecedor preservado');
expect(html).not.toContain('acesso financeiro');
});
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');
});