Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(functional): rewrite sync v3 settings test #15455

Merged
merged 2 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/functional-tests/lib/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export enum FirefoxCommand {
FxAStatus = 'fxaccounts:fxa_status',
OAuthLogin = 'fxaccounts:oauth_login',
Logout = 'fxaccounts:logout',
Login = 'fxaccounts:login',
LinkAccount = 'fxaccounts:can_link_account',
ChangePassword = 'fxaccounts:change_password',
}

export function createCustomEventDetail(
Expand Down
4 changes: 4 additions & 0 deletions packages/functional-tests/pages/settings/changePassword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export class ChangePasswordPage extends SettingsLayout {
return this.page.locator('[data-testid=cancel-password-button]').click();
}

async changePasswordSuccess() {
return this.page.innerText('[data-testid=alert-bar-content]');
}

submit() {
return Promise.all([
this.page.locator('button[type=submit]').click(),
Expand Down
130 changes: 130 additions & 0 deletions packages/functional-tests/tests/syncV3/settings.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/* 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, newPagesForSync } from '../../lib/fixtures/standard';
import { FirefoxCommand, createCustomEventDetail } from '../../lib/channels';

const firstPassword = 'password';
const secondPassword = 'new_password';
let email;
let syncBrowserPages;

test.describe.configure({ mode: 'parallel' });

test.describe('Firefox Desktop Sync v3 settings', () => {
test.beforeEach(async ({ target }) => {
test.slow();
syncBrowserPages = await newPagesForSync(target);
const { login, connectAnotherDevice, page } = syncBrowserPages;
email = login.createEmail('sync{id}');
await target.auth.signUp(email, firstPassword, {
lang: 'en',
preVerified: 'true',
});
const customEventDetail = createCustomEventDetail(
FirefoxCommand.LinkAccount,
{
ok: true,
}
);
await page.goto(
`${target.contentServerUrl}?context=fx_desktop_v3&service=sync&action=email`
);
await login.respondToWebChannelMessage(customEventDetail);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

await login.fillOutEmailFirstSignIn(email, firstPassword);
expect(await login.isSignInCodeHeader()).toBe(true);
await login.checkWebChannelMessage(FirefoxCommand.LinkAccount);
await login.fillOutSignInCode(email);
await login.checkWebChannelMessage(FirefoxCommand.Login);
expect(await connectAnotherDevice.fxaConnected.isEnabled()).toBeTruthy();
});

test.afterEach(async ({ target }, test) => {
await syncBrowserPages.browser?.close();
if (email) {
// Cleanup any accounts created during the test
try {
await target.auth.accountDestroy(email, secondPassword);
} catch (e) {
// Handle the error here
console.error('An error occurred during account cleanup:', e);
// Optionally, rethrow the error to propagate it further
throw e;
}
}
});

test('sign in, change the password', async ({ target }) => {
const { changePassword, settings, page } = syncBrowserPages;

//Goto settings sync url
await page.goto(
`${target.contentServerUrl}/settings?context=fx_desktop_v3&service=sync`
);

//Change password
await settings.password.clickChange();
await changePassword.fillOutChangePassword(firstPassword, secondPassword);
await changePassword.submit();

//Verify success message
expect(await changePassword.changePasswordSuccess()).toContain(
'Password updated'
);
});

test('sign in, change the password by browsing directly to settings', async ({
target,
}) => {
const { login, changePassword, settings } = syncBrowserPages;

//Goto settings non-sync url
await settings.goto();

//Change password
await settings.password.clickChange();
await login.noSuchWebChannelMessage(FirefoxCommand.ChangePassword);
await changePassword.fillOutChangePassword(firstPassword, secondPassword);
await changePassword.submit();

//Verify success message
expect(await changePassword.changePasswordSuccess()).toContain(
'Password updated'
);
});
});

test.describe('Firefox Desktop Sync v3 settings - delete account', () => {
test('sign in, delete the account', async ({ target }) => {
syncBrowserPages = await newPagesForSync(target);
const { login, settings, deleteAccount, page } = syncBrowserPages;
test.slow();
email = login.createEmail('sync{id}');
await target.auth.signUp(email, firstPassword, {
lang: 'en',
preVerified: 'true',
});
await page.goto(
`${target.contentServerUrl}?context=fx_desktop_v3&service=sync&action=email`
);
await login.fillOutEmailFirstSignIn(email, firstPassword);
await login.fillOutSignInCode(email);

//Go to setting page
await page.goto(
`${target.contentServerUrl}/settings?context=fx_desktop_v3&service=sync`
);
//Click Delete account
await settings.clickDeleteAccount();
await deleteAccount.checkAllBoxes();
await deleteAccount.clickContinue();

//Enter password
await deleteAccount.setPassword(firstPassword);
await deleteAccount.submit();

const success = await page.waitForSelector('.success');
expect(await success.isVisible()).toBeTruthy();
});
});