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

181 lines
5.8 KiB
TypeScript

import { App } from '@inertiajs/react';
import { renderToStaticMarkup } from 'react-dom/server';
import { expect, test } from 'vitest';
import Orders from '@/pages/purchases/index';
import Show from '@/pages/purchases/show';
const order = {
id: 1,
number: 'OC-QA',
requisition_id: 2,
issued_at: '2026-11-22T08:00:00Z',
currency: 'MZN',
total_minor: 10000,
snapshot: {
supplier: { name: 'Fornecedor <QA>' },
company: { name: 'Empresa QA' },
},
items: [
{
id: 1,
description: 'Artigo preservado',
quantity: '1.000',
unit: 'cx',
total_minor: 10000,
},
],
};
function render(
component: Parameters<typeof App>[0]['initialComponent'],
props: Record<string, unknown>,
) {
return renderToStaticMarkup(
<App
initialComponent={component}
initialPage={{
component: 'purchases/index',
url: '/ordens',
version: null,
clearHistory: false,
encryptHistory: true,
props: { errors: {}, ...props },
}}
/>,
);
}
test('an older incomplete order cannot blank the order list', () => {
const html = render(Orders, {
orders: { data: [order], prev_page_url: null, next_page_url: null },
awards: { data: [], prev_page_url: null, next_page_url: null },
});
expect(html).toContain('OC-QA');
expect(html).toContain('Fornecedor &lt;QA&gt;');
expect(html).toContain('Referência não preservada no original');
expect(html).toContain('/ordens/1');
});
test('incomplete detail identifies the missing original and preserves documented values and items', () => {
const html = render(Show, { order, history: [], snapshotComplete: false });
expect(html).toContain('Documento original incompleto');
expect(html).toContain('Artigo preservado');
expect(html).toContain('100,00');
expect(html).toContain('/ordens/1/imprimir');
expect(html).not.toContain('Aprovações do valor final');
});
test.each([
{
state: 'issued',
enabled: true,
canRequest: true,
form: true,
text: 'Ordem emitida.',
},
{
state: 'issued',
enabled: true,
canRequest: false,
form: false,
text: 'Ordem emitida.',
},
{
state: 'cancellation_pending',
enabled: false,
canRequest: false,
form: false,
text: 'Cancelamento pendente.',
},
{
state: 'cancelled',
enabled: true,
canRequest: false,
form: false,
text: 'Ordem cancelada.',
},
])(
'legacy detail preserves operational cancellation status and server authority ($state/$canRequest)',
({ state, enabled, canRequest, form, text }) => {
const html = render(Show, {
order,
history: [],
snapshotComplete: false,
orderCancellation: { state, enabled, canRequest },
});
expect(html).toContain('Estado operacional e cancelamento');
expect(html).toContain(text);
expect(html.includes('Pedir cancelamento integral')).toBe(form);
expect(html).toContain('Documento original incompleto');
expect(html).toContain('Artigo preservado');
expect(html).toContain('100,00');
expect(html).not.toContain('Aprovações do valor final');
},
);
test.each([false, true])(
'existing order documents expose only server-authorised related destinations (%s)',
(finance) => {
const html = render(Show, {
order,
history: [],
snapshotComplete: false,
financialDocumentsHref: finance
? '/facturas?purchase_order_id=1'
: null,
relatedProcesses: [
{ id: 4, number: 'REQ<QA>', href: '/requisicoes/4/processo' },
{
id: 7,
number: 'REQ-SECOND-QA',
href: '/requisicoes/7/processo',
},
],
});
expect(html).toContain('Documentos relacionados da ordem');
expect(html).toContain('href="/requisicoes/4/processo"');
expect(html).toContain('href="/requisicoes/7/processo"');
expect(html).toContain('REQ&lt;QA&gt;');
expect(html.includes('/facturas?purchase_order_id=1')).toBe(finance);
expect(html).toContain('Artigo preservado');
},
);
import ReceiptShow from '@/pages/receipts/show';
test.each([false, true])(
'receipt detail retains the original and only offers the financial link supplied by the server (%s)',
(finance) => {
const html = render(ReceiptShow, {
receipt: {
id: 8,
number: 'REC-QA',
purchase_order_id: 1,
delivery_note: 'GUIA-QA',
received_on: '2026-11-28',
confirmed_at: '2026-11-28T12:00:00Z',
status: 'complete',
snapshot: {
order: { id: 1, number: 'OC-QA' },
supplier: { name: 'Fornecedor QA' },
receiver: { name: 'Armazém QA' },
warehouse: null,
},
items: [],
},
movements: [],
financialDocumentsHref: finance
? '/facturas?purchase_order_id=1#invoice-documents'
: null,
});
expect(
html.includes(
'href="/facturas?purchase_order_id=1#invoice-documents"',
),
).toBe(finance);
expect(html).toContain('GUIA-QA');
expect(html).toContain('Recepção total aceite');
expect(html).toContain('/recepcoes/8/imprimir');
expect(html).toContain('/ordens/1/recepcoes');
},
);