package.cjs.cypress-utils.utils.member.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neeto-commons-frontend Show documentation
Show all versions of neeto-commons-frontend Show documentation
A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.memberUtils = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _common = require("./common");
var _routes = require("../constants/routes");
var _common2 = require("../constants/selectors/common");
var _member = require("../constants/selectors/member");
var _common3 = require("../constants/texts/common");
var _member2 = require("../constants/texts/member");
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var interceptMemberApi = function interceptMemberApi(alias) {
var times = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
return cy.intercept({
url: _routes.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(_member.memberSelectors.membersTab).click();
cy.url().should("include", _routes.urlPaths.members);
waitForRequest && cy.waitForMultipleRequest("@fetchMembers", 2);
cy.get(_common2.commonSelectors.heading).should("have.text", _member2.memberTexts.activeMembersHeading);
};
var addMemberViaUI = function addMemberViaUI(_ref) {
var email = _ref.email,
_ref$role = _ref.role,
role = _ref$role === void 0 ? _member2.memberTexts.agent : _ref$role,
appName = _ref.appName;
var invalidEmail = "Invalid email";
cy.get(_member.memberSelectors.newButton).should("have.text", _member2.memberTexts.addMember).click();
cy.get(_common2.commonSelectors.paneHeader).should("have.text", _member2.memberTexts.newHeading);
cy.get(_member.memberFormSelectors.emailTextField).should("be.focused");
cy.get(_member.memberFormSelectors.cancelButton).click();
cy.get(_common2.commonSelectors.paneHeader).should("not.exist");
// form validation
cy.get(_member.memberSelectors.newButton).should("be.visible").click();
cy.get(_member.memberSelectors.continueButton).should("be.disabled");
cy.get(_member.memberSelectors.roleLabel(role)).click();
cy.get(_member.memberSelectors.continueButton).click();
cy.get(_member.memberFormSelectors.emailErrorField).should("contain.text", _member2.memberFormErrorTexts.emailRequired);
cy.typeAndEnter(_member.memberFormSelectors.emailTextField, invalidEmail);
cy.get(_member.memberFormSelectors.emailErrorField).should("contains.text", _member2.memberFormErrorTexts.emailInvalid);
cy.get(_member.memberFormSelectors.emailErrorField).should("contain.text", _member2.memberFormErrorTexts.removeInvalidEmail);
cy.get(_common2.commonSelectors.paneModalCrossIcon).click();
cy.get(_common2.commonSelectors.paneHeader).should("not.exist");
// form submission
cy.get(_member.memberSelectors.newButton).click();
cy.typeAndEnter(_member.memberFormSelectors.emailTextField, email);
cy.get(_member.memberSelectors.roleLabel(role)).click();
cy.get(_member.memberSelectors.continueButton).click();
if (_common.isStagingEnv) {
cy.get(_common2.commonSelectors.checkboxLabel).should("have.text", _member2.memberTexts.addMemberToProducts(email));
cy.get(_common2.commonSelectors.paneBody).within(function () {
return cy.get(_member.memberSelectors.checkbox).uncheck();
});
cy.get(_member.memberSelectors.continueButton).click();
}
cy.get(_common2.commonSelectors.paneBody).should("contain.text", _member2.memberTexts.inviteMessage({
email: email,
role: role,
appName: appName
}));
interceptMemberApi("createAndFetchMember", 2);
cy.get(_member.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(_member.memberSelectors.dropDownIcon).click();
});
cy.get(_member.memberSelectors.editButton).should("have.text", _common3.commonTexts.edit).click();
cy.get(_common2.commonSelectors.paneHeader).should("have.text", _member2.memberTexts.editMember);
cy.get(_member.memberFormSelectors.firstNameTextField).should("be.focused");
cy.get(_member.memberSelectors.roleLabel(newRole)).click();
cy.get(_member.memberFormSelectors.emailInput).should("have.value", email);
newEmail && cy.clearAndType(_member.memberFormSelectors.emailInput, newEmail);
firstName && cy.clearAndType(_member.memberFormSelectors.firstNameTextField, firstName);
lastName && cy.clearAndType(_member.memberFormSelectors.lastNameTextField, lastName);
interceptMemberApi("updateAndFetchMember", updateCount);
cy.get(_member.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: _member.memberSelectors.searchTextField,
value: email
});
!skipSearchRequest && cy.wait("@searchMember");
return cy.contains(_common2.tableSelectors.tableRow, email).within(function () {
cy.get(_common2.tableSelectors.nthColumn(3)).should("have.text", email);
cy.get(_common2.tableSelectors.nthColumn(2)).within(function () {
name && cy.get("p").should("contain.text", name);
});
role && cy.get(_common2.tableSelectors.nthColumn(4)).should("have.text", role);
statusTag && cy.get(_member.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(_common3.commonTexts.edit);
});
cy.get(_common2.commonSelectors.paneHeader).should("have.text", _member2.memberTexts.updateMemberRole);
cy.get(_member.memberSelectors.roleLabel(role)).click();
interceptMemberApi("updateAndFetchMember", 2);
cy.get(_member.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(_common2.commonSelectors.toggleButton).click();
cy.get(_member.memberSelectors.menuBarHeading).should("have.text", _member2.memberTexts.members);
!skipFetchRequest && interceptMemberApi("fetchActivatedMembers");
cy.get(_member.memberSelectors.activatedMembersButton).click();
!skipFetchRequest && cy.wait("@fetchActivatedMembers");
verifyMemberDetails({
email: email,
skipSearchRequest: skipSearchRequest
});
cy.get(_common2.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(_common2.commonSelectors.toggleButton).click();
cy.get(_member.memberSelectors.menuBarHeading).should("have.text", _member2.memberTexts.members);
!skipFetchRequest && interceptMemberApi("fetchDeactivatedMembers");
cy.get(_member.memberSelectors.deactivatedAgentsButton).click();
!skipFetchRequest && cy.wait("@fetchDeactivatedMembers");
verifyMemberDetails({
email: email,
skipSearchRequest: skipSearchRequest
});
cy.get(_common2.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(_member.memberSelectors.dropDownIcon).click();
});
cy.get(_member.memberSelectors.activateOrDeactivateMember).should("have.text", _common3.commonTexts.activate).click();
cy.get(_common2.commonSelectors.alertTitle).should("have.text", _member2.memberTexts.activateMember);
cy.get(_common2.commonSelectors.alertModalMessage).should("have.text", _member2.memberTexts.activateMemberAlertMessage(name || email));
interceptMemberApi("activateAndFetchMember", 2);
cy.get(_common2.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(_member.memberSelectors.dropDownIcon).click();
});
cy.get(_member.memberSelectors.activateOrDeactivateMember).should("have.text", _common3.commonTexts.deactivate).click();
cy.get(_common2.commonSelectors.alertTitle).should("have.text", _member2.memberTexts.deactivateMember);
cy.get(_common2.commonSelectors.alertModalMessage).should("have.text", _member2.memberTexts.deactivateMemberAlertMessage(name || email));
interceptMemberApi("deactivateAndFetchMember", 2);
cy.get(_common2.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(_member.memberSelectors.columnCheckBox).should("be.checked").uncheck().should("not.be.checked");
});
memberUtils.clickOnColumnIcon();
cy.get(_member.memberSelectors.columnsDropdownContainer).should("not.exist");
cy.contains(_common2.tableSelectors.tableHeader, columnText).should("not.exist");
};
var checkColumnAndVerifyTableHeader = function checkColumnAndVerifyTableHeader(fieldSelector, columnText) {
clickOnColumnIcon();
cy.get(fieldSelector).parent().within(function () {
cy.get(_member.memberSelectors.columnCheckBox).should("not.be.checked").check().should("be.checked");
});
memberUtils.clickOnColumnIcon();
cy.get(_member.memberSelectors.columnsDropdownContainer).should("not.exist");
cy.contains(_common2.tableSelectors.tableHeader, columnText).should("be.visible");
};
var addMemberViaRequest = function addMemberViaRequest(_ref9) {
var email = _ref9.email,
_ref9$role = _ref9.role,
role = _ref9$role === void 0 ? _member2.memberTexts.agent : _ref9$role,
_ref9$requestCount = _ref9.requestCount,
requestCount = _ref9$requestCount === void 0 ? 0 : _ref9$requestCount,
appName = _ref9.appName;
cy.apiRequest({
method: "POST",
url: _routes.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: _routes.requestApis.teamMembers.index,
qs: {
search: email
}
}).then(function (_ref11) {
var body = _ref11.body;
var memberDetails = body.members[0];
cy.apiRequest({
method: "PUT",
url: _routes.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: _routes.requestApis.teamMembers.bulkUpdate,
body: {
users: {
active: false,
emails: [email]
}
}
});
cy.reloadAndWait(requestCount);
};
var clickOnColumnIcon = function clickOnColumnIcon() {
cy.get(_common2.commonSelectors.subheader).should("exist").within(function () {
cy.get(_member.memberSelectors.columnsButton).click();
});
};
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
};
exports.memberUtils = memberUtils;
//# sourceMappingURL=member.js.map