128 lines
4.3 KiB
TypeScript
128 lines
4.3 KiB
TypeScript
import { App } from '@inertiajs/react';
|
|
import type { ComponentProps } from 'react';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import { expect, test } from 'vitest';
|
|
import Review from '@/pages/requisitions/urgent-review';
|
|
import Queue from '@/pages/requisitions/urgent-reviews';
|
|
import Policy from '@/pages/organization/urgent-review-policy';
|
|
|
|
function render(
|
|
component: Parameters<typeof App>[0]['initialComponent'],
|
|
props: object,
|
|
) {
|
|
return renderToStaticMarkup(
|
|
<App
|
|
initialComponent={component}
|
|
initialPage={{
|
|
component: 'qa',
|
|
url: '/requisicoes/urgencias/revisoes',
|
|
version: 'qa',
|
|
clearHistory: false,
|
|
encryptHistory: true,
|
|
props: { errors: {}, ...props },
|
|
}}
|
|
/>,
|
|
);
|
|
}
|
|
const props: ComponentProps<typeof Review> = {
|
|
actorId: 1,
|
|
tenantId: 1,
|
|
canReview: true,
|
|
currentVerified: true,
|
|
current: null,
|
|
history: { data: [], prev_page_url: null, next_page_url: null },
|
|
source: {
|
|
cycle: 1,
|
|
outcome: 'expired',
|
|
fingerprint: 'a'.repeat(64),
|
|
closed_at: '2026-11-27T12:00:00Z',
|
|
request: {
|
|
id: 3,
|
|
number: 'REQ-QA',
|
|
justification: 'Necessidade original <script>de teste</script>',
|
|
total_minor: '9007199254740993',
|
|
},
|
|
items: [
|
|
{
|
|
id: 1,
|
|
description: 'Material original',
|
|
quantity: '1.000',
|
|
unit: 'un',
|
|
total_minor: '9007199254740993',
|
|
},
|
|
],
|
|
steps: [
|
|
{
|
|
id: 1,
|
|
role: 'department_head',
|
|
decision: 'pending',
|
|
comment: null,
|
|
},
|
|
],
|
|
},
|
|
};
|
|
test('expired cycle review distinguishes its original values from a later preparation and escapes source text', () => {
|
|
const html = render(Review, props);
|
|
expect(html).toContain('90.071.992.547.409,93 MZN');
|
|
expect(html).toContain('Estes dados pertencem ao ciclo expirado');
|
|
expect(html).toContain('Sem decisão antes da conclusão do ciclo');
|
|
expect(html).toContain('<script>de teste</script>');
|
|
expect(html).toContain('Registar revisão posterior');
|
|
expect(html).not.toContain('Aprovar');
|
|
});
|
|
test('unverified historical review is identified without offering a new approval or review command', () => {
|
|
const html = render(Review, {
|
|
...props,
|
|
canReview: false,
|
|
currentVerified: false,
|
|
current: {
|
|
id: 7,
|
|
version: 1,
|
|
data: { notes: 'Texto sintético preservado' },
|
|
snapshot: { fingerprint: 'a'.repeat(64) },
|
|
},
|
|
});
|
|
expect(html).toContain('não é apresentado como revisto');
|
|
expect(html).toContain('Texto sintético preservado');
|
|
expect(html).not.toContain('<form');
|
|
});
|
|
test('review queue keeps coverage and its own pagination while profile designation remains explicit', () => {
|
|
const html = render(Queue, {
|
|
coverage: { pending: 1, reviewed: 2, indeterminate: 1 },
|
|
state: 'pending',
|
|
canReview: false,
|
|
canConfigure: true,
|
|
records: {
|
|
data: [
|
|
{
|
|
key: '3:1',
|
|
number: 'REQ-QA',
|
|
cycle: 1,
|
|
outcome: 'expired',
|
|
status: 'pending',
|
|
closed_at: '2026-11-27T12:00:00Z',
|
|
href: '/requisicoes/3/ciclos/1/revisao-urgencia',
|
|
},
|
|
],
|
|
total: 21,
|
|
current_page: 1,
|
|
last_page: 2,
|
|
},
|
|
});
|
|
expect(html).toContain('Origem por conferir');
|
|
expect(html).toContain(
|
|
'/requisicoes/urgencias/revisoes?state=pending&page=2',
|
|
);
|
|
expect(html).toContain('Expirada e devolvida ao requisitante');
|
|
const settings = render(Policy, {
|
|
actorId: 1,
|
|
tenantId: 1,
|
|
current: null,
|
|
profiles: [],
|
|
history: { data: [], prev_page_url: null, next_page_url: null },
|
|
});
|
|
expect(settings).toContain('não concede permissões');
|
|
expect(settings).toContain('incluindo rejeição ou expiração');
|
|
expect(settings).toContain('Configure os perfis da empresa');
|
|
});
|