PromucFlow_constructor/app/client/cypress/support/WorkspaceCommands.js
Aishwarya-U-R e9a1f86e22
test: Cypress | CI Stablize + Other improvements (#28254)
## Description
**This PR does the below improvements:**
- Handles initial empty error toast- with cy.LogOut()
- Calling cy.LoginFromAPI() per need only - to improve execution time 
- Update agHelper.UpdateCodeInput()
- Added waitForNetworkCall for AsserHelper methods to only get api call
& validate
- Added gitSync.AuthorizeKeyToGitea() - to validate keyGenerate success
- Adding validationg for 'Unable to import application in workspace'
- cy.CreateNewAppInNewWorkspace() improved
- agHelper.RemoveUIElement() created to handle tooltip, toast,
evaluatedpopup & removed duplicates
- cy.merge() improved to call assertHelper
- assertHelper.AssertNetworkStatus() to handle both array & individual
status checks & return actual responseCode
- createBranch & generatedKey intercepts added to git operation
validations
- homePage.AssertApplication() created
- Removed cy.Logout() & Login improved - brings down total run time to
less than 1 hr from 1+ hrs
- entityExplorer.NavigateToSwitcher() improved to check status
- dataSources.ValidateDSDeletion() improved to handle one of array toast
for array value also
- assertHelper.WaitForNetworkCall() improved to wait & return latest
request
- Private methods processNetworkStatus() & processNetworkResponseData()
created
  
**Also flaky fixes below:**
- ServerSide/QueryPane/S3_2_spec.ts - Adding sleep for CI flaky
behaviour
- Trial fix for
cypress/e2e/Regression/ClientSide/OtherUIFeatures/PageOnLoad_spec.ts
- GitWithJSLibrary/GitwithCustomJSLibrary_spec.js - Handling Import
failure at various points in the flow
- ExplorerTests/Widgets_Copy_Paste_Delete_Undo_Keyboard_Event_spec.js
   - ClientSide/JSLibrary/Library_spec.ts - asserting success import
   - /OtherUIFeatures/ApplicationURL_spec.js - using cy.url()
   - /ClientSide/Templates/Fork_Template_spec.js
- ServerSide/Postgres_DataTypes/Binary_Spec.ts &
/Postgres_DataTypes/Json_Spec.ts - Adding sleep for CI flaky behaviour
   - ClientSide/Widgets/List/List4_2_spec.js
   - /Git/ExistingApps/v1.9.24/DSCrudAndBindings_Spec.ts

#### Type of change
- Script fix (non-breaking change which fixes an issue)

## Testing

#### How Has This Been Tested?
- [X] Cypress CI runs

## Checklist:
#### QA activity:
- [X] Added `Test Plan Approved` label after Cypress tests were reviewed
2023-10-25 19:33:07 +05:30

341 lines
11 KiB
JavaScript

/* eslint-disable cypress/no-unnecessary-waiting */
/* eslint-disable cypress/no-assigning-return-values */
/* Contains all methods related to Workspace features*/
require("cy-verify-downloads").addCustomCommand();
require("cypress-file-upload");
import homePage from "../locators/HomePage";
import explorer from "../locators/explorerlocators";
import { ObjectsRegistry } from "../support/Objects/Registry";
const agHelper = ObjectsRegistry.AggregateHelper;
const assertHelper = ObjectsRegistry.AssertHelper;
const homePageTS = ObjectsRegistry.HomePage;
export const initLocalstorage = () => {
cy.window().then((window) => {
window.localStorage.setItem("ShowCommentsButtonToolTip", "");
window.localStorage.setItem("updateDismissed", "true");
});
};
Cypress.Commands.add("createWorkspace", () => {
cy.get(homePage.createWorkspace)
.should("be.visible")
.first()
.click({ force: true });
});
Cypress.Commands.add("navigateToWorkspaceSettings", (workspaceName) => {
cy.get(homePage.workspaceList.concat(workspaceName).concat(")"))
.first()
.scrollIntoView()
.should("be.visible");
cy.get(homePage.workspaceList.concat(workspaceName).concat(")"))
.closest(homePage.workspaceCompleteSection)
.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("openWorkspaceOptionsPopup", (workspaceName) => {
cy.get(homePage.workspaceList.concat(workspaceName).concat(")"))
.first()
.scrollIntoView()
.should("be.visible");
cy.get(homePage.workspaceList.concat(workspaceName).concat(")"))
.closest(homePage.workspaceCompleteSection)
.find(homePage.optionsIcon)
.first()
.click({ force: true });
});
Cypress.Commands.add("inviteUserForWorkspace", (workspaceName, email, role) => {
cy.stubPostHeaderReq();
cy.get(homePage.workspaceList.concat(workspaceName).concat(")"))
.first()
.scrollIntoView()
.should("be.visible");
cy.get(
homePage.workspaceList
.concat(workspaceName)
.concat(homePage.shareWorkspace),
)
.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", (workspaceName, count) => {
cy.get(homePage.workspaceList.concat(workspaceName).concat(")"))
.first()
.scrollIntoView()
.should("be.visible");
cy.get(
homePage.workspaceList
.concat(workspaceName)
.concat(") .t--workspace-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).should("be.visible");
cy.xpath("//span[@name='expand-more']").last().click();
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", (editMode = false) => {
cy.xpath(homePage.enablePublicAccess).first().click({ force: true });
cy.wait("@changeAccess").should(
"have.nested.property",
"response.body.responseMeta.status",
200,
);
cy.wait(5000);
const closeButtonLocator = editMode
? homePage.editModeInviteModalCloseBtn
: homePage.closeBtn;
cy.get(closeButtonLocator).first().click({ force: true });
});
Cypress.Commands.add("deleteUserFromWorkspace", (workspaceName) => {
cy.get(homePage.workspaceList.concat(workspaceName).concat(")"))
.first()
.scrollIntoView()
.should("be.visible");
cy.get(homePage.workspaceList.concat(workspaceName).concat(")"))
.closest(homePage.workspaceCompleteSection)
.scrollIntoView()
.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.leaveWorkspaceConfirmModal).should("be.visible");
cy.get(homePage.leaveWorkspaceConfirmButton).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(
"updateUserRoleForWorkspace",
(workspaceName, email, role) => {
cy.stubPostHeaderReq();
cy.get(homePage.workspaceList.concat(workspaceName).concat(")"))
.first()
.scrollIntoView()
.should("be.visible");
cy.get(homePage.workspaceList.concat(workspaceName).concat(")"))
.closest(homePage.workspaceCompleteSection)
.scrollIntoView()
.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.wait(2000); //wait a bit for app to load
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("CreateAppForWorkspace", (workspaceName, appname) => {
cy.get(
homePage.workspaceList
.concat(workspaceName)
.concat(homePage.createAppFrWorkspace),
)
.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.wait("@updateApplication").should(
"have.nested.property",
"response.body.responseMeta.status",
200,
);
agHelper.RemoveUIElement("Tooltip", "Rename application");
});
Cypress.Commands.add("CreateNewAppInNewWorkspace", () => {
let applicationId, appName;
let toNavigateToHome = false;
cy.get("body").then(($ele) => {
if ($ele.find(".t--appsmith-logo").length < 0) {
toNavigateToHome = false;
} else {
toNavigateToHome = true;
}
});
homePageTS.CreateNewWorkspace("", toNavigateToHome); //Creating a new workspace for every test, since we are deleting the workspace in the end of the test
//agHelper.Sleep(2000); //for workspace to open
cy.get("@workspaceName").then((workspaceName) => {
localStorage.setItem("workspaceName", workspaceName);
homePageTS.CreateAppInWorkspace(localStorage.getItem("workspaceName"));
});
cy.get("@createNewApplication").then((xhr) => {
const response = xhr.response;
expect(response.body.responseMeta.status).to.eq(201);
applicationId = response.body.data.id;
appName = response.body.data.name;
cy.log("appName", appName);
localStorage.setItem("applicationId", applicationId);
localStorage.setItem("appName", appName);
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(4000);
cy.get("#loading").should("not.exist");
cy.url().then((url) => {
if (url.indexOf("/applications") > -1) {
homePageTS.EditAppFromAppHover(appName);
agHelper.Sleep(2000); //for app to open
}
});
});
cy.get("#sidebar").should("be.visible");
assertHelper.AssertNetworkResponseData("@getPluginForm"); //for auth rest api
assertHelper.AssertNetworkResponseData("@getPluginForm"); //for graphql
// If the intro modal is open, close it
cy.skipSignposting();
//Removing renaming of app from all tests, since its also verified in other separate tests
// cy.AppSetupForRename();
// cy.get(homePage.applicationName).type(appname + "{enter}");
// assertHelper.AssertNetworkStatus("@updateApplication");
// // Remove tooltip on the Application Name
// agHelper.RemoveTooltip("Tooltip","Rename application");
/* 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("renameEntity", (entityName, renamedEntity) => {
cy.get(`.t--entity-item:contains(${entityName})`).within(() => {
cy.get(".t--context-menu").click({ force: true });
});
cy.selectAction("Edit name");
cy.get(explorer.editEntity).last().type(`${renamedEntity}`, { force: true });
});
Cypress.Commands.add("leaveWorkspace", (newWorkspaceName) => {
cy.openWorkspaceOptionsPopup(newWorkspaceName);
cy.get(homePage.workspaceNamePopoverContent)
.find("a")
.should("have.length", 1)
.first()
.contains("Leave Workspace")
.click();
cy.contains("Are you sure").click();
cy.wait("@leaveWorkspaceApiCall")
.its("response.body.responseMeta.status")
.should("eq", 200);
cy.get(homePage.toastMessage).should(
"contain",
"You have successfully left the workspace",
);
});