import { App } from '@inertiajs/react'; import { renderToStaticMarkup } from 'react-dom/server'; import { expect, test } from 'vitest'; import Finance from '@/pages/company/finance'; import { procurementNavigation } from '@/lib/procurement-navigation'; const empty = { data: [], prev_page_url: null, next_page_url: null }; const basis = { hash: 'a'.repeat(64), rows: [] }; function render(selectedAccess: Record | null = null) { return renderToStaticMarkup( , ); } test('company setup starts without an implicit target grants accounts dates or posting rules', () => { const html = render(); expect(html).toContain('href="#finance-access"'); expect(html).not.toContain('checked=""'); expect(html).not.toContain('2026-01-01'); expect(html).not.toContain('QA-2026'); expect(html).not.toContain('value="supplier_payable.recognised" selected'); expect(html).not.toContain('View supplier debts'); }); test('explicit target is escaped and no permission is selected by reading an empty grant list', () => { const html = render({ ...basis, user: { id: 3, name: '', email: 'qa@example.invalid' }, eligible: true, person: '', actions: [], other_actions: [], identity_inconsistent: false, }); expect(html).toContain('<Finance>'); expect(html).toContain('View supplier debts'); expect(html).not.toContain('checked=""'); expect(html).not.toContain(''); }); test('financial menus expose only explicit capabilities and use full navigation for common package pages', () => { const menu = (role: string, flags = {}) => procurementNavigation( role, false, undefined, false, false, false, false, flags, ).flatMap((group) => group.entries); expect(menu('admin').some((entry) => entry.id === 'general_ledger')).toBe( false, ); const flags = { payments: true, ledger: true, configuration: true }; const admin = menu('admin', flags); expect(admin.find((entry) => entry.id === 'general_ledger')).toMatchObject({ path: '/general-ledger/cycle', fullPage: true, }); expect( admin.find((entry) => entry.id === 'supplier_settlements'), ).toMatchObject({ path: '/supplier-payments', fullPage: true }); expect( admin.find((entry) => entry.id === 'finance_configuration'), ).toMatchObject({ path: '/administracao/financeiro' }); expect( menu('finance', flags).some( (entry) => entry.id === 'finance_configuration', ), ).toBe(false); expect( menu('requester', flags).some((entry) => [ 'general_ledger', 'supplier_settlements', 'finance_configuration', ].includes(entry.id), ), ).toBe(false); const publicMenu = procurementNavigation( 'admin', false, ['/dashboard'], false, false, false, false, flags, ).flatMap((group) => group.entries); expect( publicMenu.some((entry) => [ 'general_ledger', 'supplier_settlements', 'finance_configuration', ].includes(entry.id), ), ).toBe(false); });