252 lines
8.4 KiB
TypeScript
252 lines
8.4 KiB
TypeScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { App } from '@inertiajs/react';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import { expect, test } from 'vitest';
|
|
import ReviewReport from '@/pages/purchases/review-report';
|
|
import Improvements from '@/pages/reports/supplier-improvements';
|
|
import PeopleReports from '@/pages/people/reports';
|
|
import WarehouseRequests from '@/pages/stock/requests';
|
|
import BankSupport from '@/pages/supply/import-bank-support';
|
|
|
|
const stamp = '2026-11-27T12:00:00Z';
|
|
const page = <T,>(data: T[]) => ({
|
|
data,
|
|
from: data.length ? 1 : null,
|
|
to: data.length || null,
|
|
total: data.length,
|
|
current_page: 1,
|
|
last_page: 1,
|
|
prev_page_url: null,
|
|
next_page_url: null,
|
|
});
|
|
function render(
|
|
component: Parameters<typeof App>[0]['initialComponent'],
|
|
props: object,
|
|
name: string,
|
|
) {
|
|
const html = renderToStaticMarkup(
|
|
<App
|
|
initialComponent={component}
|
|
initialPage={{
|
|
component: 'qa',
|
|
url: '/qa',
|
|
version: 'screen-review',
|
|
clearHistory: false,
|
|
encryptHistory: true,
|
|
props: { errors: {}, ...props },
|
|
}}
|
|
/>,
|
|
);
|
|
const folder = process.env.SGC_REVIEW_PREVIEW;
|
|
if (folder) {
|
|
const root = path.resolve(folder);
|
|
if (
|
|
!root.startsWith(
|
|
path.resolve('storage/framework/testing') + path.sep,
|
|
)
|
|
)
|
|
throw Error('Private preview required');
|
|
fs.mkdirSync(root, { recursive: true });
|
|
fs.writeFileSync(
|
|
path.join(root, name + '.html'),
|
|
'<!doctype html><html lang="pt-MZ"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>SGC QA ' +
|
|
name +
|
|
'</title><link rel="stylesheet" href="/preview.css"><body><aside class="print:hidden" style="padding:12px;background:#fef3c7">Pre-visualizacao isolada; dados sinteticos; sem gravacao.</aside>' +
|
|
html +
|
|
'</body></html>',
|
|
);
|
|
}
|
|
return html;
|
|
}
|
|
const policy = {
|
|
revision: 1,
|
|
configured: true,
|
|
minimum_proposals: 3,
|
|
minimum_evaluators: 2,
|
|
weights: { price: 40, quality: 20, delivery: 20, history: 10, payment: 10 },
|
|
};
|
|
test('long review report preserves all proposals, original amounts and finance visibility restriction', () => {
|
|
const rows = Array.from({ length: 30 }, (_, i) => ({
|
|
id: i + 1,
|
|
reference: 'QA-PROPOSTA-' + String(i + 1).padStart(3, '0'),
|
|
supplier: 'Fornecedor SINTETICO ' + (i + 1),
|
|
currency: 'MZN',
|
|
subtotal_minor: 10000,
|
|
tax_minor: 1600,
|
|
total_minor: 11600,
|
|
delivery_days: 15,
|
|
valid_until: '2026-12-31',
|
|
evaluation_count: 2,
|
|
score_minor: null,
|
|
eligible: false,
|
|
ineligibility_reasons: [
|
|
'Condicao sintetica por completar; nenhuma adjudicacao automatica.',
|
|
],
|
|
is_top: false,
|
|
weights: policy.weights,
|
|
}));
|
|
const report = {
|
|
generated_at: stamp,
|
|
generated_by: 'Operador SINTETICO',
|
|
company: 'Empresa SINTETICA',
|
|
requisition: {
|
|
id: 42,
|
|
number: 'REQ-SINTETICA-42',
|
|
status: 'approved',
|
|
justification:
|
|
'Necessidade sintetica para ensaio de impressao; sem operacao.',
|
|
department: 'Departamento SINTETICO',
|
|
requester: 'Requisitante SINTETICO',
|
|
},
|
|
comparison: { ready: false, top_count: 0, rows, policy },
|
|
recommendation: null,
|
|
admission: null,
|
|
qualification: null,
|
|
opening: null,
|
|
award: null,
|
|
order: null,
|
|
fulfilment: {
|
|
receipts: [],
|
|
finance_visible: false,
|
|
invoices: null,
|
|
payments: null,
|
|
},
|
|
};
|
|
const html = render(ReviewReport, { report }, 'review');
|
|
for (const row of rows) expect(html).toContain(row.reference);
|
|
expect(html).toContain('report-fulfilment');
|
|
expect(html).not.toContain('QA-FACTURA-PRIVADA');
|
|
});
|
|
test('improvement report preserves details on every visible row without changing their disclosure state', () => {
|
|
const rows = Array.from({ length: 30 }, (_, i) => ({
|
|
id: i + 1,
|
|
evaluation_id: 50 + i,
|
|
revision: 1,
|
|
supplier: 'Fornecedor SINTETICO ' + (i + 1),
|
|
responsible: 'Responsavel SINTETICO',
|
|
title: 'QA-MEDIDA-' + String(i + 1).padStart(3, '0'),
|
|
description:
|
|
'Descricao sintetica da medida de melhoria e acompanhamento da entrega com verificacao independente.',
|
|
due_on: '2026-12-01',
|
|
status: 'open',
|
|
version: 1,
|
|
overdue: false,
|
|
result: 'QA-RESULTADO-' + String(i + 1).padStart(3, '0'),
|
|
evidence: 'QA-EVIDENCIA-' + String(i + 1).padStart(3, '0'),
|
|
review_reason: 'Conferencia sintetica preservada.',
|
|
}));
|
|
const html = render(
|
|
Improvements,
|
|
{
|
|
records: page(rows),
|
|
filters: {},
|
|
counts: { open: 30 },
|
|
overdue: 0,
|
|
suppliers: [],
|
|
responsibles: [],
|
|
today: '2026-11-27',
|
|
generatedAt: stamp,
|
|
},
|
|
'improvements',
|
|
);
|
|
for (const row of rows) {
|
|
expect(html).toContain(row.title);
|
|
expect(html).toContain(row.evidence);
|
|
}
|
|
expect(html).not.toContain('<details open');
|
|
});
|
|
test('people deadline report retains all tasks and preserves visibility of unknown deadlines', () => {
|
|
const items = Array.from({ length: 35 }, (_, i) => ({
|
|
id: 'task-' + i,
|
|
reference: 'QA-PESSOAS-' + String(i + 1).padStart(3, '0'),
|
|
title: 'Processo SINTETICO ' + (i + 1),
|
|
category: 'task',
|
|
label: 'Conferencia sintetica',
|
|
responsibility: 'Responsavel SINTETICO',
|
|
due_on: null,
|
|
days_overdue: null,
|
|
href: '/pessoas/' + (i + 1),
|
|
}));
|
|
const html = render(
|
|
PeopleReports,
|
|
{
|
|
deadlineReport: {
|
|
as_of: '2026-11-27',
|
|
window: 'all',
|
|
total_items: 35,
|
|
matching_processes: 35,
|
|
processes_considered: 35,
|
|
tasks: 35,
|
|
approvals: 0,
|
|
alerts: 0,
|
|
without_deadline: 35,
|
|
overdue_items: 0,
|
|
items,
|
|
pagination: page([]),
|
|
},
|
|
selectionMetrics: {},
|
|
applicationMetrics: {},
|
|
filters: { view: 'deadlines' },
|
|
kinds: ['staff', 'service'],
|
|
generatedAt: stamp,
|
|
summary: [],
|
|
processes: page([]),
|
|
},
|
|
'people',
|
|
);
|
|
for (const item of items) expect(html).toContain(item.reference);
|
|
expect(html).toContain('Sem prazo');
|
|
});
|
|
test.each([true, false])(
|
|
'warehouse preparation remains conditional on its existing permission (%s)',
|
|
(canPrepare) => {
|
|
const html = render(
|
|
WarehouseRequests,
|
|
{
|
|
filters: {
|
|
view: 'all',
|
|
state: '',
|
|
search: '',
|
|
warehouse_id: null,
|
|
},
|
|
views: [],
|
|
states: {},
|
|
checkedAt: stamp,
|
|
ready: true,
|
|
canPrepare,
|
|
items: [],
|
|
warehouses: [],
|
|
costCenters: [],
|
|
equipment: [],
|
|
records: page([]),
|
|
},
|
|
canPrepare ? 'warehouse' : 'warehouse-read',
|
|
);
|
|
expect(html.includes('Preparar rascunho')).toBe(canPrepare);
|
|
},
|
|
);
|
|
test.each([true, false])(
|
|
'bank documentary editing remains conditional on its existing permission (%s)',
|
|
(canWrite) => {
|
|
const html = render(
|
|
BankSupport,
|
|
{
|
|
importRecord: { id: 5, record_key: 'synthetic', version: 1 },
|
|
order: { id: 2, number: 'OC-SINTETICA' },
|
|
current: page([]),
|
|
history: page([]),
|
|
documents: page([]),
|
|
types: { commitment: 'Termo sintetico' },
|
|
canWrite,
|
|
actorId: 1,
|
|
tenantId: 1,
|
|
today: '2026-11-27',
|
|
},
|
|
canWrite ? 'bank' : 'bank-read',
|
|
);
|
|
expect(html).toContain('Suporte documental bancário');
|
|
expect(html.includes('<form')).toBe(canWrite);
|
|
},
|
|
);
|