109 lines
4.5 KiB
TypeScript
109 lines
4.5 KiB
TypeScript
import { App } from '@inertiajs/react';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import { expect, test } from 'vitest';
|
|
import { RequisitionApprovalSettings } from '@/components/requisition-approval-settings';
|
|
import { procurementNavigation } from '@/lib/procurement-navigation';
|
|
|
|
function render(ready: boolean, categoryOptions: Record<string, string> = {}) {
|
|
return renderToStaticMarkup(
|
|
<App
|
|
initialComponent={RequisitionApprovalSettings}
|
|
initialPage={{
|
|
component: 'company/parameters',
|
|
url: '/administracao/parametrizacao',
|
|
version: null,
|
|
clearHistory: false,
|
|
encryptHistory: true,
|
|
props: {
|
|
errors: {},
|
|
ready,
|
|
categoryOptions,
|
|
version: 4,
|
|
profiles: [
|
|
{
|
|
id: 7,
|
|
name: 'Direcção QA',
|
|
permissions: ['requisition_approve'],
|
|
},
|
|
{
|
|
id: 8,
|
|
name: 'Consulta revogada QA',
|
|
permissions: ['requester'],
|
|
},
|
|
],
|
|
costCenters: [{ id: 1, code: 'QA', name: 'Centro QA' }],
|
|
plan: {
|
|
revision: 2,
|
|
enabled: true,
|
|
quorum: 'one_eligible',
|
|
levels: [
|
|
{
|
|
name: 'Conferência <QA>',
|
|
profile_ids: [7, 8],
|
|
scope: 'company',
|
|
min_minor: 11601,
|
|
categories: ['Material'],
|
|
...(Object.keys(categoryOptions).length
|
|
? {
|
|
procurement_categories: [
|
|
'office_equipment',
|
|
],
|
|
}
|
|
: {}),
|
|
cost_center_ids: [1],
|
|
},
|
|
],
|
|
},
|
|
},
|
|
}}
|
|
/>,
|
|
);
|
|
}
|
|
|
|
test('explicit RQ01 group conditions are separate from original article categories and remain hidden until available', () => {
|
|
const html = render(true, {
|
|
office_equipment: 'Equipamento de escritório',
|
|
capital_equipment: 'Maquinaria',
|
|
});
|
|
expect(html).toContain('Categoria da necessidade (RQ-01)');
|
|
expect(html).toContain('Categorias exactas do artigo');
|
|
expect(html).toContain('Equipamento de escritório');
|
|
expect(html).toContain('Maquinaria');
|
|
expect(html).toContain('não são classificados automaticamente');
|
|
const groups = html.slice(
|
|
html.indexOf('Categoria da necessidade (RQ-01)'),
|
|
html.indexOf('Perfis elegíveis'),
|
|
);
|
|
expect(groups).toContain('checked=""');
|
|
expect(render(true)).not.toContain('Categoria da necessidade (RQ-01)');
|
|
});
|
|
|
|
test('approval settings retain exact threshold and selected revoked profiles so the administrator can reconcile the plan', () => {
|
|
const html = render(true);
|
|
expect(html).toContain('116.01');
|
|
expect(html).toContain('Conferência <QA>');
|
|
expect(html).toContain('Direcção QA');
|
|
expect(html).toContain('Consulta revogada QA');
|
|
expect(html).toContain('Sem competência de aprovação actualmente');
|
|
expect(html).toContain('basta um aprovador');
|
|
expect(html).toContain('apenas a novas submissões');
|
|
});
|
|
|
|
test('unavailable capability explains the existing circuit without offering a nonfunctional plan form', () => {
|
|
const html = render(false);
|
|
expect(html).toContain('O circuito actual permanece em vigor');
|
|
expect(html).not.toContain('<form');
|
|
});
|
|
|
|
test('a configured approver gets approval navigation without supplier or finance access links', () => {
|
|
const entries = procurementNavigation(
|
|
['requisition_approve'],
|
|
false,
|
|
).flatMap((group) => group.entries);
|
|
expect(
|
|
entries.some((entry) => entry.path === '/requisicoes?view=approvals'),
|
|
).toBe(true);
|
|
expect(entries.some((entry) => entry.path === '/facturas')).toBe(false);
|
|
expect(entries.some((entry) => entry.path === '/fornecedores')).toBe(false);
|
|
});
|