Skip to content

Commit

Permalink
feat(mon-pix): better use of translations
Browse files Browse the repository at this point in the history
  • Loading branch information
lego-technix authored Oct 22, 2024
1 parent 5dbdef5 commit f76df29
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export default class PasswordResetDemandForm extends Component {

@tracked isLoading = false;
@tracked errorMessage;
@tracked emailInputPlaceholder = this.intl.t(
'components.authentication.password-reset-demand-form.fields.email.placeholder',
);
@tracked emailInputvalidationStatus;
@tracked emailInputvalidationErrorMessage;

Expand All @@ -27,7 +30,7 @@ export default class PasswordResetDemandForm extends Component {
this.email = event.target.value;
this.emailInputvalidationStatus = isEmailValid(this.email) ? 'success' : 'error';
this.emailInputvalidationErrorMessage = this.intl.t(
'components.authentication.password-reset-demand-form.invalid-email',
'components.authentication.password-reset-demand-form.fields.email.error-message-invalid',
);
}

Expand All @@ -53,7 +56,7 @@ export default class PasswordResetDemandForm extends Component {
body: JSON.stringify({ email }),
});
if (response.status == 404) {
this.errorMessage = this.intl.t('pages.password-reset-demand.error.message');
this.errorMessage = this.intl.t('components.authentication.password-reset-demand-form.404-message');
} else if (!response.ok) {
throw new Error(`Response status: ${response.status}`);
}
Expand Down Expand Up @@ -87,10 +90,10 @@ export default class PasswordResetDemandForm extends Component {
{{on "change" this.handleEmailChange}}
@validationStatus={{this.emailInputvalidationStatus}}
@errorMessage={{this.emailInputvalidationErrorMessage}}
placeholder="[email protected]"
placeholder={{this.emailInputPlaceholder}}
required={{true}}
>
<:label>{{t "pages.password-reset-demand.fields.email.label"}}</:label>
<:label>{{t "components.authentication.password-reset-demand-form.fields.email.label"}}</:label>
</PixInput>
</div>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module('Integration | Component | Authentication | password-reset-demand-form',
const screen = await render(<template><PasswordResetDemandForm /></template>);

// when
await fillByLabel(t('pages.password-reset-demand.fields.email.label'), validEmail);
await fillByLabel(t('components.authentication.password-reset-demand-form.fields.email.label'), validEmail);

// then
assert.dom(screen.queryByRole('alert')).doesNotExist();
Expand All @@ -44,11 +44,15 @@ module('Integration | Component | Authentication | password-reset-demand-form',
const screen = await render(<template><PasswordResetDemandForm /></template>);

// when
await fillByLabel(t('pages.password-reset-demand.fields.email.label'), invalidEmail);
await fillByLabel(t('components.authentication.password-reset-demand-form.fields.email.label'), invalidEmail);

// then
assert
.dom(screen.queryByText(t('components.authentication.password-reset-demand-form.invalid-email')))
.dom(
screen.queryByText(
t('components.authentication.password-reset-demand-form.fields.email.error-message-invalid'),
),
)
.exists();
});
});
Expand Down Expand Up @@ -76,7 +80,7 @@ module('Integration | Component | Authentication | password-reset-demand-form',
const screen = await render(<template><PasswordResetDemandForm /></template>);

// when
await fillByLabel(t('pages.password-reset-demand.fields.email.label'), email);
await fillByLabel(t('components.authentication.password-reset-demand-form.fields.email.label'), email);
await click(
screen.getByRole('button', {
name: t('components.authentication.password-reset-demand-form.actions.receive-reset-button'),
Expand Down Expand Up @@ -104,7 +108,7 @@ module('Integration | Component | Authentication | password-reset-demand-form',
const screen = await render(<template><PasswordResetDemandForm /></template>);

// when
await fillByLabel(t('pages.password-reset-demand.fields.email.label'), email);
await fillByLabel(t('components.authentication.password-reset-demand-form.fields.email.label'), email);
await click(
screen.getByRole('button', {
name: t('components.authentication.password-reset-demand-form.actions.receive-reset-button'),
Expand All @@ -114,7 +118,7 @@ module('Integration | Component | Authentication | password-reset-demand-form',
// then
// The following doesn’t work because of a PixUi span inside the role element
//assert.dom(screen.queryByRole('alert', { name: t('pages.password-reset-demand.error.message') })).exists();
assert.dom(screen.queryByText(t('pages.password-reset-demand.error.message'))).exists();
assert.dom(screen.queryByText(t('components.authentication.password-reset-demand-form.404-message'))).exists();
});
});

Expand All @@ -131,7 +135,7 @@ module('Integration | Component | Authentication | password-reset-demand-form',
const screen = await render(<template><PasswordResetDemandForm /></template>);

// when
await fillByLabel(t('pages.password-reset-demand.fields.email.label'), email);
await fillByLabel(t('components.authentication.password-reset-demand-form.fields.email.label'), email);
await click(
screen.getByRole('button', {
name: t('components.authentication.password-reset-demand-form.actions.receive-reset-button'),
Expand Down
9 changes: 8 additions & 1 deletion mon-pix/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,21 @@
"signup-heading": "Other ways to sign up"
},
"password-reset-demand-form": {
"404-message": "The email address entered does not match any Pix account",
"actions": {
"receive-reset-button": "Receive a reset link"
},
"contact-us-link": {
"link-text": "Contact us",
"link-url": "https://pix.org/en/support"
},
"invalid-email": "Your email address is invalid.",
"fields": {
"email": {
"error-message-invalid": "Your email address is invalid.",
"label": "Email address",
"placeholder": "ex: [email protected]"
}
},
"no-email-question": "No email address?",
"rule": "All fields are required."
},
Expand Down
9 changes: 8 additions & 1 deletion mon-pix/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,20 @@
}
},
"password-reset-demand-form": {
"invalid-email": "Your email address is invalid.",
"404-message": "Esta dirección de correo electrónico no corresponde a ninguna cuenta",
"rule": "All fields are required.",
"no-email-question": "No email address?",
"contact-us-link": {
"link-text": "Contact us",
"link-url": "https://pix.org/en/support"
},
"fields": {
"email": {
"invalid-email": "Your email address is invalid.",
"label": "Email address",
"placeholder": "ex: [email protected]"
}
},
"actions": {
"receive-reset-button": "Receive a reset link"
}
Expand Down
9 changes: 8 additions & 1 deletion mon-pix/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,21 @@
"signup-heading": "Autres moyens d’inscription"
},
"password-reset-demand-form": {
"404-message": "Cette adresse e-mail ne correspond à aucun compte",
"actions": {
"receive-reset-button": "Recevoir un lien de réinitialisation"
},
"contact-us-link": {
"link-text": "Contactez-nous",
"link-url": "https://pix.fr/support"
},
"invalid-email": "Votre adresse e-mail n’est pas valide.",
"fields": {
"email": {
"error-message-invalid": "Votre adresse e-mail n’est pas valide.",
"label": "Adresse e-mail",
"placeholder": "ex: [email protected]"
}
},
"no-email-question": "Pas d’adresse e-mail renseignée ?",
"rule": "Tous les champs sont obligatoires."
},
Expand Down
9 changes: 8 additions & 1 deletion mon-pix/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,20 @@
}
},
"password-reset-demand-form": {
"invalid-email": "Your email address is invalid.",
"404-message": "Dit e-mailadres komt niet overeen met een account",
"rule": "All fields are required.",
"no-email-question": "No email address?",
"contact-us-link": {
"link-text": "Contact us",
"link-url": "https://pix.org/nl-be/support"
},
"fields": {
"email": {
"error-message-invalid": "Your email address is invalid.",
"label": "Email address",
"placeholder": "ex: [email protected]"
}
},
"actions": {
"receive-reset-button": "Receive a reset link"
}
Expand Down

0 comments on commit f76df29

Please sign in to comment.