All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.cypress-utils.utils.member.js Maven / Gradle / Ivy

Go to download

A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.

There is a newer version: 4.12.3
Show newest version
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
import { isStagingEnv } from "./common";
import { requestApis, urlPaths } from "../constants/routes";
import { commonSelectors, tableSelectors } from "../constants/selectors/common";
import { memberFormSelectors, memberSelectors } from "../constants/selectors/member";
import { commonTexts } from "../constants/texts/common";
import { memberFormErrorTexts, memberTexts } from "../constants/texts/member";
var interceptMemberApi = function interceptMemberApi(alias) {
  var times = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  return cy.intercept({
    url: requestApis.teamMembers.all,
    times: times
  }).as(alias);
};
var navigateToMembersPage = function navigateToMembersPage() {
  var waitForRequest = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  waitForRequest && interceptMemberApi("fetchMembers", 2);
  cy.get(memberSelectors.membersTab).click();
  cy.url().should("include", urlPaths.members);
  waitForRequest && cy.waitForMultipleRequest("@fetchMembers", 2);
  cy.get(commonSelectors.heading).should("have.text", memberTexts.activeMembersHeading);
};
var addMemberViaUI = function addMemberViaUI(_ref) {
  var email = _ref.email,
    _ref$role = _ref.role,
    role = _ref$role === void 0 ? memberTexts.agent : _ref$role,
    appName = _ref.appName;
  var invalidEmail = "Invalid email";
  cy.get(memberSelectors.newButton).should("have.text", memberTexts.addMember).click();
  cy.get(commonSelectors.paneHeader).should("have.text", memberTexts.newHeading);
  cy.get(memberFormSelectors.emailTextField).should("be.focused");
  cy.get(memberFormSelectors.cancelButton).click();
  cy.get(commonSelectors.paneHeader).should("not.exist");

  // form validation
  cy.get(memberSelectors.newButton).should("be.visible").click();
  cy.get(memberSelectors.continueButton).should("be.disabled");
  cy.get(memberSelectors.roleLabel(role)).click();
  cy.get(memberSelectors.continueButton).click();
  cy.get(memberFormSelectors.emailErrorField).should("contain.text", memberFormErrorTexts.emailRequired);
  cy.typeAndEnter(memberFormSelectors.emailTextField, invalidEmail);
  cy.get(memberFormSelectors.emailErrorField).should("contains.text", memberFormErrorTexts.emailInvalid);
  cy.get(memberFormSelectors.emailErrorField).should("contain.text", memberFormErrorTexts.removeInvalidEmail);
  cy.get(commonSelectors.paneModalCrossIcon).click();
  cy.get(commonSelectors.paneHeader).should("not.exist");

  // form submission
  cy.get(memberSelectors.newButton).click();
  cy.typeAndEnter(memberFormSelectors.emailTextField, email);
  cy.get(memberSelectors.roleLabel(role)).click();
  cy.get(memberSelectors.continueButton).click();
  if (isStagingEnv) {
    cy.get(commonSelectors.checkboxLabel).should("have.text", memberTexts.addMemberToProducts(email));
    cy.get(commonSelectors.paneBody).within(function () {
      return cy.get(memberSelectors.checkbox).uncheck();
    });
    cy.get(memberSelectors.continueButton).click();
  }
  cy.get(commonSelectors.paneBody).should("contain.text", memberTexts.inviteMessage({
    email: email,
    role: role,
    appName: appName
  }));
  interceptMemberApi("createAndFetchMember", 2);
  cy.get(memberSelectors.submitButton).click();
  cy.wait("@createAndFetchMember");
  cy.verifyToastIcon();
  cy.wait("@createAndFetchMember");
  verifyMemberDetails({
    email: email,
    role: role,
    skipSearchRequest: false
  });
};
var editMemberViaUI = function editMemberViaUI(_ref2) {
  var email = _ref2.email,
    newRole = _ref2.newRole,
    firstName = _ref2.firstName,
    lastName = _ref2.lastName,
    newEmail = _ref2.newEmail,
    skipSearchRequest = _ref2.skipSearchRequest,
    _ref2$updateCount = _ref2.updateCount,
    updateCount = _ref2$updateCount === void 0 ? 2 : _ref2$updateCount;
  var name = firstName && lastName ? [firstName, lastName].join(" ") : null;
  verifyMemberDetails({
    email: email,
    skipSearchRequest: skipSearchRequest
  }).within(function () {
    cy.get(memberSelectors.dropDownIcon).click();
  });
  cy.get(memberSelectors.editButton).should("have.text", commonTexts.edit).click();
  cy.get(commonSelectors.paneHeader).should("have.text", memberTexts.editMember);
  cy.get(memberFormSelectors.firstNameTextField).should("be.focused");
  cy.get(memberSelectors.roleLabel(newRole)).click();
  cy.get(memberFormSelectors.emailInput).should("have.value", email);
  newEmail && cy.clearAndType(memberFormSelectors.emailInput, newEmail);
  firstName && cy.clearAndType(memberFormSelectors.firstNameTextField, firstName);
  lastName && cy.clearAndType(memberFormSelectors.lastNameTextField, lastName);
  interceptMemberApi("updateAndFetchMember", updateCount);
  cy.get(memberSelectors.submitButton).click();
  cy.wait("@updateAndFetchMember");
  cy.verifyToastIcon();
  cy.waitForMultipleRequest("@updateAndFetchMember", updateCount - 1);
  verifyMemberDetails({
    email: newEmail !== null && newEmail !== void 0 ? newEmail : email,
    role: newRole,
    name: name,
    skipSearchRequest: true
  });
};
var verifyMemberDetails = function verifyMemberDetails(_ref3) {
  var email = _ref3.email,
    role = _ref3.role,
    name = _ref3.name,
    statusTag = _ref3.statusTag,
    _ref3$skipSearchReque = _ref3.skipSearchRequest,
    skipSearchRequest = _ref3$skipSearchReque === void 0 ? true : _ref3$skipSearchReque;
  !skipSearchRequest && interceptMemberApi("searchMember");
  cy.typeOnSearchField({
    selector: memberSelectors.searchTextField,
    value: email
  });
  !skipSearchRequest && cy.wait("@searchMember");
  return cy.contains(tableSelectors.tableRow, email).within(function () {
    cy.get(tableSelectors.nthColumn(3)).should("have.text", email);
    cy.get(tableSelectors.nthColumn(2)).within(function () {
      name && cy.get("p").should("contain.text", name);
    });
    role && cy.get(tableSelectors.nthColumn(4)).should("have.text", role);
    statusTag && cy.get(memberSelectors.statusTag).should("have.text", statusTag);
  });
};
var updateMemberRole = function updateMemberRole(_ref4) {
  var email = _ref4.email,
    role = _ref4.role,
    skipSearchRequest = _ref4.skipSearchRequest;
  verifyMemberDetails({
    email: email,
    skipSearchRequest: skipSearchRequest
  }).within(function () {
    return cy.clickDropdownOption(commonTexts.edit);
  });
  cy.get(commonSelectors.paneHeader).should("have.text", memberTexts.updateMemberRole);
  cy.get(memberSelectors.roleLabel(role)).click();
  interceptMemberApi("updateAndFetchMember", 2);
  cy.get(memberSelectors.submitButton).click();
  cy.wait("@updateAndFetchMember");
  cy.verifyToastIcon();
  cy.wait("@updateAndFetchMember");
  verifyMemberDetails({
    email: email,
    role: role
  });
};
var verifyActivatedMember = function verifyActivatedMember(_ref5) {
  var email = _ref5.email,
    _ref5$skipFetchReques = _ref5.skipFetchRequest,
    skipFetchRequest = _ref5$skipFetchReques === void 0 ? false : _ref5$skipFetchReques,
    _ref5$skipSearchReque = _ref5.skipSearchRequest,
    skipSearchRequest = _ref5$skipSearchReque === void 0 ? true : _ref5$skipSearchReque;
  cy.get(commonSelectors.toggleButton).click();
  cy.get(memberSelectors.menuBarHeading).should("have.text", memberTexts.members);
  !skipFetchRequest && interceptMemberApi("fetchActivatedMembers");
  cy.get(memberSelectors.activatedMembersButton).click();
  !skipFetchRequest && cy.wait("@fetchActivatedMembers");
  verifyMemberDetails({
    email: email,
    skipSearchRequest: skipSearchRequest
  });
  cy.get(commonSelectors.toggleButton).click();
};
var verifyDeactivatedMember = function verifyDeactivatedMember(_ref6) {
  var email = _ref6.email,
    _ref6$skipFetchReques = _ref6.skipFetchRequest,
    skipFetchRequest = _ref6$skipFetchReques === void 0 ? false : _ref6$skipFetchReques,
    _ref6$skipSearchReque = _ref6.skipSearchRequest,
    skipSearchRequest = _ref6$skipSearchReque === void 0 ? true : _ref6$skipSearchReque;
  cy.get(commonSelectors.toggleButton).click();
  cy.get(memberSelectors.menuBarHeading).should("have.text", memberTexts.members);
  !skipFetchRequest && interceptMemberApi("fetchDeactivatedMembers");
  cy.get(memberSelectors.deactivatedAgentsButton).click();
  !skipFetchRequest && cy.wait("@fetchDeactivatedMembers");
  verifyMemberDetails({
    email: email,
    skipSearchRequest: skipSearchRequest
  });
  cy.get(commonSelectors.toggleButton).click();
};
var activateMember = function activateMember(_ref7) {
  var email = _ref7.email,
    name = _ref7.name,
    _ref7$skipSearchReque = _ref7.skipSearchRequest,
    skipSearchRequest = _ref7$skipSearchReque === void 0 ? true : _ref7$skipSearchReque;
  verifyMemberDetails({
    email: email,
    skipSearchRequest: skipSearchRequest
  }).within(function () {
    cy.get(memberSelectors.dropDownIcon).click();
  });
  cy.get(memberSelectors.activateOrDeactivateMember).should("have.text", commonTexts.activate).click();
  cy.get(commonSelectors.alertTitle).should("have.text", memberTexts.activateMember);
  cy.get(commonSelectors.alertModalMessage).should("have.text", memberTexts.activateMemberAlertMessage(name || email));
  interceptMemberApi("activateAndFetchMember", 2);
  cy.get(commonSelectors.alertModalSubmitButton).click();
  cy.wait("@activateAndFetchMember");
  cy.verifyToastIcon();
  cy.wait("@activateAndFetchMember");
  verifyActivatedMember({
    email: email
  });
};
var deactivateMember = function deactivateMember(_ref8) {
  var email = _ref8.email,
    name = _ref8.name,
    _ref8$skipSearchReque = _ref8.skipSearchRequest,
    skipSearchRequest = _ref8$skipSearchReque === void 0 ? true : _ref8$skipSearchReque;
  verifyMemberDetails({
    email: email,
    skipSearchRequest: skipSearchRequest
  }).within(function () {
    cy.get(memberSelectors.dropDownIcon).click();
  });
  cy.get(memberSelectors.activateOrDeactivateMember).should("have.text", commonTexts.deactivate).click();
  cy.get(commonSelectors.alertTitle).should("have.text", memberTexts.deactivateMember);
  cy.get(commonSelectors.alertModalMessage).should("have.text", memberTexts.deactivateMemberAlertMessage(name || email));
  interceptMemberApi("deactivateAndFetchMember", 2);
  cy.get(commonSelectors.alertModalSubmitButton).click();
  cy.wait("@deactivateAndFetchMember");
  cy.verifyToastIcon();
  cy.wait("@deactivateAndFetchMember");
  verifyDeactivatedMember({
    email: email
  });
};
var unCheckColumnAndVerifyTableHeader = function unCheckColumnAndVerifyTableHeader(fieldSelector, columnText) {
  clickOnColumnIcon();
  cy.get(fieldSelector).parent().within(function () {
    cy.get(memberSelectors.columnCheckBox).should("be.checked").uncheck().should("not.be.checked");
  });
  memberUtils.clickOnColumnIcon();
  cy.get(memberSelectors.columnsDropdownContainer).should("not.exist");
  cy.contains(tableSelectors.tableHeader, columnText).should("not.exist");
};
var checkColumnAndVerifyTableHeader = function checkColumnAndVerifyTableHeader(fieldSelector, columnText) {
  clickOnColumnIcon();
  cy.get(fieldSelector).parent().within(function () {
    cy.get(memberSelectors.columnCheckBox).should("not.be.checked").check().should("be.checked");
  });
  memberUtils.clickOnColumnIcon();
  cy.get(memberSelectors.columnsDropdownContainer).should("not.exist");
  cy.contains(tableSelectors.tableHeader, columnText).should("be.visible");
};
var addMemberViaRequest = function addMemberViaRequest(_ref9) {
  var email = _ref9.email,
    _ref9$role = _ref9.role,
    role = _ref9$role === void 0 ? memberTexts.agent : _ref9$role,
    _ref9$requestCount = _ref9.requestCount,
    requestCount = _ref9$requestCount === void 0 ? 0 : _ref9$requestCount,
    appName = _ref9.appName;
  cy.apiRequest({
    method: "POST",
    url: requestApis.teamMembers.index,
    body: {
      user: {
        emails: [email],
        organization_role: role,
        app_roles: [{
          app_name: appName,
          active_role: role,
          is_enabled: true
        }]
      }
    }
  });
  cy.reloadAndWait(requestCount);
};
var editMemberViaRequest = function editMemberViaRequest(_ref10) {
  var email = _ref10.email,
    firstName = _ref10.firstName,
    lastName = _ref10.lastName,
    newRole = _ref10.newRole,
    _ref10$requestCount = _ref10.requestCount,
    requestCount = _ref10$requestCount === void 0 ? 0 : _ref10$requestCount;
  cy.apiRequest({
    method: "GET",
    url: requestApis.teamMembers.index,
    qs: {
      search: email
    }
  }).then(function (_ref11) {
    var body = _ref11.body;
    var memberDetails = body.members[0];
    cy.apiRequest({
      method: "PUT",
      url: requestApis.teamMembers.show(memberDetails.id),
      body: {
        team: _objectSpread({
          active: true,
          first_name: firstName,
          last_name: lastName
        }, newRole && {
          organization_role: newRole
        })
      }
    });
  });
  cy.reloadAndWait(requestCount);
};
var deactivateMemberViaRequest = function deactivateMemberViaRequest(email) {
  var requestCount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  cy.apiRequest({
    method: "PATCH",
    url: requestApis.teamMembers.bulkUpdate,
    body: {
      users: {
        active: false,
        emails: [email]
      }
    }
  });
  cy.reloadAndWait(requestCount);
};
var clickOnColumnIcon = function clickOnColumnIcon() {
  cy.get(commonSelectors.subheader).should("exist").within(function () {
    cy.get(memberSelectors.columnsButton).click();
  });
};
export var memberUtils = {
  addMemberViaRequest: addMemberViaRequest,
  addMemberViaUI: addMemberViaUI,
  activateMember: activateMember,
  checkColumnAndVerifyTableHeader: checkColumnAndVerifyTableHeader,
  deactivateMember: deactivateMember,
  deactivateMemberViaRequest: deactivateMemberViaRequest,
  editMemberViaUI: editMemberViaUI,
  editMemberViaRequest: editMemberViaRequest,
  updateMemberRole: updateMemberRole,
  interceptMemberApi: interceptMemberApi,
  navigateToMembersPage: navigateToMembersPage,
  unCheckColumnAndVerifyTableHeader: unCheckColumnAndVerifyTableHeader,
  verifyMemberDetails: verifyMemberDetails,
  clickOnColumnIcon: clickOnColumnIcon
};
//# sourceMappingURL=member.js.map




© 2015 - 2024 Weber Informatics LLC | Privacy Policy