diff --git a/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/Applications/ApplicationURL_spec.js b/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/Applications/ApplicationURL_spec.js index 935290225f..76f6a06c61 100644 --- a/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/Applications/ApplicationURL_spec.js +++ b/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/Applications/ApplicationURL_spec.js @@ -135,7 +135,9 @@ describe("Slug URLs", () => { `/app/${application.slug}/${currentPage.slug}-${currentPage.id}/edit`, ); - cy.visit(`/${application.slug}/${currentPage.slug}-${currentPage.id}/edit`); + cy.visit( + `/${application.slug}/${currentPage.slug}-${currentPage.id}/edit`, + ); cy.location().should((loc) => { expect(loc.pathname).includes( diff --git a/app/client/cypress/support/ApiCommands.js b/app/client/cypress/support/ApiCommands.js new file mode 100644 index 0000000000..646122c9cf --- /dev/null +++ b/app/client/cypress/support/ApiCommands.js @@ -0,0 +1,468 @@ +/* eslint-disable cypress/no-unnecessary-waiting */ +/* eslint-disable cypress/no-assigning-return-values */ + +require("cy-verify-downloads").addCustomCommand(); +require("cypress-file-upload"); + +const { + addMatchImageSnapshotCommand, +} = require("cypress-image-snapshot/command"); +import ApiEditor from "../locators/ApiEditor"; +const pages = require("../locators/Pages.json"); +const commonlocators = require("../locators/commonlocators.json"); +const apiwidget = require("../locators/apiWidgetslocator.json"); +const explorer = require("../locators/explorerlocators.json"); + +export const initLocalstorage = () => { + cy.window().then((window) => { + window.localStorage.setItem("ShowCommentsButtonToolTip", ""); + window.localStorage.setItem("updateDismissed", "true"); + }); +}; + +Cypress.Commands.add("enterDatasourceAndPath", (datasource, path) => { + cy.enterDatasource(datasource + path); +}); + +Cypress.Commands.add("enterDatasource", (datasource) => { + cy.get(apiwidget.resourceUrl) + .first() + .click({ force: true }) + .type(datasource, { parseSpecialCharSequences: false }) + .type("{esc}}"); +}); + +Cypress.Commands.add("ResponseStatusCheck", (statusCode) => { + cy.xpath(apiwidget.responseStatus).should("be.visible"); + cy.xpath(apiwidget.responseStatus).contains(statusCode); +}); + +Cypress.Commands.add("ResponseCheck", () => { + //Explicit assert + cy.get(apiwidget.responseText).should("be.visible"); +}); + +Cypress.Commands.add("ResponseTextCheck", (textTocheck) => { + cy.ResponseCheck(); + cy.get(apiwidget.responseText).contains(textTocheck); +}); + +Cypress.Commands.add("NavigateToAPI_Panel", () => { + cy.get(pages.addEntityAPI) + .last() + .should("be.visible") + .click({ force: true }); + cy.get(pages.integrationCreateNew) + .should("be.visible") + .click({ force: true }); + cy.get("#loading").should("not.exist"); +}); + +Cypress.Commands.add("CreateAPI", (apiname) => { + cy.get(explorer.createNew).click({ force: true }); + cy.get(explorer.blankAPI).click({ force: true }); + cy.wait("@createNewApi"); + cy.get(apiwidget.resourceUrl).should("be.visible"); + cy.renameWithInPane(apiname); + cy.WaitAutoSave(); + // Added because api name edit takes some time to + // reflect in api sidebar after the call passes. + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(2000); +}); + +Cypress.Commands.add("CreateSubsequentAPI", (apiname) => { + cy.get(apiwidget.createApiOnSideBar) + .first() + .click({ force: true }); + cy.get(apiwidget.resourceUrl).should("be.visible"); + // cy.get(ApiEditor.nameOfApi) + cy.get(apiwidget.apiTxt) + .clear() + .type(apiname) + .should("have.value", apiname); + cy.WaitAutoSave(); +}); + +Cypress.Commands.add("EditApiName", (apiname) => { + cy.get(apiwidget.ApiName).click({ force: true }); + cy.get(apiwidget.apiTxt) + .clear() + .type(apiname, { force: true }) + .should("have.value", apiname); +}); + +Cypress.Commands.add("EditApiNameFromExplorer", (apiname) => { + /* + cy.xpath(apiwidget.popover) + .last() + .click({ force: true }); + cy.get(apiwidget.editName).click({ force: true }); + */ + cy.get(explorer.editNameField) + .clear() + .type(apiname, { force: true }) + .should("have.value", apiname) + .blur(); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(3000); +}); + +Cypress.Commands.add("RunAPI", () => { + cy.get(ApiEditor.ApiRunBtn).click({ force: true }); + cy.wait("@postExecute"); +}); + +Cypress.Commands.add("SaveAndRunAPI", () => { + cy.WaitAutoSave(); + cy.RunAPI(); +}); + +Cypress.Commands.add( + "validateRequest", + (apiName, baseurl, path, verb, error = false) => { + cy.get(".react-tabs__tab") + .contains("Logs") + .click(); + cy.get("[data-cy=t--debugger-search]") + .clear() + .type(apiName); + + if (!error) { + cy.get(".object-key") + .last() + .contains("request") + .click(); + } + cy.get(".string-value").contains(baseurl.concat(path)); + cy.get(".string-value").contains(verb); + cy.get("[data-cy=t--tab-body]") + .first() + .click({ force: true }); + }, +); + +Cypress.Commands.add( + "EnterSourceDetailsWithHeader", + (baseUrl, v1method, hKey, hValue) => { + cy.enterDatasourceAndPath(baseUrl, v1method); + cy.get(apiwidget.headerKey) + .first() + .click({ force: true }) + .type(hKey, { parseSpecialCharSequences: true }); + cy.get(apiwidget.headerValue) + .first() + .click({ force: true }) + .type(hValue, { parseSpecialCharSequences: true }); + cy.WaitAutoSave(); + }, +); + +Cypress.Commands.add("EditSourceDetail", (baseUrl, v1method) => { + cy.get(apiwidget.editResourceUrl) + .first() + .click({ force: true }) + .clear() + .type(`{backspace}${baseUrl}`); + cy.xpath(apiwidget.autoSuggest) + .first() + .click({ force: true }); + cy.get(ApiEditor.ApiRunBtn).scrollIntoView(); + cy.get(apiwidget.editResourceUrl) + .first() + .focus() + .type(v1method) + .should("have.value", v1method); + cy.WaitAutoSave(); +}); + +Cypress.Commands.add("switchToAPIInputTab", () => { + cy.get(apiwidget.apiInputTab) + .first() + .click({ force: true }); +}); + +Cypress.Commands.add("enterUrl", (apiname, url, value) => { + cy.get(url) + .first() + .type("{{".concat(apiname).concat(value), { + force: true, + parseSpecialCharSequences: false, + }); +}); + +Cypress.Commands.add( + "EnterSourceDetailsWithQueryParam", + (baseUrl, v1method, hKey, hValue, qKey, qValue) => { + cy.enterDatasourceAndPath(baseUrl, v1method); + cy.get(apiwidget.headerKey) + .first() + .click({ force: true }) + .type(hKey, { parseSpecialCharSequences: true }); + cy.get(apiwidget.headerValue) + .first() + .click({ force: true }) + .type(hValue, { parseSpecialCharSequences: true }); + cy.get(apiwidget.queryKey) + .first() + .click({ force: true }) + .type(qKey, { force: true }) + .should("have.value", qKey); + cy.get(apiwidget.queryValue) + .first() + .click({ force: true }) + .type(qValue, { force: true }) + .should("have.value", qValue); + cy.WaitAutoSave(); + }, +); + +Cypress.Commands.add("EnterSourceDetailsWithbody", (baseUrl, v1method) => { + cy.enterDatasourceAndPath(baseUrl, v1method); + cy.get(apiwidget.addHeader) + .first() + .click({ first: true }); +}); + +Cypress.Commands.add("CreationOfUniqueAPIcheck", (apiname) => { + cy.get(pages.addEntityAPI).click(); + cy.get(pages.integrationCreateNew) + .should("be.visible") + .click({ force: true }); + cy.get(apiwidget.createapi).click({ force: true }); + cy.wait("@createNewApi"); + // cy.wait("@getUser"); + cy.get(apiwidget.resourceUrl).should("be.visible"); + cy.get(apiwidget.ApiName).click({ force: true }); + cy.get(apiwidget.apiTxt) + .clear() + .focus() + .type(apiname, { force: true, delay: 500 }) + .should("have.value", apiname); + cy.get(".t--action-name-edit-error").should(($x) => { + expect($x).contain( + apiname.concat(" is already being used or is a restricted keyword."), + ); + }); + cy.get(apiwidget.apiTxt).blur(); +}); + +Cypress.Commands.add("MoveAPIToHome", () => { + cy.xpath(apiwidget.popover) + .last() + .click({ force: true }); + cy.get(apiwidget.copyTo).click({ force: true }); + cy.get(apiwidget.home).click({ force: true }); + cy.wait("@createNewApi").should( + "have.nested.property", + "response.body.responseMeta.status", + 201, + ); +}); + +Cypress.Commands.add("MoveAPIToPage", (pageName) => { + cy.xpath(apiwidget.popover) + .last() + .click({ force: true }); + cy.get(apiwidget.moveTo).click({ force: true }); + cy.get(apiwidget.page) + .contains(pageName) + .click({ force: true }); + cy.wait("@moveAction").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); +}); + +Cypress.Commands.add("copyEntityToPage", (pageName) => { + cy.xpath(apiwidget.popover) + .last() + .click({ force: true }); + cy.get(apiwidget.copyTo).click({ force: true }); + cy.get(apiwidget.page) + .contains(pageName) + .click({ force: true }); + cy.wait("@createNewApi").should( + "have.nested.property", + "response.body.responseMeta.status", + 201, + ); +}); + +Cypress.Commands.add("CopyAPIToHome", () => { + cy.xpath(apiwidget.popover) + .last() + .click({ force: true }); + cy.get(apiwidget.copyTo).click({ force: true }); + cy.get(apiwidget.home).click({ force: true }); + cy.wait("@createNewApi").should( + "have.nested.property", + "response.body.responseMeta.status", + 201, + ); +}); + +Cypress.Commands.add("RenameEntity", (value, selectFirst) => { + if (selectFirst) { + cy.xpath(apiwidget.popover) + .first() + .click({ force: true }); + } else { + cy.xpath(apiwidget.popover) + .last() + .click({ force: true }); + } + + cy.get(apiwidget.renameEntity).click({ force: true }); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(2000); + cy.get(explorer.editEntity) + .last() + .type(value, { force: true }); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(3000); +}); + +Cypress.Commands.add("CreateApiAndValidateUniqueEntityName", (apiname) => { + cy.get(apiwidget.createapi).click({ force: true }); + cy.wait("@createNewApi"); + cy.get(apiwidget.resourceUrl).should("be.visible"); + cy.get(apiwidget.ApiName).click({ force: true }); + cy.get(apiwidget.apiTxt) + .clear() + .type(apiname, { force: true }) + .should("have.value", apiname); + cy.get(".t--action-name-edit-error").should(($x) => { + expect($x).contain( + apiname.concat(" is already being used or is a restricted keyword."), + ); + }); +}); + +Cypress.Commands.add("validateMessage", (value) => { + cy.get(".bp3-popover-content").should(($x) => { + expect($x).contain(value.concat(" is already being used.")); + }); +}); + +Cypress.Commands.add( + "VerifyPopOverMessage", + (msgAbsenceToVerify, presence = false) => { + // Give this element 3 seconds to appear + let shouldCondition = "not.exist"; + if (presence) shouldCondition = "exist"; + cy.xpath( + "//div[@class='bp3-popover-content'][contains(text(),'" + + msgAbsenceToVerify + + "')]", + { timeout: 3000 }, + ).should(shouldCondition); + }, +); + +Cypress.Commands.add("DeleteAPIFromSideBar", () => { + cy.deleteEntity(); + cy.wait("@deleteAction").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); +}); + +Cypress.Commands.add("DeleteWidgetFromSideBar", () => { + cy.xpath(apiwidget.popover) + .last() + .click({ force: true }); + cy.get(apiwidget.delete).click({ force: true }); + cy.wait("@updateLayout").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); +}); + +Cypress.Commands.add("deleteEntity", () => { + cy.xpath(apiwidget.popover) + .last() + .click({ force: true }); + cy.get(apiwidget.delete).click({ force: true }); + cy.get(apiwidget.deleteConfirm).click({ force: true }); +}); + +Cypress.Commands.add("deleteEntityWithoutConfirmation", () => { + cy.xpath(apiwidget.popover) + .last() + .click({ force: true }); + cy.get(apiwidget.delete).click({ force: true }); +}); + +Cypress.Commands.add("DeleteAPI", () => { + cy.get(ApiEditor.ApiActionMenu).click({ multiple: true }); + cy.get(apiwidget.deleteAPI) + .first() + .click({ force: true }); + cy.get(apiwidget.deleteAPI) + .first() + .click({ force: true }); + cy.wait("@deleteAction").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); +}); + +Cypress.Commands.add("NavigateToApiEditor", () => { + cy.get(explorer.addEntityAPI).click({ force: true }); +}); + +Cypress.Commands.add("testCreateApiButton", () => { + cy.get(ApiEditor.createBlankApiCard).click({ force: true }); + cy.wait("@createNewApi").should( + "have.nested.property", + "response.body.responseMeta.status", + 201, + ); +}); + +Cypress.Commands.add("createAndFillApi", (url, parameters) => { + cy.NavigateToApiEditor(); + cy.get(pages.integrationCreateNew) + .should("be.visible") + .click({ force: true }); + cy.testCreateApiButton(); + cy.get("@createNewApi").then((response) => { + cy.get(ApiEditor.ApiNameField).should("be.visible"); + expect(response.response.body.responseMeta.success).to.eq(true); + cy.get(ApiEditor.ApiNameField) + .click() + .invoke("text") + .then((text) => { + const someText = text; + expect(someText).to.equal(response.response.body.data.name); + }); + }); + cy.get(apiwidget.editResourceUrl) + .first() + .click({ force: true }) + .type( + url + parameters, + { parseSpecialCharSequences: false }, + { force: true }, + ); + cy.WaitAutoSave(); + cy.get(ApiEditor.formActionButtons).should("be.visible"); + cy.get(ApiEditor.ApiRunBtn).should("not.be.disabled"); +}); + +Cypress.Commands.add("callApi", (apiname) => { + cy.get(commonlocators.callApi) + .first() + .click({ force: true }); + cy.get(commonlocators.singleSelectMenuItem) + .contains("Execute a query") + .click({ force: true }); + cy.get(commonlocators.selectMenuItem) + .contains(apiname) + .click({ force: true }); +}); diff --git a/app/client/cypress/support/OrgCommands.js b/app/client/cypress/support/OrgCommands.js new file mode 100644 index 0000000000..a6a56c54ba --- /dev/null +++ b/app/client/cypress/support/OrgCommands.js @@ -0,0 +1,304 @@ +/* eslint-disable cypress/no-unnecessary-waiting */ +/* eslint-disable cypress/no-assigning-return-values */ +/* Contains all methods related to Organisation features*/ + +require("cy-verify-downloads").addCustomCommand(); +require("cypress-file-upload"); + +const { + addMatchImageSnapshotCommand, +} = require("cypress-image-snapshot/command"); +import homePage from "../locators/HomePage"; +const generatePage = require("../locators/GeneratePage.json"); + +export const initLocalstorage = () => { + cy.window().then((window) => { + window.localStorage.setItem("ShowCommentsButtonToolTip", ""); + window.localStorage.setItem("updateDismissed", "true"); + }); +}; + +Cypress.Commands.add("createOrg", () => { + cy.get(homePage.createOrg) + .should("be.visible") + .first() + .click({ force: true }); +}); + +Cypress.Commands.add("renameOrg", (orgName, newOrgName) => { + cy.contains(orgName) + .closest(homePage.orgCompleteSection) + .find(homePage.orgNamePopover) + .find(homePage.optionsIcon) + .click({ force: true }); + cy.get(homePage.renameOrgInput) + .should("be.visible") + .type(newOrgName.concat("{enter}")); + cy.wait(3000); + //cy.get(commonlocators.homeIcon).click({ force: true }); + cy.wait("@updateOrganization").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + cy.contains(newOrgName); +}); + +Cypress.Commands.add("navigateToOrgSettings", (orgName) => { + cy.get(homePage.orgList.concat(orgName).concat(")")) + .scrollIntoView() + .should("be.visible"); + cy.get(homePage.orgList.concat(orgName).concat(")")) + .closest(homePage.orgCompleteSection) + .find(homePage.orgNamePopover) + .find(homePage.optionsIcon) + .click({ force: true }); + cy.xpath(homePage.MemberSettings).click({ force: true }); + cy.wait("@getMembers").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + cy.get(homePage.inviteUserMembersPage).should("be.visible"); +}); + +Cypress.Commands.add("openOrgOptionsPopup", (orgName) => { + cy.get(homePage.orgList.concat(orgName).concat(")")) + .scrollIntoView() + .should("be.visible"); + cy.get(homePage.orgList.concat(orgName).concat(")")) + .closest(homePage.orgCompleteSection) + .find(homePage.orgNamePopover) + .find(homePage.optionsIcon) + .click({ force: true }); +}); + +Cypress.Commands.add("inviteUserForOrg", (orgName, email, role) => { + cy.stubPostHeaderReq(); + cy.get(homePage.orgList.concat(orgName).concat(")")) + .scrollIntoView() + .should("be.visible"); + cy.get(homePage.orgList.concat(orgName).concat(homePage.shareOrg)) + .first() + .should("be.visible") + .click({ force: true }); + cy.xpath(homePage.email) + .click({ force: true }) + .type(email); + cy.xpath(homePage.selectRole).click({ force: true }); + cy.wait(500); + cy.xpath(role).click({ force: true }); + cy.xpath(homePage.inviteBtn).click({ force: true }); + cy.wait("@mockPostInvite") + .its("request.headers") + .should("have.property", "origin", "Cypress"); + cy.contains(email, { matchCase: false }); +}); + +Cypress.Commands.add("CheckShareIcon", (orgName, count) => { + cy.get(homePage.orgList.concat(orgName).concat(")")) + .scrollIntoView() + .should("be.visible"); + cy.get( + homePage.orgList.concat(orgName).concat(") .org-share-user-icons"), + ).should("have.length", count); +}); + +Cypress.Commands.add("shareApp", (email, role) => { + cy.stubPostHeaderReq(); + cy.xpath(homePage.email) + .click({ force: true }) + .type(email); + cy.xpath(homePage.selectRole).click({ force: true }); + cy.xpath(role).click({ force: true }); + cy.xpath(homePage.inviteBtn).click({ force: true }); + cy.wait("@mockPostInvite") + .its("request.headers") + .should("have.property", "origin", "Cypress"); + cy.contains(email, { matchCase: false }); + cy.get(homePage.closeBtn).click(); +}); + +Cypress.Commands.add("shareAndPublic", (email, role) => { + cy.stubPostHeaderReq(); + cy.xpath(homePage.email) + .click({ force: true }) + .type(email); + cy.xpath(homePage.selectRole).click({ force: true }); + cy.xpath(role).click({ force: true }); + cy.xpath(homePage.inviteBtn).click({ force: true }); + cy.wait("@mockPostInvite") + .its("request.headers") + .should("have.property", "origin", "Cypress"); + cy.contains(email, { matchCase: false }); + cy.enablePublicAccess(); +}); + +Cypress.Commands.add("enablePublicAccess", () => { + cy.get(homePage.enablePublicAccess).click(); + cy.wait("@changeAccess").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + cy.get(homePage.closeBtn).click(); +}); + +Cypress.Commands.add("deleteUserFromOrg", (orgName) => { + cy.get(homePage.orgList.concat(orgName).concat(")")) + .scrollIntoView() + .should("be.visible"); + cy.get(homePage.orgList.concat(orgName).concat(")")) + .closest(homePage.orgCompleteSection) + .find(homePage.orgNamePopover) + .find(homePage.optionsIcon) + .click({ force: true }); + cy.xpath(homePage.MemberSettings).click({ force: true }); + cy.wait("@getRoles").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + cy.get(homePage.DeleteBtn) + .last() + .click({ force: true }); + cy.get(homePage.leaveOrgConfirmModal).should("be.visible"); + cy.get(homePage.leaveOrgConfirmButton).click({ force: true }); + cy.xpath(homePage.appHome) + .first() + .should("be.visible") + .click(); + cy.wait("@applications").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); +}); + +Cypress.Commands.add("updateUserRoleForOrg", (orgName, email, role) => { + cy.stubPostHeaderReq(); + cy.get(homePage.orgList.concat(orgName).concat(")")) + .scrollIntoView() + .should("be.visible"); + cy.get(homePage.orgList.concat(orgName).concat(")")) + .closest(homePage.orgCompleteSection) + .find(homePage.orgNamePopover) + .find(homePage.optionsIcon) + .click({ force: true }); + cy.xpath(homePage.MemberSettings).click({ force: true }); + cy.wait("@getMembers").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + cy.get(homePage.inviteUserMembersPage).click({ force: true }); + cy.xpath(homePage.email) + .click({ force: true }) + .type(email); + cy.xpath(homePage.selectRole).click({ force: true }); + cy.xpath(role).click({ force: true }); + cy.xpath(homePage.inviteBtn).click({ force: true }); + cy.wait("@mockPostInvite") + .its("request.headers") + .should("have.property", "origin", "Cypress"); + cy.contains(email, { matchCase: false }); + cy.get(".bp3-icon-small-cross").click({ force: true }); + cy.xpath(homePage.appHome) + .first() + .should("be.visible") + .click(); + cy.wait("@applications").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); +}); + +Cypress.Commands.add("launchApp", () => { + cy.get(homePage.appView) + .should("be.visible") + .first() + .click(); + cy.get("#loading").should("not.exist"); + cy.wait("@getPagesForViewApp").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); +}); + +Cypress.Commands.add("AppSetupForRename", () => { + cy.get(homePage.applicationName).then(($appName) => { + if (!$appName.hasClass(homePage.editingAppName)) { + cy.get(homePage.applicationName).click({ force: true }); + cy.get(homePage.portalMenuItem) + .contains("Edit Name", { matchCase: false }) + .click({ force: true }); + } + }); +}); + +Cypress.Commands.add("CreateAppForOrg", (orgName, appname) => { + cy.get(homePage.orgList.concat(orgName).concat(homePage.createAppFrOrg)) + .scrollIntoView() + .should("be.visible") + .click({ force: true }); + cy.wait("@createNewApplication").then((xhr) => { + const response = xhr.response; + expect(response.body.responseMeta.status).to.eq(201); + localStorage.setItem("applicationId", response.body.data.id); + cy.wrap(response.body.data.id).as("currentApplicationId"); + }); + + cy.get("#loading").should("not.exist"); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(2000); + + cy.AppSetupForRename(); + cy.get(homePage.applicationName).type(appname + "{enter}"); + + cy.get(generatePage.buildFromScratchActionCard).click(); + + cy.wait("@updateApplication").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); +}); + +Cypress.Commands.add("CreateAppInFirstListedOrg", (appname) => { + let applicationId; + cy.get(homePage.createNew) + .first() + .click({ force: true }); + cy.wait("@createNewApplication").then((xhr) => { + const response = xhr.response; + expect(response.body.responseMeta.status).to.eq(201); + applicationId = response.body.data.id; + localStorage.setItem("applicationId", applicationId); + }); + cy.get("#loading").should("not.exist"); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(2000); + cy.AppSetupForRename(); + cy.get(homePage.applicationName).type(appname + "{enter}"); + cy.wait("@updateApplication").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + + cy.waitUntil(() => cy.get(generatePage.buildFromScratchActionCard), { + errorMsg: "Build app from scratch not visible even aft 80 secs", + timeout: 20000, + interval: 1000, + }).then(($ele) => cy.wrap($ele).should("be.visible")); + + cy.get(generatePage.buildFromScratchActionCard).click(); + + /* The server created app always has an old dsl so the layout will migrate + * To avoid race conditions between that update layout and this one + * we wait for that to finish before updating layout here + */ + cy.wait("@updateLayout"); +}); diff --git a/app/client/cypress/support/commands.js b/app/client/cypress/support/commands.js index e05f7b9c3f..d6c8d1026e 100644 --- a/app/client/cypress/support/commands.js +++ b/app/client/cypress/support/commands.js @@ -1,6 +1,8 @@ /* eslint-disable cypress/no-unnecessary-waiting */ /* eslint-disable cypress/no-assigning-return-values */ +/* This file is used to maintain comman methods across tests , refer other *.js files for adding common methods */ + require("cy-verify-downloads").addCustomCommand(); require("cypress-file-upload"); @@ -46,32 +48,6 @@ export const initLocalstorage = () => { }); }; -Cypress.Commands.add("createOrg", () => { - cy.get(homePage.createOrg) - .should("be.visible") - .first() - .click({ force: true }); -}); - -Cypress.Commands.add("renameOrg", (orgName, newOrgName) => { - cy.contains(orgName) - .closest(homePage.orgCompleteSection) - .find(homePage.orgNamePopover) - .find(homePage.optionsIcon) - .click({ force: true }); - cy.get(homePage.renameOrgInput) - .should("be.visible") - .type(newOrgName.concat("{enter}")); - cy.wait(3000); - //cy.get(commonlocators.homeIcon).click({ force: true }); - cy.wait("@updateOrganization").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); - cy.contains(newOrgName); -}); - Cypress.Commands.add("goToEditFromPublish", () => { cy.url().then((url) => { const urlObject = new URL(url); @@ -134,272 +110,12 @@ Cypress.Commands.add( }, ); -Cypress.Commands.add("navigateToOrgSettings", (orgName) => { - cy.get(homePage.orgList.concat(orgName).concat(")")) - .scrollIntoView() - .should("be.visible"); - cy.get(homePage.orgList.concat(orgName).concat(")")) - .closest(homePage.orgCompleteSection) - .find(homePage.orgNamePopover) - .find(homePage.optionsIcon) - .click({ force: true }); - cy.xpath(homePage.MemberSettings).click({ force: true }); - cy.wait("@getMembers").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); - cy.get(homePage.inviteUserMembersPage).should("be.visible"); -}); - -Cypress.Commands.add("openOrgOptionsPopup", (orgName) => { - cy.get(homePage.orgList.concat(orgName).concat(")")) - .scrollIntoView() - .should("be.visible"); - cy.get(homePage.orgList.concat(orgName).concat(")")) - .closest(homePage.orgCompleteSection) - .find(homePage.orgNamePopover) - .find(homePage.optionsIcon) - .click({ force: true }); -}); - -Cypress.Commands.add("inviteUserForOrg", (orgName, email, role) => { - cy.stubPostHeaderReq(); - cy.get(homePage.orgList.concat(orgName).concat(")")) - .scrollIntoView() - .should("be.visible"); - cy.get(homePage.orgList.concat(orgName).concat(homePage.shareOrg)) - .first() - .should("be.visible") - .click({ force: true }); - cy.xpath(homePage.email) - .click({ force: true }) - .type(email); - cy.xpath(homePage.selectRole).click({ force: true }); - cy.wait(500); - cy.xpath(role).click({ force: true }); - cy.xpath(homePage.inviteBtn).click({ force: true }); - cy.wait("@mockPostInvite") - .its("request.headers") - .should("have.property", "origin", "Cypress"); - cy.contains(email, { matchCase: false }); -}); - -Cypress.Commands.add("CheckShareIcon", (orgName, count) => { - cy.get(homePage.orgList.concat(orgName).concat(")")) - .scrollIntoView() - .should("be.visible"); - cy.get( - homePage.orgList.concat(orgName).concat(") .org-share-user-icons"), - ).should("have.length", count); -}); - Cypress.Commands.add("stubPostHeaderReq", () => { cy.intercept("POST", "/api/v1/users/invite", (req) => { req.headers["origin"] = "Cypress"; }).as("mockPostInvite"); }); -Cypress.Commands.add("shareApp", (email, role) => { - cy.stubPostHeaderReq(); - cy.xpath(homePage.email) - .click({ force: true }) - .type(email); - cy.xpath(homePage.selectRole).click({ force: true }); - cy.xpath(role).click({ force: true }); - cy.xpath(homePage.inviteBtn).click({ force: true }); - cy.wait("@mockPostInvite") - .its("request.headers") - .should("have.property", "origin", "Cypress"); - cy.contains(email, { matchCase: false }); - cy.get(homePage.closeBtn).click(); -}); - -Cypress.Commands.add("shareAndPublic", (email, role) => { - cy.stubPostHeaderReq(); - cy.xpath(homePage.email) - .click({ force: true }) - .type(email); - cy.xpath(homePage.selectRole).click({ force: true }); - cy.xpath(role).click({ force: true }); - cy.xpath(homePage.inviteBtn).click({ force: true }); - cy.wait("@mockPostInvite") - .its("request.headers") - .should("have.property", "origin", "Cypress"); - cy.contains(email, { matchCase: false }); - cy.enablePublicAccess(); -}); - -Cypress.Commands.add("enablePublicAccess", () => { - cy.get(homePage.enablePublicAccess).click(); - cy.wait("@changeAccess").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); - cy.get(homePage.closeBtn).click(); -}); - -Cypress.Commands.add("deleteUserFromOrg", (orgName, email) => { - cy.get(homePage.orgList.concat(orgName).concat(")")) - .scrollIntoView() - .should("be.visible"); - cy.get(homePage.orgList.concat(orgName).concat(")")) - .closest(homePage.orgCompleteSection) - .find(homePage.orgNamePopover) - .find(homePage.optionsIcon) - .click({ force: true }); - cy.xpath(homePage.MemberSettings).click({ force: true }); - cy.wait("@getRoles").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); - cy.get(homePage.DeleteBtn) - .last() - .click({ force: true }); - cy.get(homePage.leaveOrgConfirmModal).should("be.visible"); - cy.get(homePage.leaveOrgConfirmButton).click({ force: true }); - cy.xpath(homePage.appHome) - .first() - .should("be.visible") - .click(); - cy.wait("@applications").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); -}); - -Cypress.Commands.add("updateUserRoleForOrg", (orgName, email, role) => { - cy.stubPostHeaderReq(); - cy.get(homePage.orgList.concat(orgName).concat(")")) - .scrollIntoView() - .should("be.visible"); - cy.get(homePage.orgList.concat(orgName).concat(")")) - .closest(homePage.orgCompleteSection) - .find(homePage.orgNamePopover) - .find(homePage.optionsIcon) - .click({ force: true }); - cy.xpath(homePage.MemberSettings).click({ force: true }); - cy.wait("@getMembers").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); - cy.get(homePage.inviteUserMembersPage).click({ force: true }); - cy.xpath(homePage.email) - .click({ force: true }) - .type(email); - cy.xpath(homePage.selectRole).click({ force: true }); - cy.xpath(role).click({ force: true }); - cy.xpath(homePage.inviteBtn).click({ force: true }); - cy.wait("@mockPostInvite") - .its("request.headers") - .should("have.property", "origin", "Cypress"); - cy.contains(email, { matchCase: false }); - cy.get(".bp3-icon-small-cross").click({ force: true }); - cy.xpath(homePage.appHome) - .first() - .should("be.visible") - .click(); - cy.wait("@applications").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); -}); - -Cypress.Commands.add("launchApp", (appName) => { - cy.get(homePage.appView) - .should("be.visible") - .first() - .click(); - cy.get("#loading").should("not.exist"); - cy.wait("@getPagesForViewApp").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); -}); - -Cypress.Commands.add("AppSetupForRename", () => { - cy.get(homePage.applicationName).then(($appName) => { - if (!$appName.hasClass(homePage.editingAppName)) { - cy.get(homePage.applicationName).click({ force: true }); - cy.get(homePage.portalMenuItem) - .contains("Edit Name", { matchCase: false }) - .click({ force: true }); - } - }); -}); - -Cypress.Commands.add("CreateAppForOrg", (orgName, appname) => { - cy.get(homePage.orgList.concat(orgName).concat(homePage.createAppFrOrg)) - .scrollIntoView() - .should("be.visible") - .click({ force: true }); - cy.wait("@createNewApplication").then((xhr) => { - const response = xhr.response; - expect(response.body.responseMeta.status).to.eq(201); - localStorage.setItem("applicationId", response.body.data.id); - cy.wrap(response.body.data.id).as("currentApplicationId"); - }); - - cy.get("#loading").should("not.exist"); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(2000); - - cy.AppSetupForRename(); - cy.get(homePage.applicationName).type(appname + "{enter}"); - - cy.get(generatePage.buildFromScratchActionCard).click(); - - cy.wait("@updateApplication").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); -}); - -Cypress.Commands.add("CreateAppInFirstListedOrg", (appname) => { - let applicationId; - cy.get(homePage.createNew) - .first() - .click({ force: true }); - cy.wait("@createNewApplication").then((xhr) => { - const response = xhr.response; - expect(response.body.responseMeta.status).to.eq(201); - applicationId = response.body.data.id; - localStorage.setItem("applicationId", applicationId); - }); - cy.get("#loading").should("not.exist"); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(2000); - - cy.AppSetupForRename(); - cy.get(homePage.applicationName).type(appname + "{enter}"); - cy.wait("@updateApplication").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); - - cy.waitUntil(() => cy.get(generatePage.buildFromScratchActionCard), { - errorMsg: "Build app from scratch not visible even aft 80 secs", - timeout: 20000, - interval: 1000, - }).then(($ele) => cy.wrap($ele).should("be.visible")); - - cy.get(generatePage.buildFromScratchActionCard).click(); - - /* The server created app always has an old dsl so the layout will migrate - * To avoid race conditions between that update layout and this one - * we wait for that to finish before updating layout here - */ - cy.wait("@updateLayout"); -}); - Cypress.Commands.add( "addOauthAuthDetails", (accessTokenUrl, clientId, clientSecret, authURL) => { @@ -432,23 +148,6 @@ Cypress.Commands.add("addBasicProfileDetails", (username, password) => { cy.get(datasource.basicPassword).type(password); }); -Cypress.Commands.add("firestoreDatasourceForm", () => { - cy.get(datasourceEditor.datasourceConfigUrl).type( - datasourceFormData["database-url"], - ); - cy.get(datasourceEditor.projectID).type(datasourceFormData["projectID"]); - cy.get(datasourceEditor.serviceAccCredential) - .clear() - .type(datasourceFormData["serviceAccCredentials"]); -}); - -Cypress.Commands.add("amazonDatasourceForm", () => { - cy.get(datasourceEditor.projectID).type(datasourceFormData["access_key"]); - cy.get(datasourceEditor.serviceAccCredential) - .clear() - .type(datasourceFormData["secret_key"]); -}); - Cypress.Commands.add("DeleteApp", (appName) => { cy.get(commonlocators.homeIcon).click({ force: true }); cy.wait("@applications").should( @@ -637,82 +336,6 @@ Cypress.Commands.add("GlobalSearchEntity", (apiname1, dontAssertVisibility) => { } }); -Cypress.Commands.add("ResponseStatusCheck", (statusCode) => { - cy.xpath(apiwidget.responseStatus).should("be.visible"); - cy.xpath(apiwidget.responseStatus).contains(statusCode); -}); - -Cypress.Commands.add("ResponseCheck", (textTocheck) => { - //Explicit assert - cy.get(apiwidget.responseText).should("be.visible"); -}); - -Cypress.Commands.add("ResponseTextCheck", (textTocheck) => { - cy.ResponseCheck(); - cy.get(apiwidget.responseText).contains(textTocheck); -}); - -Cypress.Commands.add("NavigateToAPI_Panel", () => { - cy.get(pages.addEntityAPI) - .last() - .should("be.visible") - .click({ force: true }); - cy.get(pages.integrationCreateNew) - .should("be.visible") - .click({ force: true }); - cy.get("#loading").should("not.exist"); -}); - -Cypress.Commands.add("CreateAPI", (apiname) => { - cy.get(explorer.createNew).click({ force: true }); - cy.get(explorer.blankAPI).click({ force: true }); - cy.wait("@createNewApi"); - cy.get(apiwidget.resourceUrl).should("be.visible"); - cy.renameWithInPane(apiname); - cy.WaitAutoSave(); - // Added because api name edit takes some time to - // reflect in api sidebar after the call passes. - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(2000); -}); - -Cypress.Commands.add("CreateSubsequentAPI", (apiname) => { - cy.get(apiwidget.createApiOnSideBar) - .first() - .click({ force: true }); - cy.get(apiwidget.resourceUrl).should("be.visible"); - // cy.get(ApiEditor.nameOfApi) - cy.get(apiwidget.apiTxt) - .clear() - .type(apiname) - .should("have.value", apiname); - cy.WaitAutoSave(); -}); - -Cypress.Commands.add("EditApiName", (apiname) => { - cy.get(apiwidget.ApiName).click({ force: true }); - cy.get(apiwidget.apiTxt) - .clear() - .type(apiname, { force: true }) - .should("have.value", apiname); -}); - -Cypress.Commands.add("EditApiNameFromExplorer", (apiname) => { - /* - cy.xpath(apiwidget.popover) - .last() - .click({ force: true }); - cy.get(apiwidget.editName).click({ force: true }); - */ - cy.get(explorer.editNameField) - .clear() - .type(apiname, { force: true }) - .should("have.value", apiname) - .blur(); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(3000); -}); - Cypress.Commands.add( "EditEntityNameByDoubleClick", (entityName, updatedName) => { @@ -739,40 +362,6 @@ Cypress.Commands.add("WaitAutoSave", () => { //cy.wait("@postExecute"); }); -Cypress.Commands.add("RunAPI", () => { - cy.get(ApiEditor.ApiRunBtn).click({ force: true }); - cy.wait("@postExecute"); -}); - -Cypress.Commands.add("SaveAndRunAPI", () => { - cy.WaitAutoSave(); - cy.RunAPI(); -}); - -Cypress.Commands.add( - "validateRequest", - (apiName, baseurl, path, verb, error = false) => { - cy.get(".react-tabs__tab") - .contains("Logs") - .click(); - cy.get("[data-cy=t--debugger-search]") - .clear() - .type(apiName); - - if (!error) { - cy.get(".object-key") - .last() - .contains("request") - .click(); - } - cy.get(".string-value").contains(baseurl.concat(path)); - cy.get(".string-value").contains(verb); - cy.get("[data-cy=t--tab-body]") - .first() - .click({ force: true }); - }, -); - Cypress.Commands.add("SelectAction", (action) => { cy.get(ApiEditor.ApiVerb) .first() @@ -888,155 +477,6 @@ Cypress.Commands.add("SearchEntityandDblClick", (apiname1) => { .last(); }); -Cypress.Commands.add("enterDatasourceAndPath", (datasource, path) => { - cy.enterDatasource(datasource + path); -}); - -Cypress.Commands.add("enterDatasource", (datasource) => { - cy.get(apiwidget.resourceUrl) - .first() - .click({ force: true }) - .type(datasource, { parseSpecialCharSequences: false }) - .type("{esc}}"); -}); - -Cypress.Commands.add("changeZoomLevel", (zoomValue) => { - cy.get(commonlocators.changeZoomlevel) - .last() - .click(); - cy.get(".t--dropdown-option") - .children() - .contains(zoomValue) - .click(); - cy.wait("@updateLayout").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); - cy.get(commonlocators.selectedZoomlevel) - .last() - .invoke("text") - .then((text) => { - const someText = text; - expect(someText).to.equal(zoomValue); - }); -}); - -Cypress.Commands.add("changeColumnType", (dataType) => { - cy.get(commonlocators.changeColType) - .last() - .click(); - cy.get(".t--dropdown-option") - .children() - .contains(dataType) - .click(); - cy.wait("@updateLayout").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); - /* - cy.get(commonlocators.selectedColType) - .first() - .invoke("text") - .then((text) => { - const someText = text; - expect(someText).to.equal(dataType); - }); - */ -}); - -Cypress.Commands.add( - "EnterSourceDetailsWithHeader", - (baseUrl, v1method, hKey, hValue) => { - cy.enterDatasourceAndPath(baseUrl, v1method); - cy.get(apiwidget.headerKey) - .first() - .click({ force: true }) - .type(hKey, { parseSpecialCharSequences: true }); - cy.get(apiwidget.headerValue) - .first() - .click({ force: true }) - .type(hValue, { parseSpecialCharSequences: true }); - cy.WaitAutoSave(); - }, -); - -Cypress.Commands.add("EditSourceDetail", (baseUrl, v1method) => { - cy.get(apiwidget.editResourceUrl) - .first() - .click({ force: true }) - .clear() - .type(`{backspace}${baseUrl}`); - cy.xpath(apiwidget.autoSuggest) - .first() - .click({ force: true }); - cy.get(ApiEditor.ApiRunBtn).scrollIntoView(); - cy.get(apiwidget.editResourceUrl) - .first() - .focus() - .type(v1method) - .should("have.value", v1method); - cy.WaitAutoSave(); -}); - -Cypress.Commands.add("switchToPaginationTab", () => { - cy.get(apiwidget.paginationTab) - .first() - .click({ force: true }); -}); - -Cypress.Commands.add("switchToAPIInputTab", () => { - cy.get(apiwidget.apiInputTab) - .first() - .click({ force: true }); -}); - -Cypress.Commands.add("selectDateFormat", (value) => { - cy.get(".t--property-control-dateformat .bp3-popover-target") - .last() - .click({ force: true }); - cy.get(".t--dropdown-option") - .children() - .contains(value) - .click(); -}); - -Cypress.Commands.add("selectDropdownValue", (element, value) => { - cy.get(element) - .last() - .click(); - cy.get(".t--dropdown-option") - .children() - .contains(value) - .click(); -}); - -Cypress.Commands.add("assertDateFormat", () => { - cy.get(".t--draggable-datepickerwidget2 input") - .first() - .invoke("attr", "value") - .then((text) => { - const firstTxt = text; - cy.log("date time : ", firstTxt); - cy.get(commonlocators.labelTextStyle) - .first() - .should("contain", firstTxt); - cy.get(commonlocators.labelTextStyle) - .last() - .invoke("text") - .then((text) => { - const secondText = text; - cy.log("date time : ", secondText); - expect(firstTxt).not.to.equal(secondText); - }); - }); -}); - -Cypress.Commands.add("selectPaginationType", (option) => { - cy.xpath(option).click({ force: true }); -}); - Cypress.Commands.add("clickTest", (testbutton) => { // eslint-disable-next-line cypress/no-unnecessary-waiting cy.wait(2000); @@ -1047,390 +487,6 @@ Cypress.Commands.add("clickTest", (testbutton) => { cy.wait("@postExecute"); }); -Cypress.Commands.add("enterUrl", (apiname, url, value) => { - cy.get(url) - .first() - .type("{{".concat(apiname).concat(value), { - force: true, - parseSpecialCharSequences: false, - }); -}); - -Cypress.Commands.add( - "EnterSourceDetailsWithQueryParam", - (baseUrl, v1method, hKey, hValue, qKey, qValue) => { - cy.enterDatasourceAndPath(baseUrl, v1method); - cy.get(apiwidget.headerKey) - .first() - .click({ force: true }) - .type(hKey, { parseSpecialCharSequences: true }); - cy.get(apiwidget.headerValue) - .first() - .click({ force: true }) - .type(hValue, { parseSpecialCharSequences: true }); - cy.get(apiwidget.queryKey) - .first() - .click({ force: true }) - .type(qKey, { force: true }) - .should("have.value", qKey); - cy.get(apiwidget.queryValue) - .first() - .click({ force: true }) - .type(qValue, { force: true }) - .should("have.value", qValue); - cy.WaitAutoSave(); - }, -); - -Cypress.Commands.add( - "EnterSourceDetailsWithbody", - (baseUrl, v1method, hKey, hValue) => { - cy.enterDatasourceAndPath(baseUrl, v1method); - cy.get(apiwidget.addHeader) - .first() - .click({ first: true }); - }, -); - -Cypress.Commands.add("CreationOfUniqueAPIcheck", (apiname) => { - cy.get(pages.addEntityAPI).click(); - cy.get(pages.integrationCreateNew) - .should("be.visible") - .click({ force: true }); - cy.get(apiwidget.createapi).click({ force: true }); - cy.wait("@createNewApi"); - // cy.wait("@getUser"); - cy.get(apiwidget.resourceUrl).should("be.visible"); - cy.get(apiwidget.ApiName).click({ force: true }); - cy.get(apiwidget.apiTxt) - .clear() - .focus() - .type(apiname, { force: true, delay: 500 }) - .should("have.value", apiname); - cy.get(".t--action-name-edit-error").should(($x) => { - expect($x).contain( - apiname.concat(" is already being used or is a restricted keyword."), - ); - }); - cy.get(apiwidget.apiTxt).blur(); -}); - -Cypress.Commands.add("MoveAPIToHome", (apiname) => { - cy.xpath(apiwidget.popover) - .last() - .click({ force: true }); - cy.get(apiwidget.copyTo).click({ force: true }); - cy.get(apiwidget.home).click({ force: true }); - cy.wait("@createNewApi").should( - "have.nested.property", - "response.body.responseMeta.status", - 201, - ); -}); - -Cypress.Commands.add("MoveAPIToPage", (pageName) => { - cy.xpath(apiwidget.popover) - .last() - .click({ force: true }); - cy.get(apiwidget.moveTo).click({ force: true }); - cy.get(apiwidget.page) - .contains(pageName) - .click({ force: true }); - cy.wait("@moveAction").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); -}); - -Cypress.Commands.add("copyEntityToPage", (pageName) => { - cy.xpath(apiwidget.popover) - .last() - .click({ force: true }); - cy.get(apiwidget.copyTo).click({ force: true }); - cy.get(apiwidget.page) - .contains(pageName) - .click({ force: true }); - cy.wait("@createNewApi").should( - "have.nested.property", - "response.body.responseMeta.status", - 201, - ); -}); - -Cypress.Commands.add("CopyAPIToHome", () => { - cy.xpath(apiwidget.popover) - .last() - .click({ force: true }); - cy.get(apiwidget.copyTo).click({ force: true }); - cy.get(apiwidget.home).click({ force: true }); - cy.wait("@createNewApi").should( - "have.nested.property", - "response.body.responseMeta.status", - 201, - ); -}); - -Cypress.Commands.add("RenameEntity", (value, selectFirst) => { - if (selectFirst) { - cy.xpath(apiwidget.popover) - .first() - .click({ force: true }); - } else { - cy.xpath(apiwidget.popover) - .last() - .click({ force: true }); - } - - cy.get(apiwidget.renameEntity).click({ force: true }); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(2000); - cy.get(explorer.editEntity) - .last() - .type(value, { force: true }); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(3000); -}); - -Cypress.Commands.add("CreateApiAndValidateUniqueEntityName", (apiname) => { - cy.get(apiwidget.createapi).click({ force: true }); - cy.wait("@createNewApi"); - cy.get(apiwidget.resourceUrl).should("be.visible"); - cy.get(apiwidget.ApiName).click({ force: true }); - cy.get(apiwidget.apiTxt) - .clear() - .type(apiname, { force: true }) - .should("have.value", apiname); - cy.get(".t--action-name-edit-error").should(($x) => { - expect($x).contain( - apiname.concat(" is already being used or is a restricted keyword."), - ); - }); -}); - -Cypress.Commands.add("validateMessage", (value) => { - cy.get(".bp3-popover-content").should(($x) => { - expect($x).contain(value.concat(" is already being used.")); - }); -}); - -Cypress.Commands.add( - "VerifyPopOverMessage", - (msgAbsenceToVerify, presence = false) => { - // Give this element 3 seconds to appear - let shouldCondition = "not.exist"; - if (presence) shouldCondition = "exist"; - cy.xpath( - "//div[@class='bp3-popover-content'][contains(text(),'" + - msgAbsenceToVerify + - "')]", - { timeout: 3000 }, - ).should(shouldCondition); - }, -); - -Cypress.Commands.add("DeleteAPIFromSideBar", () => { - cy.deleteEntity(); - cy.wait("@deleteAction").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); -}); - -Cypress.Commands.add("DeleteWidgetFromSideBar", () => { - cy.xpath(apiwidget.popover) - .last() - .click({ force: true }); - cy.get(apiwidget.delete).click({ force: true }); - cy.wait("@updateLayout").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); -}); - -Cypress.Commands.add("deleteEntity", () => { - cy.xpath(apiwidget.popover) - .last() - .click({ force: true }); - cy.get(apiwidget.delete).click({ force: true }); - cy.get(apiwidget.deleteConfirm).click({ force: true }); -}); - -Cypress.Commands.add("deleteEntityWithoutConfirmation", () => { - cy.xpath(apiwidget.popover) - .last() - .click({ force: true }); - cy.get(apiwidget.delete).click({ force: true }); -}); - -Cypress.Commands.add("DeleteAPI", (apiname) => { - cy.get(ApiEditor.ApiActionMenu).click({ multiple: true }); - cy.get(apiwidget.deleteAPI) - .first() - .click({ force: true }); - cy.get(apiwidget.deleteAPI) - .first() - .click({ force: true }); - cy.wait("@deleteAction").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); -}); - -Cypress.Commands.add("copyJSObjectToPage", (pageName) => { - cy.xpath(apiwidget.popover) - .last() - .click({ force: true }); - cy.get(apiwidget.copyTo).click({ force: true }); - cy.get(apiwidget.page) - .contains(pageName) - .click(); - cy.wait("@createNewJSCollection").should( - "have.nested.property", - "response.body.responseMeta.status", - 201, - ); -}); - -Cypress.Commands.add("AddActionWithModal", () => { - cy.get(commonlocators.dropdownSelectButton) - .last() - .click(); - cy.get(".single-select") - .contains("Open modal") - .click({ force: true }); - cy.get(modalWidgetPage.selectModal).click(); - cy.get(modalWidgetPage.createModalButton).click({ force: true }); -}); - -Cypress.Commands.add("createModal", (ModalName) => { - cy.get(widgetsPage.actionSelect) - .first() - .click({ force: true }); - cy.selectOnClickOption("Open modal"); - cy.get(modalWidgetPage.selectModal).click(); - cy.wait(2000); - cy.get(modalWidgetPage.createModalButton).click({ force: true }); - cy.wait(3000); - cy.assertPageSave(); - cy.SearchEntityandOpen("Modal1"); - // changing the model name verify - cy.widgetText( - ModalName, - modalWidgetPage.modalName, - modalWidgetPage.modalName, - ); - - //changing the Model label - cy.get(modalWidgetPage.modalWidget + " " + widgetsPage.textWidget) - .first() - .trigger("mouseover"); - - cy.get(widgetsPage.textWidget + " " + commonlocators.editIcon).click(); - cy.testCodeMirror(ModalName); - cy.get(widgetsPage.textCenterAlign).click({ force: true }); - cy.assertPageSave(); - cy.get(".bp3-overlay-backdrop").click({ force: true }); -}); - -Cypress.Commands.add("selectOnClickOption", (option) => { - cy.get(".bp3-popover-content").should("be.visible"); - cy.get("ul.bp3-menu div.bp3-fill") - .should("be.visible") - .contains(option) - .click({ force: true }); -}); - -Cypress.Commands.add("selectWidgetOnClickOption", (option) => { - cy.get(".bp3-popover-content").should("be.visible"); - cy.get(commonlocators.selectWidgetVirtualList) - .should("be.visible") - .contains(option) - .click({ force: true }); -}); - -Cypress.Commands.add("CheckWidgetProperties", (checkboxCss) => { - cy.get(checkboxCss).check({ - force: true, - }); - cy.assertPageSave(); -}); - -Cypress.Commands.add("UncheckWidgetProperties", (checkboxCss) => { - cy.get(checkboxCss).uncheck({ - force: true, - }); - cy.assertPageSave(); -}); - -Cypress.Commands.add("EditWidgetPropertiesUsingJS", (checkboxCss, inputJS) => { - cy.get(checkboxCss, { timeout: 10000 }) - .last() - .should("exist") - .dblclick({ force: true }) - .type(inputJS); - cy.assertPageSave(); -}); - -Cypress.Commands.add( - "ChangeTextStyle", - (dropDownValue, textStylecss, labelName) => { - cy.get(commonlocators.dropDownIcon) - .last() - .click(); - cy.get(".t--dropdown-option") - .children() - .contains(dropDownValue) - .click(); - cy.get(textStylecss).should("have.text", labelName); - }, -); - -Cypress.Commands.add("widgetText", (text, inputcss, innercss) => { - cy.get(commonlocators.editWidgetName) - .click({ force: true }) - .type(text, { delay: 300 }) - .type("{enter}"); - cy.get(inputcss) - .first() - .trigger("mouseover", { force: true }); - cy.contains(innercss, text); -}); - -Cypress.Commands.add("verifyWidgetText", (text, inputcss, innercss) => { - cy.get(inputcss) - .first() - .trigger("mouseover", { force: true }); - cy.contains(innercss, text); -}); - -Cypress.Commands.add("editColName", (text) => { - cy.get(commonlocators.editColTitle) - .click({ force: true }) - .type(text) - .type("{enter}"); - cy.get(commonlocators.editColText).should("have.text", text); -}); - -Cypress.Commands.add("invalidWidgetText", () => { - // checking invalid widget name - cy.get(commonlocators.editWidgetName) - .click({ force: true }) - .type("download") - .type("{enter}"); - cy.get(commonlocators.toastmsg).contains("download is already being used."); -}); - -Cypress.Commands.add("EvaluateDataType", (dataType) => { - cy.get(commonlocators.evaluatedType) - .first() - .should("be.visible") - .contains(dataType); -}); - Cypress.Commands.add("EvaluateCurrentValue", (currentValue) => { // eslint-disable-next-line cypress/no-unnecessary-waiting cy.wait(3000); @@ -1469,225 +525,6 @@ Cypress.Commands.add("PublishtheApp", () => { cy.wait(1000); //wait time for page to load! }); -Cypress.Commands.add("getCodeMirror", () => { - return cy - .get(".CodeMirror textarea") - .first() - .focus() - .type("{ctrl}{shift}{downarrow}"); -}); - -Cypress.Commands.add("testCodeMirror", (value) => { - cy.get(".CodeMirror textarea") - .first() - .focus() - .type("{ctrl}{shift}{downarrow}") - .then(($cm) => { - if ($cm.val() !== "") { - cy.get(".CodeMirror textarea") - .first() - .clear({ - force: true, - }); - } - - cy.get(".CodeMirror textarea") - .first() - .type(value, { - force: true, - parseSpecialCharSequences: false, - }); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(2000); - cy.get(".CodeMirror textarea") - .first() - .should("have.value", value); - }); -}); - -Cypress.Commands.add("updateComputedValue", (value) => { - cy.get(".CodeMirror textarea") - .first() - .focus({ force: true }) - .type("{uparrow}", { force: true }) - .type("{ctrl}{shift}{downarrow}", { force: true }); - cy.focused().then(($cm) => { - if ($cm.contents !== "") { - cy.log("The field is empty"); - cy.get(".CodeMirror textarea") - .first() - .clear({ - force: true, - }); - } - cy.get(".CodeMirror textarea") - .first() - .type(value, { - force: true, - parseSpecialCharSequences: false, - }); - }); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(1000); -}); - -Cypress.Commands.add("testCodeMirrorLast", (value) => { - cy.get(".CodeMirror textarea") - .last() - .focus() - .type("{ctrl}{shift}{downarrow}") - .then(($cm) => { - if ($cm.val() !== "") { - cy.get(".CodeMirror textarea") - .last() - .clear({ - force: true, - }); - } - - cy.get(".CodeMirror textarea") - .last() - .clear({ force: true }) - .type(value, { - force: true, - parseSpecialCharSequences: false, - }); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(200); - cy.get(".CodeMirror textarea") - .last() - .should("have.value", value); - }); -}); - -Cypress.Commands.add("testJsontext", (endp, value, paste = true) => { - cy.get(".t--property-control-" + endp + " .CodeMirror textarea") - .first() - .focus({ force: true }) - .type("{uparrow}", { force: true }) - .type("{ctrl}{shift}{downarrow}", { force: true }); - cy.focused().then(($cm) => { - if ($cm.contents !== "") { - cy.log("The field is not empty"); - cy.get(".t--property-control-" + endp + " .CodeMirror textarea") - .first() - .click({ force: true }) - .focused({ force: true }) - .clear({ - force: true, - }); - } - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(500); - cy.get(".t--property-control-" + endp + " .CodeMirror textarea") - .first() - .then((el) => { - const input = cy.get(el); - if (paste) { - input.invoke("val", value); - } else { - input.type(value, { - force: true, - parseSpecialCharSequences: false, - }); - } - }); - }); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(2500); //Allowing time for Evaluate value to capture value -}); - -/** - * Usage: - * Find the element which has a code editor input and then pass it in the function - * - * cy.get(...).then(el => cy.updateCodeInput(el, "test")); - * - */ -Cypress.Commands.add("updateCodeInput", ($selector, value) => { - cy.get($selector) - .find(".CodeMirror") - .first() - .then((ins) => { - const input = ins[0].CodeMirror; - input.focus(); - cy.wait(200); - input.setValue(value); - cy.wait(200); //time for value to set - //input.focus(); - }); -}); - -Cypress.Commands.add("selectColor", (GivenProperty) => { - // Property pane of the widget is opened, and click given property. - cy.get( - ".t--property-control-" + GivenProperty + " .bp3-input-group input", - ).click({ - force: true, - }); - cy.get(widgetsPage.colorsAvailable) - .first() - .click({ force: true }); -}); - -Cypress.Commands.add("toggleJsAndUpdate", (endp, value) => { - cy.get(".CodeMirror textarea") - .last() - .focus({ force: true }) - .type("{uparrow}", { force: true }) - .type("{ctrl}{shift}{downarrow}", { force: true }); - cy.focused().then(($cm) => { - if ($cm.contents !== "") { - cy.log("The field is empty"); - cy.get(".CodeMirror textarea") - .last() - .clear({ - force: true, - }); - } - cy.get(".CodeMirror textarea") - .last() - .type(value, { - force: true, - parseSpecialCharSequences: false, - }); - }); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(200); -}); - -Cypress.Commands.add("assertControlVisibility", (endp, value) => { - cy.get(".t--property-control-" + endp + " .CodeMirror") - .first() - .should("not.be.visible"); -}); - -Cypress.Commands.add("tableColumnDataValidation", (columnName) => { - cy.get("[data-rbd-draggable-id='" + columnName + "'] input") - .scrollIntoView() - .first() - .focus({ force: true }) - .should("be.visible"); -}); - -Cypress.Commands.add("tableColumnPopertyUpdate", (colId, newColName) => { - cy.get("[data-rbd-draggable-id='" + colId + "'] input") - .scrollIntoView() - .should("be.visible") - .click({ - force: true, - }); - cy.get("[data-rbd-draggable-id='" + colId + "'] input").clear({ - force: true, - }); - cy.get("[data-rbd-draggable-id='" + colId + "'] input").type(newColName, { - force: true, - }); - cy.get(".draggable-header ") - .contains(newColName) - .should("be.visible"); -}); - Cypress.Commands.add("tabPopertyUpdate", (tabId, newTabName) => { cy.get("[data-rbd-draggable-id='" + tabId + "'] input") .scrollIntoView() @@ -1706,245 +543,6 @@ Cypress.Commands.add("tabPopertyUpdate", (tabId, newTabName) => { .should("be.visible"); }); -Cypress.Commands.add("hideColumn", (colId) => { - cy.get("[data-rbd-draggable-id='" + colId + "'] .t--show-column-btn").click({ - force: true, - }); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(1000); -}); - -Cypress.Commands.add("showColumn", (colId) => { - cy.get("[data-rbd-draggable-id='" + colId + "'] .t--show-column-btn").click({ - force: true, - }); - cy.get(".draggable-header ") - .contains(colId) - .should("be.visible"); -}); -Cypress.Commands.add("deleteColumn", (colId) => { - cy.get("[data-rbd-draggable-id='" + colId + "'] .t--delete-column-btn").click( - { - force: true, - }, - ); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(1000); -}); - -Cypress.Commands.add("openFieldConfiguration", (fieldIdentifier) => { - cy.get( - "[data-rbd-draggable-id='" + fieldIdentifier + "'] .t--edit-column-btn", - ).click({ - force: true, - }); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(1000); -}); - -Cypress.Commands.add("makeColumnVisible", (colId) => { - cy.get("[data-rbd-draggable-id='" + colId + "'] .t--show-column-btn").click({ - force: true, - }); - cy.wait(1000); -}); - -Cypress.Commands.add("addColumn", (colId) => { - cy.get(widgetsPage.addColumn).scrollIntoView(); - cy.get(widgetsPage.addColumn) - .should("be.visible") - .click({ force: true }); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(3000); - cy.get(widgetsPage.defaultColName).clear({ - force: true, - }); - cy.get(widgetsPage.defaultColName).type(colId, { force: true }); -}); - -Cypress.Commands.add("editColumn", (colId) => { - cy.get("[data-rbd-draggable-id='" + colId + "'] .t--edit-column-btn").click(); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(1500); -}); - -Cypress.Commands.add("readTextDataValidateCSS", (cssProperty, cssValue) => { - cy.get(commonlocators.headingTextStyle).should( - "have.css", - cssProperty, - cssValue, - ); -}); - -Cypress.Commands.add("evaluateErrorMessage", (value) => { - cy.get(commonlocators.evaluateMsg) - .first() - .click() - .invoke("text") - .then((text) => { - const someText = text; - expect(someText).to.equal(value); - }); -}); - -Cypress.Commands.add("addAction", (value) => { - cy.get(commonlocators.dropdownSelectButton) - .last() - .click(); - cy.get(commonlocators.chooseAction) - .children() - .contains("Show message") - .click(); - cy.enterActionValue(value); -}); - -Cypress.Commands.add("onTableAction", (value, value1, value2) => { - cy.get(commonlocators.dropdownSelectButton) - .eq(value) - .click(); - cy.get(commonlocators.chooseAction) - .children() - .contains("Show message") - .click(); - cy.testJsontext(value1, value2); -}); - -Cypress.Commands.add("selectShowMsg", () => { - cy.get(commonlocators.chooseAction) - .children() - .contains("Show message") - .click(); -}); - -Cypress.Commands.add("addSuccessMessage", (value) => { - cy.get(commonlocators.chooseMsgType) - .last() - .click(); - cy.get(commonlocators.chooseAction) - .children() - .contains("Success") - .click(); - cy.enterActionValue(value); -}); - -Cypress.Commands.add("SetDateToToday", () => { - cy.get(formWidgetsPage.datepickerFooterPublish) - .contains("Today") - .click({ force: true }); - cy.assertPageSave(); -}); - -Cypress.Commands.add("enterActionValue", (value) => { - cy.get(".CodeMirror textarea") - .last() - .focus() - .type("{ctrl}{shift}{downarrow}") - .then(($cm) => { - if ($cm.val() !== "") { - cy.get(".CodeMirror textarea") - .last() - .clear({ - force: true, - }); - } - - cy.get(".CodeMirror textarea") - .last() - .type(value, { - force: true, - parseSpecialCharSequences: false, - }); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(200); - }); -}); - -Cypress.Commands.add("enterNavigatePageName", (value) => { - cy.get("ul.tree") - .children() - .first() - .within(() => { - cy.get(".CodeMirror textarea") - .first() - .focus() - .type("{ctrl}{shift}{downarrow}") - .then(($cm) => { - if ($cm.val() !== "") { - cy.get(".CodeMirror textarea") - .first() - .clear({ - force: true, - }); - } - cy.get(".CodeMirror textarea") - .first() - .type(value, { - force: true, - parseSpecialCharSequences: false, - }); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(200); - cy.get(".CodeMirror textarea") - .first() - .should("have.value", value); - }); - cy.root(); - }); -}); - -Cypress.Commands.add("ClearDate", () => { - cy.get(".t--property-control-defaultdate input").clear(); - cy.assertPageSave(); -}); - -Cypress.Commands.add("ClearDateFooter", () => { - cy.get(formWidgetsPage.datepickerFooterPublish) - .contains("Clear") - .click({ force: true }); - //cy.assertPageSave(); -}); - -Cypress.Commands.add("DeleteModal", () => { - cy.get(widgetsPage.textbuttonWidget).dblclick("topRight", { force: true }); - cy.get(widgetsPage.deleteWidget) - .first() - .click({ force: true }); -}); - -Cypress.Commands.add("Createpage", (pageName) => { - let pageId; - cy.get(pages.AddPage) - .first() - .click({ force: true }); - cy.wait("@createPage").then((xhr) => { - expect(xhr.response.body.responseMeta.status).to.equal(201); - if (pageName) { - pageId = xhr.response.body.data.id; - cy.wait(2000); - cy.get(`div[id=entity-${pageId}] .t--context-menu`).click({ - force: true, - }); - cy.get(pages.editName).click({ force: true }); - cy.get(pages.editInput).type(pageName + "{enter}"); - pageidcopy = pageName; - cy.wrap(pageId).as("currentPageId"); - } - cy.get(generatePage.buildFromScratchActionCard).click(); - cy.get("#loading").should("not.exist"); - }); -}); - -Cypress.Commands.add("Deletepage", (Pagename) => { - cy.CheckAndUnfoldEntityItem("PAGES"); - cy.get(`.t--entity-item:contains(${Pagename})`).within(() => { - cy.get(".t--context-menu").click({ force: true }); - }); - cy.selectAction("Delete"); - cy.selectAction("Are you sure?"); - cy.wait("@deletePage"); - cy.get("@deletePage").should("have.property", "status", 200); -}); - Cypress.Commands.add("generateUUID", () => { const uuid = require("uuid"); const id = uuid.v4(); @@ -2016,105 +614,6 @@ Cypress.Commands.add("optionValue", (value, value2) => { .type(value2); }); -Cypress.Commands.add("dropdownDynamic", (text) => { - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(2000); - cy.get("ul.bp3-menu") - .contains(text) - .click({ force: true }) - .should("have.text", text); -}); - -Cypress.Commands.add("dropdownMultiSelectDynamic", (text) => { - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(2000); - cy.get(".multi-select-dropdown") - .contains(text) - .click({ force: true }) - .should("have.text", text); -}); - -Cypress.Commands.add("treeSelectDropdown", (text) => { - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(2000); - cy.get(".tree-select-dropdown") - .contains(text) - .click({ force: true }) - .should("have.text", text); -}); - -Cypress.Commands.add("treeMultiSelectDropdown", (text) => { - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(2000); - cy.get(".tree-multiselect-dropdown") - .contains(text) - .click({ force: true }) - .should("have.text", text); -}); - -Cypress.Commands.add("dropdownDynamicUpdated", (text) => { - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(2000); - cy.get(commonlocators.dropdownmenu) - .contains(text) - .click({ force: true }); - cy.xpath(commonlocators.dropDownOptSelected).should("have.text", text); -}); - -Cypress.Commands.add("selectTextSize", (text) => { - cy.get(".t--dropdown-option") - .first() - .contains(text) - .click({ force: true }); -}); - -Cypress.Commands.add("getAlert", (alertcss) => { - cy.get(commonlocators.dropdownSelectButton).click({ force: true }); - cy.get(widgetsPage.menubar) - .contains("Show Alert") - .click({ force: true }) - .should("have.text", "Show Alert"); - - cy.get(alertcss) - .click({ force: true }) - .type("hello"); - cy.get(".t--open-dropdown-Select-type").click({ force: true }); - cy.get(".bp3-popover-content .bp3-menu li") - .contains("Success") - .click({ force: true }); -}); - -Cypress.Commands.add("togglebar", (value) => { - cy.get(value) - .check({ force: true }) - .should("be.checked"); -}); -Cypress.Commands.add("togglebarDisable", (value) => { - cy.get(value) - .uncheck({ force: true }) - .should("not.checked"); -}); - -Cypress.Commands.add( - "getAlert", - (alertcss, propertyControl = commonlocators.dropdownSelectButton) => { - cy.get(propertyControl) - .first() - .click({ force: true }); - cy.get(widgetsPage.menubar) - .contains("Show message") - .click({ force: true }); - - cy.get(alertcss) - .click({ force: true }) - .type("hello"); - cy.get(".t--open-dropdown-Select-type").click({ force: true }); - cy.get(".bp3-popover-content .bp3-menu li") - .contains("Success") - .click({ force: true }); - }, -); - Cypress.Commands.add("typeIntoDraftEditor", (selector, text) => { cy.get(selector).then((input) => { var textarea = input.get(0); @@ -2128,42 +627,6 @@ Cypress.Commands.add("typeIntoDraftEditor", (selector, text) => { }); }); -Cypress.Commands.add("addQueryFromLightningMenu", (QueryName) => { - cy.get(commonlocators.dropdownSelectButton) - .first() - .click({ force: true }) - .selectOnClickOption("Execute a query") - .selectOnClickOption(QueryName); -}); - -Cypress.Commands.add("addAPIFromLightningMenu", (ApiName) => { - cy.get(commonlocators.dropdownSelectButton) - .first() - .click({ force: true }) - .selectOnClickOption("Execute a query") - .selectOnClickOption(ApiName); -}); - -Cypress.Commands.add("radioInput", (index, text) => { - cy.get(widgetsPage.RadioInput) - .eq(index) - .click({ force: true }) - .clear({ force: true }) - .type(text) - .wait(200); -}); -Cypress.Commands.add("tabVerify", (index, text) => { - cy.get(".t--property-control-tabs input") - .eq(index) - .click({ force: true }) - .clear() - .type(text); - cy.get(LayoutPage.tabWidget) - .contains(text) - .click({ force: true }) - .should("be.visible"); -}); - Cypress.Commands.add("getPluginFormsAndCreateDatasource", () => { /* cy.wait("@getPluginForm").should( @@ -2179,18 +642,10 @@ Cypress.Commands.add("getPluginFormsAndCreateDatasource", () => { */ }); -Cypress.Commands.add("NavigateToApiEditor", () => { - cy.get(explorer.addEntityAPI).click({ force: true }); -}); - Cypress.Commands.add("NavigateToWidgetsInExplorer", () => { cy.get(explorer.entityWidget).click({ force: true }); }); -Cypress.Commands.add("NavigateToQueriesInExplorer", () => { - cy.get(explorer.entityQuery).click({ force: true }); -}); - Cypress.Commands.add("NavigateToJSEditor", () => { cy.get(explorer.createNew).click({ force: true }); cy.get(".t--file-operation") @@ -2198,52 +653,6 @@ Cypress.Commands.add("NavigateToJSEditor", () => { .click({ force: true }); }); -Cypress.Commands.add("testCreateApiButton", () => { - cy.get(ApiEditor.createBlankApiCard).click({ force: true }); - cy.wait("@createNewApi").should( - "have.nested.property", - "response.body.responseMeta.status", - 201, - ); -}); - -Cypress.Commands.add("testSaveDeleteDatasource", () => { - // Instead of deleting the last datasource on the active datasources list, - // we delete the datasource that was just created (identified by its title) - cy.get(datasourceEditor.datasourceTitle) - .invoke("text") - .then((datasourceTitle) => { - // test datasource - cy.get(".t--test-datasource").click(); - cy.wait("@testDatasource"); - // .should("have.nested.property", "response.body.data.success", true) - // .debug(); - - // save datasource - cy.get(".t--save-datasource").click(); - cy.wait("@saveDatasource").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); - // select datasource to be deleted by datasource title - cy.get(`${datasourceEditor.datasourceCard}`) - .contains(datasourceTitle) - .last() - .click(); - // delete datasource - cy.get(".t--delete-datasource").click(); - cy.get(".t--delete-datasource") - .contains("Are you sure?") - .click(); - cy.wait("@deleteDatasource").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); - }); -}); - Cypress.Commands.add("importCurl", () => { cy.get(ApiEditor.curlImportBtn).click({ force: true }); cy.wait("@curlImport").should( @@ -2253,21 +662,6 @@ Cypress.Commands.add("importCurl", () => { ); }); -Cypress.Commands.add("NavigateToDatasourceEditor", () => { - cy.get(explorer.addDBQueryEntity) - .last() - .click({ force: true }); - cy.get(pages.integrationCreateNew) - .should("be.visible") - .click({ force: true }); -}); - -Cypress.Commands.add("NavigateToQueryEditor", () => { - cy.get(explorer.addDBQueryEntity) - .last() - .click({ force: true }); -}); - Cypress.Commands.add("NavigateToActiveTab", () => { cy.get(explorer.activeTab).click({ force: true }); @@ -2276,367 +670,6 @@ Cypress.Commands.add("NavigateToActiveTab", () => { // .click({ force: true }); }); -Cypress.Commands.add("NavigateToActiveDSQueryPane", (datasourceName) => { - cy.NavigateToQueryEditor(); - cy.NavigateToActiveTab(); - - cy.get(datasource.datasourceCard) - .contains(datasourceName) - .scrollIntoView() - .should("be.visible") - .closest(datasource.datasourceCard) - .within(() => { - cy.get(queryLocators.createQuery).click({ force: true }); - }) - .wait(2000); //for the specified page to load -}); - -Cypress.Commands.add("NavigateToDSGeneratePage", (datasourceName) => { - cy.NavigateToQueryEditor(); - cy.NavigateToActiveTab(); - - cy.get(datasource.datasourceCard) - .contains(datasourceName) - .scrollIntoView() - .should("be.visible") - .closest(datasource.datasourceCard) - .within(() => { - cy.get(datasource.datasourceCardGeneratePageBtn).click(); - }) - .wait(2000); //for the specified page to load -}); - -Cypress.Commands.add("ClickGotIt", () => { - cy.get("span:contains('GOT IT')").click(); -}); - -Cypress.Commands.add("testDatasource", (expectedRes = true) => { - cy.get(".t--test-datasource").click({ force: true }); - cy.wait("@testDatasource").should( - "have.nested.property", - "response.body.data.success", - expectedRes, - ); -}); - -Cypress.Commands.add("saveDatasource", () => { - cy.get(".t--save-datasource").click({ force: true }); - cy.wait("@saveDatasource") - .then((xhr) => { - cy.log(JSON.stringify(xhr.response.body)); - }) - .should("have.nested.property", "response.body.responseMeta.status", 200); -}); - -Cypress.Commands.add("testSaveDatasource", (expectedRes = true) => { - cy.testDatasource(expectedRes); - cy.saveDatasource(); - // cy.get(datasourceEditor.datasourceCard) - // .last() - // .click(); -}); - -Cypress.Commands.add("fillGoogleSheetsDatasourceForm", () => { - cy.get(datasourceEditor["scope"]).click(); -}); - -Cypress.Commands.add( - "fillMongoDatasourceForm", - (shouldAddTrailingSpaces = false) => { - const hostAddress = shouldAddTrailingSpaces - ? datasourceFormData["mongo-host"] + " " - : datasourceFormData["mongo-host"]; - // const databaseName = shouldAddTrailingSpaces - // ? datasourceFormData["mongo-databaseName"] + " " - // : datasourceFormData["mongo-databaseName"]; - - cy.get(datasourceEditor["host"]).type(hostAddress); - cy.get(datasourceEditor.port).type(datasourceFormData["mongo-port"]); - //cy.get(datasourceEditor["port"]).type(datasourceFormData["mongo-port"]); - //cy.get(datasourceEditor["selConnectionType"]).click(); - //cy.contains(datasourceFormData["connection-type"]).click(); - //cy.get(datasourceEditor["defaultDatabaseName"]).type(databaseName);//is optional hence removing - - cy.get(datasourceEditor.sectionAuthentication).click(); - cy.get(datasourceEditor["databaseName"]) - .clear() - .type(datasourceFormData["mongo-databaseName"]); - cy.get(datasourceEditor.sectionAuthentication).click(); - // cy.get(datasourceEditor["username"]).type( - // datasourceFormData["mongo-username"], - // ); - // cy.get(datasourceEditor["password"]).type( - // datasourceFormData["mongo-password"], - // ); - // cy.get(datasourceEditor["authenticationAuthtype"]).click(); - // cy.contains(datasourceFormData["mongo-authenticationAuthtype"]).click({ - // force: true, - // }); - }, -); - -Cypress.Commands.add("fillAuthenticatedAPIForm", () => { - const URL = datasourceFormData["authenticatedApiUrl"]; - cy.get(datasourceEditor.url).type(URL); -}); - -Cypress.Commands.add( - "fillPostgresDatasourceForm", - (shouldAddTrailingSpaces = false) => { - const hostAddress = shouldAddTrailingSpaces - ? datasourceFormData["postgres-host"] + " " - : datasourceFormData["postgres-host"]; - const databaseName = shouldAddTrailingSpaces - ? datasourceFormData["postgres-databaseName"] + " " - : datasourceFormData["postgres-databaseName"]; - - cy.get(datasourceEditor.host).type(hostAddress); - cy.get(datasourceEditor.port).type(datasourceFormData["postgres-port"]); - cy.get(datasourceEditor.databaseName) - .clear() - .type(databaseName); - cy.get(datasourceEditor.sectionAuthentication).click(); - cy.get(datasourceEditor.username).type( - datasourceFormData["postgres-username"], - ); - cy.get(datasourceEditor.password).type( - datasourceFormData["postgres-password"], - ); - cy.get(datasourceEditor.sectionAuthentication).click(); - }, -); - -Cypress.Commands.add( - "fillMySQLDatasourceForm", - (shouldAddTrailingSpaces = false) => { - const hostAddress = shouldAddTrailingSpaces - ? datasourceFormData["mysql-host"] + " " - : datasourceFormData["mysql-host"]; - const databaseName = shouldAddTrailingSpaces - ? datasourceFormData["mysql-databaseName"] + " " - : datasourceFormData["mysql-databaseName"]; - - cy.get(datasourceEditor.host).type(hostAddress); - cy.get(datasourceEditor.port).type(datasourceFormData["mysql-port"]); - cy.get(datasourceEditor.databaseName) - .clear() - .type(databaseName); - - cy.get(datasourceEditor.sectionAuthentication).click(); - cy.get(datasourceEditor.username).type( - datasourceFormData["mysql-username"], - ); - cy.get(datasourceEditor.password).type( - datasourceFormData["mysql-password"], - ); - cy.get(datasourceEditor.sectionAuthentication).click(); - }, -); - -Cypress.Commands.add( - "fillMsSQLDatasourceForm", - (shouldAddTrailingSpaces = false) => { - const hostAddress = shouldAddTrailingSpaces - ? datasourceFormData["mssql-host"] + " " - : datasourceFormData["mssql-host"]; - const databaseName = shouldAddTrailingSpaces - ? datasourceFormData["mssql-databaseName"] + " " - : datasourceFormData["mssql-databaseName"]; - - cy.get(datasourceEditor.host).type(hostAddress); - cy.get(datasourceEditor.port).type(datasourceFormData["mssql-port"]); - cy.get(datasourceEditor.databaseName) - .clear() - .type(databaseName); - - cy.get(datasourceEditor.sectionAuthentication).click(); - cy.get(datasourceEditor.username).type( - datasourceFormData["mssql-username"], - ); - cy.get(datasourceEditor.password).type( - datasourceFormData["mssql-password"], - ); - }, -); - -Cypress.Commands.add( - "fillArangoDBDatasourceForm", - (shouldAddTrailingSpaces = false) => { - const hostAddress = shouldAddTrailingSpaces - ? datasourceFormData["arango-host"] + " " - : datasourceFormData["arango-host"]; - const databaseName = shouldAddTrailingSpaces - ? datasourceFormData["arango-databaseName"] + " " - : datasourceFormData["arango-databaseName"]; - - cy.get(datasourceEditor.host).type(hostAddress); - cy.get(datasourceEditor.port).type(datasourceFormData["arango-port"]); - cy.get(datasourceEditor.databaseName) - .clear() - .type(databaseName); - - cy.get(datasourceEditor.sectionAuthentication).click(); - cy.get(datasourceEditor.username).type( - datasourceFormData["arango-username"], - ); - cy.get(datasourceEditor.password).type( - datasourceFormData["arango-password"], - ); - }, -); - -Cypress.Commands.add( - "fillRedshiftDatasourceForm", - (shouldAddTrailingSpaces = false) => { - const hostAddress = shouldAddTrailingSpaces - ? datasourceFormData["redshift-host"] + " " - : datasourceFormData["redshift-host"]; - const databaseName = shouldAddTrailingSpaces - ? datasourceFormData["redshift-databaseName"] + " " - : datasourceFormData["redshift-databaseName"]; - - cy.get(datasourceEditor.host).type(hostAddress); - cy.get(datasourceEditor.port).type(datasourceFormData["redshift-port"]); - cy.get(datasourceEditor.databaseName) - .clear() - .type(databaseName); - - cy.get(datasourceEditor.sectionAuthentication).click(); - cy.get(datasourceEditor.username).type( - datasourceFormData["redshift-username"], - ); - cy.get(datasourceEditor.password).type( - datasourceFormData["redshift-password"], - ); - }, -); - -Cypress.Commands.add( - "fillUsersMockDatasourceForm", - (shouldAddTrailingSpaces = false) => { - const userMockDatabaseName = shouldAddTrailingSpaces - ? `${datasourceFormData["mockDatabaseName"] + " "}` - : datasourceFormData["mockDatabaseName"]; - - const userMockHostAddress = shouldAddTrailingSpaces - ? `${datasourceFormData["mockHostAddress"] + " "}` - : datasourceFormData["mockHostAddress"]; - - const userMockDatabaseUsername = shouldAddTrailingSpaces - ? `${datasourceFormData["mockDatabaseUsername"] + " "}` - : datasourceFormData["mockDatabaseUsername"]; - - cy.get(datasourceEditor["host"]) - .clear() - .type(userMockHostAddress); - - cy.get(datasourceEditor["databaseName"]) - .clear() - .type(userMockDatabaseName); - - cy.get(datasourceEditor["sectionAuthentication"]).click(); - - cy.get(datasourceEditor["password"]) - .clear() - .type(datasourceFormData["mockDatabasePassword"]); - - cy.get(datasourceEditor["username"]) - .clear() - .type(userMockDatabaseUsername); - }, -); -Cypress.Commands.add( - "fillSMTPDatasourceForm", - (shouldAddTrailingSpaces = false) => { - const hostAddress = shouldAddTrailingSpaces - ? datasourceFormData["smtp-host"] + " " - : datasourceFormData["smtp-host"]; - cy.get(datasourceEditor.host).type(hostAddress); - cy.get(datasourceEditor.port).type(datasourceFormData["smtp-port"]); - - cy.get(datasourceEditor.sectionAuthentication).click(); - cy.get(datasourceEditor.username).type(datasourceFormData["smtp-username"]); - cy.get(datasourceEditor.password).type(datasourceFormData["smtp-password"]); - }, -); - -Cypress.Commands.add("createPostgresDatasource", () => { - cy.NavigateToDatasourceEditor(); - cy.get(datasourceEditor.PostgreSQL).click(); - //cy.getPluginFormsAndCreateDatasource(); - cy.fillPostgresDatasourceForm(); - cy.testSaveDatasource(); -}); - -Cypress.Commands.add("deleteDatasource", (datasourceName) => { - cy.NavigateToQueryEditor(); - cy.get(pages.integrationActiveTab) - .should("be.visible") - .click({ force: true }); - cy.contains(".t--datasource-name", datasourceName).click(); - cy.get(".t--delete-datasource").click(); - cy.get(".t--delete-datasource") - .contains("Are you sure?") - .click(); - cy.wait("@deleteDatasource").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); -}); - -Cypress.Commands.add("runQuery", (expectedRes = true) => { - cy.onlyQueryRun(); - cy.wait("@postExecute").should( - "have.nested.property", - "response.body.data.isExecutionSuccess", - expectedRes, - ); - - // cy.wait("@postExecute").should( - // "have.nested.property", - // "response.body.responseMeta.status", - // 200, - // ); -}); - -Cypress.Commands.add("onlyQueryRun", () => { - cy.xpath(queryEditor.runQuery) - .last() - .click({ force: true }) - .wait(1000); -}); - -Cypress.Commands.add("hoverAndClick", () => { - cy.xpath(apiwidget.popover) - .last() - .should("be.hidden") - .invoke("show") - .click({ force: true }); - cy.xpath(apiwidget.popover) - .last() - .click({ force: true }); -}); - -Cypress.Commands.add("hoverAndClickParticularIndex", (index) => { - cy.xpath(apiwidget.popover) - .eq(index) - .should("be.hidden") - .invoke("show") - .click({ force: true }); -}); - -Cypress.Commands.add("deleteQuery", () => { - cy.hoverAndClick(); - cy.get(apiwidget.delete).click({ force: true }); - cy.get(apiwidget.deleteConfirm).click({ force: true }); - cy.wait("@deleteAction").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); -}); - Cypress.Commands.add("selectAction", (option) => { cy.get(".single-select") .contains(option) @@ -2670,26 +703,6 @@ Cypress.Commands.add("deleteDataSource", () => { ); }); -Cypress.Commands.add("deleteQueryUsingContext", () => { - cy.get(queryEditor.queryMoreAction) - .first() - .click(); - cy.get(queryEditor.deleteUsingContext).click(); - cy.get(queryEditor.deleteUsingContext) - .contains("Are you sure?") - .click(); - cy.wait("@deleteAction").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); -}); - -Cypress.Commands.add("runAndDeleteQuery", () => { - cy.runQuery(); - cy.deleteQueryUsingContext(); -}); - Cypress.Commands.add("dragAndDropToCanvas", (widgetType, { x, y }) => { const selector = `.t--widget-card-draggable-${widgetType}`; cy.wait(500); @@ -2720,73 +733,6 @@ Cypress.Commands.add( }, ); -Cypress.Commands.add("executeDbQuery", (queryName) => { - cy.get(widgetsPage.buttonOnClick) - .get(commonlocators.dropdownSelectButton) - .click({ force: true }) - .get("ul.bp3-menu") - .children() - .contains("Execute a query") - .click({ force: true }) - .get("ul.bp3-menu") - .children() - .contains(queryName) - .click({ force: true }); -}); - -Cypress.Commands.add("CreateMockQuery", (queryName) => { - // cy.get(queryEditor.addNewQueryBtn).click({ force: true }); - // cy.get(queryEditor.createQuery) - // .first() - // .click({ force: true }); - cy.get(queryEditor.queryNameField).type(queryName + "{enter}", { - force: true, - }); - cy.assertPageSave(); - cy.get(queryEditor.templateMenu + " div") - .contains("Select") - .click({ force: true }); - cy.runQuery(); - // cy.wait(3000); - // cy.get(queryEditor.runQuery) - // .click({force: true}); -}); - -Cypress.Commands.add("openPropertyPane", (widgetType) => { - const selector = `.t--draggable-${widgetType}`; - cy.wait(500); - cy.get(selector) - .first() - .trigger("mouseover", { force: true }) - .wait(500); - cy.get( - `${selector}:first-of-type .t--widget-propertypane-toggle > .t--widget-name`, - ) - .first() - .click({ force: true }); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(1000); -}); - -Cypress.Commands.add("openPropertyPaneCopy", (widgetType) => { - if (widgetType === "List1Copy") { - cy.SearchEntityandOpen(widgetType); - } else { - const selector = `.t--draggable-${widgetType}`; - cy.get(selector) - .last() - .trigger("mouseover", { force: true }) - .wait(500); - cy.get( - `${selector}:first-of-type .t--widget-propertypane-toggle > .t--widget-name`, - ) - .first() - .click({ force: true }); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(1000); - } -}); - Cypress.Commands.add("changeButtonColor", (buttonColor) => { cy.get(widgetsPage.buttonColor) .click({ force: true }) @@ -2840,93 +786,6 @@ Cypress.Commands.add("onClickActions", (forSuccess, forFailure, endp) => { .selectOnClickOption(forFailure); }); -Cypress.Commands.add("copyWidget", (widget, widgetLocator) => { - const modifierKey = Cypress.platform === "darwin" ? "meta" : "ctrl"; - //Copy widget and verify all properties - cy.get(widgetsPage.propertypaneText) - .children() - .last() - .invoke("text") - .then((x) => { - cy.log(x); - let originalWidget = x.replaceAll("x", ""); - originalWidget = originalWidget.replaceAll(/\u200B/g, ""); - cy.log(originalWidget); - cy.get(widgetsPage.copyWidget).click({ force: true }); - cy.wait(2000); - cy.reload(); - // Wait for the widget to be appear in the DOM and press Ctrl/Cmd + V to paste the button. - cy.get(widgetLocator).should("be.visible"); - cy.get("body").type(`{${modifierKey}}v`); - cy.wait(2000); - cy.openPropertyPaneCopy(widget); - cy.get(widgetsPage.propertypaneText) - .children() - .last() - .invoke("text") - .then((y) => { - cy.log(y); - let copiedWidget = y.replaceAll("x", ""); - copiedWidget = copiedWidget.replaceAll(/\u200B/g, ""); - cy.log(copiedWidget); - expect(originalWidget).to.be.equal(copiedWidget); - }); - }); -}); - -Cypress.Commands.add("deleteWidget", (widget) => { - // Delete the button widget - cy.get(widgetsPage.removeWidget).click({ force: true }); - cy.wait(5000); - cy.wait("@updateLayout"); -}); - -Cypress.Commands.add("UpdateChartType", (typeOfChart) => { - // Command to change the chart type if the property pane of the chart widget is opened. - cy.get(viewWidgetsPage.chartType) - .last() - .click({ force: true }); - cy.get(commonlocators.dropdownmenu) - .children() - .contains(typeOfChart) - .click({ force: true }); - - cy.get(viewWidgetsPage.chartType + " span.cs-text").should( - "have.text", - typeOfChart, - ); -}); - -Cypress.Commands.add("createAndFillApi", (url, parameters) => { - cy.NavigateToApiEditor(); - cy.get(pages.integrationCreateNew) - .should("be.visible") - .click({ force: true }); - cy.testCreateApiButton(); - cy.get("@createNewApi").then((response) => { - cy.get(ApiEditor.ApiNameField).should("be.visible"); - expect(response.response.body.responseMeta.success).to.eq(true); - cy.get(ApiEditor.ApiNameField) - .click() - .invoke("text") - .then((text) => { - const someText = text; - expect(someText).to.equal(response.response.body.data.name); - }); - }); - cy.get(apiwidget.editResourceUrl) - .first() - .click({ force: true }) - .type( - url + parameters, - { parseSpecialCharSequences: false }, - { force: true }, - ); - cy.WaitAutoSave(); - cy.get(ApiEditor.formActionButtons).should("be.visible"); - cy.get(ApiEditor.ApiRunBtn).should("not.be.disabled"); -}); - Cypress.Commands.add("isSelectRow", (index) => { cy.get('.tbody .td[data-rowindex="' + index + '"][data-colindex="' + 0 + '"]') .first() @@ -3091,6 +950,7 @@ Cypress.Commands.add("startServerAndRoutes", () => { cy.route("POST", "api/v1/git/connect/*").as("connectGitRepo"); cy.route("POST", "api/v1/git/commit/*").as("commit"); cy.route("POST", "/api/v1/git/import/*").as("importFromGit"); + cy.route("PUT", "api/v1/collections/actions/refactor").as("renameJsAction"); cy.route("POST", "/api/v1/collections/actions").as("createNewJSCollection"); @@ -3111,109 +971,6 @@ Cypress.Commands.add("startErrorRoutes", () => { ); }); -Cypress.Commands.add("alertValidate", (text) => { - cy.get(commonlocators.success) - .should("be.visible") - .and("have.text", text); -}); - -Cypress.Commands.add("ExportVerify", (togglecss, name) => { - cy.togglebar(togglecss); - cy.get(".t--draggable-tablewidget button") - .invoke("attr", "aria-label") - .should("contain", name); - cy.togglebarDisable(togglecss); -}); - -Cypress.Commands.add("getTableDataSelector", (rowNum, colNum) => { - const selector = `.t--widget-tablewidget .tbody .td[data-rowindex=${rowNum}][data-colindex=${colNum}] div div`; - return selector; -}); - -Cypress.Commands.add("readTabledata", (rowNum, colNum) => { - // const selector = `.t--draggable-tablewidget .e-gridcontent.e-lib.e-droppable td[index=${rowNum}][aria-colindex=${colNum}]`; - const selector = `.tbody .td[data-rowindex="${rowNum}"][data-colindex="${colNum}"] div div`; - const tabVal = cy.get(selector).invoke("text"); - return tabVal; -}); - -Cypress.Commands.add( - "readTabledataPublish", - (rowNum, colNum, shouldNotGoOneLeveDeeper) => { - // const selector = `.t--widget-tablewidget .e-gridcontent.e-lib.e-droppable td[index=${rowNum}][aria-colindex=${colNum}]`; - const selector = `.t--widget-tablewidget .tbody .td[data-rowindex=${rowNum}][data-colindex=${colNum}] div ${ - !shouldNotGoOneLeveDeeper ? "div" : "" - }`; - const tabVal = cy.get(selector).invoke("text"); - return tabVal; - }, -); - -Cypress.Commands.add( - "readTabledataValidateCSS", - (rowNum, colNum, cssProperty, cssValue, shouldNotGotOneLeveDeeper) => { - const selector = `.t--widget-tablewidget .tbody .td[data-rowindex=${rowNum}][data-colindex=${colNum}] div ${ - !shouldNotGotOneLeveDeeper ? "div" : "" - }`; - cy.get(selector).should("have.css", cssProperty, cssValue); - }, -); - -Cypress.Commands.add( - "readTabledataFromSpecificIndex", - (rowNum, colNum, index) => { - // const selector = `.t--widget-tablewidget .e-gridcontent.e-lib.e-droppable td[index=${rowNum}][aria-colindex=${colNum}]`; - const selector = `.t--widget-tablewidget .tbody .td[data-rowindex=${rowNum}][data-colindex=${colNum}] div`; - const tabVal = cy - .get(selector) - .eq(index) - .invoke("text"); - return tabVal; - }, -); - -Cypress.Commands.add("tablefirstdataRow", () => { - let tabVal = cy - .xpath( - "//div[@class='tableWrap']//div[@class='table']//div[contains(@class, 'tbody')]/div[@class='tr']/div[@class ='td']", - { timeout: 10000 }, - ) - .first() - .invoke("text"); - return tabVal; -}); - -Cypress.Commands.add("scrollTabledataPublish", (rowNum, colNum) => { - const selector = `.t--widget-tablewidget .tbody .td[data-rowindex=${rowNum}][data-colindex=${colNum}] div div`; - const tabVal = cy - .get(selector) - .scrollIntoView() - .invoke("text"); - return tabVal; -}); - -Cypress.Commands.add("readTableLinkPublish", (rowNum, colNum) => { - const selector = `.t--widget-tablewidget .tbody .td[data-rowindex=${rowNum}][data-colindex=${colNum}] div .image-cell-wrapper .image-cell`; - const bgUrl = cy.get(selector).should("have.css", "background-image"); - return bgUrl; -}); - -Cypress.Commands.add("assertEvaluatedValuePopup", (expectedType) => { - cy.get(commonlocators.evaluatedTypeTitle) - .first() - .find("span") - .click(); - cy.get(dynamicInputLocators.evaluatedValue) - .should("be.visible") - .find("pre") - .first() - .should("have.text", expectedType); -}); - -Cypress.Commands.add("validateToastMessage", (value) => { - cy.get(commonlocators.toastMsg).should("contain.text", value); -}); - Cypress.Commands.add("NavigateToPaginationTab", () => { cy.get(ApiEditor.apiTab) .contains("Pagination") @@ -3281,39 +1038,10 @@ Cypress.Commands.add("ValidatePaginationInputData", () => { }); }); -Cypress.Commands.add("callApi", (apiname) => { - cy.get(commonlocators.callApi) - .first() - .click({ force: true }); - cy.get(commonlocators.singleSelectMenuItem) - .contains("Execute a query") - .click({ force: true }); - cy.get(commonlocators.selectMenuItem) - .contains(apiname) - .click({ force: true }); -}); - Cypress.Commands.add("assertPageSave", () => { cy.get(commonlocators.saveStatusSuccess, { timeout: 40000 }).should("exist"); }); -Cypress.Commands.add( - "validateWidgetExists", - { prevSubject: true }, - (selector) => { - cy.get(selector).should("exist"); - }, -); - -Cypress.Commands.add("ValidateQueryParams", (param) => { - cy.xpath(apiwidget.paramsTab) - .should("be.visible") - .click({ force: true }); - - cy.validateCodeEditorContent(apiwidget.paramKey, param.key); - cy.validateCodeEditorContent(apiwidget.paramValue, param.value); -}); - Cypress.Commands.add( "validateCodeEditorContent", (selector, contentToValidate) => { @@ -3323,35 +1051,10 @@ Cypress.Commands.add( }, ); -Cypress.Commands.add("renameDatasource", (datasourceName) => { - cy.get(".t--edit-datasource-name").click(); - cy.get(".t--edit-datasource-name input") - .clear() - .type(datasourceName, { force: true }) - .should("have.value", datasourceName) - .blur(); -}); - Cypress.Commands.add("skipGenerateCRUDPage", () => { cy.get(generatePage.buildFromScratchActionCard).click(); }); -Cypress.Commands.add("fillAmazonS3DatasourceForm", () => { - cy.get(datasourceEditor.projectID) - .clear() - .type(Cypress.env("S3_ACCESS_KEY")); - cy.get(datasourceEditor.serviceAccCredential) - .clear() - .type(Cypress.env("S3_SECRET_KEY")); -}); - -Cypress.Commands.add("createAmazonS3Datasource", () => { - cy.NavigateToDatasourceEditor(); - cy.get(datasourceEditor.AmazonS3).click(); - cy.fillAmazonS3DatasourceForm(); - cy.testSaveDatasource(); -}); - Cypress.Commands.add("updateMapType", (mapType) => { // Command to change the map chart type if the property pane of the map chart widget is opened. cy.get(viewWidgetsPage.mapType) @@ -3456,18 +1159,6 @@ Cypress.Commands.add("SignupFromAPI", (uname, pword) => { //Generate CRUD page methods: -Cypress.Commands.add("fillMongoDatasourceFormWithURI", () => { - cy.xpath(datasourceEditor["mongoUriDropdown"]) - .click() - .wait(500); - cy.xpath(datasourceEditor["mongoUriYes"]) - .click() - .wait(500); - cy.xpath(datasourceEditor["mongoUriInput"]).type( - datasourceFormData["mongo-uri"], - ); -}); - Cypress.Commands.add("startInterceptRoutesForMySQL", () => { //All stubbing - updating app id to current app id for Delete app by api call to be successfull: @@ -3562,260 +1253,6 @@ Cypress.Commands.add("skipCommentsOnboarding", () => { cy.get("button[type='submit']").click(); }); -Cypress.Commands.add("revokeAccessGit", (appName) => { - cy.xpath("//span[text()= `${appName}`]") - .parent() - .next() - .click(); - cy.get(gitSyncLocators.disconnectAppNameInput).type(appName); - cy.get(gitSyncLocators.disconnectButton).click(); - cy.route("POST", "api/v1/git/disconnect/*").as("disconnect"); - cy.get(gitSyncLocators.disconnectButton).click(); - cy.wait("@disconnect").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); - cy.window() - .its("store") - .invoke("getState") - .then((state) => { - const { id, name } = state.ui.gitSync.disconnectingGitApp; - expect(name).to.eq(""); - expect(id).to.eq(""); - }); -}); -Cypress.Commands.add( - "connectToGitRepo", - (repo, shouldCommit = true, assertConnectFailure) => { - const testEmail = "test@test.com"; - const testUsername = "testusername"; - const owner = Cypress.env("TEST_GITHUB_USER_NAME"); - - let generatedKey; - // open gitSync modal - cy.get(homePage.deployPopupOptionTrigger).click(); - cy.get(homePage.connectToGitBtn).click({ force: true }); - - cy.intercept( - { - url: "api/v1/git/connect/*", - hostname: window.location.host, - }, - (req) => { - req.headers["origin"] = "Cypress"; - }, - ); - cy.intercept("POST", "/api/v1/applications/ssh-keypair/*").as( - `generateKey-${repo}`, - ); - cy.get(gitSyncLocators.gitRepoInput).type( - `git@github.com:${owner}/${repo}.git`, - ); - cy.get(gitSyncLocators.generateDeployKeyBtn).click(); - cy.wait(`@generateKey-${repo}`).then((result) => { - generatedKey = result.response.body.data.publicKey; - generatedKey = generatedKey.slice(0, generatedKey.length - 1); - // fetch the generated key and post to the github repo - cy.request({ - method: "POST", - url: `${GITHUB_API_BASE}/repos/${Cypress.env( - "TEST_GITHUB_USER_NAME", - )}/${repo}/keys`, - headers: { - Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`, - }, - body: { - title: "key0", - key: generatedKey, - }, - }); - - cy.get(gitSyncLocators.useGlobalGitConfig).click(); - - cy.get(gitSyncLocators.gitConfigNameInput).type( - `{selectall}${testUsername}`, - ); - cy.get(gitSyncLocators.gitConfigEmailInput).type( - `{selectall}${testEmail}`, - ); - // click on the connect button and verify - cy.get(gitSyncLocators.connectSubmitBtn).click(); - - if (!assertConnectFailure) { - // check for connect success - cy.wait("@connectGitRepo").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); - - // click commit button - if (shouldCommit) { - cy.get(gitSyncLocators.commitCommentInput).type("Initial Commit"); - cy.get(gitSyncLocators.commitButton).click(); - // check for commit success - cy.wait("@commit").should( - "have.nested.property", - "response.body.responseMeta.status", - 201, - ); - - cy.get(gitSyncLocators.closeGitSyncModal).click(); - } - } else { - cy.wait("@connectGitRepo").then((interception) => { - const status = interception.response.body.responseMeta.status; - expect(status).to.be.gte(400); - }); - } - }); - }, -); - -Cypress.Commands.add("createGitBranch", (branch) => { - cy.get(gitSyncLocators.branchButton).click({ force: true }); - cy.get(gitSyncLocators.branchSearchInput).type(`{selectall}${branch}{enter}`); - // increasing timeout to reduce flakyness - cy.get(".bp3-spinner", { timeout: 30000 }).should("exist"); - cy.get(".bp3-spinner", { timeout: 30000 }).should("not.exist"); -}); - -Cypress.Commands.add("switchGitBranch", (branch, expectError) => { - cy.get(gitSyncLocators.branchButton).click({ force: true }); - cy.get(gitSyncLocators.branchSearchInput).type(`{selectall}${branch}`); - cy.get(gitSyncLocators.branchListItem) - .contains(branch) - .click(); - if (!expectError) { - // increasing timeout to reduce flakyness - cy.get(".bp3-spinner", { timeout: 30000 }).should("exist"); - cy.get(".bp3-spinner", { timeout: 30000 }).should("not.exist"); - } -}); - -Cypress.Commands.add("createTestGithubRepo", (repo, privateFlag = false) => { - cy.request({ - method: "POST", - url: `${GITHUB_API_BASE}/user/repos`, - headers: { - Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`, - }, - body: { - name: repo, - private: privateFlag, - }, - }); -}); - -Cypress.Commands.add("mergeViaGithubApi", ({ base, head, repo }) => { - const owner = Cypress.env("TEST_GITHUB_USER_NAME"); - cy.request({ - method: "POST", - url: `${GITHUB_API_BASE}/repos/${owner}/${repo}/merges`, - headers: { - Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`, - }, - body: { - base, - head, - }, - }); -}); - -Cypress.Commands.add("deleteTestGithubRepo", (repo) => { - cy.request({ - method: "DELETE", - url: `${GITHUB_API_BASE}/repos/${Cypress.env( - "TEST_GITHUB_USER_NAME", - )}/${repo}`, - headers: { - Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`, - }, - }); -}); - -Cypress.Commands.add( - "renameBranchViaGithubApi", - (repo, currentName, newName) => { - cy.request({ - method: "POST", - url: `${GITHUB_API_BASE}/repos/${Cypress.env( - "TEST_GITHUB_USER_NAME", - )}/${repo}/branches/${currentName}/rename`, - headers: { - Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`, - }, - body: { - new_name: newName, - }, - }); - }, -); - -Cypress.Commands.add("commitAndPush", (assertFailure) => { - cy.get(homePage.publishButton).click(); - cy.get(gitSyncLocators.commitCommentInput).type("Initial Commit"); - cy.get(gitSyncLocators.commitButton).click(); - - if (!assertFailure) { - // check for commit success - cy.wait("@commit").should( - "have.nested.property", - "response.body.responseMeta.status", - 201, - ); - } else { - cy.wait("@commit").then((interception) => { - const status = interception.response.body.responseMeta.status; - expect(status).to.be.gte(400); - }); - } - - cy.get(gitSyncLocators.closeGitSyncModal).click(); -}); - -// todo rishabh s: refactor -Cypress.Commands.add( - "createAppAndConnectGit", - (appname, shouldConnect = true, assertConnectFailure) => { - cy.get(homePage.homeIcon).click({ force: true }); - cy.get(homePage.createNew) - .first() - .click({ force: true }); - cy.wait("@createNewApplication").should( - "have.nested.property", - "response.body.responseMeta.status", - 201, - ); - cy.get("#loading").should("not.exist"); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(2000); - - cy.AppSetupForRename(); - cy.get(homePage.applicationName).type(appname + "{enter}"); - cy.wait("@updateApplication").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); - - cy.createTestGithubRepo(appname, true); - cy.connectToGitRepo(appname, false, assertConnectFailure); - cy.get(gitSyncLocators.closeGitSyncModal).click({ force: true }); - }, -); - -Cypress.Commands.add("merge", (destinationBranch) => { - cy.get(gitSyncLocators.bottomBarMergeButton).click(); - cy.get(gitSyncLocators.mergeBranchDropdownDestination).click(); - cy.get(commonLocators.dropdownmenu) - .contains(destinationBranch) - .click(); - cy.contains(Cypress.env("MESSAGES").NO_MERGE_CONFLICT()); - cy.get(gitSyncLocators.mergeCTA).click(); -}); - Cypress.Commands.add( "paste", { prevSubject: true }, @@ -3834,120 +1271,6 @@ Cypress.Commands.add( }, ); -Cypress.Commands.add( - "importAppFromGit", - (repo, shouldCommit = true, assertConnectFailure) => { - const testEmail = "test@test.com"; - const testUsername = "testusername"; - const owner = Cypress.env("TEST_GITHUB_USER_NAME"); - - let generatedKey; - cy.intercept( - { - url: "api/v1/git/connect/*", - hostname: window.location.host, - }, - (req) => { - req.headers["origin"] = "Cypress"; - }, - ); - cy.intercept("GET", "api/v1/git/import/keys").as(`generateKey-${repo}`); - cy.get(gitSyncLocators.gitRepoInput).type( - `git@github.com:${owner}/${repo}.git`, - ); - cy.get(gitSyncLocators.generateDeployKeyBtn).click(); - cy.wait(`@generateKey-${repo}`).then((result) => { - generatedKey = result.response.body.data.publicKey; - generatedKey = generatedKey.slice(0, generatedKey.length - 1); - // fetch the generated key and post to the github repo - cy.request({ - method: "POST", - url: `${GITHUB_API_BASE}/repos/${Cypress.env( - "TEST_GITHUB_USER_NAME", - )}/${repo}/keys`, - headers: { - Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`, - }, - body: { - title: "key0", - key: generatedKey, - }, - }); - - cy.get(gitSyncLocators.useGlobalGitConfig).click(); - - cy.get(gitSyncLocators.gitConfigNameInput).type( - `{selectall}${testUsername}`, - ); - cy.get(gitSyncLocators.gitConfigEmailInput).type( - `{selectall}${testEmail}`, - ); - // click on the connect button and verify - cy.get(gitSyncLocators.connectSubmitBtn).click(); - - if (!assertConnectFailure) { - // check for connect success - cy.wait("@importFromGit").should( - "have.nested.property", - "response.body.responseMeta.status", - 201, - ); - } else { - cy.wait("@importFromGit").then((interception) => { - const status = interception.response.body.responseMeta.status; - expect(status).to.be.gte(400); - }); - } - }); - }, -); - -Cypress.Commands.add("ReconnectDatasource", (datasource) => { - cy.xpath(`//span[text()='${datasource}']`).click(); -}); - -Cypress.Commands.add("clearPropertyValue", (value) => { - cy.get(".CodeMirror textarea") - .eq(value) - .focus({ force: true }) - .type("{uparrow}", { force: true }) - .type("{ctrl}{shift}{downarrow}", { force: true }); - cy.focused().then(($cm) => { - if ($cm.contents !== "") { - cy.log("The field is empty"); - cy.get(".CodeMirror textarea") - .eq(value) - .clear({ - force: true, - }); - } - }); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(1000); -}); - -Cypress.Commands.add( - "validateNSelectDropdown", - (ddTitle, currentValue, newValue) => { - let toChange = false; - cy.xpath('//span[contains(text(),"' + currentValue + '")]').should( - "exist", - currentValue + " dropdown value not present", - ); - if (newValue) toChange = true; - if (toChange) { - cy.xpath( - "//p[text()='" + - ddTitle + - "']/parent::label/following-sibling::div/div/div", - ).click(); //to expand the dropdown - cy.xpath('//span[contains(text(),"' + newValue + '")]') - .last() - .click({ force: true }); //to select the new value - } - }, -); - Cypress.Commands.add("typeValueNValidate", (valueToType, fieldName = "") => { if (fieldName) { cy.xpath( diff --git a/app/client/cypress/support/dataSourceCommands.js b/app/client/cypress/support/dataSourceCommands.js new file mode 100644 index 0000000000..347652fc1c --- /dev/null +++ b/app/client/cypress/support/dataSourceCommands.js @@ -0,0 +1,384 @@ +/* eslint-disable cypress/no-unnecessary-waiting */ +/* eslint-disable cypress/no-assigning-return-values */ + +require("cy-verify-downloads").addCustomCommand(); +require("cypress-file-upload"); + +const { + addMatchImageSnapshotCommand, +} = require("cypress-image-snapshot/command"); +const pages = require("../locators/Pages.json"); +const datasourceEditor = require("../locators/DatasourcesEditor.json"); +const datasourceFormData = require("../fixtures/datasources.json"); +const explorer = require("../locators/explorerlocators.json"); + +export const initLocalstorage = () => { + cy.window().then((window) => { + window.localStorage.setItem("ShowCommentsButtonToolTip", ""); + window.localStorage.setItem("updateDismissed", "true"); + }); +}; + +Cypress.Commands.add("firestoreDatasourceForm", () => { + cy.get(datasourceEditor.datasourceConfigUrl).type( + datasourceFormData["database-url"], + ); + cy.get(datasourceEditor.projectID).type(datasourceFormData["projectID"]); + cy.get(datasourceEditor.serviceAccCredential) + .clear() + .type(datasourceFormData["serviceAccCredentials"]); +}); + +Cypress.Commands.add("amazonDatasourceForm", () => { + cy.get(datasourceEditor.projectID).type(datasourceFormData["access_key"]); + cy.get(datasourceEditor.serviceAccCredential) + .clear() + .type(datasourceFormData["secret_key"]); +}); + +Cypress.Commands.add("testSaveDeleteDatasource", () => { + // Instead of deleting the last datasource on the active datasources list, + // we delete the datasource that was just created (identified by its title) + cy.get(datasourceEditor.datasourceTitle) + .invoke("text") + .then((datasourceTitle) => { + // test datasource + cy.get(".t--test-datasource").click(); + cy.wait("@testDatasource"); + // .should("have.nested.property", "response.body.data.success", true) + // .debug(); + + // save datasource + cy.get(".t--save-datasource").click(); + cy.wait("@saveDatasource").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + // select datasource to be deleted by datasource title + cy.get(`${datasourceEditor.datasourceCard}`) + .contains(datasourceTitle) + .last() + .click(); + // delete datasource + cy.get(".t--delete-datasource").click(); + cy.get(".t--delete-datasource") + .contains("Are you sure?") + .click(); + cy.wait("@deleteDatasource").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + }); +}); + +Cypress.Commands.add("NavigateToDatasourceEditor", () => { + cy.get(explorer.addDBQueryEntity) + .last() + .click({ force: true }); + cy.get(pages.integrationCreateNew) + .should("be.visible") + .click({ force: true }); +}); + +Cypress.Commands.add("testDatasource", (expectedRes = true) => { + cy.get(".t--test-datasource").click({ force: true }); + cy.wait("@testDatasource").should( + "have.nested.property", + "response.body.data.success", + expectedRes, + ); +}); + +Cypress.Commands.add("saveDatasource", () => { + cy.get(".t--save-datasource").click({ force: true }); + cy.wait("@saveDatasource") + .then((xhr) => { + cy.log(JSON.stringify(xhr.response.body)); + }) + .should("have.nested.property", "response.body.responseMeta.status", 200); +}); + +Cypress.Commands.add("testSaveDatasource", (expectedRes = true) => { + cy.testDatasource(expectedRes); + cy.saveDatasource(); + // cy.get(datasourceEditor.datasourceCard) + // .last() + // .click(); +}); + +Cypress.Commands.add( + "fillMongoDatasourceForm", + (shouldAddTrailingSpaces = false) => { + const hostAddress = shouldAddTrailingSpaces + ? datasourceFormData["mongo-host"] + " " + : datasourceFormData["mongo-host"]; + // const databaseName = shouldAddTrailingSpaces + // ? datasourceFormData["mongo-databaseName"] + " " + // : datasourceFormData["mongo-databaseName"]; + cy.get(datasourceEditor["host"]).type(hostAddress); + cy.get(datasourceEditor.port).type(datasourceFormData["mongo-port"]); + //cy.get(datasourceEditor["port"]).type(datasourceFormData["mongo-port"]); + //cy.get(datasourceEditor["selConnectionType"]).click(); + //cy.contains(datasourceFormData["connection-type"]).click(); + //cy.get(datasourceEditor["defaultDatabaseName"]).type(databaseName);//is optional hence removing + cy.get(datasourceEditor.sectionAuthentication).click(); + cy.get(datasourceEditor["databaseName"]) + .clear() + .type(datasourceFormData["mongo-databaseName"]); + // cy.get(datasourceEditor["username"]).type( + // datasourceFormData["mongo-username"], + // ); + // cy.get(datasourceEditor["password"]).type( + // datasourceFormData["mongo-password"], + // ); + // cy.get(datasourceEditor["authenticationAuthtype"]).click(); + // cy.contains(datasourceFormData["mongo-authenticationAuthtype"]).click({ + // force: true, + // }); + }, +); + +Cypress.Commands.add( + "fillPostgresDatasourceForm", + (shouldAddTrailingSpaces = false) => { + const hostAddress = shouldAddTrailingSpaces + ? datasourceFormData["postgres-host"] + " " + : datasourceFormData["postgres-host"]; + const databaseName = shouldAddTrailingSpaces + ? datasourceFormData["postgres-databaseName"] + " " + : datasourceFormData["postgres-databaseName"]; + + cy.get(datasourceEditor.host).type(hostAddress); + cy.get(datasourceEditor.port).type(datasourceFormData["postgres-port"]); + cy.get(datasourceEditor.databaseName) + .clear() + .type(databaseName); + cy.get(datasourceEditor.sectionAuthentication).click(); + cy.get(datasourceEditor.username).type( + datasourceFormData["postgres-username"], + ); + cy.get(datasourceEditor.password).type( + datasourceFormData["postgres-password"], + ); + }, +); + +Cypress.Commands.add( + "fillMySQLDatasourceForm", + (shouldAddTrailingSpaces = false) => { + const hostAddress = shouldAddTrailingSpaces + ? datasourceFormData["mysql-host"] + " " + : datasourceFormData["mysql-host"]; + const databaseName = shouldAddTrailingSpaces + ? datasourceFormData["mysql-databaseName"] + " " + : datasourceFormData["mysql-databaseName"]; + + cy.get(datasourceEditor.host).type(hostAddress); + cy.get(datasourceEditor.port).type(datasourceFormData["mysql-port"]); + cy.get(datasourceEditor.databaseName) + .clear() + .type(databaseName); + + cy.get(datasourceEditor.sectionAuthentication).click(); + cy.get(datasourceEditor.username).type( + datasourceFormData["mysql-username"], + ); + cy.get(datasourceEditor.password).type( + datasourceFormData["mysql-password"], + ); + }, +); + +Cypress.Commands.add( + "fillMsSQLDatasourceForm", + (shouldAddTrailingSpaces = false) => { + const hostAddress = shouldAddTrailingSpaces + ? datasourceFormData["mssql-host"] + " " + : datasourceFormData["mssql-host"]; + const databaseName = shouldAddTrailingSpaces + ? datasourceFormData["mssql-databaseName"] + " " + : datasourceFormData["mssql-databaseName"]; + + cy.get(datasourceEditor.host).type(hostAddress); + cy.get(datasourceEditor.port).type(datasourceFormData["mssql-port"]); + cy.get(datasourceEditor.databaseName) + .clear() + .type(databaseName); + + cy.get(datasourceEditor.sectionAuthentication).click(); + cy.get(datasourceEditor.username).type( + datasourceFormData["mssql-username"], + ); + cy.get(datasourceEditor.password).type( + datasourceFormData["mssql-password"], + ); + }, +); + +Cypress.Commands.add( + "fillArangoDBDatasourceForm", + (shouldAddTrailingSpaces = false) => { + const hostAddress = shouldAddTrailingSpaces + ? datasourceFormData["arango-host"] + " " + : datasourceFormData["arango-host"]; + const databaseName = shouldAddTrailingSpaces + ? datasourceFormData["arango-databaseName"] + " " + : datasourceFormData["arango-databaseName"]; + + cy.get(datasourceEditor.host).type(hostAddress); + cy.get(datasourceEditor.port).type(datasourceFormData["arango-port"]); + cy.get(datasourceEditor.databaseName) + .clear() + .type(databaseName); + + cy.get(datasourceEditor.sectionAuthentication).click(); + cy.get(datasourceEditor.username).type( + datasourceFormData["arango-username"], + ); + cy.get(datasourceEditor.password).type( + datasourceFormData["arango-password"], + ); + }, +); + +Cypress.Commands.add( + "fillRedshiftDatasourceForm", + (shouldAddTrailingSpaces = false) => { + const hostAddress = shouldAddTrailingSpaces + ? datasourceFormData["redshift-host"] + " " + : datasourceFormData["redshift-host"]; + const databaseName = shouldAddTrailingSpaces + ? datasourceFormData["redshift-databaseName"] + " " + : datasourceFormData["redshift-databaseName"]; + + cy.get(datasourceEditor.host).type(hostAddress); + cy.get(datasourceEditor.port).type(datasourceFormData["redshift-port"]); + cy.get(datasourceEditor.databaseName) + .clear() + .type(databaseName); + + cy.get(datasourceEditor.sectionAuthentication).click(); + cy.get(datasourceEditor.username).type( + datasourceFormData["redshift-username"], + ); + cy.get(datasourceEditor.password).type( + datasourceFormData["redshift-password"], + ); + }, +); + +Cypress.Commands.add( + "fillUsersMockDatasourceForm", + (shouldAddTrailingSpaces = false) => { + const userMockDatabaseName = shouldAddTrailingSpaces + ? `${datasourceFormData["mockDatabaseName"] + " "}` + : datasourceFormData["mockDatabaseName"]; + + const userMockHostAddress = shouldAddTrailingSpaces + ? `${datasourceFormData["mockHostAddress"] + " "}` + : datasourceFormData["mockHostAddress"]; + + const userMockDatabaseUsername = shouldAddTrailingSpaces + ? `${datasourceFormData["mockDatabaseUsername"] + " "}` + : datasourceFormData["mockDatabaseUsername"]; + + cy.get(datasourceEditor["host"]) + .clear() + .type(userMockHostAddress); + + cy.get(datasourceEditor["databaseName"]) + .clear() + .type(userMockDatabaseName); + + cy.get(datasourceEditor["sectionAuthentication"]).click(); + + cy.get(datasourceEditor["password"]) + .clear() + .type(datasourceFormData["mockDatabasePassword"]); + + cy.get(datasourceEditor["username"]) + .clear() + .type(userMockDatabaseUsername); + }, +); +Cypress.Commands.add( + "fillSMTPDatasourceForm", + (shouldAddTrailingSpaces = false) => { + const hostAddress = shouldAddTrailingSpaces + ? datasourceFormData["smtp-host"] + " " + : datasourceFormData["smtp-host"]; + cy.get(datasourceEditor.host).type(hostAddress); + cy.get(datasourceEditor.port).type(datasourceFormData["smtp-port"]); + cy.get(datasourceEditor.sectionAuthentication).click(); + cy.get(datasourceEditor.username).type(datasourceFormData["smtp-username"]); + cy.get(datasourceEditor.password).type(datasourceFormData["smtp-password"]); + }, +); + +Cypress.Commands.add("createPostgresDatasource", () => { + cy.NavigateToDatasourceEditor(); + cy.get(datasourceEditor.PostgreSQL).click(); + //cy.getPluginFormsAndCreateDatasource(); + cy.fillPostgresDatasourceForm(); + cy.testSaveDatasource(); +}); + +Cypress.Commands.add("deleteDatasource", (datasourceName) => { + cy.NavigateToQueryEditor(); + cy.get(pages.integrationActiveTab) + .should("be.visible") + .click({ force: true }); + cy.contains(".t--datasource-name", datasourceName).click(); + cy.get(".t--delete-datasource").click(); + cy.get(".t--delete-datasource") + .contains("Are you sure?") + .click(); + cy.wait("@deleteDatasource").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); +}); + +Cypress.Commands.add("renameDatasource", (datasourceName) => { + cy.get(".t--edit-datasource-name").click(); + cy.get(".t--edit-datasource-name input") + .clear() + .type(datasourceName, { force: true }) + .should("have.value", datasourceName) + .blur(); +}); + +Cypress.Commands.add("fillAmazonS3DatasourceForm", () => { + cy.get(datasourceEditor.projectID) + .clear() + .type(Cypress.env("S3_ACCESS_KEY")); + cy.get(datasourceEditor.serviceAccCredential) + .clear() + .type(Cypress.env("S3_SECRET_KEY")); +}); + +Cypress.Commands.add("createAmazonS3Datasource", () => { + cy.NavigateToDatasourceEditor(); + cy.get(datasourceEditor.AmazonS3).click(); + cy.fillAmazonS3DatasourceForm(); + cy.testSaveDatasource(); +}); + +Cypress.Commands.add("fillMongoDatasourceFormWithURI", () => { + cy.xpath(datasourceEditor["mongoUriDropdown"]) + .click() + .wait(500); + cy.xpath(datasourceEditor["mongoUriYes"]) + .click() + .wait(500); + cy.xpath(datasourceEditor["mongoUriInput"]).type( + datasourceFormData["mongo-uri"], + ); +}); + +Cypress.Commands.add("ReconnectDatasource", (datasource) => { + cy.xpath(`//span[text()='${datasource}']`).click(); +}); diff --git a/app/client/cypress/support/gitSync.js b/app/client/cypress/support/gitSync.js new file mode 100644 index 0000000000..96f170c5ed --- /dev/null +++ b/app/client/cypress/support/gitSync.js @@ -0,0 +1,336 @@ +/* eslint-disable cypress/no-unnecessary-waiting */ +/* eslint-disable cypress/no-assigning-return-values */ + +require("cy-verify-downloads").addCustomCommand(); +require("cypress-file-upload"); + +const { + addMatchImageSnapshotCommand, +} = require("cypress-image-snapshot/command"); +import gitSyncLocators from "../locators/gitSyncLocators"; +import homePage from "../locators/HomePage"; +const commonLocators = require("../locators/commonlocators.json"); + +const GITHUB_API_BASE = "https://api.github.com"; + +Cypress.Commands.add("revokeAccessGit", (appName) => { + cy.xpath("//span[text()= `${appName}`]") + .parent() + .next() + .click(); + cy.get(gitSyncLocators.disconnectAppNameInput).type(appName); + cy.get(gitSyncLocators.disconnectButton).click(); + cy.route("POST", "api/v1/git/disconnect/*").as("disconnect"); + cy.get(gitSyncLocators.disconnectButton).click(); + cy.wait("@disconnect").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + cy.window() + .its("store") + .invoke("getState") + .then((state) => { + const { id, name } = state.ui.gitSync.disconnectingGitApp; + expect(name).to.eq(""); + expect(id).to.eq(""); + }); +}); +Cypress.Commands.add( + "connectToGitRepo", + (repo, shouldCommit = true, assertConnectFailure) => { + const testEmail = "test@test.com"; + const testUsername = "testusername"; + const owner = Cypress.env("TEST_GITHUB_USER_NAME"); + + let generatedKey; + // open gitSync modal + cy.get(homePage.deployPopupOptionTrigger).click(); + cy.get(homePage.connectToGitBtn).click({ force: true }); + + cy.intercept( + { + url: "api/v1/git/connect/*", + hostname: window.location.host, + }, + (req) => { + req.headers["origin"] = "Cypress"; + }, + ); + cy.intercept("POST", "/api/v1/applications/ssh-keypair/*").as( + `generateKey-${repo}`, + ); + cy.get(gitSyncLocators.gitRepoInput).type( + `git@github.com:${owner}/${repo}.git`, + ); + cy.get(gitSyncLocators.generateDeployKeyBtn).click(); + cy.wait(`@generateKey-${repo}`).then((result) => { + generatedKey = result.response.body.data.publicKey; + generatedKey = generatedKey.slice(0, generatedKey.length - 1); + // fetch the generated key and post to the github repo + cy.request({ + method: "POST", + url: `${GITHUB_API_BASE}/repos/${Cypress.env( + "TEST_GITHUB_USER_NAME", + )}/${repo}/keys`, + headers: { + Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`, + }, + body: { + title: "key0", + key: generatedKey, + }, + }); + + cy.get(gitSyncLocators.useGlobalGitConfig).click(); + + cy.get(gitSyncLocators.gitConfigNameInput).type( + `{selectall}${testUsername}`, + ); + cy.get(gitSyncLocators.gitConfigEmailInput).type( + `{selectall}${testEmail}`, + ); + // click on the connect button and verify + cy.get(gitSyncLocators.connectSubmitBtn).click(); + + if (!assertConnectFailure) { + // check for connect success + cy.wait("@connectGitRepo").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + + // click commit button + if (shouldCommit) { + cy.get(gitSyncLocators.commitCommentInput).type("Initial Commit"); + cy.get(gitSyncLocators.commitButton).click(); + // check for commit success + cy.wait("@commit").should( + "have.nested.property", + "response.body.responseMeta.status", + 201, + ); + + cy.get(gitSyncLocators.closeGitSyncModal).click(); + } + } else { + cy.wait("@connectGitRepo").then((interception) => { + const status = interception.response.body.responseMeta.status; + expect(status).to.be.gte(400); + }); + } + }); + }, +); + +Cypress.Commands.add("createGitBranch", (branch) => { + cy.get(gitSyncLocators.branchButton).click({ force: true }); + cy.get(gitSyncLocators.branchSearchInput).type(`{selectall}${branch}{enter}`); + // increasing timeout to reduce flakyness + cy.get(".bp3-spinner", { timeout: 30000 }).should("exist"); + cy.get(".bp3-spinner", { timeout: 30000 }).should("not.exist"); +}); + +Cypress.Commands.add("switchGitBranch", (branch, expectError) => { + cy.get(gitSyncLocators.branchButton).click({ force: true }); + cy.get(gitSyncLocators.branchSearchInput).type(`{selectall}${branch}`); + cy.get(gitSyncLocators.branchListItem) + .contains(branch) + .click(); + if (!expectError) { + // increasing timeout to reduce flakyness + cy.get(".bp3-spinner", { timeout: 30000 }).should("exist"); + cy.get(".bp3-spinner", { timeout: 30000 }).should("not.exist"); + } +}); + +Cypress.Commands.add("createTestGithubRepo", (repo, privateFlag = false) => { + cy.request({ + method: "POST", + url: `${GITHUB_API_BASE}/user/repos`, + headers: { + Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`, + }, + body: { + name: repo, + private: privateFlag, + }, + }); +}); + +Cypress.Commands.add("mergeViaGithubApi", ({ base, head, repo }) => { + const owner = Cypress.env("TEST_GITHUB_USER_NAME"); + cy.request({ + method: "POST", + url: `${GITHUB_API_BASE}/repos/${owner}/${repo}/merges`, + headers: { + Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`, + }, + body: { + base, + head, + }, + }); +}); + +Cypress.Commands.add("deleteTestGithubRepo", (repo) => { + cy.request({ + method: "DELETE", + url: `${GITHUB_API_BASE}/repos/${Cypress.env( + "TEST_GITHUB_USER_NAME", + )}/${repo}`, + headers: { + Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`, + }, + }); +}); + +Cypress.Commands.add( + "renameBranchViaGithubApi", + (repo, currentName, newName) => { + cy.request({ + method: "POST", + url: `${GITHUB_API_BASE}/repos/${Cypress.env( + "TEST_GITHUB_USER_NAME", + )}/${repo}/branches/${currentName}/rename`, + headers: { + Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`, + }, + body: { + new_name: newName, + }, + }); + }, +); + +Cypress.Commands.add("commitAndPush", (assertFailure) => { + cy.get(homePage.publishButton).click(); + cy.get(gitSyncLocators.commitCommentInput).type("Initial Commit"); + cy.get(gitSyncLocators.commitButton).click(); + + if (!assertFailure) { + // check for commit success + cy.wait("@commit").should( + "have.nested.property", + "response.body.responseMeta.status", + 201, + ); + } else { + cy.wait("@commit").then((interception) => { + const status = interception.response.body.responseMeta.status; + expect(status).to.be.gte(400); + }); + } + + cy.get(gitSyncLocators.closeGitSyncModal).click(); +}); + +// todo rishabh s: refactor +Cypress.Commands.add( + "createAppAndConnectGit", + (appname, shouldConnect = true, assertConnectFailure) => { + cy.get(homePage.homeIcon).click({ force: true }); + cy.get(homePage.createNew) + .first() + .click({ force: true }); + cy.wait("@createNewApplication").should( + "have.nested.property", + "response.body.responseMeta.status", + 201, + ); + cy.get("#loading").should("not.exist"); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(2000); + + cy.AppSetupForRename(); + cy.get(homePage.applicationName).type(appname + "{enter}"); + cy.wait("@updateApplication").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + + cy.createTestGithubRepo(appname, true); + cy.connectToGitRepo(appname, false, assertConnectFailure); + cy.get(gitSyncLocators.closeGitSyncModal).click({ force: true }); + }, +); + +Cypress.Commands.add("merge", (destinationBranch) => { + cy.get(gitSyncLocators.bottomBarMergeButton).click(); + cy.get(gitSyncLocators.mergeBranchDropdownDestination).click(); + cy.get(commonLocators.dropdownmenu) + .contains(destinationBranch) + .click(); + cy.contains(Cypress.env("MESSAGES").NO_MERGE_CONFLICT()); + cy.get(gitSyncLocators.mergeCTA).click(); +}); + +Cypress.Commands.add( + "importAppFromGit", + (repo, shouldCommit = true, assertConnectFailure) => { + const testEmail = "test@test.com"; + const testUsername = "testusername"; + const owner = Cypress.env("TEST_GITHUB_USER_NAME"); + + let generatedKey; + cy.intercept( + { + url: "api/v1/git/connect/*", + hostname: window.location.host, + }, + (req) => { + req.headers["origin"] = "Cypress"; + }, + ); + cy.intercept("GET", "api/v1/git/import/keys").as(`generateKey-${repo}`); + cy.get(gitSyncLocators.gitRepoInput).type( + `git@github.com:${owner}/${repo}.git`, + ); + cy.get(gitSyncLocators.generateDeployKeyBtn).click(); + cy.wait(`@generateKey-${repo}`).then((result) => { + generatedKey = result.response.body.data.publicKey; + generatedKey = generatedKey.slice(0, generatedKey.length - 1); + // fetch the generated key and post to the github repo + cy.request({ + method: "POST", + url: `${GITHUB_API_BASE}/repos/${Cypress.env( + "TEST_GITHUB_USER_NAME", + )}/${repo}/keys`, + headers: { + Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`, + }, + body: { + title: "key0", + key: generatedKey, + }, + }); + + cy.get(gitSyncLocators.useGlobalGitConfig).click(); + + cy.get(gitSyncLocators.gitConfigNameInput).type( + `{selectall}${testUsername}`, + ); + cy.get(gitSyncLocators.gitConfigEmailInput).type( + `{selectall}${testEmail}`, + ); + // click on the connect button and verify + cy.get(gitSyncLocators.connectSubmitBtn).click(); + + if (!assertConnectFailure) { + // check for connect success + cy.wait("@importFromGit").should( + "have.nested.property", + "response.body.responseMeta.status", + 201, + ); + } else { + cy.wait("@importFromGit").then((interception) => { + const status = interception.response.body.responseMeta.status; + expect(status).to.be.gte(400); + }); + } + }); + }, +); diff --git a/app/client/cypress/support/index.js b/app/client/cypress/support/index.js index a45c718b64..dd4edda58a 100644 --- a/app/client/cypress/support/index.js +++ b/app/client/cypress/support/index.js @@ -15,26 +15,28 @@ /// import "cypress-real-events/support"; -import "cypress-xpath"; import "cypress-wait-until"; -/// - -let appName; -let applicationId; - +import "cypress-xpath"; +import * as MESSAGES from "../../../client/src/ce/constants/messages.ts"; +import "./ApiCommands"; // Import commands.js using ES2015 syntax: import "./commands"; import { initLocalstorage } from "./commands"; +import "./dataSourceCommands"; +import "./gitSync"; import { initLocalstorageRegistry } from "./Objects/Registry"; -import * as MESSAGES from "../../../client/src/ce/constants/messages.ts"; +import "./OrgCommands"; +import "./queryCommands"; +import "./widgetCommands"; +/// -Cypress.on("uncaught:exception", (err, runnable) => { +Cypress.on("uncaught:exception", () => { // returning false here prevents Cypress from // failing the test return false; }); -Cypress.on("fail", (error, runnable) => { +Cypress.on("fail", (error) => { throw error; // throw error to have test still fail }); diff --git a/app/client/cypress/support/queryCommands.js b/app/client/cypress/support/queryCommands.js new file mode 100644 index 0000000000..ecee8f55fb --- /dev/null +++ b/app/client/cypress/support/queryCommands.js @@ -0,0 +1,191 @@ +/* eslint-disable cypress/no-unnecessary-waiting */ +/* eslint-disable cypress/no-assigning-return-values */ + +require("cy-verify-downloads").addCustomCommand(); +require("cypress-file-upload"); + +const { + addMatchImageSnapshotCommand, +} = require("cypress-image-snapshot/command"); +const datasourceEditor = require("../locators/DatasourcesEditor.json"); +const datasourceFormData = require("../fixtures/datasources.json"); +const commonlocators = require("../locators/commonlocators.json"); +const queryEditor = require("../locators/QueryEditor.json"); +const widgetsPage = require("../locators/Widgets.json"); +const apiwidget = require("../locators/apiWidgetslocator.json"); +const explorer = require("../locators/explorerlocators.json"); +const datasource = require("../locators/DatasourcesEditor.json"); +const queryLocators = require("../locators/QueryEditor.json"); + +export const initLocalstorage = () => { + cy.window().then((window) => { + window.localStorage.setItem("ShowCommentsButtonToolTip", ""); + window.localStorage.setItem("updateDismissed", "true"); + }); +}; + +Cypress.Commands.add("NavigateToQueryEditor", () => { + cy.get(explorer.addDBQueryEntity) + .last() + .click({ force: true }); +}); + +Cypress.Commands.add("NavigateToQueriesInExplorer", () => { + cy.get(explorer.entityQuery).click({ force: true }); +}); + +Cypress.Commands.add("NavigateToActiveDSQueryPane", (datasourceName) => { + cy.NavigateToQueryEditor(); + cy.NavigateToActiveTab(); + + cy.get(datasource.datasourceCard) + .contains(datasourceName) + .scrollIntoView() + .should("be.visible") + .closest(datasource.datasourceCard) + .within(() => { + cy.get(queryLocators.createQuery).click({ force: true }); + }) + .wait(2000); //for the specified page to load +}); + +Cypress.Commands.add("NavigateToDSGeneratePage", (datasourceName) => { + cy.NavigateToQueryEditor(); + cy.NavigateToActiveTab(); + + cy.get(datasource.datasourceCard) + .contains(datasourceName) + .scrollIntoView() + .should("be.visible") + .closest(datasource.datasourceCard) + .within(() => { + cy.get(datasource.datasourceCardGeneratePageBtn).click(); + }) + .wait(2000); //for the specified page to load +}); + +Cypress.Commands.add("ClickGotIt", () => { + cy.get("span:contains('GOT IT')").click(); +}); + +Cypress.Commands.add("fillGoogleSheetsDatasourceForm", () => { + cy.get(datasourceEditor["scope"]).click(); +}); + +Cypress.Commands.add("fillAuthenticatedAPIForm", () => { + const URL = datasourceFormData["authenticatedApiUrl"]; + cy.get(datasourceEditor.url).type(URL); +}); + +Cypress.Commands.add("runQuery", (expectedRes = true) => { + cy.onlyQueryRun(); + cy.wait("@postExecute").should( + "have.nested.property", + "response.body.data.isExecutionSuccess", + expectedRes, + ); + + // cy.wait("@postExecute").should( + // "have.nested.property", + // "response.body.responseMeta.status", + // 200, + // ); +}); + +Cypress.Commands.add("onlyQueryRun", () => { + cy.xpath(queryEditor.runQuery) + .last() + .click({ force: true }) + .wait(1000); +}); + +Cypress.Commands.add("hoverAndClick", () => { + cy.xpath(apiwidget.popover) + .last() + .should("be.hidden") + .invoke("show") + .click({ force: true }); + cy.xpath(apiwidget.popover) + .last() + .click({ force: true }); +}); + +Cypress.Commands.add("hoverAndClickParticularIndex", (index) => { + cy.xpath(apiwidget.popover) + .eq(index) + .should("be.hidden") + .invoke("show") + .click({ force: true }); +}); + +Cypress.Commands.add("deleteQuery", () => { + cy.hoverAndClick(); + cy.get(apiwidget.delete).click({ force: true }); + cy.get(apiwidget.deleteConfirm).click({ force: true }); + cy.wait("@deleteAction").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); +}); + +Cypress.Commands.add("deleteQueryUsingContext", () => { + cy.get(queryEditor.queryMoreAction) + .first() + .click(); + cy.get(queryEditor.deleteUsingContext).click(); + cy.get(queryEditor.deleteUsingContext) + .contains("Are you sure?") + .click(); + cy.wait("@deleteAction").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); +}); + +Cypress.Commands.add("runAndDeleteQuery", () => { + cy.runQuery(); + cy.deleteQueryUsingContext(); +}); + +Cypress.Commands.add("executeDbQuery", (queryName) => { + cy.get(widgetsPage.buttonOnClick) + .get(commonlocators.dropdownSelectButton) + .click({ force: true }) + .get("ul.bp3-menu") + .children() + .contains("Execute a query") + .click({ force: true }) + .get("ul.bp3-menu") + .children() + .contains(queryName) + .click({ force: true }); +}); + +Cypress.Commands.add("CreateMockQuery", (queryName) => { + // cy.get(queryEditor.addNewQueryBtn).click({ force: true }); + // cy.get(queryEditor.createQuery) + // .first() + // .click({ force: true }); + cy.get(queryEditor.queryNameField).type(queryName + "{enter}", { + force: true, + }); + cy.assertPageSave(); + cy.get(queryEditor.templateMenu + " div") + .contains("Select") + .click({ force: true }); + cy.runQuery(); + // cy.wait(3000); + // cy.get(queryEditor.runQuery) + // .click({force: true}); +}); + +Cypress.Commands.add("ValidateQueryParams", (param) => { + cy.xpath(apiwidget.paramsTab) + .should("be.visible") + .click({ force: true }); + + cy.validateCodeEditorContent(apiwidget.paramKey, param.key); + cy.validateCodeEditorContent(apiwidget.paramValue, param.value); +}); diff --git a/app/client/cypress/support/widgetCommands.js b/app/client/cypress/support/widgetCommands.js new file mode 100644 index 0000000000..09a79d3964 --- /dev/null +++ b/app/client/cypress/support/widgetCommands.js @@ -0,0 +1,1114 @@ +/* eslint-disable cypress/no-unnecessary-waiting */ +/* eslint-disable cypress/no-assigning-return-values */ + +require("cy-verify-downloads").addCustomCommand(); +require("cypress-file-upload"); + +const { + addMatchImageSnapshotCommand, +} = require("cypress-image-snapshot/command"); +const pages = require("../locators/Pages.json"); +const commonlocators = require("../locators/commonlocators.json"); +const modalWidgetPage = require("../locators/ModalWidget.json"); +const widgetsPage = require("../locators/Widgets.json"); +const LayoutPage = require("../locators/Layout.json"); +const formWidgetsPage = require("../locators/FormWidgets.json"); +const apiwidget = require("../locators/apiWidgetslocator.json"); +const dynamicInputLocators = require("../locators/DynamicInput.json"); +const viewWidgetsPage = require("../locators/ViewWidgets.json"); +const generatePage = require("../locators/GeneratePage.json"); + +let pageidcopy = " "; + +export const initLocalstorage = () => { + cy.window().then((window) => { + window.localStorage.setItem("ShowCommentsButtonToolTip", ""); + window.localStorage.setItem("updateDismissed", "true"); + }); +}; + +Cypress.Commands.add("changeZoomLevel", (zoomValue) => { + cy.get(commonlocators.changeZoomlevel) + .last() + .click(); + cy.get(".t--dropdown-option") + .children() + .contains(zoomValue) + .click(); + cy.wait("@updateLayout").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + cy.get(commonlocators.selectedZoomlevel) + .last() + .invoke("text") + .then((text) => { + const someText = text; + expect(someText).to.equal(zoomValue); + }); +}); + +Cypress.Commands.add("changeColumnType", (dataType) => { + cy.get(commonlocators.changeColType) + .last() + .click(); + cy.get(".t--dropdown-option") + .children() + .contains(dataType) + .click(); + cy.wait("@updateLayout").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + /* + cy.get(commonlocators.selectedColType) + .first() + .invoke("text") + .then((text) => { + const someText = text; + expect(someText).to.equal(dataType); + }); + */ +}); + +Cypress.Commands.add("switchToPaginationTab", () => { + cy.get(apiwidget.paginationTab) + .first() + .click({ force: true }); +}); + +Cypress.Commands.add("selectDateFormat", (value) => { + cy.get(".t--property-control-dateformat .bp3-popover-target") + .last() + .click({ force: true }); + cy.get(".t--dropdown-option") + .children() + .contains(value) + .click(); +}); + +Cypress.Commands.add("selectDropdownValue", (element, value) => { + cy.get(element) + .last() + .click(); + cy.get(".t--dropdown-option") + .children() + .contains(value) + .click(); +}); + +Cypress.Commands.add("assertDateFormat", () => { + cy.get(".t--draggable-datepickerwidget2 input") + .first() + .invoke("attr", "value") + .then((text) => { + const firstTxt = text; + cy.log("date time : ", firstTxt); + cy.get(commonlocators.labelTextStyle) + .first() + .should("contain", firstTxt); + cy.get(commonlocators.labelTextStyle) + .last() + .invoke("text") + .then((text) => { + const secondText = text; + cy.log("date time : ", secondText); + expect(firstTxt).not.to.equal(secondText); + }); + }); +}); + +Cypress.Commands.add("selectPaginationType", (option) => { + cy.xpath(option).click({ force: true }); +}); + +Cypress.Commands.add("copyJSObjectToPage", (pageName) => { + cy.xpath(apiwidget.popover) + .last() + .click({ force: true }); + cy.get(apiwidget.copyTo).click({ force: true }); + cy.get(apiwidget.page) + .contains(pageName) + .click(); + cy.wait("@createNewJSCollection").should( + "have.nested.property", + "response.body.responseMeta.status", + 201, + ); +}); + +Cypress.Commands.add("AddActionWithModal", () => { + cy.get(commonlocators.dropdownSelectButton) + .last() + .click(); + cy.get(".single-select") + .contains("Open modal") + .click({ force: true }); + cy.get(modalWidgetPage.selectModal).click(); + cy.get(modalWidgetPage.createModalButton).click({ force: true }); +}); + +Cypress.Commands.add("createModal", (ModalName) => { + cy.get(widgetsPage.actionSelect) + .first() + .click({ force: true }); + cy.selectOnClickOption("Open modal"); + cy.get(modalWidgetPage.selectModal).click(); + cy.wait(2000); + cy.get(modalWidgetPage.createModalButton).click({ force: true }); + cy.wait(3000); + cy.assertPageSave(); + cy.SearchEntityandOpen("Modal1"); + // changing the model name verify + cy.widgetText( + ModalName, + modalWidgetPage.modalName, + modalWidgetPage.modalName, + ); + + //changing the Model label + cy.get(modalWidgetPage.modalWidget + " " + widgetsPage.textWidget) + .first() + .trigger("mouseover"); + + cy.get(widgetsPage.textWidget + " " + commonlocators.editIcon).click(); + cy.testCodeMirror(ModalName); + cy.get(widgetsPage.textCenterAlign).click({ force: true }); + cy.assertPageSave(); + cy.get(".bp3-overlay-backdrop").click({ force: true }); +}); + +Cypress.Commands.add("selectOnClickOption", (option) => { + cy.get(".bp3-popover-content").should("be.visible"); + cy.get("ul.bp3-menu div.bp3-fill") + .should("be.visible") + .contains(option) + .click({ force: true }); +}); + +Cypress.Commands.add("selectWidgetOnClickOption", (option) => { + cy.get(".bp3-popover-content").should("be.visible"); + cy.get(commonlocators.selectWidgetVirtualList) + .should("be.visible") + .contains(option) + .click({ force: true }); +}); + +Cypress.Commands.add("CheckWidgetProperties", (checkboxCss) => { + cy.get(checkboxCss).check({ + force: true, + }); + cy.assertPageSave(); +}); + +Cypress.Commands.add("UncheckWidgetProperties", (checkboxCss) => { + cy.get(checkboxCss).uncheck({ + force: true, + }); + cy.assertPageSave(); +}); + +Cypress.Commands.add("EditWidgetPropertiesUsingJS", (checkboxCss, inputJS) => { + cy.get(checkboxCss, { timeout: 10000 }) + .last() + .should("exist") + .dblclick({ force: true }) + .type(inputJS); + cy.assertPageSave(); +}); + +Cypress.Commands.add( + "ChangeTextStyle", + (dropDownValue, textStylecss, labelName) => { + cy.get(commonlocators.dropDownIcon) + .last() + .click(); + cy.get(".t--dropdown-option") + .children() + .contains(dropDownValue) + .click(); + cy.get(textStylecss).should("have.text", labelName); + }, +); + +Cypress.Commands.add("widgetText", (text, inputcss, innercss) => { + cy.get(commonlocators.editWidgetName) + .click({ force: true }) + .type(text, { delay: 300 }) + .type("{enter}"); + cy.get(inputcss) + .first() + .trigger("mouseover", { force: true }); + cy.contains(innercss, text); +}); + +Cypress.Commands.add("verifyWidgetText", (text, inputcss, innercss) => { + cy.get(inputcss) + .first() + .trigger("mouseover", { force: true }); + cy.contains(innercss, text); +}); + +Cypress.Commands.add("editColName", (text) => { + cy.get(commonlocators.editColTitle) + .click({ force: true }) + .type(text) + .type("{enter}"); + cy.get(commonlocators.editColText).should("have.text", text); +}); + +Cypress.Commands.add("invalidWidgetText", () => { + // checking invalid widget name + cy.get(commonlocators.editWidgetName) + .click({ force: true }) + .type("download") + .type("{enter}"); + cy.get(commonlocators.toastmsg).contains("download is already being used."); +}); + +Cypress.Commands.add("EvaluateDataType", (dataType) => { + cy.get(commonlocators.evaluatedType) + .first() + .should("be.visible") + .contains(dataType); +}); + +Cypress.Commands.add("getCodeMirror", () => { + return cy + .get(".CodeMirror textarea") + .first() + .focus() + .type("{ctrl}{shift}{downarrow}"); +}); + +Cypress.Commands.add("testCodeMirror", (value) => { + cy.get(".CodeMirror textarea") + .first() + .focus() + .type("{ctrl}{shift}{downarrow}") + .then(($cm) => { + if ($cm.val() !== "") { + cy.get(".CodeMirror textarea") + .first() + .clear({ + force: true, + }); + } + + cy.get(".CodeMirror textarea") + .first() + .type(value, { + force: true, + parseSpecialCharSequences: false, + }); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(2000); + cy.get(".CodeMirror textarea") + .first() + .should("have.value", value); + }); +}); + +Cypress.Commands.add("updateComputedValue", (value) => { + cy.get(".CodeMirror textarea") + .first() + .focus({ force: true }) + .type("{uparrow}", { force: true }) + .type("{ctrl}{shift}{downarrow}", { force: true }); + cy.focused().then(($cm) => { + if ($cm.contents !== "") { + cy.log("The field is empty"); + cy.get(".CodeMirror textarea") + .first() + .clear({ + force: true, + }); + } + cy.get(".CodeMirror textarea") + .first() + .type(value, { + force: true, + parseSpecialCharSequences: false, + }); + }); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(1000); +}); + +Cypress.Commands.add("testCodeMirrorLast", (value) => { + cy.get(".CodeMirror textarea") + .last() + .focus() + .type("{ctrl}{shift}{downarrow}") + .then(($cm) => { + if ($cm.val() !== "") { + cy.get(".CodeMirror textarea") + .last() + .clear({ + force: true, + }); + } + + cy.get(".CodeMirror textarea") + .last() + .clear({ force: true }) + .type(value, { + force: true, + parseSpecialCharSequences: false, + }); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(200); + cy.get(".CodeMirror textarea") + .last() + .should("have.value", value); + }); +}); + +Cypress.Commands.add("testJsontext", (endp, value, paste = true) => { + cy.get(".t--property-control-" + endp + " .CodeMirror textarea") + .first() + .focus({ force: true }) + .type("{uparrow}", { force: true }) + .type("{ctrl}{shift}{downarrow}", { force: true }); + cy.focused().then(($cm) => { + if ($cm.contents !== "") { + cy.log("The field is not empty"); + cy.get(".t--property-control-" + endp + " .CodeMirror textarea") + .first() + .click({ force: true }) + .focused({ force: true }) + .clear({ + force: true, + }); + } + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(500); + cy.get(".t--property-control-" + endp + " .CodeMirror textarea") + .first() + .then((el) => { + const input = cy.get(el); + if (paste) { + input.invoke("val", value); + } else { + input.type(value, { + force: true, + parseSpecialCharSequences: false, + }); + } + }); + }); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(2500); //Allowing time for Evaluate value to capture value +}); + +/** + * Usage: + * Find the element which has a code editor input and then pass it in the function + * + * cy.get(...).then(el => cy.updateCodeInput(el, "test")); + * + */ +Cypress.Commands.add("updateCodeInput", ($selector, value) => { + cy.get($selector) + .find(".CodeMirror") + .first() + .then((ins) => { + const input = ins[0].CodeMirror; + input.focus(); + cy.wait(200); + input.setValue(value); + cy.wait(200); //time for value to set + //input.focus(); + }); +}); + +Cypress.Commands.add("selectColor", (GivenProperty) => { + // Property pane of the widget is opened, and click given property. + cy.get( + ".t--property-control-" + GivenProperty + " .bp3-input-group input", + ).click({ + force: true, + }); + cy.get(widgetsPage.colorsAvailable) + .first() + .click({ force: true }); +}); + +Cypress.Commands.add("toggleJsAndUpdate", (endp, value) => { + cy.get(".CodeMirror textarea") + .last() + .focus({ force: true }) + .type("{uparrow}", { force: true }) + .type("{ctrl}{shift}{downarrow}", { force: true }); + cy.focused().then(($cm) => { + if ($cm.contents !== "") { + cy.log("The field is empty"); + cy.get(".CodeMirror textarea") + .last() + .clear({ + force: true, + }); + } + cy.get(".CodeMirror textarea") + .last() + .type(value, { + force: true, + parseSpecialCharSequences: false, + }); + }); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(200); +}); + +Cypress.Commands.add("assertControlVisibility", (endp) => { + cy.get(".t--property-control-" + endp + " .CodeMirror") + .first() + .should("not.be.visible"); +}); + +Cypress.Commands.add("tableColumnDataValidation", (columnName) => { + cy.get("[data-rbd-draggable-id='" + columnName + "'] input") + .scrollIntoView() + .first() + .focus({ force: true }) + .should("be.visible"); +}); + +Cypress.Commands.add("tableColumnPopertyUpdate", (colId, newColName) => { + cy.get("[data-rbd-draggable-id='" + colId + "'] input") + .scrollIntoView() + .should("be.visible") + .click({ + force: true, + }); + cy.get("[data-rbd-draggable-id='" + colId + "'] input").clear({ + force: true, + }); + cy.get("[data-rbd-draggable-id='" + colId + "'] input").type(newColName, { + force: true, + }); + cy.get(".draggable-header ") + .contains(newColName) + .should("be.visible"); +}); + +Cypress.Commands.add("hideColumn", (colId) => { + cy.get("[data-rbd-draggable-id='" + colId + "'] .t--show-column-btn").click({ + force: true, + }); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(1000); +}); + +Cypress.Commands.add("showColumn", (colId) => { + cy.get("[data-rbd-draggable-id='" + colId + "'] .t--show-column-btn").click({ + force: true, + }); + cy.get(".draggable-header ") + .contains(colId) + .should("be.visible"); +}); +Cypress.Commands.add("deleteColumn", (colId) => { + cy.get("[data-rbd-draggable-id='" + colId + "'] .t--delete-column-btn").click( + { + force: true, + }, + ); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(1000); +}); + +Cypress.Commands.add("openFieldConfiguration", (fieldIdentifier) => { + cy.get( + "[data-rbd-draggable-id='" + fieldIdentifier + "'] .t--edit-column-btn", + ).click({ + force: true, + }); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(1000); +}); + +Cypress.Commands.add("makeColumnVisible", (colId) => { + cy.get("[data-rbd-draggable-id='" + colId + "'] .t--show-column-btn").click({ + force: true, + }); + cy.wait(1000); +}); + +Cypress.Commands.add("addColumn", (colId) => { + cy.get(widgetsPage.addColumn).scrollIntoView(); + cy.get(widgetsPage.addColumn) + .should("be.visible") + .click({ force: true }); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(3000); + cy.get(widgetsPage.defaultColName).clear({ + force: true, + }); + cy.get(widgetsPage.defaultColName).type(colId, { force: true }); +}); + +Cypress.Commands.add("editColumn", (colId) => { + cy.get("[data-rbd-draggable-id='" + colId + "'] .t--edit-column-btn").click(); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(1500); +}); + +Cypress.Commands.add("readTextDataValidateCSS", (cssProperty, cssValue) => { + cy.get(commonlocators.headingTextStyle).should( + "have.css", + cssProperty, + cssValue, + ); +}); + +Cypress.Commands.add("evaluateErrorMessage", (value) => { + cy.get(commonlocators.evaluateMsg) + .first() + .click() + .invoke("text") + .then((text) => { + const someText = text; + expect(someText).to.equal(value); + }); +}); + +Cypress.Commands.add("addAction", (value) => { + cy.get(commonlocators.dropdownSelectButton) + .last() + .click(); + cy.get(commonlocators.chooseAction) + .children() + .contains("Show message") + .click(); + cy.enterActionValue(value); +}); + +Cypress.Commands.add("onTableAction", (value, value1, value2) => { + cy.get(commonlocators.dropdownSelectButton) + .eq(value) + .click(); + cy.get(commonlocators.chooseAction) + .children() + .contains("Show message") + .click(); + cy.testJsontext(value1, value2); +}); + +Cypress.Commands.add("selectShowMsg", () => { + cy.get(commonlocators.chooseAction) + .children() + .contains("Show message") + .click(); +}); + +Cypress.Commands.add("addSuccessMessage", (value) => { + cy.get(commonlocators.chooseMsgType) + .last() + .click(); + cy.get(commonlocators.chooseAction) + .children() + .contains("Success") + .click(); + cy.enterActionValue(value); +}); + +Cypress.Commands.add("SetDateToToday", () => { + cy.get(formWidgetsPage.datepickerFooterPublish) + .contains("Today") + .click({ force: true }); + cy.assertPageSave(); +}); + +Cypress.Commands.add("enterActionValue", (value) => { + cy.get(".CodeMirror textarea") + .last() + .focus() + .type("{ctrl}{shift}{downarrow}") + .then(($cm) => { + if ($cm.val() !== "") { + cy.get(".CodeMirror textarea") + .last() + .clear({ + force: true, + }); + } + + cy.get(".CodeMirror textarea") + .last() + .type(value, { + force: true, + parseSpecialCharSequences: false, + }); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(200); + }); +}); + +Cypress.Commands.add("enterNavigatePageName", (value) => { + cy.get("ul.tree") + .children() + .first() + .within(() => { + cy.get(".CodeMirror textarea") + .first() + .focus() + .type("{ctrl}{shift}{downarrow}") + .then(($cm) => { + if ($cm.val() !== "") { + cy.get(".CodeMirror textarea") + .first() + .clear({ + force: true, + }); + } + cy.get(".CodeMirror textarea") + .first() + .type(value, { + force: true, + parseSpecialCharSequences: false, + }); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(200); + cy.get(".CodeMirror textarea") + .first() + .should("have.value", value); + }); + cy.root(); + }); +}); + +Cypress.Commands.add("ClearDate", () => { + cy.get(".t--property-control-defaultdate input").clear(); + cy.assertPageSave(); +}); + +Cypress.Commands.add("ClearDateFooter", () => { + cy.get(formWidgetsPage.datepickerFooterPublish) + .contains("Clear") + .click({ force: true }); + //cy.assertPageSave(); +}); + +Cypress.Commands.add("DeleteModal", () => { + cy.get(widgetsPage.textbuttonWidget).dblclick("topRight", { force: true }); + cy.get(widgetsPage.deleteWidget) + .first() + .click({ force: true }); +}); + +Cypress.Commands.add("Createpage", (pageName) => { + let pageId; + cy.get(pages.AddPage) + .first() + .click({ force: true }); + cy.wait("@createPage").then((xhr) => { + expect(xhr.response.body.responseMeta.status).to.equal(201); + if (pageName) { + pageId = xhr.response.body.data.id; + cy.wait(2000); + cy.get(`div[id=entity-${pageId}] .t--context-menu`).click({ + force: true, + }); + cy.get(pages.editName).click({ force: true }); + cy.get(pages.editInput).type(pageName + "{enter}"); + pageidcopy = pageName; + cy.wrap(pageId).as("currentPageId"); + } + cy.get(generatePage.buildFromScratchActionCard).click(); + cy.get("#loading").should("not.exist"); + }); +}); + +Cypress.Commands.add("Deletepage", (Pagename) => { + cy.CheckAndUnfoldEntityItem("PAGES"); + cy.get(`.t--entity-item:contains(${Pagename})`).within(() => { + cy.get(".t--context-menu").click({ force: true }); + }); + cy.selectAction("Delete"); + cy.selectAction("Are you sure?"); + cy.wait("@deletePage"); + cy.get("@deletePage").should("have.property", "status", 200); +}); + +Cypress.Commands.add("dropdownDynamic", (text) => { + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(2000); + cy.get("ul.bp3-menu") + .contains(text) + .click({ force: true }) + .should("have.text", text); +}); + +Cypress.Commands.add("dropdownMultiSelectDynamic", (text) => { + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(2000); + cy.get(".multi-select-dropdown") + .contains(text) + .click({ force: true }) + .should("have.text", text); +}); + +Cypress.Commands.add("treeSelectDropdown", (text) => { + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(2000); + cy.get(".tree-select-dropdown") + .contains(text) + .click({ force: true }) + .should("have.text", text); +}); + +Cypress.Commands.add("treeMultiSelectDropdown", (text) => { + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(2000); + cy.get(".tree-multiselect-dropdown") + .contains(text) + .click({ force: true }) + .should("have.text", text); +}); + +Cypress.Commands.add("dropdownDynamicUpdated", (text) => { + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(2000); + cy.get(commonlocators.dropdownmenu) + .contains(text) + .click({ force: true }); + cy.xpath(commonlocators.dropDownOptSelected).should("have.text", text); +}); + +Cypress.Commands.add("selectTextSize", (text) => { + cy.get(".t--dropdown-option") + .first() + .contains(text) + .click({ force: true }); +}); + +Cypress.Commands.add("getAlert", (alertcss) => { + cy.get(commonlocators.dropdownSelectButton).click({ force: true }); + cy.get(widgetsPage.menubar) + .contains("Show Alert") + .click({ force: true }) + .should("have.text", "Show Alert"); + + cy.get(alertcss) + .click({ force: true }) + .type("hello"); + cy.get(".t--open-dropdown-Select-type").click({ force: true }); + cy.get(".bp3-popover-content .bp3-menu li") + .contains("Success") + .click({ force: true }); +}); + +Cypress.Commands.add("togglebar", (value) => { + cy.get(value) + .check({ force: true }) + .should("be.checked"); +}); +Cypress.Commands.add("togglebarDisable", (value) => { + cy.get(value) + .uncheck({ force: true }) + .should("not.checked"); +}); + +Cypress.Commands.add( + "getAlert", + (alertcss, propertyControl = commonlocators.dropdownSelectButton) => { + cy.get(propertyControl) + .first() + .click({ force: true }); + cy.get(widgetsPage.menubar) + .contains("Show message") + .click({ force: true }); + + cy.get(alertcss) + .click({ force: true }) + .type("hello"); + cy.get(".t--open-dropdown-Select-type").click({ force: true }); + cy.get(".bp3-popover-content .bp3-menu li") + .contains("Success") + .click({ force: true }); + }, +); + +Cypress.Commands.add("addQueryFromLightningMenu", (QueryName) => { + cy.get(commonlocators.dropdownSelectButton) + .first() + .click({ force: true }) + .selectOnClickOption("Execute a query") + .selectOnClickOption(QueryName); +}); + +Cypress.Commands.add("addAPIFromLightningMenu", (ApiName) => { + cy.get(commonlocators.dropdownSelectButton) + .first() + .click({ force: true }) + .selectOnClickOption("Execute a query") + .selectOnClickOption(ApiName); +}); + +Cypress.Commands.add("radioInput", (index, text) => { + cy.get(widgetsPage.RadioInput) + .eq(index) + .click({ force: true }) + .clear({ force: true }) + .type(text) + .wait(200); +}); +Cypress.Commands.add("tabVerify", (index, text) => { + cy.get(".t--property-control-tabs input") + .eq(index) + .click({ force: true }) + .clear() + .type(text); + cy.get(LayoutPage.tabWidget) + .contains(text) + .click({ force: true }) + .should("be.visible"); +}); + +Cypress.Commands.add("openPropertyPane", (widgetType) => { + const selector = `.t--draggable-${widgetType}`; + cy.wait(500); + cy.get(selector) + .first() + .trigger("mouseover", { force: true }) + .wait(500); + cy.get( + `${selector}:first-of-type .t--widget-propertypane-toggle > .t--widget-name`, + ) + .first() + .click({ force: true }); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(1000); +}); + +Cypress.Commands.add("openPropertyPaneCopy", (widgetType) => { + if (widgetType === "List1Copy") { + cy.SearchEntityandOpen(widgetType); + } else { + const selector = `.t--draggable-${widgetType}`; + cy.get(selector) + .last() + .trigger("mouseover", { force: true }) + .wait(500); + cy.get( + `${selector}:first-of-type .t--widget-propertypane-toggle > .t--widget-name`, + ) + .first() + .click({ force: true }); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(1000); + } +}); + +Cypress.Commands.add("copyWidget", (widget, widgetLocator) => { + const modifierKey = Cypress.platform === "darwin" ? "meta" : "ctrl"; + //Copy widget and verify all properties + cy.get(widgetsPage.propertypaneText) + .children() + .last() + .invoke("text") + .then((x) => { + cy.log(x); + let originalWidget = x.replaceAll("x", ""); + originalWidget = originalWidget.replaceAll(/\u200B/g, ""); + cy.log(originalWidget); + cy.get(widgetsPage.copyWidget).click({ force: true }); + cy.wait(2000); + cy.reload(); + // Wait for the widget to be appear in the DOM and press Ctrl/Cmd + V to paste the button. + cy.get(widgetLocator).should("be.visible"); + cy.get("body").type(`{${modifierKey}}v`); + cy.wait(2000); + cy.openPropertyPaneCopy(widget); + cy.get(widgetsPage.propertypaneText) + .children() + .last() + .invoke("text") + .then((y) => { + cy.log(y); + let copiedWidget = y.replaceAll("x", ""); + copiedWidget = copiedWidget.replaceAll(/\u200B/g, ""); + cy.log(copiedWidget); + expect(originalWidget).to.be.equal(copiedWidget); + }); + }); +}); + +Cypress.Commands.add("deleteWidget", () => { + // Delete the button widget + cy.get(widgetsPage.removeWidget).click({ force: true }); + cy.wait(5000); + cy.wait("@updateLayout"); +}); + +Cypress.Commands.add("UpdateChartType", (typeOfChart) => { + // Command to change the chart type if the property pane of the chart widget is opened. + cy.get(viewWidgetsPage.chartType) + .last() + .click({ force: true }); + cy.get(commonlocators.dropdownmenu) + .children() + .contains(typeOfChart) + .click({ force: true }); + + cy.get(viewWidgetsPage.chartType + " span.cs-text").should( + "have.text", + typeOfChart, + ); +}); + +Cypress.Commands.add("alertValidate", (text) => { + cy.get(commonlocators.success) + .should("be.visible") + .and("have.text", text); +}); + +Cypress.Commands.add("ExportVerify", (togglecss, name) => { + cy.togglebar(togglecss); + cy.get(".t--draggable-tablewidget button") + .invoke("attr", "aria-label") + .should("contain", name); + cy.togglebarDisable(togglecss); +}); + +Cypress.Commands.add("getTableDataSelector", (rowNum, colNum) => { + const selector = `.t--widget-tablewidget .tbody .td[data-rowindex=${rowNum}][data-colindex=${colNum}] div div`; + return selector; +}); + +Cypress.Commands.add("readTabledata", (rowNum, colNum) => { + // const selector = `.t--draggable-tablewidget .e-gridcontent.e-lib.e-droppable td[index=${rowNum}][aria-colindex=${colNum}]`; + const selector = `.tbody .td[data-rowindex="${rowNum}"][data-colindex="${colNum}"] div div`; + const tabVal = cy.get(selector).invoke("text"); + return tabVal; +}); + +Cypress.Commands.add( + "readTabledataPublish", + (rowNum, colNum, shouldNotGoOneLeveDeeper) => { + // const selector = `.t--widget-tablewidget .e-gridcontent.e-lib.e-droppable td[index=${rowNum}][aria-colindex=${colNum}]`; + const selector = `.t--widget-tablewidget .tbody .td[data-rowindex=${rowNum}][data-colindex=${colNum}] div ${ + !shouldNotGoOneLeveDeeper ? "div" : "" + }`; + const tabVal = cy.get(selector).invoke("text"); + return tabVal; + }, +); + +Cypress.Commands.add( + "readTabledataValidateCSS", + (rowNum, colNum, cssProperty, cssValue, shouldNotGotOneLeveDeeper) => { + const selector = `.t--widget-tablewidget .tbody .td[data-rowindex=${rowNum}][data-colindex=${colNum}] div ${ + !shouldNotGotOneLeveDeeper ? "div" : "" + }`; + cy.get(selector).should("have.css", cssProperty, cssValue); + }, +); + +Cypress.Commands.add( + "readTabledataFromSpecificIndex", + (rowNum, colNum, index) => { + // const selector = `.t--widget-tablewidget .e-gridcontent.e-lib.e-droppable td[index=${rowNum}][aria-colindex=${colNum}]`; + const selector = `.t--widget-tablewidget .tbody .td[data-rowindex=${rowNum}][data-colindex=${colNum}] div`; + const tabVal = cy + .get(selector) + .eq(index) + .invoke("text"); + return tabVal; + }, +); + +Cypress.Commands.add("tablefirstdataRow", () => { + let tabVal = cy + .xpath( + "//div[@class='tableWrap']//div[@class='table']//div[contains(@class, 'tbody')]/div[@class='tr']/div[@class ='td']", + { timeout: 10000 }, + ) + .first() + .invoke("text"); + return tabVal; +}); + +Cypress.Commands.add("scrollTabledataPublish", (rowNum, colNum) => { + const selector = `.t--widget-tablewidget .tbody .td[data-rowindex=${rowNum}][data-colindex=${colNum}] div div`; + const tabVal = cy + .get(selector) + .scrollIntoView() + .invoke("text"); + return tabVal; +}); + +Cypress.Commands.add("readTableLinkPublish", (rowNum, colNum) => { + const selector = `.t--widget-tablewidget .tbody .td[data-rowindex=${rowNum}][data-colindex=${colNum}] div .image-cell-wrapper .image-cell`; + const bgUrl = cy.get(selector).should("have.css", "background-image"); + return bgUrl; +}); + +Cypress.Commands.add("assertEvaluatedValuePopup", (expectedType) => { + cy.get(commonlocators.evaluatedTypeTitle) + .first() + .find("span") + .click(); + cy.get(dynamicInputLocators.evaluatedValue) + .should("be.visible") + .find("pre") + .first() + .should("have.text", expectedType); +}); + +Cypress.Commands.add("validateToastMessage", (value) => { + cy.get(commonlocators.toastMsg).should("contain.text", value); +}); + +Cypress.Commands.add( + "validateWidgetExists", + { prevSubject: true }, + (selector) => { + cy.get(selector).should("exist"); + }, +); + +Cypress.Commands.add("clearPropertyValue", (value) => { + cy.get(".CodeMirror textarea") + .eq(value) + .focus({ force: true }) + .type("{uparrow}", { force: true }) + .type("{ctrl}{shift}{downarrow}", { force: true }); + cy.focused().then(($cm) => { + if ($cm.contents !== "") { + cy.log("The field is empty"); + cy.get(".CodeMirror textarea") + .eq(value) + .clear({ + force: true, + }); + } + }); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(1000); +}); + +Cypress.Commands.add( + "validateNSelectDropdown", + (ddTitle, currentValue, newValue) => { + let toChange = false; + cy.xpath('//span[contains(text(),"' + currentValue + '")]').should( + "exist", + currentValue + " dropdown value not present", + ); + if (newValue) toChange = true; + if (toChange) { + cy.xpath( + "//p[text()='" + + ddTitle + + "']/parent::label/following-sibling::div/div/div", + ).click(); //to expand the dropdown + cy.xpath('//span[contains(text(),"' + newValue + '")]') + .last() + .click({ force: true }); //to select the new value + } + }, +);