package.cypress-utils.utils.navigation.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.
/* eslint-disable xss/no-location-href-assign */
import { requestApis } from "../constants/routes";
import { commonSelectors, profileSelectors } from "../constants/selectors/common";
import { chatWidgetSelectors, helpIconSelectors } from "../constants/selectors/navigation";
import { commonTexts } from "../constants/texts/common";
import { helpIconTexts, profileTexts } from "../constants/texts/navigation";
var verifyTabMenu = function verifyTabMenu(_ref) {
var tabSelector = _ref.tabSelector,
_ref$alias = _ref.alias,
alias = _ref$alias === void 0 ? "fetchData" : _ref$alias,
_ref$requestCount = _ref.requestCount,
requestCount = _ref$requestCount === void 0 ? 1 : _ref$requestCount;
requestCount && cy.interceptApi(alias, requestCount);
cy.get(tabSelector).click();
requestCount && cy.waitForMultipleRequest("@".concat(alias), requestCount);
cy.verifyAttribute({
selector: tabSelector,
attr: "class",
value: "active"
});
};
var clickOnHelpSubTab = function clickOnHelpSubTab(tabSelector, tabText) {
_openProfileOrHelpCenter({
tabSelector: helpIconSelectors.helpButton,
subTabLink: helpIconSelectors.whatsNewButton,
count: 5
});
cy.get(tabSelector).should("have.text", tabText).invoke("click");
};
var verifyHelpDocumentationLink = function verifyHelpDocumentationLink(_ref2) {
var articleTitle = _ref2.articleTitle,
alias = _ref2.alias,
_ref2$requestCount = _ref2.requestCount,
requestCount = _ref2$requestCount === void 0 ? 3 : _ref2$requestCount;
_openProfileOrHelpCenter({
tabSelector: helpIconSelectors.helpButton,
subTabLink: helpIconSelectors.whatsNewButton,
count: 5
});
cy.clickByRemoveTargetAttr(helpIconSelectors.documentationButton);
cy.get(commonSelectors.articlePageTitle, {
timeout: 10000
}).should("have.text", articleTitle);
cy.interceptApi(alias, requestCount);
cy.go("back");
cy.waitForMultipleRequest("@".concat(alias), requestCount);
};
var verifyKeyboardShortcutsPane = function verifyKeyboardShortcutsPane() {
clickOnHelpSubTab(helpIconSelectors.keyboardShortcutButton, helpIconTexts.keyboardShortcuts);
cy.get(helpIconSelectors.keyboardShortcutPaneHeading).should("have.text", helpIconTexts.keyboardShortcuts);
cy.get(helpIconSelectors.keyboardShortcutPaneCrossIcon).click();
};
var verifyWhatsNewTab = function verifyWhatsNewTab(whatsNewHeading) {
_openProfileOrHelpCenter({
tabSelector: helpIconSelectors.helpButton,
subTabLink: helpIconSelectors.whatsNewButton,
count: 5
});
cy.get(helpIconSelectors.whatsNewButton).should("contain.text", helpIconTexts.whatsNew);
_openWhatsNewPane();
cy.get(helpIconSelectors.whatsNewWidgetInfo).should("have.text", whatsNewHeading);
cy.get(helpIconSelectors.whatsNewWidgetCloseButton).last().click();
cy.get(helpIconSelectors.whatsNewWidgetInfo).should("not.exist");
};
var _waitForChatWidget = function waitForChatWidget() {
var timeOut = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
var defaultWait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 500;
if (timeOut === 0) return;
cy.ifNotExist(chatWidgetSelectors.widgetIframe, function () {
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(defaultWait);
navigationUtils.clickOnHelpSubTab(helpIconSelectors.chatButton, helpIconTexts.liveChat);
cy.ifNotExist(chatWidgetSelectors.widgetIframe, function () {
_waitForChatWidget(timeOut - 1);
});
});
};
var verifyChatWithUsTab = function verifyChatWithUsTab(_ref3) {
var alias = _ref3.alias,
_ref3$requestCount = _ref3.requestCount,
requestCount = _ref3$requestCount === void 0 ? 3 : _ref3$requestCount;
requestCount && cy.interceptNonVersionedApi({
url: requestApis.allChatPath,
alias: alias,
times: requestCount
});
clickOnHelpSubTab(helpIconSelectors.chatButton, helpIconTexts.liveChat);
requestCount && cy.waitForMultipleRequest("@".concat(alias), requestCount);
_waitForChatWidget();
cy.withinIframe(chatWidgetSelectors.widgetIframe, function () {
requestCount && cy.interceptNonVersionedApi({
url: requestApis.allChatPath,
alias: alias,
times: requestCount
});
cy.get(chatWidgetSelectors.chatWidgetHomeCard, {
timeout: 10000
}).click({
force: true
});
requestCount && cy.wait("@".concat(alias), requestCount);
requestCount && cy.interceptNonVersionedApi({
url: requestApis.allChatPath,
alias: alias,
times: requestCount
});
cy.get(chatWidgetSelectors.widgetSubmitButton).click();
requestCount && cy.waitForMultipleRequest("@".concat(alias), requestCount);
cy.get(chatWidgetSelectors.chatBubbleMessage).should("be.visible");
});
cy.get(chatWidgetSelectors.chatCloseButton).click();
cy.get(chatWidgetSelectors.widgetIframe).should("not.exist");
};
var verifyMyProfileTab = function verifyMyProfileTab(_ref4) {
var alias = _ref4.alias,
_ref4$requestCount = _ref4.requestCount,
requestCount = _ref4$requestCount === void 0 ? 2 : _ref4$requestCount;
_openProfileOrHelpCenter({
tabSelector: profileSelectors.tab,
subTabLink: profileSelectors.logoutLink,
count: 5
});
cy.get(profileSelectors.myProfileButton).should("have.text", profileTexts.myProfile);
cy.globalState("subdomainName").then(function (subdomainName) {
cy.window().then(function (win) {
cy.stub(win, "open").as(alias).callsFake(function (newUrl) {
return win.location.href = newUrl;
});
});
cy.get(profileSelectors.myProfileButton).invoke("click");
cy.get("@".concat(alias)).should("be.called");
cy.url().should("include", requestApis.myProfilePath(subdomainName));
});
cy.get(commonSelectors.heading).should("have.text", profileTexts.profileSettings);
cy.globalState("subdomainName").then(function (subdomainName) {
return cy.url().should("include", requestApis.myProfilePath(subdomainName));
});
cy.interceptApi(alias, requestCount);
cy.go("back");
cy.waitForMultipleRequest("@".concat(alias), requestCount);
};
var verifyOrganizationTab = function verifyOrganizationTab() {
_openProfileOrHelpCenter({
tabSelector: profileSelectors.tab,
subTabLink: profileSelectors.logoutLink,
count: 5
});
cy.get(profileSelectors.organizationSettingsButton).should("have.text", profileTexts.myOrganization);
cy.globalState("subdomainName").then(function (subdomainName) {
cy.window().then(function (win) {
cy.stub(win, "open").as("navigateToSettings").callsFake(function (newUrl) {
return win.location.href = newUrl;
});
});
cy.get(profileSelectors.organizationSettingsButton).invoke("click");
cy.get("@navigateToSettings").should("be.called");
cy.url().should("include", requestApis.settingsPath(subdomainName));
});
cy.get(commonSelectors.heading).should("have.text", commonTexts.settings);
cy.globalState("subdomainName").then(function (subdomainName) {
return cy.url().should("include", requestApis.settingsPath(subdomainName));
});
};
var _openProfileOrHelpCenter = function openProfileOrHelpCenter(_ref5) {
var tabSelector = _ref5.tabSelector,
subTabLink = _ref5.subTabLink,
_ref5$count = _ref5.count,
count = _ref5$count === void 0 ? 1 : _ref5$count,
_ref5$timeout = _ref5.timeout,
timeout = _ref5$timeout === void 0 ? 2000 : _ref5$timeout;
if (count === 0) return;
cy.get(tabSelector).click();
cy.ifNotExist(subTabLink, function () {
cy.wait(timeout); // eslint-disable-line cypress/no-unnecessary-waiting
_openProfileOrHelpCenter({
tabSelector: tabSelector,
subTabLink: subTabLink,
count: count - 1,
timeout: timeout
});
});
};
var _openWhatsNewPane = function openWhatsNewPane() {
var count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 7;
var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2000;
if (count === 0) return;
cy.get(helpIconSelectors.whatsNewButton).invoke("click");
cy.ifNotExist(helpIconSelectors.whatsNewWidgetInfo, function () {
cy.wait(timeout); // eslint-disable-line cypress/no-unnecessary-waiting
_openWhatsNewPane(count - 1);
});
};
export var navigationUtils = {
verifyTabMenu: verifyTabMenu,
clickOnHelpSubTab: clickOnHelpSubTab,
verifyHelpDocumentationLink: verifyHelpDocumentationLink,
verifyKeyboardShortcutsPane: verifyKeyboardShortcutsPane,
verifyWhatsNewTab: verifyWhatsNewTab,
verifyChatWithUsTab: verifyChatWithUsTab,
verifyMyProfileTab: verifyMyProfileTab,
verifyOrganizationTab: verifyOrganizationTab,
openProfileOrHelpCenter: _openProfileOrHelpCenter,
openWhatsNewPane: _openWhatsNewPane
};
//# sourceMappingURL=navigation.js.map