121 lines
4.0 KiB
TypeScript
121 lines
4.0 KiB
TypeScript
import { renderToString } from 'react-dom/server';
|
|
import { expect, test } from 'vitest';
|
|
import { EvidenceBrief } from '@/components/evidence-brief';
|
|
import { App } from '@inertiajs/react';
|
|
import type { Page } from '@inertiajs/core';
|
|
import ReviewReport from '@/pages/purchases/review-report';
|
|
|
|
test('real report renders source targets and preserves printable report sections', () => {
|
|
const report = {
|
|
generated_at: '2026-10-30T12:00:00Z',
|
|
generated_by: 'Pessoa fictícia',
|
|
company: 'Empresa fictícia',
|
|
requisition: {
|
|
id: 42,
|
|
number: 'REQ-42',
|
|
status: 'approved',
|
|
justification: 'Necessidade fictícia',
|
|
department: 'Operações',
|
|
requester: 'Requisitante fictício',
|
|
},
|
|
comparison: {
|
|
ready: false,
|
|
top_count: 0,
|
|
rows: [],
|
|
policy: {
|
|
revision: 0,
|
|
configured: false,
|
|
minimum_proposals: 3,
|
|
minimum_evaluators: 2,
|
|
weights: {
|
|
price: 40,
|
|
quality: 20,
|
|
delivery: 20,
|
|
history: 10,
|
|
payment: 10,
|
|
},
|
|
},
|
|
},
|
|
recommendation: null,
|
|
admission: null,
|
|
qualification: null,
|
|
opening: null,
|
|
award: null,
|
|
order: null,
|
|
fulfilment: {
|
|
receipts: [],
|
|
finance_visible: false,
|
|
invoices: null,
|
|
payments: null,
|
|
},
|
|
};
|
|
const page = {
|
|
component: 'purchases/review-report',
|
|
url: '/requisicoes/42/relatorio',
|
|
version: 'brief',
|
|
props: {
|
|
errors: {},
|
|
report,
|
|
brief: {
|
|
method: 'procurement_evidence_brief_v1',
|
|
generated_at: report.generated_at,
|
|
basis_sha256: 'a'.repeat(64),
|
|
finance_visible: false,
|
|
claims: [],
|
|
},
|
|
},
|
|
clearHistory: false,
|
|
encryptHistory: true,
|
|
} satisfies Page;
|
|
const html = renderToString(
|
|
<App initialPage={page} initialComponent={ReviewReport} />,
|
|
);
|
|
for (const section of [
|
|
'request',
|
|
'comparison',
|
|
'qualification',
|
|
'records',
|
|
'fulfilment',
|
|
])
|
|
expect(html).toContain(`id="report-${section}"`);
|
|
expect(html).toContain('Síntese com fontes');
|
|
expect(html).toContain('Imprimir esta consulta');
|
|
expect(html).toContain('Necessidade fictícia');
|
|
});
|
|
|
|
test.each([true, false])(
|
|
'evidence brief exposes provenance and the correct financial visibility (%s)',
|
|
(finance_visible) => {
|
|
const html = renderToString(
|
|
<EvidenceBrief
|
|
data={{
|
|
method: 'procurement_evidence_brief_v1',
|
|
generated_at: '2026-10-30T12:00:00Z',
|
|
basis_sha256: 'a'.repeat(64),
|
|
finance_visible,
|
|
claims: [
|
|
{
|
|
id: 'request',
|
|
text: 'A requisição encontra-se aprovada. <script>alert(1)</script>',
|
|
basis_sha256: 'b'.repeat(64),
|
|
source: {
|
|
label: 'Identificação do pedido',
|
|
href: '#report-request',
|
|
pointer: 'requisition.status',
|
|
},
|
|
},
|
|
],
|
|
}}
|
|
/>,
|
|
);
|
|
expect(html).toContain('href="#report-request"');
|
|
expect(html).toContain('sem modelo de IA activo');
|
|
expect(html).toContain('não é uma assinatura ou aprovação');
|
|
expect(html).not.toContain('<script>');
|
|
expect(html).toContain('<script>');
|
|
expect(html.includes('O âmbito financeiro está reservado')).toBe(
|
|
!finance_visible,
|
|
);
|
|
},
|
|
);
|