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

67 lines
2.0 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: typeof Orders | typeof Show,
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');
});