128 lines
4.3 KiB
TypeScript
128 lines
4.3 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 Opportunity from '@/pages/candidate/opportunity';
|
|
import Receipt from '@/pages/candidate/receipt';
|
|
import Access from '@/pages/candidate/access';
|
|
|
|
const page = {
|
|
component: 'candidate/opportunity',
|
|
url: '/candidaturas/1/oportunidades/1',
|
|
version: 'submission',
|
|
props: { errors: {} },
|
|
clearHistory: false,
|
|
encryptHistory: true,
|
|
} satisfies Page;
|
|
const definition = {
|
|
fields: [
|
|
{
|
|
key: 'full_name',
|
|
label: 'Nome completo',
|
|
type: 'text',
|
|
required: true,
|
|
},
|
|
{
|
|
key: 'availability_location',
|
|
label: 'Disponibilidade',
|
|
type: 'location',
|
|
required: true,
|
|
},
|
|
],
|
|
documents: [],
|
|
};
|
|
test.each([true, false])(
|
|
'actual submission form reuses geographic profile and requires email confirmation (%s)',
|
|
(emailVerified) => {
|
|
const initialPage = {
|
|
...page,
|
|
props: {
|
|
...page.props,
|
|
companyId: 1,
|
|
email: 'candidate@example.invalid',
|
|
emailVerified,
|
|
opportunity: {
|
|
id: 1,
|
|
title: 'Oportunidade fictícia',
|
|
description: 'Descrição pública',
|
|
closes_on: '2026-11-10',
|
|
publication_version: 1,
|
|
form: { version: 2, definition },
|
|
},
|
|
profile: {
|
|
version: 3,
|
|
data: {
|
|
name: 'Nome do perfil',
|
|
summary: 'Perfil fictício',
|
|
availability: {
|
|
province: 'Província do perfil',
|
|
district: 'Distrito do perfil',
|
|
locality: 'Localidade do perfil',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
const html = renderToString(
|
|
<App initialPage={initialPage} initialComponent={Opportunity} />,
|
|
);
|
|
expect(html).toContain('value="Nome do perfil"');
|
|
expect(html).toContain('value="Distrito do perfil"');
|
|
expect(html).toContain('Submeter candidatura e obter comprovativo');
|
|
expect(html.includes('disabled=""')).toBe(!emailVerified);
|
|
},
|
|
);
|
|
test('receipt displays user labels and geographic values without exposing internal field keys or evaluation', () => {
|
|
const initialPage = {
|
|
...page,
|
|
component: 'candidate/receipt',
|
|
props: {
|
|
...page.props,
|
|
companyId: 1,
|
|
receipt: {
|
|
reference: 'CAND-TEST',
|
|
received_at: '2026-10-30',
|
|
snapshot: {
|
|
opportunity: {
|
|
title: 'Oportunidade',
|
|
form: { definition },
|
|
},
|
|
profile: { version: 3 },
|
|
answers: {
|
|
availability_location: {
|
|
province: 'Província fictícia',
|
|
district: 'Distrito fictício',
|
|
locality: 'Localidade fictícia',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
const html = renderToString(
|
|
<App initialPage={initialPage} initialComponent={Receipt} />,
|
|
);
|
|
expect(html).toContain('Disponibilidade');
|
|
expect(html).toContain('Distrito fictício');
|
|
expect(html).not.toContain('availability_location');
|
|
expect(html).not.toContain('Avaliação interna');
|
|
});
|
|
test('recovery never claims delivery when the mail transport is absent', () => {
|
|
const initialPage = {
|
|
...page,
|
|
component: 'candidate/access',
|
|
props: {
|
|
...page.props,
|
|
companyId: 1,
|
|
purpose: 'recuperar',
|
|
emailDeliveryAvailable: false,
|
|
accessStatus: null,
|
|
},
|
|
};
|
|
const html = renderToString(
|
|
<App initialPage={initialPage} initialComponent={Access} />,
|
|
);
|
|
expect(html).toContain('O envio de email ainda não está configurado');
|
|
expect(html).toContain('disabled=""');
|
|
});
|