commit compras5 2711
tests / ci (push) Waiting to run

This commit is contained in:
2026-11-27 20:19:21 +02:00
parent 7486007fcf
commit d58b75c87a
57 changed files with 2803 additions and 116 deletions
+108
View File
@@ -0,0 +1,108 @@
import { App } from '@inertiajs/react';
import { renderToStaticMarkup } from 'react-dom/server';
import { expect, test } from 'vitest';
import ExpenseAllocation from '../../resources/js/pages/payments/expense-allocation';
import { ProcurementCategoryInsights } from '../../resources/js/components/procurement-category-insights';
function render(canWrite: boolean) {
return renderToStaticMarkup(
<App
initialComponent={ExpenseAllocation}
initialPage={{
component: 'payments/expense-allocation',
url: '/pagamentos/1/categorias',
version: null,
clearHistory: false,
encryptHistory: true,
props: {
errors: {},
canWrite,
actorId: 1,
tenantId: 1,
payment: {
id: 1,
invoice_id: 1,
invoice_number: 'FT-QA',
currency: 'MZN',
amount_minor: '4000',
},
categories: ['Material', '<script>Serviços</script>'],
fingerprint: 'a'.repeat(64),
current: {
id: 1,
version: 1,
reason: 'Synthetic explicit allocation',
data: {
allocations: [
{ category: 'Material', amount_minor: '1500' },
],
},
},
history: {
data: [],
prev_page_url: null,
next_page_url: null,
},
},
}}
/>,
);
}
test('read-only financial viewer sees the preserved attribution without a write form', () => {
const html = render(false);
expect(html).toContain('15,00 MZN');
expect(html).not.toContain('<form');
});
test('Finance starts with blank amounts and deliberately chooses whether to reuse the current attribution', () => {
const html = render(true);
expect(html).toContain('Usar a imputação actual como preparação');
expect(html).toContain('&lt;script&gt;Serviços&lt;/script&gt;');
expect(html).not.toContain('value="15.00"');
expect(html).toContain('Guardar imputação');
});
test('category summary preserves unassigned expenses and separates currencies without allocating them automatically', () => {
const html = renderToStaticMarkup(
<ProcurementCategoryInsights
pageHref="/relatorios?from=2026-11-01&supplier_page=2"
data={{
coverage: { allocated: 1, unallocated: 1, indeterminate: 1 },
unassigned: [
{
state: 'unallocated',
currency: 'USD',
count: 1,
amount_minor: '4000',
},
{
state: 'indeterminate',
currency: 'MZN',
count: 1,
amount_minor: '5000',
},
],
groups: {
data: [
{
category: 'Material',
currency: 'MZN',
count: 1,
amount_minor: '1500',
},
],
total: 21,
current_page: 1,
last_page: 2,
},
}}
/>,
);
expect(html).toContain('Despesa não imputada: 40,00 USD');
expect(html).toContain('Imputação indeterminada: 50,00 MZN');
expect(html).toContain('15,00 MZN');
expect(html).toContain('Não há distribuição proporcional automática');
expect(html).toContain('category_page=2');
expect(html).toContain('supplier_page=2');
});