-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajout du lien au back-end sur le formulaire coordinateur (#220)
* Ajout du lien au back-end sur le formulaire coordinateur * Ajout de tests * Correction de l'appel à la GeoAPI --------- Co-authored-by: Ornella <[email protected]>
- Loading branch information
1 parent
9467c9e
commit c247614
Showing
8 changed files
with
328 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { render, screen, within } from '@testing-library/react'; | ||
import { render, screen, within, fireEvent, act } from '@testing-library/react'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
import CandidatureCoordinateur from './CandidatureCoordinateur'; | ||
import { textMatcher } from '../../../test/test-utils'; | ||
import { textMatcher, dateDujour } from '../../../test/test-utils'; | ||
import * as ReactRouterDom from 'react-router-dom'; | ||
|
||
vi.mock('react-router-dom', () => ({ | ||
useLocation: () => ({ hash: '' }), | ||
|
@@ -142,22 +143,22 @@ describe('candidature coordinateur', () => { | |
|
||
const oui = screen.getByRole('radio', { name: 'Oui' }); | ||
expect(oui).toBeRequired(); | ||
expect(oui).toHaveAttribute('name', 'aIdentifieCandidat'); | ||
expect(oui).toHaveAttribute('name', 'aIdentifieCoordinateur'); | ||
|
||
const non = screen.getByRole('radio', { name: 'Non' }); | ||
expect(non).toBeRequired(); | ||
expect(non).toHaveAttribute('name', 'aIdentifieCandidat'); | ||
expect(non).toHaveAttribute('name', 'aIdentifieCoordinateur'); | ||
|
||
const leCoordinateur = within(etapeBesoinCoordinateur).getByText(textMatcher('Le coordinateur*'), { selector: 'p' }); | ||
expect(leCoordinateur).toBeInTheDocument(); | ||
|
||
const coordination = screen.getByRole('radio', { name: 'Effectuera uniquement des missions de coordination' }); | ||
expect(coordination).toBeRequired(); | ||
expect(coordination).toHaveAttribute('name', 'coordinateur'); | ||
expect(coordination).toHaveAttribute('name', 'coordinateurTypeContrat'); | ||
|
||
const publics = screen.getByRole('radio', { name: 'Accompagnera également des publics' }); | ||
expect(publics).toBeRequired(); | ||
expect(publics).toHaveAttribute('name', 'coordinateur'); | ||
expect(publics).toHaveAttribute('name', 'coordinateurTypeContrat'); | ||
|
||
const dateAccueilCoordinateur = within(etapeBesoinCoordinateur).getByText( | ||
textMatcher('À partir de quand êtes vous prêt à accueillir votre coordinateur ?*'), | ||
|
@@ -243,5 +244,116 @@ describe('candidature coordinateur', () => { | |
const formulaire = screen.getByRole('form', { name: 'Candidature coordinateur' }); | ||
within(formulaire).getByRole('button', { name: 'Envoyer votre candidature' }); | ||
}); | ||
|
||
it('quand je remplis le formulaire, que je l’envoie et que le serveur me renvoie une erreur, alors elle s’affiche sur la page', async () => { | ||
// GIVEN | ||
vi.useFakeTimers(); | ||
vi.setSystemTime(new Date(2023, 11, 12, 13)); | ||
|
||
vi.stubGlobal('fetch', vi.fn( | ||
() => ({ status: 400, json: async () => Promise.resolve({ message: 'Cette adresse mail est déjà utilisée' }) })) | ||
); | ||
|
||
render(<CandidatureCoordinateur />); | ||
const siret = screen.getByLabelText('SIRET / RIDET *'); | ||
fireEvent.change(siret, { target: { value: '1234567890123' } }); | ||
const denomination = screen.getByLabelText('Dénomination *'); | ||
fireEvent.change(denomination, { target: { value: 'Entreprise' } }); | ||
const adresse = screen.getByLabelText('Adresse *'); | ||
fireEvent.change(adresse, { target: { value: '75056 Paris' } }); | ||
const typeStructure = screen.getByRole('radio', { name: 'Une commune' }); | ||
fireEvent.click(typeStructure); | ||
const prenom = screen.getByLabelText('Prénom *'); | ||
fireEvent.change(prenom, { target: { value: 'Jean' } }); | ||
const nom = screen.getByLabelText('Nom *'); | ||
fireEvent.change(nom, { target: { value: 'Dupont' } }); | ||
const fonction = screen.getByLabelText('Fonction *'); | ||
fireEvent.change(fonction, { target: { value: 'Test' } }); | ||
const email = screen.getByLabelText('Adresse e-mail *'); | ||
fireEvent.change(email, { target: { value: '[email protected]' } }); | ||
const telephone = screen.getByLabelText('Téléphone *'); | ||
fireEvent.change(telephone, { target: { value: '+33123456789' } }); | ||
const identificationCandidat = screen.getByRole('radio', { name: 'Oui' }); | ||
fireEvent.click(identificationCandidat); | ||
const typeMission = screen.getByRole('radio', { name: 'Accompagnera également des publics' }); | ||
fireEvent.click(typeMission); | ||
const date = screen.getByLabelText('Choisir une date'); | ||
fireEvent.change(date, { target: { value: dateDujour() } }); | ||
const descriptionMotivation = screen.getByLabelText('Votre message *'); | ||
fireEvent.change(descriptionMotivation, { target: { value: 'je suis motivé !' } }); | ||
const confirmation = screen.getByRole('checkbox', { name: 'Je confirme avoir lu et pris connaissance des conditions d’engagement. *' }); | ||
fireEvent.click(confirmation); | ||
|
||
// WHEN | ||
const envoyer = screen.getByRole('button', { name: 'Envoyer votre candidature' }); | ||
|
||
// eslint-disable-next-line testing-library/no-unnecessary-act | ||
await act(() => { | ||
fireEvent.click(envoyer); | ||
}); | ||
|
||
// THEN | ||
const titreErreurValidation = screen.getByRole('heading', { level: 3, name: 'Erreur de validation' }); | ||
expect(titreErreurValidation).toBeInTheDocument(); | ||
const contenuErreurValidation = screen.getByText('Cette adresse mail est déjà utilisée', { selector: 'p' }); | ||
expect(contenuErreurValidation).toBeInTheDocument(); | ||
vi.useRealTimers(); | ||
}); | ||
|
||
it('quand je remplis le formulaire avec toutes les informations valides, alors je suis redirigé vers la page de candidature validée', async () => { | ||
// GIVEN | ||
vi.useFakeTimers(); | ||
vi.setSystemTime(new Date(2023, 11, 12, 13)); | ||
|
||
vi.stubGlobal('fetch', vi.fn( | ||
() => ({ status: 200, json: async () => Promise.resolve({}) })) | ||
); | ||
|
||
const mockNavigate = vi.fn().mockReturnValue(() => { }); | ||
vi.spyOn(ReactRouterDom, 'useNavigate').mockReturnValue(mockNavigate); | ||
|
||
render(<CandidatureCoordinateur />); | ||
const siret = screen.getByLabelText('SIRET / RIDET *'); | ||
fireEvent.change(siret, { target: { value: '1234567890123' } }); | ||
const denomination = screen.getByLabelText('Dénomination *'); | ||
fireEvent.change(denomination, { target: { value: 'Entreprise' } }); | ||
const adresse = screen.getByLabelText('Adresse *'); | ||
fireEvent.change(adresse, { target: { value: '75056 Paris' } }); | ||
const typeStructure = screen.getByRole('radio', { name: 'Une commune' }); | ||
fireEvent.click(typeStructure); | ||
const prenom = screen.getByLabelText('Prénom *'); | ||
fireEvent.change(prenom, { target: { value: 'Jean' } }); | ||
const nom = screen.getByLabelText('Nom *'); | ||
fireEvent.change(nom, { target: { value: 'Dupont' } }); | ||
const fonction = screen.getByLabelText('Fonction *'); | ||
fireEvent.change(fonction, { target: { value: 'Test' } }); | ||
const email = screen.getByLabelText('Adresse e-mail *'); | ||
fireEvent.change(email, { target: { value: '[email protected]' } }); | ||
const telephone = screen.getByLabelText('Téléphone *'); | ||
fireEvent.change(telephone, { target: { value: '+33123456789' } }); | ||
const identificationCandidat = screen.getByRole('radio', { name: 'Oui' }); | ||
fireEvent.click(identificationCandidat); | ||
const typeMission = screen.getByRole('radio', { name: 'Accompagnera également des publics' }); | ||
fireEvent.click(typeMission); | ||
const date = screen.getByLabelText('Choisir une date'); | ||
fireEvent.change(date, { target: { value: dateDujour() } }); | ||
const descriptionMotivation = screen.getByLabelText('Votre message *'); | ||
fireEvent.change(descriptionMotivation, { target: { value: 'je suis motivé !' } }); | ||
const confirmation = screen.getByRole('checkbox', { name: 'Je confirme avoir lu et pris connaissance des conditions d’engagement. *' }); | ||
fireEvent.click(confirmation); | ||
|
||
// WHEN | ||
const envoyer = screen.getByRole('button', { name: 'Envoyer votre candidature' }); | ||
|
||
// eslint-disable-next-line testing-library/no-unnecessary-act | ||
await act(() => { | ||
fireEvent.click(envoyer); | ||
}); | ||
|
||
// THEN | ||
expect(mockNavigate).toHaveBeenCalledWith('/candidature-validee'); | ||
|
||
vi.useRealTimers(); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,3 +70,7 @@ | |
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
html { | ||
scroll-behavior: smooth; | ||
} |
Oops, something went wrong.