import { App } from '@inertiajs/react'; import { renderToStaticMarkup } from 'react-dom/server'; import { expect, test } from 'vitest'; import CapitalRegister from '../../resources/js/pages/equipment/capital-register'; import CapitalAssignments from '../../resources/js/pages/requisitions/capital-assignments'; import CapitalAssignmentSummary from '../../resources/js/components/capital-assignment-summary'; const source = { id: 2, version: 3, record_key: 'source', state: 'archived', reason: 'Synthetic archive reason', data: { type: 'project', code: 'PRJ-QA', name: '', reference: 'Frozen documentary reference', department_id: 1, equipment_id: null, }, }; const page = (data: T[]) => ({ data, prev_page_url: null, next_page_url: null, }); const assignment = { id: 5, version: 1, state: 'linked', reason: 'Synthetic deliberate assignment', data: { requisition_item_id: 1 }, snapshot: { item: { description: 'Synthetic item' }, source }, }; function render( component: typeof CapitalRegister | typeof CapitalAssignments, props: object, ) { return renderToStaticMarkup( , ); } test('read-only capital register preserves archived identity and history without management forms', () => { const html = render(CapitalRegister, { records: page([source]), history: page([source]), departments: [], equipment: [], canManage: false, actorId: 1, tenantId: 1, }); expect(html).toContain('Arquivado'); expect(html).toContain('Histórico do registo'); expect(html).toContain('<script>QA</script>'); expect(html).not.toContain(' { const html = render(CapitalAssignments, { requisition: { id: 1, number: 'REQ-QA', status: 'approved' }, items: [], current: [assignment], choices: page([]), history: page([assignment]), canWrite: false, actorId: 1, tenantId: 1, }); expect(html).toContain('PRJ-QA'); expect(html).toContain('versão 3'); expect(html).not.toContain(', ); expect(frozen).toContain('Frozen documentary reference'); expect(frozen).toContain('<script>QA</script>'); expect(renderToStaticMarkup()).toBe(''); }); test('capital lineage distinguishes the original receipt from current returns and reversal', () => { const html = render(CapitalRegister, { records: page([source]), history: page([source]), departments: [], equipment: [], canManage: false, actorId: 1, tenantId: 1, trace: { orders: page([ { id: 7, description: 'Synthetic item', quantity: '2.000', unit: 'un', order_id: 8, order_number: 'OC-QA', }, ]), receipts: page([ { id: 9, description: 'Synthetic item', unit: 'un', receipt_id: 10, order_id: 8, received_on: '2026-11-27', quality_status: 'compliant', accepted_quantity: '2.000', reversed: true, returned_quantity: '1.000', }, ]), }, }); expect(html).toContain('Aceite no original: 2.000'); expect(html).toContain('Devolução ao fornecedor: 1.000'); expect(html).toContain('Recepção estornada'); expect(html).toContain('/ordens/8'); expect(html).not.toContain('