@@ -0,0 +1,67 @@
|
||||
import { App, router } from '@inertiajs/react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { afterEach, expect, test, vi } from 'vitest';
|
||||
import PrivateAudit from '@/pages/audit/private';
|
||||
import { procurementNavigation } from '@/lib/procurement-navigation';
|
||||
|
||||
afterEach(() => vi.restoreAllMocks());
|
||||
|
||||
test('private audit preparation shows only granted families and does not submit on opening', () => {
|
||||
const post = vi.spyOn(router, 'post');
|
||||
const html = renderToStaticMarkup(
|
||||
<App
|
||||
initialComponent={PrivateAudit}
|
||||
initialPage={{
|
||||
component: 'audit/private',
|
||||
url: '/auditoria/privada',
|
||||
version: null,
|
||||
clearHistory: false,
|
||||
encryptHistory: true,
|
||||
props: {
|
||||
errors: {},
|
||||
auth: {
|
||||
user: {
|
||||
id: 7,
|
||||
tenant_id: 4,
|
||||
name: 'Synthetic auditor',
|
||||
},
|
||||
},
|
||||
organizationAccess: {
|
||||
permissions: ['audit_private_stock_read'],
|
||||
},
|
||||
families: [{ key: 'stock', label: 'Stock autorizado' }],
|
||||
exports: {
|
||||
data: [],
|
||||
prev_page_url: null,
|
||||
next_page_url: null,
|
||||
},
|
||||
},
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain('Stock autorizado');
|
||||
expect(html).not.toContain('value="finance"');
|
||||
expect(html).toContain('disabled');
|
||||
expect(post).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('private audit navigation needs both QA availability and dedicated family authority', () => {
|
||||
const paths = (permissions: string[], available: boolean) =>
|
||||
procurementNavigation(
|
||||
permissions,
|
||||
false,
|
||||
undefined,
|
||||
false,
|
||||
false,
|
||||
available,
|
||||
).flatMap((group) => group.entries.map((entry) => entry.path));
|
||||
expect(paths(['audit_private_stock_read'], true)).toContain(
|
||||
'/auditoria/privada',
|
||||
);
|
||||
expect(paths(['audit_private_stock_read'], false)).not.toContain(
|
||||
'/auditoria/privada',
|
||||
);
|
||||
for (const permission of ['audit_metadata_read', 'finance', 'admin']) {
|
||||
expect(paths([permission], true)).not.toContain('/auditoria/privada');
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user