-
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.
Gestion des erreurs sur les inputs (#249)
* Ajout d'erreur sur les inputs * test état d'erreur * Ajout des erreurs sur le formulaire structure * Ajout d'erreur pour le formulaire coordinateur --------- Co-authored-by: ornella <[email protected]>
- Loading branch information
1 parent
31b6f96
commit 57f7e43
Showing
21 changed files
with
381 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const checkValidity = (ref, setErrors) => { | ||
const formData = new FormData(ref.current); | ||
const keys = Array.from(formData.keys()); | ||
const formElements = keys.map(key => document.getElementById(key)).filter(key => key !== null); | ||
const errors = formElements.map(formElement => ({ | ||
[formElement.id]: formElement.validationMessage, | ||
})); | ||
setErrors(Object.assign({}, ...errors)); | ||
}; |
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 |
---|---|---|
|
@@ -725,7 +725,7 @@ describe('candidature conseiller', () => { | |
vi.useRealTimers(); | ||
}); | ||
|
||
it('quand je remplis le formulaire et que je saisi mon lieu d’habitation alors la recherche est lancer à partir de 3 caractères', async () => { | ||
it('quand je remplis le formulaire et que je saisis mon lieu d’habitation alors la recherche est lancée à partir de 3 caractères', async () => { | ||
// GIVEN | ||
vi.useFakeTimers(); | ||
const searchByNameSpy = vi.fn(); | ||
|
@@ -753,4 +753,59 @@ describe('candidature conseiller', () => { | |
|
||
vi.useRealTimers(); | ||
}); | ||
|
||
it.each([ | ||
{ | ||
description: 'un prénom', | ||
selector: 'Prénom *', | ||
message: 'Veuillez renseigner le prénom' | ||
}, | ||
{ | ||
description: 'un nom', | ||
selector: 'Nom *', | ||
message: 'Veuillez renseigner le nom' | ||
}, | ||
{ | ||
description: 'un email', | ||
selector: 'Adresse électronique * Format attendu : [email protected]', | ||
message: 'Veuillez renseigner le mail' | ||
}, | ||
{ | ||
description: 'une adresse', | ||
selector: 'Votre lieu d’habitation * Saississez le nom ou le code postal de votre commune.', | ||
message: 'Veuillez renseigner l’adresse' | ||
}, | ||
{ | ||
description: 'une date', | ||
selector: 'Choisir une date', | ||
message: 'Veuillez renseigner la date' | ||
}, | ||
{ | ||
description: 'une motivation', | ||
selector: 'Votre message * Limité à 2500 caractères', | ||
message: 'Veuillez renseigner la motivation' | ||
}, | ||
])('quand je valide le formulaire avec $description vide alors j’ai un message d’erreur ', async ({ selector, message }) => { | ||
// GIVEN | ||
vi.stubGlobal('turnstile', { | ||
reset: vi.fn(), | ||
remove: vi.fn(), | ||
render: vi.fn() | ||
}); | ||
render(<CandidatureConseiller />); | ||
const champDeFormulaire = screen.getByLabelText(selector); | ||
Object.defineProperty(champDeFormulaire, 'validationMessage', { | ||
value: message, | ||
configurable: true, | ||
}); | ||
|
||
// WHEN | ||
const envoyer = screen.getByRole('button', { name: 'Envoyer votre candidature' }); | ||
|
||
fireEvent.click(envoyer); | ||
|
||
// THEN | ||
const contenuErreurValidation = await screen.findByText(message, { selector: 'p' }); | ||
expect(contenuErreurValidation).toBeInTheDocument(); | ||
}); | ||
}); |
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,26 +1,30 @@ | ||
import React from 'react'; | ||
import Input from '../../components/commun/Input'; | ||
import AddressChooser from './AddressChooser'; | ||
import PropTypes from 'prop-types'; | ||
|
||
export default function InformationsDeContact() { | ||
export default function InformationsDeContact({ errors }) { | ||
return ( | ||
<fieldset className="fr-border cc-section fr-p-3w fr-mb-3w" id="informations-de-contact"> | ||
<legend className="fr-h5">Vos informations de contact</legend> | ||
<hr /> | ||
<Input | ||
id="prenom" | ||
error={errors.prenom} | ||
> | ||
Prénom <span className="cc-obligatoire">*</span> | ||
</Input> | ||
<Input | ||
id="nom" | ||
error={errors.nom} | ||
> | ||
Nom <span className="cc-obligatoire">*</span> | ||
</Input> | ||
<Input | ||
id="email" | ||
type="email" | ||
pattern=".+@.+\..{2,}" | ||
error={errors.email} | ||
> | ||
Adresse électronique <span className="cc-obligatoire">*</span> <span className="fr-hint-text">Format attendu : [email protected]</span> | ||
</Input> | ||
|
@@ -29,10 +33,15 @@ export default function InformationsDeContact() { | |
type="tel" | ||
pattern="([+][0-9]{11,12})|([0-9]{10})" | ||
isRequired={false} | ||
error={errors.telephone} | ||
> | ||
Téléphone <span className="fr-hint-text">Format attendu : 0122334455 ou +33122334455</span> | ||
</Input> | ||
<AddressChooser /> | ||
<AddressChooser error={errors.lieuHabitation} /> | ||
</fieldset> | ||
); | ||
} | ||
|
||
InformationsDeContact.propTypes = { | ||
errors: PropTypes.object | ||
}; |
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,17 +1,22 @@ | ||
import React from 'react'; | ||
import ZoneDeTexte from '../../components/commun/ZoneDeTexte'; | ||
import PropTypes from 'prop-types'; | ||
|
||
export default function Motivation() { | ||
export default function Motivation({ errors }) { | ||
return ( | ||
<fieldset className="fr-border cc-section fr-p-3w fr-mb-3w" id="votre-motivation"> | ||
<legend className="fr-h5" id="titreMotivation">Votre motivation</legend> | ||
<p className="fr-text--sm fr-hint-text"> | ||
En quelques lignes, décrivez votre motivation personnelle pour devenir conseiller numérique et{' '} | ||
aider les personnes à devenir autonomes dans l’utilisation des outils numériques. | ||
</p> | ||
<ZoneDeTexte id="motivation"> | ||
<ZoneDeTexte id="motivation" error={errors.motivation}> | ||
Votre message <span className="cc-obligatoire">*</span> <span className="fr-hint-text">Limité à 2500 caractères</span> | ||
</ZoneDeTexte> | ||
</fieldset> | ||
); | ||
} | ||
|
||
Motivation.propTypes = { | ||
errors: PropTypes.object | ||
}; |
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
Oops, something went wrong.