From 5537ca889cc33388d6abac0755c0dd4c483b3cc4 Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Tue, 29 Oct 2024 17:33:51 +0100 Subject: [PATCH] feat(mon-pix): handle errors service in PasswordResetDemandForm component --- .../password-reset-demand-form.gjs | 5 ++++- .../password-reset-demand-form-test.gjs | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/mon-pix/app/components/authentication/password-reset-demand/password-reset-demand-form.gjs b/mon-pix/app/components/authentication/password-reset-demand/password-reset-demand-form.gjs index 098ff4a51d6..2d543f49e92 100644 --- a/mon-pix/app/components/authentication/password-reset-demand/password-reset-demand-form.gjs +++ b/mon-pix/app/components/authentication/password-reset-demand/password-reset-demand-form.gjs @@ -4,6 +4,7 @@ import PixInput from '@1024pix/pix-ui/components/pix-input'; import PixMessage from '@1024pix/pix-ui/components/pix-message'; import { on } from '@ember/modifier'; import { action } from '@ember/object'; +import { service } from '@ember/service'; import Component from '@glimmer/component'; import { tracked } from '@glimmer/tracking'; import { t } from 'ember-intl'; @@ -14,8 +15,10 @@ import isEmailValid from '../../../utils/email-validator.js'; import PasswordResetDemandReceivedInfo from './password-reset-demand-received-info'; export default class PasswordResetDemandForm extends Component { + @service errors; + + @tracked globalError = this.errors.hasErrors && this.errors.shift(); @tracked isLoading = false; - @tracked globalError; @tracked isPasswordResetDemandReceived = false; validation = new FormValidation({ diff --git a/mon-pix/tests/integration/components/authentication/password-reset-demand/password-reset-demand-form-test.gjs b/mon-pix/tests/integration/components/authentication/password-reset-demand/password-reset-demand-form-test.gjs index 87548117b15..aedba90906e 100644 --- a/mon-pix/tests/integration/components/authentication/password-reset-demand/password-reset-demand-form-test.gjs +++ b/mon-pix/tests/integration/components/authentication/password-reset-demand/password-reset-demand-form-test.gjs @@ -178,6 +178,21 @@ module('Integration | Component | Authentication | PasswordResetDemand | passwor assert.dom(screen.queryByText(t('common.api-error-messages.internal-server-error'))).exists(); }); }); + + module('when there is an error in errors service', function () { + test('it displays the error on the corresponding banner', async function (assert) { + // given + const errorKeyMessageToBeDisplayed = 'pages.reset-password.error.expired-demand'; + const errorsService = this.owner.lookup('service:errors'); + + // when + errorsService.push(errorKeyMessageToBeDisplayed); + const screen = await render(); + + // then + assert.dom(screen.getByRole('alert', { value: t(errorKeyMessageToBeDisplayed) })).exists(); + }); + }); }); });