From 384e78823efe7698ef596bdaa4045d2f125d92dc Mon Sep 17 00:00:00 2001 From: wojteknowacki Date: Fri, 17 Nov 2023 14:33:08 +0100 Subject: [PATCH] user should be able to change password test --- package-lock.json | 46 +-- package.json | 2 +- playwright/data/e2eTestData.ts | 7 + playwright/pages/accountSettingsPage.ts | 36 ++ .../pages/dialogs/changePasswordDialog.ts | 30 ++ playwright/pages/loginPage.ts | 7 + playwright/pages/mainMenuPage.ts | 9 + playwright/tests/auth.setup.ts | 289 ++++++++-------- playwright/tests/staffMembers.spec.ts | 313 ++++++++++-------- .../StaffPasswordResetDialog.tsx | 2 + 10 files changed, 439 insertions(+), 302 deletions(-) create mode 100644 playwright/pages/accountSettingsPage.ts create mode 100644 playwright/pages/dialogs/changePasswordDialog.ts diff --git a/package-lock.json b/package-lock.json index 92bd6897a5a..418930176c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -119,7 +119,7 @@ "@graphql-codegen/typescript-apollo-client-helpers": "^2.1.10", "@graphql-codegen/typescript-operations": "^2.2.4", "@graphql-codegen/typescript-react-apollo": "^3.2.5", - "@playwright/test": "^1.38.1", + "@playwright/test": "^1.40.0", "@saleor/app-sdk": "0.43.0", "@sentry/cli": "^2.20.6", "@swc/jest": "^0.2.26", @@ -7316,12 +7316,12 @@ } }, "node_modules/@playwright/test": { - "version": "1.38.1", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.38.1.tgz", - "integrity": "sha512-NqRp8XMwj3AK+zKLbZShl0r/9wKgzqI/527bkptKXomtuo+dOjU9NdMASQ8DNC9z9zLOMbG53T4eihYr3XR+BQ==", + "version": "1.40.0", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.40.0.tgz", + "integrity": "sha512-PdW+kn4eV99iP5gxWNSDQCbhMaDVej+RXL5xr6t04nbKLCBwYtA046t7ofoczHOm8u6c+45hpDKQVZqtqwkeQg==", "dev": true, "dependencies": { - "playwright": "1.38.1" + "playwright": "1.40.0" }, "bin": { "playwright": "cli.js" @@ -36813,12 +36813,12 @@ } }, "node_modules/playwright": { - "version": "1.38.1", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.38.1.tgz", - "integrity": "sha512-oRMSJmZrOu1FP5iu3UrCx8JEFRIMxLDM0c/3o4bpzU5Tz97BypefWf7TuTNPWeCe279TPal5RtPPZ+9lW/Qkow==", + "version": "1.40.0", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.40.0.tgz", + "integrity": "sha512-gyHAgQjiDf1m34Xpwzaqb76KgfzYrhK7iih+2IzcOCoZWr/8ZqmdBw+t0RU85ZmfJMgtgAiNtBQ/KS2325INXw==", "dev": true, "dependencies": { - "playwright-core": "1.38.1" + "playwright-core": "1.40.0" }, "bin": { "playwright": "cli.js" @@ -36831,9 +36831,9 @@ } }, "node_modules/playwright-core": { - "version": "1.38.1", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.38.1.tgz", - "integrity": "sha512-tQqNFUKa3OfMf4b2jQ7aGLB8o9bS3bOY0yMEtldtC2+spf8QXG9zvXLTXUeRsoNuxEYMgLYR+NXfAa1rjKRcrg==", + "version": "1.40.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.40.0.tgz", + "integrity": "sha512-fvKewVJpGeca8t0ipM56jkVSU6Eo0RmFvQ/MaCQNDYm+sdvKkMBBWTE1FdeMqIdumRaXXjZChWHvIzCGM/tA/Q==", "dev": true, "bin": { "playwright-core": "cli.js" @@ -48952,12 +48952,12 @@ "optional": true }, "@playwright/test": { - "version": "1.38.1", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.38.1.tgz", - "integrity": "sha512-NqRp8XMwj3AK+zKLbZShl0r/9wKgzqI/527bkptKXomtuo+dOjU9NdMASQ8DNC9z9zLOMbG53T4eihYr3XR+BQ==", + "version": "1.40.0", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.40.0.tgz", + "integrity": "sha512-PdW+kn4eV99iP5gxWNSDQCbhMaDVej+RXL5xr6t04nbKLCBwYtA046t7ofoczHOm8u6c+45hpDKQVZqtqwkeQg==", "dev": true, "requires": { - "playwright": "1.38.1" + "playwright": "1.40.0" } }, "@radix-ui/number": { @@ -68756,13 +68756,13 @@ } }, "playwright": { - "version": "1.38.1", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.38.1.tgz", - "integrity": "sha512-oRMSJmZrOu1FP5iu3UrCx8JEFRIMxLDM0c/3o4bpzU5Tz97BypefWf7TuTNPWeCe279TPal5RtPPZ+9lW/Qkow==", + "version": "1.40.0", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.40.0.tgz", + "integrity": "sha512-gyHAgQjiDf1m34Xpwzaqb76KgfzYrhK7iih+2IzcOCoZWr/8ZqmdBw+t0RU85ZmfJMgtgAiNtBQ/KS2325INXw==", "dev": true, "requires": { "fsevents": "2.3.2", - "playwright-core": "1.38.1" + "playwright-core": "1.40.0" }, "dependencies": { "fsevents": { @@ -68775,9 +68775,9 @@ } }, "playwright-core": { - "version": "1.38.1", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.38.1.tgz", - "integrity": "sha512-tQqNFUKa3OfMf4b2jQ7aGLB8o9bS3bOY0yMEtldtC2+spf8QXG9zvXLTXUeRsoNuxEYMgLYR+NXfAa1rjKRcrg==", + "version": "1.40.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.40.0.tgz", + "integrity": "sha512-fvKewVJpGeca8t0ipM56jkVSU6Eo0RmFvQ/MaCQNDYm+sdvKkMBBWTE1FdeMqIdumRaXXjZChWHvIzCGM/tA/Q==", "dev": true }, "please-upgrade-node": { diff --git a/package.json b/package.json index 4770e9c313e..f2ffc211886 100644 --- a/package.json +++ b/package.json @@ -126,7 +126,7 @@ "@graphql-codegen/typescript-apollo-client-helpers": "^2.1.10", "@graphql-codegen/typescript-operations": "^2.2.4", "@graphql-codegen/typescript-react-apollo": "^3.2.5", - "@playwright/test": "^1.38.1", + "@playwright/test": "^1.40.0", "@saleor/app-sdk": "0.43.0", "@sentry/cli": "^2.20.6", "@swc/jest": "^0.2.26", diff --git a/playwright/data/e2eTestData.ts b/playwright/data/e2eTestData.ts index 1c8600cfcde..10f4202ed40 100644 --- a/playwright/data/e2eTestData.ts +++ b/playwright/data/e2eTestData.ts @@ -37,4 +37,11 @@ export const USERS = { name: "e2e", lastName: "user", }, + userForPasswordChange: { + email: "change-password-user@gmail.com", + newPassword: "4321test", + info: "User used in change password test", + name: "change password", + lastName: "user", + }, }; diff --git a/playwright/pages/accountSettingsPage.ts b/playwright/pages/accountSettingsPage.ts new file mode 100644 index 00000000000..b7311445733 --- /dev/null +++ b/playwright/pages/accountSettingsPage.ts @@ -0,0 +1,36 @@ +import type { Locator, Page } from "@playwright/test"; + +import { BasePage } from "./basePage"; +import { ChangePasswordDialog } from "./dialogs/changePasswordDialog"; + +export class AccountSettingsPage { + readonly page: Page; + readonly basePage: BasePage; + readonly changePasswordButton: Locator; + readonly saveButton: Locator; + readonly changePasswordDialog: ChangePasswordDialog; + + constructor(page: Page) { + this.page = page; + this.basePage = new BasePage(page); + this.changePasswordDialog = new ChangePasswordDialog(page); + this.changePasswordButton = page.getByTestId("changePasswordBtn"); + this.saveButton = page.getByTestId("button-bar-confirm"); + } + + async clickChangePasswordButton() { + await this.changePasswordButton.click(); + } + + async typeOldAndNewPasswords(oldPassword: string, newPassword: string) { + await this.changePasswordDialog.typeOldPassword(oldPassword); + await this.changePasswordDialog.typeNewPassword(newPassword); + } + + async clickSaveChangedPasswordButton() { + await this.changePasswordDialog.clickSaveButton(); + } + async clickSaveButton() { + await this.saveButton.click(); + } +} diff --git a/playwright/pages/dialogs/changePasswordDialog.ts b/playwright/pages/dialogs/changePasswordDialog.ts new file mode 100644 index 00000000000..697e359a6e5 --- /dev/null +++ b/playwright/pages/dialogs/changePasswordDialog.ts @@ -0,0 +1,30 @@ +import type { Locator, Page } from "@playwright/test"; + +export class ChangePasswordDialog { + readonly page: Page; + readonly newPasswordInput: Locator; + readonly oldPasswordInput: Locator; + readonly saveButton: Locator; + + constructor(page: Page) { + this.page = page; + this.saveButton = page.getByTestId("submit"); + this.newPasswordInput = page + .getByTestId("new-password-input") + .locator("input"); + this.oldPasswordInput = page + .getByTestId("old-password-input") + .locator("input"); + } + + async clickSaveButton() { + await this.saveButton.click(); + } + + async typeNewPassword(newPassword: string) { + await this.newPasswordInput.fill(newPassword); + } + async typeOldPassword(oldPassword: string) { + await this.oldPasswordInput.fill(oldPassword); + } +} diff --git a/playwright/pages/loginPage.ts b/playwright/pages/loginPage.ts index 449a213b033..8392bc8d3a5 100644 --- a/playwright/pages/loginPage.ts +++ b/playwright/pages/loginPage.ts @@ -45,6 +45,13 @@ export class LoginPage { // End of authentication steps. await page.context().storageState({ path }); } + async basicUiLogin(userEmail: string, userPassword: string) { + await this.goto(); + await this.typeEmail(userEmail); + await this.typePassword(userPassword); + await this.clickSignInButton(); + await expect(this.homePage.welcomeMessage).toContainText("Hello there,"); + } async typeEmail(email: string) { await this.emailInput.fill(email); } diff --git a/playwright/pages/mainMenuPage.ts b/playwright/pages/mainMenuPage.ts index 7b090517ba5..061537c7fbf 100644 --- a/playwright/pages/mainMenuPage.ts +++ b/playwright/pages/mainMenuPage.ts @@ -22,9 +22,13 @@ export class MainMenuPage { readonly menuItem: Locator; readonly drafts: Locator; readonly collections: Locator; + readonly accountSettings: Locator; + readonly userMenu: Locator; constructor(page: Page) { this.page = page; + this.userMenu = page.getByTestId("userMenu"); + this.accountSettings = page.getByTestId("account-settings-button"); this.catalog = page.getByTestId("menu-item-label-catalogue"); this.content = page.getByTestId("menu-item-label-pages"); this.categories = page.getByTestId("menu-item-label-categories"); @@ -45,6 +49,11 @@ export class MainMenuPage { this.menuItem = page.locator("[data-test-id*='menu-item-label-']"); } + async gotoAccountSettings() { + await this.userMenu.click(); + await this.accountSettings.click(); + } + async openDiscounts() { await this.discounts.click(); } diff --git a/playwright/tests/auth.setup.ts b/playwright/tests/auth.setup.ts index ab629708210..141bf12b3a1 100644 --- a/playwright/tests/auth.setup.ts +++ b/playwright/tests/auth.setup.ts @@ -1,3 +1,4 @@ +import { USER_PERMISSION } from "@data/userPermissions"; import { LoginPage } from "@pages/loginPage"; import { test as setup } from "@playwright/test"; @@ -20,15 +21,15 @@ const customerWebhooksPermissionsFile = "playwright/.auth/customer.json"; const unauthenticatedUserPermissionsFile = "playwright/.auth/unauthenticated-user.json"; -// setup("authenticate as admin", async ({ page }) => { -// const loginPage = await new LoginPage(page); -// await loginPage.loginAndSetStorageState( -// process.env.CYPRESS_USER_NAME!, -// process.env.CYPRESS_USER_PASSWORD!, -// page, -// adminFile, -// ); -// }); +setup("authenticate as admin", async ({ page }) => { + const loginPage = await new LoginPage(page); + await loginPage.loginAndSetStorageState( + process.env.CYPRESS_USER_NAME!, + process.env.CYPRESS_USER_PASSWORD!, + page, + adminFile, + ); +}); setup("unauthenticated user ", async ({ page }) => { const loginPage = await new LoginPage(page); await loginPage.goto(); @@ -38,139 +39,139 @@ setup("unauthenticated user ", async ({ page }) => { .context() .storageState({ path: unauthenticatedUserPermissionsFile }); }); -// setup("authenticate as user with discount permissions", async ({ page }) => { -// const loginPage = new LoginPage(page); -// await loginPage.loginAndSetStorageState( -// USER_PERMISSION.discount, -// process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, -// page, -// discountPermissionsFile, -// ); -// }); +setup("authenticate as user with discount permissions", async ({ page }) => { + const loginPage = new LoginPage(page); + await loginPage.loginAndSetStorageState( + USER_PERMISSION.discount, + process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, + page, + discountPermissionsFile, + ); +}); -// setup("authenticate as user with orders permissions", async ({ page }) => { -// const loginPage = new LoginPage(page); -// await loginPage.loginAndSetStorageState( -// USER_PERMISSION.order, -// process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, -// page, -// ordersPermissionsFile, -// ); -// }); -// setup("authenticate as user with apps permissions", async ({ page }) => { -// const loginPage = new LoginPage(page); -// await loginPage.loginAndSetStorageState( -// USER_PERMISSION.app, -// process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, -// page, -// appsPermissionsFile, -// ); -// }); -// setup("authenticate as user with channels permissions", async ({ page }) => { -// const loginPage = new LoginPage(page); -// await loginPage.loginAndSetStorageState( -// USER_PERMISSION.channel, -// process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, -// page, -// channelsWebhooksPermissionsFile, -// ); -// }); -// setup("authenticate as user with customer permissions", async ({ page }) => { -// const loginPage = new LoginPage(page); -// await loginPage.loginAndSetStorageState( -// USER_PERMISSION.customer, -// process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, -// page, -// customerWebhooksPermissionsFile, -// ); -// }); -// setup("authenticate as user with gift cards permissions", async ({ page }) => { -// const loginPage = new LoginPage(page); -// await loginPage.loginAndSetStorageState( -// USER_PERMISSION.giftCard, -// process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, -// page, -// giftCardsPermissionsFile, -// ); -// }); -// setup( -// "authenticate as user with content aka page permissions", -// async ({ page }) => { -// const loginPage = new LoginPage(page); -// await loginPage.loginAndSetStorageState( -// USER_PERMISSION.page, -// process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, -// page, -// contentPermissionsFile, -// ); -// }, -// ); -// setup("authenticate as user with plugins permissions", async ({ page }) => { -// const loginPage = new LoginPage(page); -// await loginPage.loginAndSetStorageState( -// USER_PERMISSION.plugin, -// process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, -// page, -// pluginPermissionsFile, -// ); -// }); -// setup( -// "authenticate as user with product type permissions", -// async ({ page }) => { -// const loginPage = new LoginPage(page); -// await loginPage.loginAndSetStorageState( -// USER_PERMISSION.productTypeAndAttribute, -// process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, -// page, -// productTypePermissionsFile, -// ); -// }, -// ); -// setup("authenticate as user with settings permissions", async ({ page }) => { -// const loginPage = new LoginPage(page); -// await loginPage.loginAndSetStorageState( -// USER_PERMISSION.settings, -// process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, -// page, -// settingsPermissionsFile, -// ); -// }); -// setup( -// "authenticate as user with staff member permissions", -// async ({ page }) => { -// const loginPage = new LoginPage(page); -// await loginPage.loginAndSetStorageState( -// USER_PERMISSION.staff, -// process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, -// page, -// staffMemberPermissionsFile, -// ); -// }, -// ); -// setup("authenticate as user with shipping permissions", async ({ page }) => { -// const loginPage = new LoginPage(page); -// await loginPage.loginAndSetStorageState( -// USER_PERMISSION.shipping, -// process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, -// page, -// shippingPermissionsFile, -// ); -// }); -// setup("authenticate as user with translation permissions", async ({ page }) => { -// const loginPage = new LoginPage(page); -// await loginPage.loginAndSetStorageState( -// USER_PERMISSION.translations, -// process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, -// page, -// translationPermissionsFile, -// ); -// }); -// setup("authenticate as user with product permissions", async ({ page }) => { -// const loginPage = new LoginPage(page); -// await loginPage.loginAndSetStorageState( -// USER_PERMISSION.product, -// process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, -// page, -// productPermissionsFile, -// ); -// }); +setup("authenticate as user with orders permissions", async ({ page }) => { + const loginPage = new LoginPage(page); + await loginPage.loginAndSetStorageState( + USER_PERMISSION.order, + process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, + page, + ordersPermissionsFile, + ); +}); +setup("authenticate as user with apps permissions", async ({ page }) => { + const loginPage = new LoginPage(page); + await loginPage.loginAndSetStorageState( + USER_PERMISSION.app, + process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, + page, + appsPermissionsFile, + ); +}); +setup("authenticate as user with channels permissions", async ({ page }) => { + const loginPage = new LoginPage(page); + await loginPage.loginAndSetStorageState( + USER_PERMISSION.channel, + process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, + page, + channelsWebhooksPermissionsFile, + ); +}); +setup("authenticate as user with customer permissions", async ({ page }) => { + const loginPage = new LoginPage(page); + await loginPage.loginAndSetStorageState( + USER_PERMISSION.customer, + process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, + page, + customerWebhooksPermissionsFile, + ); +}); +setup("authenticate as user with gift cards permissions", async ({ page }) => { + const loginPage = new LoginPage(page); + await loginPage.loginAndSetStorageState( + USER_PERMISSION.giftCard, + process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, + page, + giftCardsPermissionsFile, + ); +}); +setup( + "authenticate as user with content aka page permissions", + async ({ page }) => { + const loginPage = new LoginPage(page); + await loginPage.loginAndSetStorageState( + USER_PERMISSION.page, + process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, + page, + contentPermissionsFile, + ); + }, +); +setup("authenticate as user with plugins permissions", async ({ page }) => { + const loginPage = new LoginPage(page); + await loginPage.loginAndSetStorageState( + USER_PERMISSION.plugin, + process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, + page, + pluginPermissionsFile, + ); +}); +setup( + "authenticate as user with product type permissions", + async ({ page }) => { + const loginPage = new LoginPage(page); + await loginPage.loginAndSetStorageState( + USER_PERMISSION.productTypeAndAttribute, + process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, + page, + productTypePermissionsFile, + ); + }, +); +setup("authenticate as user with settings permissions", async ({ page }) => { + const loginPage = new LoginPage(page); + await loginPage.loginAndSetStorageState( + USER_PERMISSION.settings, + process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, + page, + settingsPermissionsFile, + ); +}); +setup( + "authenticate as user with staff member permissions", + async ({ page }) => { + const loginPage = new LoginPage(page); + await loginPage.loginAndSetStorageState( + USER_PERMISSION.staff, + process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, + page, + staffMemberPermissionsFile, + ); + }, +); +setup("authenticate as user with shipping permissions", async ({ page }) => { + const loginPage = new LoginPage(page); + await loginPage.loginAndSetStorageState( + USER_PERMISSION.shipping, + process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, + page, + shippingPermissionsFile, + ); +}); +setup("authenticate as user with translation permissions", async ({ page }) => { + const loginPage = new LoginPage(page); + await loginPage.loginAndSetStorageState( + USER_PERMISSION.translations, + process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, + page, + translationPermissionsFile, + ); +}); +setup("authenticate as user with product permissions", async ({ page }) => { + const loginPage = new LoginPage(page); + await loginPage.loginAndSetStorageState( + USER_PERMISSION.product, + process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD!, + page, + productPermissionsFile, + ); +}); diff --git a/playwright/tests/staffMembers.spec.ts b/playwright/tests/staffMembers.spec.ts index c94c62f75e4..11ec4d59d4e 100644 --- a/playwright/tests/staffMembers.spec.ts +++ b/playwright/tests/staffMembers.spec.ts @@ -1,149 +1,194 @@ import { BasicApiService } from "@api/basics"; import { USERS } from "@data/e2eTestData"; import { URL_LIST } from "@data/url"; +import { AccountSettingsPage } from "@pages/accountSettingsPage"; import { ConfigurationPage } from "@pages/configurationPage"; import { HomePage } from "@pages/homePage"; import { LoginPage } from "@pages/loginPage"; +import { MainMenuPage } from "@pages/mainMenuPage"; import { SetUpNewPasswordPage } from "@pages/setUpNewPasswordPage"; import { StaffMembersPage } from "@pages/staffMembersPage"; import { expect, test } from "@playwright/test"; -test.use({ storageState: "playwright/.auth/admin.json" }); - -test("TC: SALEOR_36 User should be able to invite staff member with full access permissions @basic-regression @staff-members", async ({ - page, - request, -}) => { - const configurationPage = new ConfigurationPage(page); - const staffMembersPage = new StaffMembersPage(page, request); - const userEmail = `francesca${await staffMembersPage.basePage.getRandomInt( - 1000000, - )}@gmail.com`; - - await page.goto(URL_LIST.configuration); - await configurationPage.openStaffMembers(); - - await staffMembersPage.clickInviteStaffMemberButton(); - await staffMembersPage.inviteStaffMembersDialog.typeNameLastNameAndEmail( - "Francesca", - "Leek", - userEmail, - ); - await staffMembersPage.inviteStaffMembersDialog.clickSendInviteButton(); - - await staffMembersPage.clickPermissionsGroupSelectButton(); - await staffMembersPage.assignUserToPermissionGroup("Full Access"); - await staffMembersPage.clickSaveButton(); - await staffMembersPage.basePage.expectSuccessBanner(); - expect(await staffMembersPage.assignedPermissionGroups.count()).toEqual(1); - expect(staffMembersPage.assignedPermissionGroups).toContainText( - "Full Access", - ); - - const singleUserEmails = - await staffMembersPage.mailpitService.getEmailsForUser(userEmail); - - await expect(singleUserEmails[0].Subject).toContain( - "Set Your Dashboard Password", - ); +test.describe("Authenticated admin users", () => { + test.use({ storageState: "playwright/.auth/admin.json" }); + + test("TC: SALEOR_36 User should be able to invite staff member with full access permissions @basic-regression @staff-members", async ({ + page, + request, + }) => { + const configurationPage = new ConfigurationPage(page); + const staffMembersPage = new StaffMembersPage(page, request); + const userEmail = `francesca${await staffMembersPage.basePage.getRandomInt( + 1000000, + )}@gmail.com`; + + await page.goto(URL_LIST.configuration); + await configurationPage.openStaffMembers(); + + await staffMembersPage.clickInviteStaffMemberButton(); + await staffMembersPage.inviteStaffMembersDialog.typeNameLastNameAndEmail( + "Francesca", + "Leek", + userEmail, + ); + await staffMembersPage.inviteStaffMembersDialog.clickSendInviteButton(); + + await staffMembersPage.clickPermissionsGroupSelectButton(); + await staffMembersPage.assignUserToPermissionGroup("Full Access"); + await staffMembersPage.clickSaveButton(); + await staffMembersPage.basePage.expectSuccessBanner(); + expect(await staffMembersPage.assignedPermissionGroups.count()).toEqual(1); + expect(staffMembersPage.assignedPermissionGroups).toContainText( + "Full Access", + ); + + const singleUserEmails = + await staffMembersPage.mailpitService.getEmailsForUser(userEmail); + + await expect(singleUserEmails[0].Subject).toContain( + "Set Your Dashboard Password", + ); + }); + + test("TC: SALEOR_37 Admin User should be able to deactivate other user @basic-regression @staff-members", async ({ + page, + request, + }) => { + const staffMembersPage = new StaffMembersPage(page, request); + const basicApiService = new BasicApiService(request); + + await page.goto(URL_LIST.staffMembers + USERS.userToBeDeactivated.id); + await staffMembersPage.clickIsActiveCheckbox(); + await staffMembersPage.clickSaveButton(); + await staffMembersPage.basePage.expectSuccessBanner(); + await expect(await staffMembersPage.isActiveCheckbox.isChecked()).toEqual( + false, + ); + + const loginViaApiDeactivatedUserResponse = + await basicApiService.logInUserViaApi({ + email: USERS.userToBeDeactivated.email, + password: process.env.E2E_PERMISSIONS_USERS_PASSWORD!, + }); + await expect( + loginViaApiDeactivatedUserResponse.data.tokenCreate.errors[0].code, + ).toEqual("INACTIVE"); + }); + + test("TC: SALEOR_38 Admin User should be able to activate other user @basic-regression @staff-members", async ({ + page, + request, + }) => { + const staffMembersPage = new StaffMembersPage(page, request); + const basicApiService = new BasicApiService(request); + + await page.goto(URL_LIST.staffMembers + USERS.userToBeActivated.id); + await staffMembersPage.clickIsActiveCheckbox(); + await staffMembersPage.clickSaveButton(); + await staffMembersPage.basePage.expectSuccessBanner(); + await expect(await staffMembersPage.isActiveCheckbox.isChecked()).toEqual( + true, + ); + + const loginViaApiDeactivatedUserResponse = + await basicApiService.logInUserViaApi({ + email: USERS.userToBeActivated.email, + password: process.env.E2E_PERMISSIONS_USERS_PASSWORD!, + }); + await expect( + loginViaApiDeactivatedUserResponse.data.tokenCreate.errors, + ).toEqual([]); + await expect( + loginViaApiDeactivatedUserResponse.data.tokenCreate.token, + ).not.toEqual(null); + }); }); -test("TC: SALEOR_37 Admin User should be able to deactivate other user @basic-regression @staff-members", async ({ - page, - request, -}) => { - const staffMembersPage = new StaffMembersPage(page, request); - const basicApiService = new BasicApiService(request); - - await page.goto(URL_LIST.staffMembers + USERS.userToBeDeactivated.id); - await staffMembersPage.clickIsActiveCheckbox(); - await staffMembersPage.clickSaveButton(); - await staffMembersPage.basePage.expectSuccessBanner(); - await expect(await staffMembersPage.isActiveCheckbox.isChecked()).toEqual( - false, - ); - - const loginViaApiDeactivatedUserResponse = - await basicApiService.logInUserViaApi({ - email: USERS.userToBeDeactivated.email, - password: process.env.E2E_PERMISSIONS_USERS_PASSWORD!, - }); - await expect( - loginViaApiDeactivatedUserResponse.data.tokenCreate.errors[0].code, - ).toEqual("INACTIVE"); +test.describe("Unauthenticated admin users", () => { + test.use({ storageState: "playwright/.auth/unauthenticated-user.json" }); + + test("TC: SALEOR_39 User should be able to reset password @daily @staff-members", async ({ + page, + request, + }) => { + const loginPage = new LoginPage(page); + const homePage = new HomePage(page); + const setUpNewPasswordPage = new SetUpNewPasswordPage(page, request); + const basicApiService = new BasicApiService(request); + + await page.goto("/"); + await loginPage.clickResetPasswordLink(); + await loginPage.typeEmail(USERS.userForPasswordReset.email); + await loginPage.clickSendEmailWithResetLinkButton(); + await loginPage.clickBackToLoginPageButton(); + await loginPage.emailInput.waitFor({ state: "visible" }); + await setUpNewPasswordPage.gotoUserResetPasswordPage( + USERS.userForPasswordReset.email, + ); + await setUpNewPasswordPage.typePassword( + USERS.userForPasswordReset.newPassword, + ); + await setUpNewPasswordPage.typeConfirmedPassword( + USERS.userForPasswordReset.newPassword, + ); + await setUpNewPasswordPage.clickSetNewPasswordButton(); + await expect(homePage.welcomeMessage).toBeVisible({ timeout: 10000 }); + await expect(homePage.welcomeMessage).toContainText( + `${USERS.userForPasswordReset.name} ${USERS.userForPasswordReset.lastName}`, + ); + + const userWithNewPasswordLoginResponse = + await basicApiService.logInUserViaApi({ + email: USERS.userForPasswordReset.email, + password: USERS.userForPasswordReset.newPassword, + }); + await expect( + userWithNewPasswordLoginResponse.data.tokenCreate.errors, + ).toEqual([]); + await expect( + userWithNewPasswordLoginResponse.data.tokenCreate.token, + ).not.toEqual(null); + }); }); -test("TC: SALEOR_38 Admin User should be able to activate other user @basic-regression @staff-members", async ({ - page, - request, -}) => { - const staffMembersPage = new StaffMembersPage(page, request); - const basicApiService = new BasicApiService(request); - - await page.goto(URL_LIST.staffMembers + USERS.userToBeActivated.id); - await staffMembersPage.clickIsActiveCheckbox(); - await staffMembersPage.clickSaveButton(); - await staffMembersPage.basePage.expectSuccessBanner(); - await expect(await staffMembersPage.isActiveCheckbox.isChecked()).toEqual( - true, - ); - - const loginViaApiDeactivatedUserResponse = - await basicApiService.logInUserViaApi({ - email: USERS.userToBeActivated.email, - password: process.env.E2E_PERMISSIONS_USERS_PASSWORD!, - }); - await expect( - loginViaApiDeactivatedUserResponse.data.tokenCreate.errors, - ).toEqual([]); - await expect( - loginViaApiDeactivatedUserResponse.data.tokenCreate.token, - ).not.toEqual(null); -}); - -test.use({ storageState: "playwright/.auth/unauthenticated-user.json" }); - -test("TC: SALEOR_39 User should be able to reset password @basic-regression @staff-members", async ({ - page, - request, -}) => { - const loginPage = new LoginPage(page); - const homePage = new HomePage(page); - const setUpNewPasswordPage = new SetUpNewPasswordPage(page, request); - const basicApiService = new BasicApiService(request); - - await page.goto("/"); - await loginPage.clickResetPasswordLink(); - await loginPage.typeEmail(USERS.userForPasswordReset.email); - await loginPage.clickSendEmailWithResetLinkButton(); - await loginPage.clickBackToLoginPageButton(); - await loginPage.emailInput.waitFor({ state: "visible" }); - - await setUpNewPasswordPage.gotoUserResetPasswordPage( - USERS.userForPasswordReset.email, - ); - - await setUpNewPasswordPage.typePassword( - USERS.userForPasswordReset.newPassword, - ); - await setUpNewPasswordPage.typeConfirmedPassword( - USERS.userForPasswordReset.newPassword, - ); - await setUpNewPasswordPage.clickSetNewPasswordButton(); - await expect(homePage.welcomeMessage).toBeVisible({ timeout: 10000 }); - await expect(homePage.welcomeMessage).toContainText( - `${USERS.userForPasswordReset.name} ${USERS.userForPasswordReset.lastName}`, - ); - - const userWithNewPasswordLoginResponse = - await basicApiService.logInUserViaApi({ - email: USERS.userForPasswordReset.email, - password: USERS.userForPasswordReset.newPassword, - }); - await expect( - userWithNewPasswordLoginResponse.data.tokenCreate.errors, - ).toEqual([]); - await expect( - userWithNewPasswordLoginResponse.data.tokenCreate.token, - ).not.toEqual(null); +test.describe("Admin which log in via UI", () => { + // Reset storage state for this file to avoid being authenticated + test.use({ storageState: { cookies: [], origins: [] } }); + + test("TC: SALEOR_40 User should be able to change password @daily @staff-members", async ({ + page, + request, + }) => { + const loginPage = new LoginPage(page); + const mainMenuPage = new MainMenuPage(page); + const accountSettingsPage = new AccountSettingsPage(page); + const basicApiService = new BasicApiService(request); + + await loginPage.basicUiLogin( + USERS.userForPasswordChange.email, + process.env.E2E_PERMISSIONS_USERS_PASSWORD!, + ); + await mainMenuPage.gotoAccountSettings(); + await accountSettingsPage.clickChangePasswordButton(); + await accountSettingsPage.typeOldAndNewPasswords( + process.env.E2E_PERMISSIONS_USERS_PASSWORD!, + USERS.userForPasswordChange.newPassword, + ); + await accountSettingsPage.clickSaveChangedPasswordButton(); + await accountSettingsPage.clickSaveButton(); + await accountSettingsPage.basePage.expectSuccessBanner(); + + const userWithNewPasswordLoginResponse = + await basicApiService.logInUserViaApi({ + email: USERS.userForPasswordChange.email, + password: USERS.userForPasswordChange.newPassword, + }); + await expect( + userWithNewPasswordLoginResponse.data.tokenCreate.errors, + ).toEqual([]); + await expect( + userWithNewPasswordLoginResponse.data.tokenCreate.token, + ).not.toEqual(null); + }); }); diff --git a/src/staff/components/StaffPasswordResetDialog/StaffPasswordResetDialog.tsx b/src/staff/components/StaffPasswordResetDialog/StaffPasswordResetDialog.tsx index 9c5c8a7a42f..dd09eab1052 100644 --- a/src/staff/components/StaffPasswordResetDialog/StaffPasswordResetDialog.tsx +++ b/src/staff/components/StaffPasswordResetDialog/StaffPasswordResetDialog.tsx @@ -79,6 +79,7 @@ const StaffPasswordResetDialog: React.FC = ({ description: "input label", })} name="oldPassword" + data-test-id="old-password-input" type="password" onChange={change} inputProps={{ @@ -103,6 +104,7 @@ const StaffPasswordResetDialog: React.FC = ({ description: "input label", })} name="newPassword" + data-test-id="new-password-input" type="password" onChange={change} inputProps={{