Files
compras/tests/frontend/order-parts.test.tsx
T
nala e709d900d1
tests / ci (push) Waiting to run
commit compras 2711
2026-11-27 13:49:31 +02:00

140 lines
5.3 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { App } from '@inertiajs/react';
import { renderToStaticMarkup } from 'react-dom/server';
import Parts from '@/pages/purchases/parts';
import {
orderPartDraftKey,
orderPartMinor,
} from '../../resources/js/lib/order-parts';
it('preserves remembered allocations across label changes but separates quantities and offsets', () => {
const first = {
requisition_id: 1,
award_id: 2,
label: 'old',
items: [
{
quotation_item_id: 3,
quantity_milli: 400,
quantity_offset_milli: 0,
},
],
};
const second = { ...first, requisition_id: 4, award_id: 5 };
expect(orderPartDraftKey([first, second])).toBe(
orderPartDraftKey([second, { ...first, label: 'new' }]),
);
expect(orderPartDraftKey([first])).not.toBe(
orderPartDraftKey([
{ ...first, items: [{ ...first.items[0], quantity_milli: 401 }] },
]),
);
expect(orderPartDraftKey([first])).not.toBe(
orderPartDraftKey([
{
...first,
items: [{ ...first.items[0], quantity_offset_milli: 400 }],
},
]),
);
});
describe('explicit order-part monetary input', () => {
it('preserves cents and large exact native integers without floating rounding', () => {
expect(orderPartMinor('12.34')).toBe(1234);
expect(orderPartMinor('0.01')).toBe(1);
expect(orderPartMinor('0.00')).toBe(0);
expect(orderPartMinor('999999999999.99')).toBe(99999999999999);
expect(orderPartMinor('1000000000000.00')).toBe(100000000000000);
expect(orderPartMinor('1000000000000.01')).toBeNull();
});
it.each(['', '-1', '1,25', '1.234', '1e2', ' 1.00', '10000000000000'])(
'refuses an invalid or rounded monetary representation %s',
(value) => {
expect(orderPartMinor(value)).toBeNull();
},
);
});
it('foreign legacy adoption shows an unknown reference as pending instead of a zero amount', () => {
const html = renderToStaticMarkup(
<App
initialComponent={Parts}
initialPage={{
component: 'purchases/parts',
url: '/ordens/preparar',
version: null,
clearHistory: false,
encryptHistory: true,
props: {
errors: {},
candidates: {
data: [],
prev_page_url: null,
next_page_url: null,
},
preview: {
selection: {
sources: [
{
award_id: 2,
items: [
{
quotation_item_id: 3,
quantity: '1.000',
},
],
},
],
},
can_issue: false,
financial: [
{
origin: 1,
award_id: 2,
requires_adoption: true,
allocations: [],
adoption_lines: [
{
line_id: 4,
description:
'Synthetic imported material',
subtotal_minor: 100,
total_minor: 100,
},
],
},
],
prepared: {
fingerprint: 'a'.repeat(64),
currency: 'USD',
subtotal_minor: 100,
total_minor: 100,
sources: [
{
requisition_id: 1,
award_id: 2,
currency: 'USD',
items: [
{
description:
'Synthetic imported material',
quotation_item_id: 3,
quantity_offset_milli: 0,
quantity_milli: 1000,
total_minor: 100,
},
],
},
],
},
},
},
}}
/>,
);
expect(html).toContain('Referência por conferir');
expect(html).toContain('todos os artigos da proposta');
expect(html).not.toContain('0,00');
});