From f466137b7af765c84be04c16eda9c2594f64c2cb Mon Sep 17 00:00:00 2001 From: Thibault Reidy Date: Wed, 21 Aug 2024 14:49:43 +0200 Subject: [PATCH] fix(test): use correct magic link email input --- cypress/e2e/SignInPassword.cy.ts | 4 ---- cypress/e2e/util.ts | 8 ++------ cypress/support/commands.ts | 12 ++---------- src/components/MagicLinkForm.tsx | 7 +++++-- src/components/SignInPasswordForm.tsx | 2 +- src/config/selectors.ts | 2 +- 6 files changed, 11 insertions(+), 24 deletions(-) diff --git a/cypress/e2e/SignInPassword.cy.ts b/cypress/e2e/SignInPassword.cy.ts index bb9caa96..f2eb88aa 100644 --- a/cypress/e2e/SignInPassword.cy.ts +++ b/cypress/e2e/SignInPassword.cy.ts @@ -18,8 +18,6 @@ describe('Email and Password Validation', () => { const { WRONG_EMAIL, WRONG_PASSWORD, GRAASP } = MEMBERS; cy.visit(SIGN_IN_PATH); - // Select sign in method - cy.signInPasswordMethodAndCheck(); // Signing in with wrong email cy.signInPasswordAndCheck(WRONG_EMAIL); // Signing in with a valid email but empty password @@ -42,8 +40,6 @@ describe('Email and Password Validation', () => { const { WRONG_EMAIL, WRONG_PASSWORD, GRAASP } = MEMBERS; cy.visit(SIGN_IN_PATH); - // Select sign in method - cy.signInPasswordMethodAndCheck(); // Signing in with wrong email cy.signInPasswordAndCheck(WRONG_EMAIL); // Signing in with a valid email but empty password diff --git a/cypress/e2e/util.ts b/cypress/e2e/util.ts index dca4dd6c..de272c34 100644 --- a/cypress/e2e/util.ts +++ b/cypress/e2e/util.ts @@ -1,10 +1,10 @@ import { EMAIL_SIGN_IN_FIELD_ID, + EMAIL_SIGN_IN_MAGIC_LINK_FIELD_ID, EMAIL_SIGN_UP_FIELD_ID, NAME_SIGN_UP_FIELD_ID, PASSWORD_SIGN_IN_BUTTON_ID, PASSWORD_SIGN_IN_FIELD_ID, - PASSWORD_SIGN_IN_METHOD_BUTTON_ID, SIGN_IN_BUTTON_ID, SIGN_UP_BUTTON_ID, } from '../../src/config/selectors'; @@ -38,7 +38,7 @@ export const checkInvitationFields = ({ }; export const fillSignInLayout = ({ email }: { email?: string }) => { - cy.get(`#${EMAIL_SIGN_IN_FIELD_ID}`).clear().type(email); + cy.get(`#${EMAIL_SIGN_IN_MAGIC_LINK_FIELD_ID}`).clear().type(email); }; export const submitSignIn = () => { @@ -49,10 +49,6 @@ export const submitSignUp = () => { cy.get(`#${SIGN_UP_BUTTON_ID}`).click(); }; -export const passwordSignInMethod = () => { - cy.get(`#${PASSWORD_SIGN_IN_METHOD_BUTTON_ID}`).click(); -}; - export const fillPasswordSignInLayout = ({ email, password, diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index c080fc34..7b29ef83 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -11,17 +11,16 @@ import { Member } from '@graasp/sdk'; import { EMAIL_SIGN_IN_FIELD_ID, + EMAIL_SIGN_IN_MAGIC_LINK_FIELD_ID, EMAIL_SIGN_UP_FIELD_ID, NAME_SIGN_UP_FIELD_ID, PASSWORD_SIGN_IN_FIELD_ID, - PASSWORD_SIGN_IN_METHOD_BUTTON_ID, SIGN_UP_AGREEMENTS_CHECKBOX_ID, } from '../../src/config/selectors'; import { fillPasswordSignInLayout, fillSignInLayout, fillSignUpLayout, - passwordSignInMethod, submitPasswordSignIn, submitSignIn, submitSignUp, @@ -62,8 +61,6 @@ declare global { }, ): Chainable>; - signInPasswordMethodAndCheck(): Chainable>; - signInPasswordAndCheck( member: Member & { nameValid?: boolean; @@ -115,12 +112,7 @@ Cypress.Commands.add('signUpAndCheck', (user, acceptAllTerms) => { Cypress.Commands.add('signInAndCheck', (user) => { fillSignInLayout(user); submitSignIn(); - cy.checkErrorTextField(EMAIL_SIGN_IN_FIELD_ID, user.emailValid); -}); - -Cypress.Commands.add('signInPasswordMethodAndCheck', () => { - passwordSignInMethod(); - cy.get(`#${PASSWORD_SIGN_IN_METHOD_BUTTON_ID}`).should('be.disabled'); + cy.checkErrorTextField(EMAIL_SIGN_IN_MAGIC_LINK_FIELD_ID, user.emailValid); }); Cypress.Commands.add('signInPasswordAndCheck', (user) => { diff --git a/src/components/MagicLinkForm.tsx b/src/components/MagicLinkForm.tsx index 11352f42..3c5928c7 100644 --- a/src/components/MagicLinkForm.tsx +++ b/src/components/MagicLinkForm.tsx @@ -8,7 +8,10 @@ import { LoadingButton } from '@mui/lab'; import { useAuthTranslation } from '../config/i18n'; import { SIGN_IN_MAGIC_LINK_SUCCESS_PATH } from '../config/paths'; import { mutations } from '../config/queryClient'; -import { EMAIL_SIGN_IN_FIELD_ID, SIGN_IN_BUTTON_ID } from '../config/selectors'; +import { + EMAIL_SIGN_IN_MAGIC_LINK_FIELD_ID, + SIGN_IN_BUTTON_ID, +} from '../config/selectors'; import { useRecaptcha } from '../context/RecaptchaContext'; import { useMobileAppLogin } from '../hooks/mobile'; import { useRedirection } from '../hooks/searchParams'; @@ -87,7 +90,7 @@ const MagicLinkForm = () => { diff --git a/src/components/SignInPasswordForm.tsx b/src/components/SignInPasswordForm.tsx index e9c77b72..ab36c314 100644 --- a/src/components/SignInPasswordForm.tsx +++ b/src/components/SignInPasswordForm.tsx @@ -80,7 +80,7 @@ const SignInPasswordForm = () => { url: redirect.url, })); // successful redirect - if (result && result.resource) { + if (result?.resource) { window.location.href = result.resource; } } diff --git a/src/config/selectors.ts b/src/config/selectors.ts index 46c3a490..f473082c 100644 --- a/src/config/selectors.ts +++ b/src/config/selectors.ts @@ -1,5 +1,6 @@ export const NAME_SIGN_UP_FIELD_ID = 'nameSignUpFieldId'; export const EMAIL_SIGN_UP_FIELD_ID = 'emailSignUpFieldId'; +export const EMAIL_SIGN_IN_MAGIC_LINK_FIELD_ID = 'emailSignInMagicLinkFieldId'; export const EMAIL_SIGN_IN_FIELD_ID = 'emailSignInFieldId'; export const PASSWORD_SIGN_IN_FIELD_ID = 'passwordSignInFieldId'; export const PASSWORD_SIGN_IN_BUTTON_ID = 'passwordSignInButtonId'; @@ -10,7 +11,6 @@ export const SIGN_IN_HEADER_ID = 'signInHeaderId'; export const SIGN_UP_HEADER_ID = 'signUpHeaderId'; export const SIGN_UP_SAVE_ACTIONS_ID = 'signUpSaveActionsId'; export const EMAIL_SIGN_IN_METHOD_BUTTON_ID = 'emailSignInMethodButton'; -export const PASSWORD_SIGN_IN_METHOD_BUTTON_ID = 'passwordSignInMethodButton'; export const USER_SWITCH_ID = 'userSwitch'; export const SUCCESS_CONTENT_ID = 'successContent'; export const BACK_BUTTON_ID = 'backButtonId';