Files
compras/tests/frontend/order-parts.test.tsx
T
nala dc73540558
tests / ci (push) Waiting to run
commit melhorias compras6
2026-11-23 06:37:16 +02:00

55 lines
1.8 KiB
TypeScript

import { describe, expect, it } from 'vitest';
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();
},
);
});