import { App, router } from '@inertiajs/react'; import { renderToStaticMarkup } from 'react-dom/server'; import { afterEach, expect, test, vi } from 'vitest'; import Payments from '@/pages/payments/index'; afterEach(() => vi.restoreAllMocks()); const base = 'payments:4:7:finance:finance'; const identity = `${base}:true:all:all`; const invoice = { id: 3, number: 'INV-QA', supplier_id: 1, supplier_name: 'Synthetic supplier', total_minor: 10000, outstanding_minor: 10000, currency: 'MZN', bank_id: 5, bank_revision: 2, bank_state: 'approved', banks: [ { id: 5, revision: 2, label: 'Synthetic bank', currency: 'MZN', state: 'approved', }, ], }; function render(overrides = {}, actor = 7, tenant = 4, context = 'finance') { return renderToStaticMarkup( , ); } test('external payment preparation restores its selected invoice without carrying values to another source or bank version', () => { vi.spyOn(router, 'restore').mockImplementation((key) => { if (key === `${identity}:invoice`) return '3'; if ( key === `${identity}:registration:3:5:2:approved:10000:5.2.approved:data` ) return { supplier_bank_detail_id: 5, amount: '40.00', paid_on: '2026-11-28', external_reference: 'EXTERNAL-DRAFT-QA', evidence_reference: 'Synthetic documentary evidence', }; return undefined; }); const post = vi.spyOn(router, 'post'); const html = render(); expect(html).toContain('EXTERNAL-DRAFT-QA'); expect(html).toContain('value="3" selected=""'); expect(html).toContain('form="external-payment-registration"'); expect(html).toContain('
{ vi.spyOn(router, 'restore').mockImplementation((key) => key === `${base}:review:9:pending:4000:5:true:data` ? { decision: 'rejected', reason: 'REVIEW-DRAFT-QA', independently_verified: true, } : undefined, ); const post = vi.spyOn(router, 'post'); expect(render()).toContain('REVIEW-DRAFT-QA'); expect(render()).toContain('data-preparation-dirty="true"'); expect(render({}, 8)).not.toContain('REVIEW-DRAFT-QA'); expect(render({}, 7, 5)).not.toContain('REVIEW-DRAFT-QA'); expect(render({}, 7, 4, 'procurement.internal')).not.toContain( 'REVIEW-DRAFT-QA', ); expect( render({ payments: { data: [], prev_page_url: null, next_page_url: null }, }), ).not.toContain('REVIEW-DRAFT-QA'); expect(post).not.toHaveBeenCalled(); }); test('missing or settled remembered invoice is explicit and cannot enable registration', () => { vi.spyOn(router, 'restore').mockImplementation((key) => key === `${identity}:invoice` ? '3' : undefined, ); for (const invoices of [[], [{ ...invoice, outstanding_minor: 0 }]]) { const html = render({ invoices }); expect(html).toContain( 'Factura seleccionada indisponĂ­vel ou sem saldo', ); expect(html).toMatch( /]*disabled=""[^>]*>Registar para conferĂȘncia independente/, ); } }); test('unmodified payment forms remain clean without sending a command', () => { vi.spyOn(router, 'restore').mockReturnValue(undefined); const post = vi.spyOn(router, 'post'); expect(render()).not.toContain('data-preparation-dirty="true"'); expect(post).not.toHaveBeenCalled(); });