import { App, router } from '@inertiajs/react'; import { renderToStaticMarkup } from 'react-dom/server'; import { afterEach, expect, test, vi } from 'vitest'; import Bank from '@/pages/suppliers/bank'; afterEach(() => vi.restoreAllMocks()); const identity = 'supplier-bank:4:7:2:legacy:3:true:true'; const proposal = { previous_id: 3, account_key: null, bank_name: 'BANK-QA-NOT-SUBMITTED', country: 'MZ', currency: 'MZN', beneficiary: 'Synthetic beneficiary', account_identifier: 'SYNTHETIC-IDENTIFIER', evidence_reference: 'Synthetic evidence', reason: 'Unsubmitted synthetic proposal', }; function render( actor = 7, tenant = 4, version = 3, canPropose = true, canReview = true, accountKey: string | null = null, ) { return renderToStaticMarkup( , ); } test('unsubmitted bank proposal is restored privately without proposing or reviewing automatically', () => { vi.spyOn(router, 'restore').mockImplementation((key) => key === `${identity}:proposal:data` ? proposal : undefined, ); const post = vi.spyOn(router, 'post'); const html = render(); expect(html).toContain('BANK-QA-NOT-SUBMITTED'); expect(html).toContain('SYNTHETIC-IDENTIFIER'); expect(html).toContain('data-preparation-dirty="true"'); expect(post).not.toHaveBeenCalled(); expect(render(8)).not.toContain('BANK-QA-NOT-SUBMITTED'); expect(render(7, 5)).not.toContain('BANK-QA-NOT-SUBMITTED'); expect(render(7, 4, 4)).not.toContain('BANK-QA-NOT-SUBMITTED'); expect(render(7, 4, 3, false)).not.toContain('BANK-QA-NOT-SUBMITTED'); expect( render(7, 4, 3, true, true, '00000000-0000-4000-8000-000000000002'), ).not.toContain('BANK-QA-NOT-SUBMITTED'); }); test('independent account preparation restores its pending identity and mode without creating the account', () => { const accountKey = '00000000-0000-4000-8000-000000000002'; vi.spyOn(router, 'restore').mockImplementation((key) => key === `${identity}:adding` ? true : key === `${identity}:proposal:data` ? { ...proposal, previous_id: 0, account_key: accountKey } : undefined, ); const post = vi.spyOn(router, 'post'); const html = render(); expect(html).toContain('Propor conta independente'); expect(html).toContain('BANK-QA-NOT-SUBMITTED'); expect(post).not.toHaveBeenCalled(); }); test('bank review preparation remains tied to the same reviewer and exact bank version', () => { vi.spyOn(router, 'restore').mockImplementation((key) => key === `${identity}:review:data` ? { decision: 'rejected', reason: 'REVIEW-QA-NOT-SUBMITTED', independently_verified: true, } : undefined, ); const post = vi.spyOn(router, 'post'); expect(render()).toContain('REVIEW-QA-NOT-SUBMITTED'); expect(render(8)).not.toContain('REVIEW-QA-NOT-SUBMITTED'); expect(render(7, 4, 4)).not.toContain('REVIEW-QA-NOT-SUBMITTED'); expect(render(7, 4, 3, true, false)).not.toContain( 'REVIEW-QA-NOT-SUBMITTED', ); expect(post).not.toHaveBeenCalled(); }); test('empty bank preparation stays clean', () => { expect(render()).not.toContain('data-preparation-dirty="true"'); });