@@ -0,0 +1,90 @@
|
||||
import { App } from '@inertiajs/react';
|
||||
import type { Page } from '@inertiajs/core';
|
||||
import { renderToString } from 'react-dom/server';
|
||||
import { expect, test } from 'vitest';
|
||||
import SubmissionForms from '@/pages/company/submission-forms';
|
||||
|
||||
const page = {
|
||||
component: 'company/submission-forms',
|
||||
url: '/administracao/candidaturas/formularios',
|
||||
version: 'forms',
|
||||
props: { errors: {} },
|
||||
clearHistory: false,
|
||||
encryptHistory: true,
|
||||
} satisfies Page;
|
||||
|
||||
test.each([true, false])(
|
||||
'form editor preserves revision and respects write authority (%s)',
|
||||
(canManage) => {
|
||||
const definition = {
|
||||
available: false,
|
||||
fields: [
|
||||
{
|
||||
key: 'availability_location',
|
||||
label: 'Local de disponibilidade',
|
||||
type: 'location',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
key: 'full_name',
|
||||
label: 'Nome completo',
|
||||
type: 'text',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
documents: [
|
||||
{
|
||||
key: 'cv',
|
||||
label: 'CV',
|
||||
formats: ['pdf'],
|
||||
max_kb: 2048,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
const initialPage = {
|
||||
...page,
|
||||
props: {
|
||||
...page.props,
|
||||
ready: true,
|
||||
canManage,
|
||||
externalPortalAvailable: false,
|
||||
forms: [
|
||||
{
|
||||
audience: 'staff',
|
||||
modality: 'competition',
|
||||
version: 2,
|
||||
definition,
|
||||
history: [
|
||||
{
|
||||
id: 1,
|
||||
version: 1,
|
||||
created_by: 4,
|
||||
created_at: '2026-10-30',
|
||||
reason: 'Definição anterior preservada',
|
||||
definition,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
const html = renderToString(
|
||||
<App
|
||||
initialPage={initialPage}
|
||||
initialComponent={SubmissionForms}
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain('Recrutamento');
|
||||
expect(html).toContain('Nome completo');
|
||||
expect(html).toContain('Definição anterior preservada');
|
||||
expect(html).toContain('Ainda não abre candidaturas externas');
|
||||
expect(html.includes('Guardar nova versão')).toBe(canManage);
|
||||
expect(html).toContain('placeholder="Província"');
|
||||
expect(html).toContain('placeholder="Distrito"');
|
||||
expect(html).toContain('placeholder="Localidade"');
|
||||
expect(html.includes('<fieldset disabled="" class="space-y-5"')).toBe(
|
||||
!canManage,
|
||||
);
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user