PromucFlow_constructor/app/client/cypress/support/WorkspaceCommands.js
Hetu Nandu ca1713c73e
fix: Improvements to Sidebar for navigation (#29205)
## Description

- Rename to Pages to Editor in the Sidebar
- Move Editor to top
- Update "Home" to "All apps"

#### PR fixes following issue(s)
Fixes #29206

#### Media
> A video or a GIF is preferred. when using Loom, don’t embed because it
looks like it’s a GIF. instead, just link to the video
>
>
#### Type of change
> Please delete options that are not relevant.
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- Chore (housekeeping or task changes that don't impact user perception)
- This change requires a documentation update
>
>
>
## Testing
>
#### How Has This Been Tested?
> Please describe the tests that you ran to verify your changes. Also
list any relevant details for your test configuration.
> Delete anything that is not relevant
- [ ] Manual
- [ ] JUnit
- [ ] Jest
- [ ] Cypress
>
>
#### Test Plan
> Add Testsmith test cases links that relate to this PR
>
>
#### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
>
>
>
## Checklist:
#### Dev activity
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-11-30 06:11:59 +05:30

332 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 { 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("Rename", { 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("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",
);
});