import { App, router } from '@inertiajs/react'; import { renderToStaticMarkup } from 'react-dom/server'; import { afterEach, expect, test, vi } from 'vitest'; import Award from '@/pages/purchases/award'; import { money } from '@/types/procurement'; afterEach(() => vi.restoreAllMocks()); const option = { allocation_key: 'qa-a', line_id: 12, centre_id: 4, subtotal: '50.00', total: '50.00', line_label: 'Artigo sintético', centre_label: 'Centro sintético', }; function render( currency = 'MZN', reference: object | null = null, actorId = 7, ) { return renderToStaticMarkup( , ); } function rememberSelection() { vi.spyOn(router, 'restore').mockImplementation((key) => key === 'award-selection:3:7:2:4:data' ? { quotation_id: '1', justification: '', delivery_date: '', delivery_location: '', reason: '', budget_distribution_preparation: [option], } : undefined, ); } test('quote is chosen before explicit allocations and a different actor cannot inherit the selection', () => { expect(render()).not.toContain('Distribuição explícita'); rememberSelection(); const html = render(); expect(html.indexOf('id="award-quote"')).toBeLessThan( html.indexOf('Distribuição explícita'), ); expect(html).toContain('Referência da proposta em MZN'); expect(render('MZN', null, 8)).not.toContain( 'Distribuição explícita', ); }); test('foreign values never replace an unavailable MZN reference and a frozen reference is shown exactly', () => { rememberSelection(); const missing = render('USD'); expect(missing).toContain('Referência em MZN indisponível'); expect(missing).toMatch(/disabled=""[^>]*>Registar adjudicação/); const converted = render('USD', { subtotal_minor: 600000, tax_minor: 0, total_minor: 600000, }); expect(converted).toContain(money(600000, 'MZN')); expect(converted).not.toContain(`sem IVA ${money(10000, 'MZN')}`); expect(converted).not.toContain('Referência em MZN indisponível'); });