import { App } from '@inertiajs/react'; import { renderToStaticMarkup } from 'react-dom/server'; import { expect, test } from 'vitest'; import Expiry from '../../resources/js/pages/requisitions/expiry'; function render(extra: object) { return renderToStaticMarkup( synthetic', request: { number: 'REQ-QA' }, steps: [ { id: 1, position: 1, role: 'department_head', decision: 'approved', }, ], }, ], prev_page_url: null, next_page_url: null, }, ...extra, }, }} />, ); } test('returned owner sees the same draft and preserved approval without expiry controls', () => { const html = render({}); expect(html).toContain('/requisicoes/1/editar'); expect(html).toContain('Aprovação preservada'); expect(html).toContain('<script>synthetic</script>'); expect(html).not.toContain(' { const html = render({ history: { prev_page_url: null, next_page_url: null, data: [ { id: 8, data: { cycle: 1, next_cycle: 2 }, created_at: '2026-11-27T12:31:00Z', reason: 'Devolução sintética', request: { number: 'REQ-QA', priority: 'normal', submitted_at: '2026-11-27T12:00:00Z', needed_by: '2026-12-01', justification: 'ORIGINAL-QA-JUSTIFICATION', subtotal_minor: 10000, tax_minor: 0, total_minor: 10000, }, rules: { first_limit_minor: 5000, second_limit_minor: 20000, approval_includes_tax: false, rules_provisional: true, }, items: [ { id: 3, description: 'ORIGINAL-QA-ITEM', quantity: '1.000', unit: 'un', unit_price_minor: 10000, tax_rate: '0.00', subtotal_minor: 10000, tax_minor: 0, total_minor: 10000, }, ], steps: [ { id: 4, position: 1, role: 'configured_1', routing: { name: 'Direcção preservada' }, decision: 'approved', approver_id: 7, decided_at: '2026-11-27T12:05:00Z', comment: '', }, { id: 5, position: 2, role: 'procurement', decision: 'pending', }, ], }, ], }, }); expect(html).toContain('ORIGINAL-QA-JUSTIFICATION'); expect(html).toContain('ORIGINAL-QA-ITEM'); expect(html).toContain('100,00'); expect(html).toContain('sem IVA'); expect(html).toContain('Regras provisórias na submissão original'); expect(html).toContain('Direcção preservada'); expect(html).toContain('Utilizador #7'); expect(html).toContain('<script>ORIGINAL-QA-DECISION</script>'); expect(html).toContain('Etapa pendente no momento da devolução'); expect(html).toContain('não são as aprovações da nova'); expect(html).not.toContain(' { const html = render({}); expect(html).toContain('Não preservado'); expect(html).toContain('Artigos não preservados neste registo'); expect(html).not.toContain('0,00'); expect(html).not.toContain('Regras provisórias na submissão original'); }); test('historical routing amount remains distinct from goods and a preserved zero remains zero', () => { const history = { prev_page_url: null, next_page_url: null, data: [ { id: 8, data: { cycle: 1, next_cycle: 2 }, reason: 'Synthetic source', request: { number: 'REQ-QA', subtotal_minor: 10000, tax_minor: 0, total_minor: 10000, }, approval_amount_minor: 11000, approval_uses_separate_basis: true, rules: { approval_includes_tax: true, routing_plan_revision: 3, }, steps: [], items: [], }, ], }; const html = render({ history }); expect(html).toContain('100,00'); expect(html).toContain('110,00'); expect(html).toContain('Base adicional preservada'); expect(html).toContain('Plano de encaminhamento · versão 3'); const zero = render({ history: { ...history, data: [{ ...history.data[0], approval_amount_minor: 0 }], }, }); expect(zero).toContain('Valor usado no encaminhamento: 0,00'); }); test('a pending configured deadline exposes due actions only when allowed', () => { const html = render({ canEdit: false, canCheck: true, deadline: { state: 'running', step_id: 2, expires_at: '2026-11-27T12:30:00Z', basis_hash: 'a'.repeat(64), }, }); expect(html).toContain('Verificar e executar acções devidas'); expect(html).not.toContain('Rever rascunho'); expect(html).not.toContain('Devolver ao requisitante'); }); test('urgent deadline explains the frozen shorter policy without exposing a new approval grant', () => { const html = render({ canEdit: false, canCheck: true, deadline: { state: 'running', step_id: 2, timing: 'urgent_override', expires_at: '2026-11-27T12:05:00Z', reminder_at: '2026-11-27T12:01:00Z', escalation_at: '2026-11-27T12:02:00Z', basis_hash: 'a'.repeat(64), }, }); expect(html).toContain( 'Prazos reduzidos para urgência, preservados na submissão.', ); expect(html).toContain('Escalamento previsto'); expect(html).not.toContain('Aprovar'); });