commit compras3 2911
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-29 16:03:11 +02:00
parent 7da8d6c87a
commit 30bfb1a773
72 changed files with 10998 additions and 98 deletions
+129
View File
@@ -0,0 +1,129 @@
import { App } from '@inertiajs/react';
import { renderToStaticMarkup } from 'react-dom/server';
import { expect, test } from 'vitest';
import Finance from '@/pages/company/finance';
import { procurementNavigation } from '@/lib/procurement-navigation';
const empty = { data: [], prev_page_url: null, next_page_url: null };
const basis = { hash: 'a'.repeat(64), rows: [] };
function render(selectedAccess: Record<string, unknown> | null = null) {
return renderToStaticMarkup(
<App
initialComponent={Finance}
initialPage={{
component: 'company/finance',
url: '/administracao/financeiro',
version: null,
clearHistory: false,
encryptHistory: true,
props: {
errors: {},
actorId: 1,
tenantId: 1,
q: '',
users: empty,
selectedAccess,
accounts: basis,
periods: basis,
rules: basis,
actions: {
view: 'View supplier debts',
prepare: 'Prepare recognition',
},
effects: {
'supplier_payable.recognised': 'Recognise payable',
},
history: empty,
},
}}
/>,
);
}
test('company setup starts without an implicit target grants accounts dates or posting rules', () => {
const html = render();
expect(html).toContain('href="#finance-access"');
expect(html).not.toContain('checked=""');
expect(html).not.toContain('2026-01-01');
expect(html).not.toContain('QA-2026');
expect(html).not.toContain('value="supplier_payable.recognised" selected');
expect(html).not.toContain('View supplier debts');
});
test('explicit target is escaped and no permission is selected by reading an empty grant list', () => {
const html = render({
...basis,
user: { id: 3, name: '<Finance>', email: 'qa@example.invalid' },
eligible: true,
person: '',
actions: [],
other_actions: [],
identity_inconsistent: false,
});
expect(html).toContain('&lt;Finance&gt;');
expect(html).toContain('View supplier debts');
expect(html).not.toContain('checked=""');
expect(html).not.toContain('<Finance>');
});
test('financial menus expose only explicit capabilities and use full navigation for common package pages', () => {
const menu = (role: string, flags = {}) =>
procurementNavigation(
role,
false,
undefined,
false,
false,
false,
false,
flags,
).flatMap((group) => group.entries);
expect(menu('admin').some((entry) => entry.id === 'general_ledger')).toBe(
false,
);
const flags = { payments: true, ledger: true, configuration: true };
const admin = menu('admin', flags);
expect(admin.find((entry) => entry.id === 'general_ledger')).toMatchObject({
path: '/general-ledger/cycle',
fullPage: true,
});
expect(
admin.find((entry) => entry.id === 'supplier_settlements'),
).toMatchObject({ path: '/supplier-payments', fullPage: true });
expect(
admin.find((entry) => entry.id === 'finance_configuration'),
).toMatchObject({ path: '/administracao/financeiro' });
expect(
menu('finance', flags).some(
(entry) => entry.id === 'finance_configuration',
),
).toBe(false);
expect(
menu('requester', flags).some((entry) =>
[
'general_ledger',
'supplier_settlements',
'finance_configuration',
].includes(entry.id),
),
).toBe(false);
const publicMenu = procurementNavigation(
'admin',
false,
['/dashboard'],
false,
false,
false,
false,
flags,
).flatMap((group) => group.entries);
expect(
publicMenu.some((entry) =>
[
'general_ledger',
'supplier_settlements',
'finance_configuration',
].includes(entry.id),
),
).toBe(false);
});
@@ -65,6 +65,59 @@ test('incomplete detail identifies the missing original and preserves documented
expect(html).not.toContain('Aprovações do valor final');
});
test.each([true, false, undefined])(
'complete order preserves its recorded development classification: %s',
(development) => {
const html = render(Show, {
order: {
...order,
subtotal_minor: 10000,
tax_minor: 0,
snapshot: {
...order.snapshot,
development_only: development,
budget_checked: true,
supplier: {
name: 'Synthetic supplier',
nuit: '000000000',
contact: '',
phone: '',
email: '',
address: '',
},
department: { name: 'Synthetic operations' },
cost_center: { code: 'SYN', name: 'Synthetic centre' },
requisition: { number: 'RQ-SYN' },
issuer: { name: 'Synthetic issuer' },
requester: { name: 'Synthetic requester' },
quotation: {
reference: 'PROP-SYN',
payment_terms: 'Synthetic documentary terms',
},
award: {
justification: 'Synthetic approved example',
delivery_date: '2026-11-29',
delivery_location: 'Synthetic location',
},
approval_rules: {
approval_includes_tax: true,
rules_provisional: false,
},
decision_matrix: [],
final_approvals: [],
},
},
history: [],
snapshotComplete: true,
});
expect(html.includes('Documento de desenvolvimento')).toBe(
development !== false,
);
expect(html).toContain('Controlo orçamental registado na emissão');
expect(html).toContain('RQ-SYN');
},
);
test.each([
{
state: 'issued',