ToolJet/cypress-tests/cypress/support/utils/dashboard.js
Ajith KV 46abf0bdfe
Cypress test for dashboard, app and folder CRUD operations (#3677)
* Add and modify data-cy attribute for elements

* Add and modify common and dashboard selector and text

* Add task to delete download folder

* Modify faker file

* Add common methods

* Add methods specific for dashboard spec

* Modify dashboard spec

* Review changes

* Add and modify data-cy for elements

* Add custom command to verify elements

* Modify verify elements command

* Remove exported app file
2022-08-04 20:40:46 +05:30

66 lines
2.3 KiB
JavaScript

import { commonSelectors } from "Selectors/common";
import { dashboardSelector } from "Selectors/dashboard";
import { dashboardText } from "Texts/dashboard";
import { loginSelectors } from "Selectors/login";
import { commonText } from "Texts/common";
import {
viewAppCardOptions,
verifyModal,
closeModal,
cancelModal,
} from "Support/utils/common";
export const login = () => {
cy.visit("/");
cy.clearAndType(loginSelectors.emailField, "[email protected]");
cy.clearAndType(loginSelectors.passwordField, "password");
cy.get(loginSelectors.signInButton).click();
};
export const modifyAndVerifyAppCardIcon = (appName) => {
var random = function (obj) {
var keys = Object.keys(obj);
return obj[keys[(keys.length * Math.random()) << 0]];
};
const randomIcon = random(dashboardText.iconText);
cy.get(commonSelectors.appCardOptions(commonText.changeIconOption)).click();
verifyModal(dashboardText.changeIconTitle, dashboardText.changeButton);
for (const icons in dashboardText.iconText) {
cy.get(dashboardSelector.appIcon(dashboardText.iconText[icons])).should(
"be.visible"
);
}
closeModal(commonText.closeButton);
cy.get(dashboardSelector.appCardDefaultIcon).should("exist");
viewAppCardOptions(appName);
cy.get(commonSelectors.appCardOptions(commonText.changeIconOption)).click();
cy.get(dashboardSelector.appIcon(randomIcon)).click();
cancelModal(commonText.cancelButton);
cy.get(dashboardSelector.appCardDefaultIcon).should("exist");
viewAppCardOptions(appName);
cy.get(commonSelectors.appCardOptions(commonText.changeIconOption)).click();
cy.get(dashboardSelector.appIcon(randomIcon)).click();
cy.get(dashboardSelector.changeButton).click();
cy.verifyToastMessage(
commonSelectors.toastMessage,
dashboardText.iconUpdatedToast
);
cy.get(dashboardSelector.appCardIcon(randomIcon)).should("exist");
cy.get(dashboardText.modalComponent).should("not.exist");
};
export const verifyAppDelete = (appName) => {
cy.get("body").then(($title) => {
if (!$title.text().includes(commonText.introductionMessage)) {
cy.clearAndType(commonSelectors.homePageSearchBar, appName);
cy.get(commonSelectors.appCard(appName)).should("not.exist");
cy.get(commonSelectors.homePageSearchBar).clear();
}
});
};