From b396c8e9a50e9aff77fff3f9bf7afb92752be887 Mon Sep 17 00:00:00 2001 From: wojteknowacki <124166231+wojteknowacki@users.noreply.github.com> Date: Tue, 23 May 2023 09:51:36 +0200 Subject: [PATCH] fixes staff members tests (#3678) * fixes staff members tests * removing 'only' from suite --- cypress/e2e/staffMembers.js | 87 ++++++++++--------- cypress/elements/index.js | 2 + cypress/elements/shared/sharedElements.js | 1 + .../elements/staffMembers/staffMembersList.js | 1 + cypress/fixtures/index.js | 2 +- cypress/fixtures/messages.js | 1 + cypress/support/api/requests/index.js | 5 ++ cypress/support/api/utils/index.js | 5 ++ cypress/support/pages/index.js | 12 +++ src/staff/components/StaffList/StaffList.tsx | 4 +- 10 files changed, 79 insertions(+), 41 deletions(-) diff --git a/cypress/e2e/staffMembers.js b/cypress/e2e/staffMembers.js index 2678894ec..d8cd35041 100644 --- a/cypress/e2e/staffMembers.js +++ b/cypress/e2e/staffMembers.js @@ -3,33 +3,36 @@ import faker from "faker"; -import { LEFT_MENU_SELECTORS } from "../elements/account/left-menu/left-menu-selectors"; -import { LOGIN_SELECTORS } from "../elements/account/login-selectors"; -import { BUTTON_SELECTORS } from "../elements/shared/button-selectors"; -import { SHARED_ELEMENTS } from "../elements/shared/sharedElements"; -import { INVITE_STAFF_MEMBER_FORM_SELECTORS } from "../elements/staffMembers/inviteStaffMemberForm"; -import { STAFF_MEMBER_DETAILS_SELECTORS } from "../elements/staffMembers/staffMemberDetails"; -import { STAFF_MEMBERS_LIST_SELECTORS } from "../elements/staffMembers/staffMembersList"; -import { urlList, userDetailsUrl } from "../fixtures/urlList"; -import { TEST_ADMIN_USER } from "../fixtures/users"; -import { activatePlugin, updatePlugin } from "../support/api/requests/Plugins"; import { + BUTTON_SELECTORS, + HOMEPAGE_SELECTORS, + INVITE_STAFF_MEMBER_FORM_SELECTORS, + SHARED_ELEMENTS, + STAFF_MEMBER_DETAILS_SELECTORS, + STAFF_MEMBERS_LIST_SELECTORS, +} from "../elements/"; +import { LOGIN_SELECTORS } from "../elements/account/login-selectors"; +import { MESSAGES, TEST_ADMIN_USER, urlList } from "../fixtures"; +import { userDetailsUrl } from "../fixtures/urlList"; +import { + activatePlugin, deleteStaffMembersStartsWith, + updatePlugin, updateStaffMember, -} from "../support/api/requests/StaffMembers"; +} from "../support/api/requests/"; import { getMailActivationLinkForUser, getMailActivationLinkForUserAndSubject, inviteStaffMemberWithFirstPermission, -} from "../support/api/utils/users"; -import { expectWelcomeMessageIncludes } from "../support/pages/homePage"; -import { getDisplayedSelectors } from "../support/pages/permissionsPage"; +} from "../support/api/utils/"; import { + expectMainMenuAvailableSections, + expectWelcomeMessageIncludes, fillUpOnlyUserDetails, fillUpSetPassword, fillUpUserDetailsAndAddFirstPermission, updateUserActiveFlag, -} from "../support/pages/userPage"; +} from "../support/pages/"; describe("Staff members", () => { const startsWith = "StaffMembers"; @@ -43,7 +46,6 @@ describe("Staff members", () => { cy.clearSessionData().loginUserViaRequest(); deleteStaffMembersStartsWith(startsWith); activatePlugin({ id: "mirumee.notifications.admin_email" }); - inviteStaffMemberWithFirstPermission({ email }) .then(({ user: userResp }) => { user = userResp; @@ -63,7 +65,7 @@ describe("Staff members", () => { it( "should be able to invite staff user. TC: SALEOR_3501", - { tags: ["@staffMembers", "@allEnv"] }, + { tags: ["@staffMembers", "@allEnv", "@critical"] }, () => { const firstName = faker.name.firstName(); const emailInvite = `${startsWith}${firstName}@example.com`; @@ -102,7 +104,7 @@ describe("Staff members", () => { it( "should activate user. TC: SALEOR_3503", - { tags: ["@staffMembers", "@allEnv"] }, + { tags: ["@staffMembers", "@allEnv", "@critical"] }, () => { const serverStoredEmail = email.toLowerCase(); @@ -133,18 +135,15 @@ describe("Staff members", () => { .loginUserViaRequest("auth", { email, password }) .visit(urlList.homePage); expectWelcomeMessageIncludes(serverStoredEmail); - getDisplayedSelectors().then(displayedSelectors => { - expect(Object.values(displayedSelectors)).to.have.length(1); - expect(Object.values(displayedSelectors)[0]).to.eq( - LEFT_MENU_SELECTORS.home, - ); - }); + expectMainMenuAvailableSections(1); + cy.get(HOMEPAGE_SELECTORS.activity).should("not.exist"); + cy.get(HOMEPAGE_SELECTORS.topProducts).should("not.exist"); }, ); it( "should reset password. TC: SALEOR_3505", - { tags: ["@staffMembers", "@allEnv"] }, + { tags: ["@staffMembers", "@allEnv", "@critical"] }, () => { const newPassword = faker.random.alphaNumeric(8); updatePlugin( @@ -180,7 +179,7 @@ describe("Staff members", () => { it( "should not be able to create staff member with not unique email. TC: SALEOR_3508", - { tags: ["@staffMembers", "@allEnv"] }, + { tags: ["@staffMembers", "@allEnv", "@critical"] }, () => { const firstName = faker.name.firstName(); const emailInvite = TEST_ADMIN_USER.email; @@ -201,18 +200,14 @@ describe("Staff members", () => { "should not be able to update staff member with not unique email. TC: SALEOR_3509", { tags: ["@staffMembers", "@allEnv"] }, () => { + cy.addAliasToGraphRequest("StaffList"); cy.visit(urlList.staffMembers) - .expectSkeletonIsVisible() + .waitForRequestAndCheckIfNoErrors("@StaffList") .get(SHARED_ELEMENTS.searchInput) - .type(`${email} {enter}`); - cy.waitForProgressBarToNotExist(); - cy.get(STAFF_MEMBERS_LIST_SELECTORS.staffAvatar) - .first() - .should("be.visible"); - cy.waitForProgressBarToNotExist() - .get(STAFF_MEMBERS_LIST_SELECTORS.staffStatusText) - .first() - .should("be.visible") + .type(`${email} {enter}`) + .waitForRequestAndCheckIfNoErrors("@StaffList"); + cy.get(STAFF_MEMBERS_LIST_SELECTORS.usersEmails) + .should("contain.text", email.toLowerCase()) .click(); cy.get(STAFF_MEMBER_DETAILS_SELECTORS.staffEmail) .click() @@ -221,6 +216,7 @@ describe("Staff members", () => { .get(BUTTON_SELECTORS.confirm) .click() .confirmationErrorMessageShouldAppear(); + cy.contains(MESSAGES.invalidEmailAddress).should("be.visible"); }, ); @@ -276,7 +272,7 @@ describe("Staff members", () => { it( "should create new user and successfully change password. TC: SALEOR_3510", - { tags: ["@staffMembers", "@allEnv"] }, + { tags: ["@staffMembers", "@allEnv", "@critical"] }, () => { const newPass = "newTestPass"; const newLastName = faker.name.lastName(); @@ -300,6 +296,11 @@ describe("Staff members", () => { cy.visit(urlList.staffMembers).get(LOGIN_SELECTORS.userMenu).click(); cy.get(LOGIN_SELECTORS.accountSettings).click(); + cy.get(STAFF_MEMBER_DETAILS_SELECTORS.changePasswordBtn).should( + "be.visible", + ); + // there is small bug which keep control panel opens and block any interaction via cypress - it does not affect real user - click on body can be removed when this pr is done https://github.com/saleor/saleor-dashboard/issues/3675 + cy.get(SHARED_ELEMENTS.body).click({ force: true }); cy.get(STAFF_MEMBER_DETAILS_SELECTORS.changePasswordBtn).click(); cy.get( STAFF_MEMBER_DETAILS_SELECTORS.changePasswordModal.oldPassword, @@ -307,13 +308,21 @@ describe("Staff members", () => { cy.get( STAFF_MEMBER_DETAILS_SELECTORS.changePasswordModal.newPassword, ).type(newPass); - cy.get(BUTTON_SELECTORS.submit).click().confirmationMessageShouldAppear(); + cy.addAliasToGraphRequest("ChangeUserPassword") + .get(BUTTON_SELECTORS.submit) + .click() + .confirmationMessageShouldAppear() + .waitForRequestAndCheckIfNoErrors("@ChangeUserPassword"); cy.clearSessionData().loginUserViaRequest("auth", { email: newEmail, password: newPass, }); - cy.visit(urlList.staffMembers).expectSkeletonIsVisible(); + cy.visit(urlList.homePage) + .get(HOMEPAGE_SELECTORS.welcomeMessage) + .should("be.visible"); + cy.get(HOMEPAGE_SELECTORS.activity).should("be.visible"); + cy.get(HOMEPAGE_SELECTORS.topProducts).should("be.visible"); }, ); }); diff --git a/cypress/elements/index.js b/cypress/elements/index.js index bbaf68080..fb50ddae0 100644 --- a/cypress/elements/index.js +++ b/cypress/elements/index.js @@ -18,6 +18,8 @@ export { CUSTOMER_DETAILS_SELECTORS, CUSTOMERS_LIST_SELECTORS, } from "./customer/"; +export { MENU as LEFT_MENU_SELECTORS } from "./account/left-menu/left-menu-selectors"; + export { SALES_SELECTORS, VOUCHERS_SELECTORS } from "./discounts"; export { HOMEPAGE_SELECTORS } from "./homePage/homePage-selectors"; export { PAGINATION } from "./navigation"; diff --git a/cypress/elements/shared/sharedElements.js b/cypress/elements/shared/sharedElements.js index d9068c2ef..302ce1e0f 100644 --- a/cypress/elements/shared/sharedElements.js +++ b/cypress/elements/shared/sharedElements.js @@ -1,4 +1,5 @@ export const SHARED_ELEMENTS = { + body: "body", header: "[data-test-id='page-header']", progressBar: '[role="progressbar"]', circularProgress: '[class*="CircularProgress-circle"]', diff --git a/cypress/elements/staffMembers/staffMembersList.js b/cypress/elements/staffMembers/staffMembersList.js index 800766d45..c9eff9ab5 100644 --- a/cypress/elements/staffMembers/staffMembersList.js +++ b/cypress/elements/staffMembers/staffMembersList.js @@ -2,4 +2,5 @@ export const STAFF_MEMBERS_LIST_SELECTORS = { inviteStaffMemberButton: '[data-test-id="invite-staff-member"]', staffStatusText: '[data-test-id="staffStatusText"]', staffAvatar: '[data-test-id="staffAvatar"]', + usersEmails: '[data-test-id="user-mail"]', }; diff --git a/cypress/fixtures/index.js b/cypress/fixtures/index.js index 140bc893d..1b918768b 100644 --- a/cypress/fixtures/index.js +++ b/cypress/fixtures/index.js @@ -1,5 +1,5 @@ export { bodyMockHomePage } from "./bodyMocks"; export { orderDraftCreateDemoResponse } from "./errors/demo/orderDratCreate"; export { urlList } from "./urlList"; -export { ONE_PERMISSION_USERS } from "./users"; +export { ONE_PERMISSION_USERS, TEST_ADMIN_USER } from "./users"; export { MESSAGES } from "./messages"; diff --git a/cypress/fixtures/messages.js b/cypress/fixtures/messages.js index 1019c85f9..2bc3b3f0f 100644 --- a/cypress/fixtures/messages.js +++ b/cypress/fixtures/messages.js @@ -1,4 +1,5 @@ export const MESSAGES = { noProductFound: "No products found", confirmProductsDeletion: "Are you sure you want to delete 2 products?", + invalidEmailAddress: "Enter a valid email address.", }; diff --git a/cypress/support/api/requests/index.js b/cypress/support/api/requests/index.js index 87a73a2df..8ebde3ad9 100644 --- a/cypress/support/api/requests/index.js +++ b/cypress/support/api/requests/index.js @@ -3,3 +3,8 @@ export { createCustomer, deleteCustomersStartsWith } from "./Customer"; export { createDraftOrder, getOrder } from "./Order"; export { updateMetadata, updatePrivateMetadata } from "./Metadata"; export { getProductMetadata } from "./storeFront/ProductDetails"; +export { activatePlugin, updatePlugin } from "./Plugins"; +export { + deleteStaffMembersStartsWith, + updateStaffMember, +} from "./StaffMembers"; diff --git a/cypress/support/api/utils/index.js b/cypress/support/api/utils/index.js index 35e62e456..6f1e3e458 100644 --- a/cypress/support/api/utils/index.js +++ b/cypress/support/api/utils/index.js @@ -6,3 +6,8 @@ export { updateTaxConfigurationForChannel, } from "./taxesUtils"; export * as productsUtils from "./products/productsUtils"; +export { + getMailActivationLinkForUser, + getMailActivationLinkForUserAndSubject, + inviteStaffMemberWithFirstPermission, +} from "./users"; diff --git a/cypress/support/pages/index.js b/cypress/support/pages/index.js index ca27ae561..7e43f34e2 100644 --- a/cypress/support/pages/index.js +++ b/cypress/support/pages/index.js @@ -1,2 +1,14 @@ export * as ordersOperationsHelpers from "./ordersOperations"; export * as transactionsOrderUtils from "./ordersTransactionUtils"; +export { expectWelcomeMessageIncludes } from "./homePage"; +export { getDisplayedSelectors } from "./permissionsPage"; +export { + fillUpOnlyUserDetails, + fillUpSetPassword, + fillUpUserDetailsAndAddFirstPermission, + updateUserActiveFlag, +} from "./userPage"; +export { + expectMainMenuAvailableSections, + expectMainMenuSectionsToBeVisible, +} from "./mainMenuPage"; diff --git a/src/staff/components/StaffList/StaffList.tsx b/src/staff/components/StaffList/StaffList.tsx index 8449ef695..3e85daf02 100644 --- a/src/staff/components/StaffList/StaffList.tsx +++ b/src/staff/components/StaffList/StaffList.tsx @@ -143,7 +143,9 @@ const StaffList: React.FC = props => { - {staffMember?.email} + + {staffMember?.email} + ),