90 lines
2.9 KiB
TypeScript
90 lines
2.9 KiB
TypeScript
import { App } from '@inertiajs/react';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import { expect, test } from 'vitest';
|
|
import CapitalRegister from '../../resources/js/pages/equipment/capital-register';
|
|
import CapitalAssignments from '../../resources/js/pages/requisitions/capital-assignments';
|
|
import CapitalAssignmentSummary from '../../resources/js/components/capital-assignment-summary';
|
|
|
|
const source = {
|
|
id: 2,
|
|
version: 3,
|
|
record_key: 'source',
|
|
state: 'archived',
|
|
reason: 'Synthetic archive reason',
|
|
data: {
|
|
type: 'project',
|
|
code: 'PRJ-QA',
|
|
name: '<script>QA</script>',
|
|
reference: 'Frozen documentary reference',
|
|
department_id: 1,
|
|
equipment_id: null,
|
|
},
|
|
};
|
|
const page = <T,>(data: T[]) => ({
|
|
data,
|
|
prev_page_url: null,
|
|
next_page_url: null,
|
|
});
|
|
const assignment = {
|
|
id: 5,
|
|
version: 1,
|
|
state: 'linked',
|
|
reason: 'Synthetic deliberate assignment',
|
|
data: { requisition_item_id: 1 },
|
|
snapshot: { item: { description: 'Synthetic item' }, source },
|
|
};
|
|
function render(
|
|
component: typeof CapitalRegister | typeof CapitalAssignments,
|
|
props: object,
|
|
) {
|
|
return renderToStaticMarkup(
|
|
<App
|
|
initialComponent={component}
|
|
initialPage={{
|
|
component: 'qa',
|
|
url: '/qa',
|
|
version: null,
|
|
clearHistory: false,
|
|
encryptHistory: true,
|
|
props: { errors: {}, ...props },
|
|
}}
|
|
/>,
|
|
);
|
|
}
|
|
test('read-only capital register preserves archived identity and history without management forms', () => {
|
|
const html = render(CapitalRegister, {
|
|
records: page([source]),
|
|
history: page([source]),
|
|
departments: [],
|
|
equipment: [],
|
|
canManage: false,
|
|
actorId: 1,
|
|
tenantId: 1,
|
|
});
|
|
expect(html).toContain('Arquivado');
|
|
expect(html).toContain('Histórico do registo');
|
|
expect(html).toContain('<script>QA</script>');
|
|
expect(html).not.toContain('<form');
|
|
});
|
|
test('approved requisitions display the preserved source independently of available new choices', () => {
|
|
const html = render(CapitalAssignments, {
|
|
requisition: { id: 1, number: 'REQ-QA', status: 'approved' },
|
|
items: [],
|
|
current: [assignment],
|
|
choices: page([]),
|
|
history: page([assignment]),
|
|
canWrite: false,
|
|
actorId: 1,
|
|
tenantId: 1,
|
|
});
|
|
expect(html).toContain('PRJ-QA');
|
|
expect(html).toContain('versão 3');
|
|
expect(html).not.toContain('<form');
|
|
const frozen = renderToStaticMarkup(
|
|
<CapitalAssignmentSummary records={{ 1: assignment }} />,
|
|
);
|
|
expect(frozen).toContain('Frozen documentary reference');
|
|
expect(frozen).toContain('<script>QA</script>');
|
|
expect(renderToStaticMarkup(<CapitalAssignmentSummary />)).toBe('');
|
|
});
|