73 lines
2.8 KiB
TypeScript
73 lines
2.8 KiB
TypeScript
import { App } from '@inertiajs/react';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import { expect, test } from 'vitest';
|
|
import ImportEstimate from '@/pages/supply/import-estimate';
|
|
import { estimateMinor, estimateMoney } from '@/lib/import-estimate-money';
|
|
|
|
test('estimate money input stays exact and invalid values reach server validation without rounding', () => {
|
|
expect(estimateMinor('999999999999,99')).toBe(99999999999999);
|
|
expect(estimateMinor('1.01')).toBe(101);
|
|
expect(estimateMinor('1000000000000.00')).toBe(100000000000000);
|
|
expect(estimateMinor('1.001')).toBe('1.001');
|
|
expect(estimateMinor('-1')).toBe('-1');
|
|
expect(estimateMoney(99999999999999)).toBe('999999999999.99');
|
|
expect(estimateMoney(null)).toBe('');
|
|
});
|
|
|
|
test('estimate readers see unknown cost coverage and preserved history without an editable form', () => {
|
|
const html = renderToStaticMarkup(
|
|
<App
|
|
initialComponent={ImportEstimate}
|
|
initialPage={{
|
|
component: 'supply/import-estimate',
|
|
url: '/requisicoes/1/estimativa-importacao',
|
|
version: null,
|
|
clearHistory: false,
|
|
encryptHistory: true,
|
|
props: {
|
|
errors: {},
|
|
requisition: {
|
|
id: 1,
|
|
number: 'QA',
|
|
status: 'pending',
|
|
total_minor: 10000,
|
|
},
|
|
actorId: 2,
|
|
tenantId: 3,
|
|
canPrepare: false,
|
|
nativeChanged: true,
|
|
budgets: {
|
|
data: [],
|
|
prev_page_url: null,
|
|
next_page_url: null,
|
|
},
|
|
latest: {
|
|
id: 4,
|
|
version: 1,
|
|
state: 'incomplete',
|
|
reason: 'Synthetic',
|
|
data: { budget_id: 1, components: [] },
|
|
snapshot: {
|
|
plan: {
|
|
complete: false,
|
|
budget_amount_minor: null,
|
|
known_total_minor: 10000,
|
|
unknown: ['duty'],
|
|
},
|
|
},
|
|
},
|
|
history: {
|
|
data: [],
|
|
prev_page_url: null,
|
|
next_page_url: null,
|
|
},
|
|
},
|
|
}}
|
|
/>,
|
|
);
|
|
expect(html).toContain('total permanece indeterminado');
|
|
expect(html).toContain('requisição mudou');
|
|
expect(html).not.toContain('<form');
|
|
expect(html).not.toContain('Guardar estimativa');
|
|
});
|