fixes staff members tests (#3678)

* fixes staff members tests

* removing 'only' from suite
This commit is contained in:
wojteknowacki 2023-05-23 09:51:36 +02:00 committed by GitHub
parent 30ee7c1ff9
commit b396c8e9a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 79 additions and 41 deletions

View file

@ -3,33 +3,36 @@
import faker from "faker"; 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 { 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, deleteStaffMembersStartsWith,
updatePlugin,
updateStaffMember, updateStaffMember,
} from "../support/api/requests/StaffMembers"; } from "../support/api/requests/";
import { import {
getMailActivationLinkForUser, getMailActivationLinkForUser,
getMailActivationLinkForUserAndSubject, getMailActivationLinkForUserAndSubject,
inviteStaffMemberWithFirstPermission, inviteStaffMemberWithFirstPermission,
} from "../support/api/utils/users"; } from "../support/api/utils/";
import { expectWelcomeMessageIncludes } from "../support/pages/homePage";
import { getDisplayedSelectors } from "../support/pages/permissionsPage";
import { import {
expectMainMenuAvailableSections,
expectWelcomeMessageIncludes,
fillUpOnlyUserDetails, fillUpOnlyUserDetails,
fillUpSetPassword, fillUpSetPassword,
fillUpUserDetailsAndAddFirstPermission, fillUpUserDetailsAndAddFirstPermission,
updateUserActiveFlag, updateUserActiveFlag,
} from "../support/pages/userPage"; } from "../support/pages/";
describe("Staff members", () => { describe("Staff members", () => {
const startsWith = "StaffMembers"; const startsWith = "StaffMembers";
@ -43,7 +46,6 @@ describe("Staff members", () => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
deleteStaffMembersStartsWith(startsWith); deleteStaffMembersStartsWith(startsWith);
activatePlugin({ id: "mirumee.notifications.admin_email" }); activatePlugin({ id: "mirumee.notifications.admin_email" });
inviteStaffMemberWithFirstPermission({ email }) inviteStaffMemberWithFirstPermission({ email })
.then(({ user: userResp }) => { .then(({ user: userResp }) => {
user = userResp; user = userResp;
@ -63,7 +65,7 @@ describe("Staff members", () => {
it( it(
"should be able to invite staff user. TC: SALEOR_3501", "should be able to invite staff user. TC: SALEOR_3501",
{ tags: ["@staffMembers", "@allEnv"] }, { tags: ["@staffMembers", "@allEnv", "@critical"] },
() => { () => {
const firstName = faker.name.firstName(); const firstName = faker.name.firstName();
const emailInvite = `${startsWith}${firstName}@example.com`; const emailInvite = `${startsWith}${firstName}@example.com`;
@ -102,7 +104,7 @@ describe("Staff members", () => {
it( it(
"should activate user. TC: SALEOR_3503", "should activate user. TC: SALEOR_3503",
{ tags: ["@staffMembers", "@allEnv"] }, { tags: ["@staffMembers", "@allEnv", "@critical"] },
() => { () => {
const serverStoredEmail = email.toLowerCase(); const serverStoredEmail = email.toLowerCase();
@ -133,18 +135,15 @@ describe("Staff members", () => {
.loginUserViaRequest("auth", { email, password }) .loginUserViaRequest("auth", { email, password })
.visit(urlList.homePage); .visit(urlList.homePage);
expectWelcomeMessageIncludes(serverStoredEmail); expectWelcomeMessageIncludes(serverStoredEmail);
getDisplayedSelectors().then(displayedSelectors => { expectMainMenuAvailableSections(1);
expect(Object.values(displayedSelectors)).to.have.length(1); cy.get(HOMEPAGE_SELECTORS.activity).should("not.exist");
expect(Object.values(displayedSelectors)[0]).to.eq( cy.get(HOMEPAGE_SELECTORS.topProducts).should("not.exist");
LEFT_MENU_SELECTORS.home,
);
});
}, },
); );
it( it(
"should reset password. TC: SALEOR_3505", "should reset password. TC: SALEOR_3505",
{ tags: ["@staffMembers", "@allEnv"] }, { tags: ["@staffMembers", "@allEnv", "@critical"] },
() => { () => {
const newPassword = faker.random.alphaNumeric(8); const newPassword = faker.random.alphaNumeric(8);
updatePlugin( updatePlugin(
@ -180,7 +179,7 @@ describe("Staff members", () => {
it( it(
"should not be able to create staff member with not unique email. TC: SALEOR_3508", "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 firstName = faker.name.firstName();
const emailInvite = TEST_ADMIN_USER.email; 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", "should not be able to update staff member with not unique email. TC: SALEOR_3509",
{ tags: ["@staffMembers", "@allEnv"] }, { tags: ["@staffMembers", "@allEnv"] },
() => { () => {
cy.addAliasToGraphRequest("StaffList");
cy.visit(urlList.staffMembers) cy.visit(urlList.staffMembers)
.expectSkeletonIsVisible() .waitForRequestAndCheckIfNoErrors("@StaffList")
.get(SHARED_ELEMENTS.searchInput) .get(SHARED_ELEMENTS.searchInput)
.type(`${email} {enter}`); .type(`${email} {enter}`)
cy.waitForProgressBarToNotExist(); .waitForRequestAndCheckIfNoErrors("@StaffList");
cy.get(STAFF_MEMBERS_LIST_SELECTORS.staffAvatar) cy.get(STAFF_MEMBERS_LIST_SELECTORS.usersEmails)
.first() .should("contain.text", email.toLowerCase())
.should("be.visible");
cy.waitForProgressBarToNotExist()
.get(STAFF_MEMBERS_LIST_SELECTORS.staffStatusText)
.first()
.should("be.visible")
.click(); .click();
cy.get(STAFF_MEMBER_DETAILS_SELECTORS.staffEmail) cy.get(STAFF_MEMBER_DETAILS_SELECTORS.staffEmail)
.click() .click()
@ -221,6 +216,7 @@ describe("Staff members", () => {
.get(BUTTON_SELECTORS.confirm) .get(BUTTON_SELECTORS.confirm)
.click() .click()
.confirmationErrorMessageShouldAppear(); .confirmationErrorMessageShouldAppear();
cy.contains(MESSAGES.invalidEmailAddress).should("be.visible");
}, },
); );
@ -276,7 +272,7 @@ describe("Staff members", () => {
it( it(
"should create new user and successfully change password. TC: SALEOR_3510", "should create new user and successfully change password. TC: SALEOR_3510",
{ tags: ["@staffMembers", "@allEnv"] }, { tags: ["@staffMembers", "@allEnv", "@critical"] },
() => { () => {
const newPass = "newTestPass"; const newPass = "newTestPass";
const newLastName = faker.name.lastName(); const newLastName = faker.name.lastName();
@ -300,6 +296,11 @@ describe("Staff members", () => {
cy.visit(urlList.staffMembers).get(LOGIN_SELECTORS.userMenu).click(); cy.visit(urlList.staffMembers).get(LOGIN_SELECTORS.userMenu).click();
cy.get(LOGIN_SELECTORS.accountSettings).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.changePasswordBtn).click();
cy.get( cy.get(
STAFF_MEMBER_DETAILS_SELECTORS.changePasswordModal.oldPassword, STAFF_MEMBER_DETAILS_SELECTORS.changePasswordModal.oldPassword,
@ -307,13 +308,21 @@ describe("Staff members", () => {
cy.get( cy.get(
STAFF_MEMBER_DETAILS_SELECTORS.changePasswordModal.newPassword, STAFF_MEMBER_DETAILS_SELECTORS.changePasswordModal.newPassword,
).type(newPass); ).type(newPass);
cy.get(BUTTON_SELECTORS.submit).click().confirmationMessageShouldAppear(); cy.addAliasToGraphRequest("ChangeUserPassword")
.get(BUTTON_SELECTORS.submit)
.click()
.confirmationMessageShouldAppear()
.waitForRequestAndCheckIfNoErrors("@ChangeUserPassword");
cy.clearSessionData().loginUserViaRequest("auth", { cy.clearSessionData().loginUserViaRequest("auth", {
email: newEmail, email: newEmail,
password: newPass, 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");
}, },
); );
}); });

View file

@ -18,6 +18,8 @@ export {
CUSTOMER_DETAILS_SELECTORS, CUSTOMER_DETAILS_SELECTORS,
CUSTOMERS_LIST_SELECTORS, CUSTOMERS_LIST_SELECTORS,
} from "./customer/"; } from "./customer/";
export { MENU as LEFT_MENU_SELECTORS } from "./account/left-menu/left-menu-selectors";
export { SALES_SELECTORS, VOUCHERS_SELECTORS } from "./discounts"; export { SALES_SELECTORS, VOUCHERS_SELECTORS } from "./discounts";
export { HOMEPAGE_SELECTORS } from "./homePage/homePage-selectors"; export { HOMEPAGE_SELECTORS } from "./homePage/homePage-selectors";
export { PAGINATION } from "./navigation"; export { PAGINATION } from "./navigation";

View file

@ -1,4 +1,5 @@
export const SHARED_ELEMENTS = { export const SHARED_ELEMENTS = {
body: "body",
header: "[data-test-id='page-header']", header: "[data-test-id='page-header']",
progressBar: '[role="progressbar"]', progressBar: '[role="progressbar"]',
circularProgress: '[class*="CircularProgress-circle"]', circularProgress: '[class*="CircularProgress-circle"]',

View file

@ -2,4 +2,5 @@ export const STAFF_MEMBERS_LIST_SELECTORS = {
inviteStaffMemberButton: '[data-test-id="invite-staff-member"]', inviteStaffMemberButton: '[data-test-id="invite-staff-member"]',
staffStatusText: '[data-test-id="staffStatusText"]', staffStatusText: '[data-test-id="staffStatusText"]',
staffAvatar: '[data-test-id="staffAvatar"]', staffAvatar: '[data-test-id="staffAvatar"]',
usersEmails: '[data-test-id="user-mail"]',
}; };

View file

@ -1,5 +1,5 @@
export { bodyMockHomePage } from "./bodyMocks"; export { bodyMockHomePage } from "./bodyMocks";
export { orderDraftCreateDemoResponse } from "./errors/demo/orderDratCreate"; export { orderDraftCreateDemoResponse } from "./errors/demo/orderDratCreate";
export { urlList } from "./urlList"; export { urlList } from "./urlList";
export { ONE_PERMISSION_USERS } from "./users"; export { ONE_PERMISSION_USERS, TEST_ADMIN_USER } from "./users";
export { MESSAGES } from "./messages"; export { MESSAGES } from "./messages";

View file

@ -1,4 +1,5 @@
export const MESSAGES = { export const MESSAGES = {
noProductFound: "No products found", noProductFound: "No products found",
confirmProductsDeletion: "Are you sure you want to delete 2 products?", confirmProductsDeletion: "Are you sure you want to delete 2 products?",
invalidEmailAddress: "Enter a valid email address.",
}; };

View file

@ -3,3 +3,8 @@ export { createCustomer, deleteCustomersStartsWith } from "./Customer";
export { createDraftOrder, getOrder } from "./Order"; export { createDraftOrder, getOrder } from "./Order";
export { updateMetadata, updatePrivateMetadata } from "./Metadata"; export { updateMetadata, updatePrivateMetadata } from "./Metadata";
export { getProductMetadata } from "./storeFront/ProductDetails"; export { getProductMetadata } from "./storeFront/ProductDetails";
export { activatePlugin, updatePlugin } from "./Plugins";
export {
deleteStaffMembersStartsWith,
updateStaffMember,
} from "./StaffMembers";

View file

@ -6,3 +6,8 @@ export {
updateTaxConfigurationForChannel, updateTaxConfigurationForChannel,
} from "./taxesUtils"; } from "./taxesUtils";
export * as productsUtils from "./products/productsUtils"; export * as productsUtils from "./products/productsUtils";
export {
getMailActivationLinkForUser,
getMailActivationLinkForUserAndSubject,
inviteStaffMemberWithFirstPermission,
} from "./users";

View file

@ -1,2 +1,14 @@
export * as ordersOperationsHelpers from "./ordersOperations"; export * as ordersOperationsHelpers from "./ordersOperations";
export * as transactionsOrderUtils from "./ordersTransactionUtils"; 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";

View file

@ -143,7 +143,9 @@ const StaffList: React.FC<StaffListProps> = props => {
</Box> </Box>
</TableCell> </TableCell>
<TableCell> <TableCell>
<Text size="small">{staffMember?.email}</Text> <Text size="small" data-test-id="user-mail">
{staffMember?.email}
</Text>
</TableCell> </TableCell>
</TableRowLink> </TableRowLink>
), ),