101 lines
3.6 KiB
TypeScript
101 lines
3.6 KiB
TypeScript
import { App, router } from '@inertiajs/react';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import { afterEach, expect, test, vi } from 'vitest';
|
|
import Investment from '@/pages/investment/index';
|
|
|
|
afterEach(() => vi.restoreAllMocks());
|
|
const identity = 'investment:4:7:finance:true:admin';
|
|
function render(
|
|
overrides = {},
|
|
actor = 7,
|
|
tenant = 4,
|
|
context = 'finance',
|
|
id = 3,
|
|
) {
|
|
return renderToStaticMarkup(
|
|
<App
|
|
initialComponent={Investment}
|
|
initialPage={{
|
|
component: 'investment/index',
|
|
url: '/regras-investimento',
|
|
version: null,
|
|
clearHistory: false,
|
|
encryptHistory: true,
|
|
props: {
|
|
errors: {},
|
|
auth: { user: { id: actor, tenant_id: tenant } },
|
|
workContext: { active: context },
|
|
organizationAccess: { permissions: ['admin'] },
|
|
canManage: true,
|
|
policies: [
|
|
{
|
|
id,
|
|
created_by: 9,
|
|
revision: 1,
|
|
status: 'pending',
|
|
mode: 'ceiling',
|
|
scope: 'process_total',
|
|
currency: 'MZN',
|
|
ceiling_minor: 10000,
|
|
includes_tax: true,
|
|
valid_from: '2026-11-01',
|
|
valid_until: '2026-12-31',
|
|
reason: 'Synthetic policy',
|
|
},
|
|
],
|
|
reviews: [],
|
|
currentPolicyId: null,
|
|
...overrides,
|
|
},
|
|
}}
|
|
/>,
|
|
);
|
|
}
|
|
test.each([
|
|
[
|
|
'proposal:3',
|
|
{
|
|
previous_id: 3,
|
|
mode: 'ceiling',
|
|
scope: 'process_total',
|
|
currency: 'MZN',
|
|
ceiling: '123.45',
|
|
includes_tax: '0',
|
|
valid_from: '2026-12-01',
|
|
valid_until: '2026-12-31',
|
|
reason: 'INVESTMENT-DRAFT-QA',
|
|
},
|
|
],
|
|
['review:3', { decision: 'rejected', reason: 'INVESTMENT-DRAFT-QA' }],
|
|
])(
|
|
'%s preparation stays private to identity capability and immutable predecessor or policy',
|
|
(suffix, data) => {
|
|
vi.spyOn(router, 'restore').mockImplementation((k) =>
|
|
k === `${identity}:${suffix}:data` ? data : undefined,
|
|
);
|
|
const post = vi.spyOn(router, 'post');
|
|
expect(render()).toContain('INVESTMENT-DRAFT-QA');
|
|
expect(render()).toContain('data-preparation-dirty="true"');
|
|
expect(render({}, 8)).not.toContain('INVESTMENT-DRAFT-QA');
|
|
expect(render({}, 7, 5)).not.toContain('INVESTMENT-DRAFT-QA');
|
|
expect(render({}, 7, 4, 'procurement.internal')).not.toContain(
|
|
'INVESTMENT-DRAFT-QA',
|
|
);
|
|
expect(render({}, 7, 4, 'finance', 4)).not.toContain(
|
|
'INVESTMENT-DRAFT-QA',
|
|
);
|
|
expect(render({ canManage: false })).not.toContain(
|
|
'INVESTMENT-DRAFT-QA',
|
|
);
|
|
expect(post).not.toHaveBeenCalled();
|
|
},
|
|
);
|
|
test('unmodified policy preparation stays clean and leaves company parameters undecided', () => {
|
|
vi.spyOn(router, 'restore').mockReturnValue(undefined);
|
|
const post = vi.spyOn(router, 'post');
|
|
const html = render();
|
|
expect(html).not.toContain('data-preparation-dirty="true"');
|
|
expect(html).toContain('value="" selected=""');
|
|
expect(post).not.toHaveBeenCalled();
|
|
});
|