130 lines
4.3 KiB
TypeScript
130 lines
4.3 KiB
TypeScript
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('<Finance>');
|
|
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);
|
|
});
|