Files
compras/tests/frontend/audit-investigation.test.tsx
T
nala eb32c74c56
tests / ci (push) Waiting to run
commit compras1 2811
2026-11-28 07:11:35 +02:00

72 lines
2.6 KiB
TypeScript

import { App } from '@inertiajs/react';
import { renderToStaticMarkup } from 'react-dom/server';
import { expect, test } from 'vitest';
import Metadata from '@/pages/audit/metadata';
function render(allowed: boolean) {
return renderToStaticMarkup(
<App
initialComponent={Metadata}
initialPage={{
component: 'audit/metadata',
url: '/auditoria/eventos',
version: null,
clearHistory: false,
encryptHistory: true,
props: {
errors: {},
filters: {
request_reference: 'QA<REQ>%_',
action: '0',
actor_id: 7,
from: '2026-11-01',
to: '2026-11-01',
page: 2,
},
requestContext: allowed
? {
number: 'QA<REQ>%_',
href: '/requisicoes/7#requisition-history',
}
: null,
events: {
data: [
{
id: 4,
action: '0',
created_at: '2026-11-01T12:00:00Z',
user_id: 7,
},
],
total: 131,
current_page: 2,
last_page: 6,
prev_page_url:
'/auditoria/eventos?request_reference=QA&page=1',
next_page_url: null,
},
},
}}
/>,
);
}
test('audit investigation carries applied criteria into the whole-scope CSV and escapes the reference', () => {
const html = render(false);
expect(html).toContain('Referência exacta da requisição');
expect(html).toContain('QA&lt;REQ&gt;%_');
expect(html).toContain(
'/auditoria/eventos.csv?request_reference=QA%3CREQ%3E%25_&amp;action=0&amp;actor_id=7&amp;from=2026-11-01&amp;to=2026-11-01',
);
expect(html).not.toContain('/requisicoes/7');
expect(html).not.toContain('PRIVATE-');
});
test('only an independently authorised native process locator is rendered', () => {
const html = render(true);
expect(html).toContain('href="/requisicoes/7#requisition-history"');
expect(html).toContain(
'Consultar o processo e o histórico de QA&lt;REQ&gt;%_',
);
});