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'; import { CandidateDocumentList } from '@/components/candidate-documents'; 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: [ { key: 'cv', label: 'Currículo obrigatório', required: true, formats: ['pdf', 'docx'], max_kb: 1024, }, ], }; test('received files use guarded download links and retain their fingerprint without a storage URL', () => { const html = renderToString( , ); expect(html).toContain('/candidaturas/1/submissoes/7/documentos/cv'); expect(html).toContain('abc123'); expect(html).toContain('autenticidade dependem da análise documental'); expect(html).not.toContain('/storage/'); expect( renderToString( , ), ).toBe(''); }); 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', additional_availability: [ { province: 'Outra província', district: 'Outro distrito', locality: 'Outra localidade', }, ], availability: { province: 'Província do perfil', district: 'Distrito do perfil', locality: 'Localidade do perfil', }, }, }, }, }; const html = renderToString( , ); expect(html).toContain('value="Nome do perfil"'); expect(html).toContain('value="Distrito do perfil"'); expect(html).toContain('Usar local guardado no perfil'); expect(html).toContain('Outra localidade'); expect(html).toContain('type="file"'); expect(html).toContain('Currículo obrigatório'); expect(html).toContain('accept=".pdf,.docx"'); 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( , ); 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( , ); expect(html).toContain('O envio de email ainda não está configurado'); expect(html).toContain('disabled=""'); });