import { App } from '@inertiajs/react'; import { renderToStaticMarkup } from 'react-dom/server'; import { expect, test } from 'vitest'; import Orders from '@/pages/purchases/index'; import Show from '@/pages/purchases/show'; const order = { id: 1, number: 'OC-QA', requisition_id: 2, issued_at: '2026-11-22T08:00:00Z', currency: 'MZN', total_minor: 10000, snapshot: { supplier: { name: 'Fornecedor ' }, company: { name: 'Empresa QA' }, }, items: [ { id: 1, description: 'Artigo preservado', quantity: '1.000', unit: 'cx', total_minor: 10000, }, ], }; function render( component: Parameters[0]['initialComponent'], props: Record, ) { return renderToStaticMarkup( , ); } test('an older incomplete order cannot blank the order list', () => { const html = render(Orders, { orders: { data: [order], prev_page_url: null, next_page_url: null }, awards: { data: [], prev_page_url: null, next_page_url: null }, }); expect(html).toContain('OC-QA'); expect(html).toContain('Fornecedor <QA>'); expect(html).toContain('Referência não preservada no original'); expect(html).toContain('/ordens/1'); }); test('incomplete detail identifies the missing original and preserves documented values and items', () => { const html = render(Show, { order, history: [], snapshotComplete: false }); expect(html).toContain('Documento original incompleto'); expect(html).toContain('Artigo preservado'); expect(html).toContain('100,00'); expect(html).toContain('/ordens/1/imprimir'); expect(html).not.toContain('Aprovações do valor final'); }); test.each([ { state: 'issued', enabled: true, canRequest: true, form: true, text: 'Ordem emitida.', }, { state: 'issued', enabled: true, canRequest: false, form: false, text: 'Ordem emitida.', }, { state: 'cancellation_pending', enabled: false, canRequest: false, form: false, text: 'Cancelamento pendente.', }, { state: 'cancelled', enabled: true, canRequest: false, form: false, text: 'Ordem cancelada.', }, ])( 'legacy detail preserves operational cancellation status and server authority ($state/$canRequest)', ({ state, enabled, canRequest, form, text }) => { const html = render(Show, { order, history: [], snapshotComplete: false, orderCancellation: { state, enabled, canRequest }, }); expect(html).toContain('Estado operacional e cancelamento'); expect(html).toContain(text); expect(html.includes('Pedir cancelamento integral')).toBe(form); expect(html).toContain('Documento original incompleto'); expect(html).toContain('Artigo preservado'); expect(html).toContain('100,00'); expect(html).not.toContain('Aprovações do valor final'); }, ); test.each([false, true])( 'existing order documents expose only server-authorised related destinations (%s)', (finance) => { const html = render(Show, { order, history: [], snapshotComplete: false, financialDocumentsHref: finance ? '/facturas?purchase_order_id=1' : null, relatedProcesses: [ { id: 4, number: 'REQ', href: '/requisicoes/4/processo' }, { id: 7, number: 'REQ-SECOND-QA', href: '/requisicoes/7/processo', }, ], }); expect(html).toContain('Documentos relacionados da ordem'); expect(html).toContain('href="/requisicoes/4/processo"'); expect(html).toContain('href="/requisicoes/7/processo"'); expect(html).toContain('REQ<QA>'); expect(html.includes('/facturas?purchase_order_id=1')).toBe(finance); expect(html).toContain('Artigo preservado'); }, ); import ReceiptShow from '@/pages/receipts/show'; test.each([false, true])( 'receipt detail retains the original and only offers the financial link supplied by the server (%s)', (finance) => { const html = render(ReceiptShow, { receipt: { id: 8, number: 'REC-QA', purchase_order_id: 1, delivery_note: 'GUIA-QA', received_on: '2026-11-28', confirmed_at: '2026-11-28T12:00:00Z', status: 'complete', snapshot: { order: { id: 1, number: 'OC-QA' }, supplier: { name: 'Fornecedor QA' }, receiver: { name: 'Armazém QA' }, warehouse: null, }, items: [], }, movements: [], financialDocumentsHref: finance ? '/facturas?purchase_order_id=1#invoice-documents' : null, }); expect( html.includes( 'href="/facturas?purchase_order_id=1#invoice-documents"', ), ).toBe(finance); expect(html).toContain('GUIA-QA'); expect(html).toContain('Recepção total aceite'); expect(html).toContain('/recepcoes/8/imprimir'); expect(html).toContain('/ordens/1/recepcoes'); }, );