Files
compras/tests/frontend/people-registry.test.tsx
T
nala c6373365bf
tests / ci (push) Canceled after 0s
commit9
2026-10-30 20:02:30 +02:00

120 lines
3.8 KiB
TypeScript

import { App } from '@inertiajs/react';
import type { Page } from '@inertiajs/core';
import { renderToString } from 'react-dom/server';
import { expect, test } from 'vitest';
import Registry from '@/pages/people/registry';
import PeopleShow from '@/pages/people/show';
import { PeopleRegistryChoice } from '@/components/people-registry-choice';
const page = {
component: 'people/registry',
url: '/pessoas/cadastro',
version: 'registry',
props: { errors: {} },
clearHistory: false,
encryptHistory: true,
} satisfies Page;
const person = {
id: 7,
name: 'Pessoa do cadastro',
reference: 'CAD-7',
profile_summary: 'Perfil profissional reutilizável.',
active: true,
version: 2,
canEdit: false,
};
test.each([true, false])(
'registry respects directory editing authority (%s) without linking to restricted processes',
(canCreate) => {
const initialPage = {
...page,
props: {
...page.props,
ready: true,
canCreate,
records: {
data: [person],
total: 1,
prev_page_url: null,
next_page_url: null,
},
filters: {},
},
};
const html = renderToString(
<App initialPage={initialPage} initialComponent={Registry} />,
);
expect(html).toContain('Pessoa do cadastro');
expect(html).toContain('Perfil profissional reutilizável.');
expect(html.includes('Registar pessoa</button>')).toBe(canCreate);
expect(html).not.toContain('Guardar nova versão');
expect(html).not.toContain('/pessoas/7');
},
);
test('process registry selection identifies source version without repeating an entire registration form', () => {
const html = renderToString(
<PeopleRegistryChoice
processId={1}
selected="7"
data={{
ready: true,
canCreate: true,
search: 'CAD',
items: [person],
}}
choose={() => {}}
/>,
);
expect(html).toContain('CAD-7');
expect(html.replace(/<!--.*?-->/g, '')).toContain('v2');
expect(html).toContain('Pesquisar cadastro');
expect(html).toContain('A candidatura conserva a versão');
expect(html).not.toContain('<form');
});
test('real reception form offers reuse and saving the first profile in the same flow', () => {
const initialPage = {
...page,
component: 'people/show',
url: '/pessoas/1',
props: {
...page.props,
process: {
id: 1,
title: 'Recepção fictícia',
purpose: 'Âmbito fictício',
kind: 'service',
status: 'open',
version: 2,
closes_on: '2026-10-30',
rules: {
minimum_reviews: 1,
criteria: [{ label: 'Competências', weight: 100 }],
},
selection: null,
selected_application_id: null,
contract: null,
},
candidates: [],
canPrepare: true,
canReview: false,
history: [],
registry: {
ready: true,
canCreate: true,
search: 'CAD',
items: [person],
},
},
};
const html = renderToString(
<App initialPage={initialPage} initialComponent={PeopleShow} />,
);
expect(html).toContain('Reutilizar pessoa do cadastro');
expect(html).toContain('Guardar também no meu cadastro para reutilizar');
expect(html).toContain('CAD-7');
expect(html).toContain('Referência documental da candidatura');
});