diff --git a/packages/functional-tests/pages/forceAuth/index.ts b/packages/functional-tests/pages/forceAuth/index.ts index 3eaf8a9419e..6610e69c9b8 100644 --- a/packages/functional-tests/pages/forceAuth/index.ts +++ b/packages/functional-tests/pages/forceAuth/index.ts @@ -6,7 +6,7 @@ import { BaseLayout } from '../layout'; import uaStrings from '../../lib/ua-strings'; import { Credentials } from '../../lib/targets/base'; -export abstract class ForceAuthPage extends BaseLayout { +export class ForceAuthPage extends BaseLayout { readonly path = 'force_auth'; context; service; diff --git a/packages/functional-tests/pages/index.ts b/packages/functional-tests/pages/index.ts index c8ab3ac67b8..bdd381a4400 100644 --- a/packages/functional-tests/pages/index.ts +++ b/packages/functional-tests/pages/index.ts @@ -7,6 +7,7 @@ import { DeleteAccountPage } from './settings/deleteAccount'; import { DisplayNamePage } from './settings/displayName'; import { FourOhFourPage } from './fourOhFour'; import { FxDesktopV3ForceAuthPage } from './forceAuth/fxDesktopV3'; +import { ForceAuthPage } from './forceAuth'; import { LoginPage } from './login'; import { RecoveryKeyPage } from './settings/recoveryKey'; import { RelierPage } from './relier'; @@ -31,6 +32,7 @@ export function create(page: Page, target: BaseTarget) { displayName: new DisplayNamePage(page, target), fourOhFour: new FourOhFourPage(page, target), fxDesktopV3ForceAuth: new FxDesktopV3ForceAuthPage(page, target), + forceAuth: new ForceAuthPage(page, target), login: new LoginPage(page, target), page, recoveryKey: new RecoveryKeyPage(page, target), diff --git a/packages/functional-tests/pages/resetPassword.ts b/packages/functional-tests/pages/resetPassword.ts index 516ed302b0f..c3095fa731e 100644 --- a/packages/functional-tests/pages/resetPassword.ts +++ b/packages/functional-tests/pages/resetPassword.ts @@ -9,6 +9,7 @@ export const selectors = { VPASSWORD: '#vpassword', PASSWORD: '#password', RESEND_RESET_PASSWORD_LINK: '#resend', + REMEMBER_PASSWORD: 'text="Remember password? Sign in"', RESEND_SUCCESS: '.success', UNKNOWN_ACCOUNT_ERROR: '.error', RESET_PASSWORD_COMPLETE_HEADER: '#fxa-reset-password-complete-header', @@ -70,6 +71,10 @@ export class ResetPasswordPage extends BaseLayout { await this.page.locator(selectors.RESEND_RESET_PASSWORD_LINK).click(); } + async clickRememberPassword() { + await this.page.locator(selectors.REMEMBER_PASSWORD).click(); + } + async resendSuccessMessage() { await this.page.locator(selectors.RESEND_SUCCESS).waitFor(); return this.page.innerText(selectors.RESEND_SUCCESS); diff --git a/packages/functional-tests/tests/misc/forceAuth.spec.ts b/packages/functional-tests/tests/misc/forceAuth.spec.ts new file mode 100644 index 00000000000..9850d52d2d7 --- /dev/null +++ b/packages/functional-tests/tests/misc/forceAuth.spec.ts @@ -0,0 +1,71 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import { test, expect } from '../../lib/fixtures/standard'; + +test.describe('force auth', () => { + test('with a registered email, registered uid', async ({ + credentials, + pages: { login, forceAuth }, + }) => { + await forceAuth.open(credentials); + await login.setPassword(credentials.password); + await login.submit(); + expect(await login.loginHeader()).toBe(true); + }); + + test('forgot password flow via force_auth', async ({ + credentials, + pages: { login, resetPassword, forceAuth }, + }) => { + await forceAuth.open(credentials); + await login.clickForgotPassword(); + + // Verify reset password header + expect(await resetPassword.resetPasswordHeader()).toBe(true); + + //Verify email is prefilled + expect(await login.getPrefilledEmail()).toContain(credentials.email); + + //Click 'Remember password? Sign in', redirected to force auth page + await resetPassword.clickRememberPassword(); + expect(await login.getPrefilledEmail()).toContain(credentials.email); + + //Click forgot password again + await login.clickForgotPassword(); + await resetPassword.clickBeginReset(); + + //Verify confirm reset password header + expect(await resetPassword.confirmResetPasswordHeader()).toBe(true); + + //Click 'Remember password? Sign in', redirected to force auth page + await resetPassword.clickRememberPassword(); + expect(await login.getPrefilledEmail()).toContain(credentials.email); + }); + + test('form prefill information is cleared after sign in->sign out', async ({ + credentials, + pages: { login, forceAuth, settings }, + }) => { + await forceAuth.open(credentials); + await login.setPassword(credentials.password); + await login.submit(); + expect(await login.loginHeader()).toBe(true); + + //Sign out + await settings.signOut(); + + //Verify user need to enter email + expect(await login.isEmailHeader()).toBe(true); + await login.setEmail(credentials.email); + await login.submit(); + + //Verify password is empty and user need to enter password + expect(await login.isPasswordHeader()).toBe(true); + expect(await login.getPasswordInput()).toContain(''); + await login.setPassword(credentials.password); + await login.submit(); + expect(await login.loginHeader()).toBe(true); + }); +});