Skip to content

Commit

Permalink
add force auth tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ashrivastava-qa committed Jun 29, 2023
1 parent 3603292 commit 7415718
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/functional-tests/pages/forceAuth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions packages/functional-tests/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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),
Expand Down
5 changes: 5 additions & 0 deletions packages/functional-tests/pages/resetPassword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
Expand Down
71 changes: 71 additions & 0 deletions packages/functional-tests/tests/misc/forceAuth.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 7415718

Please sign in to comment.