PromucFlow_constructor/app/client/cypress/support/Pages/Onboarding.ts
sneha122 4228173c98
fix: cypress test added for onboarding start with data (#30720)
## Description

This PR adds cypress test for issue
https://github.com/appsmithorg/appsmith/issues/30620

#### PR fixes following issue(s)
Fixes #30554 
#### 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
- Chore (housekeeping or task changes that don't impact user perception)
>
>
>
## 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
- [x] 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


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Tests**
- Added automated tests for the "Start with data" user flow in the
onboarding process.
- **New Features**
- Enhanced the UI interaction in the Data Sources page by introducing an
index-based element selection feature.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: “sneha122” <“sneha@appsmith.com”>
2024-01-30 12:52:10 +05:30

144 lines
5.4 KiB
TypeScript

import { ObjectsRegistry } from "../Objects/Registry";
import localForage from "localforage";
const OnboardingLocator = require("../../locators/FirstTimeUserOnboarding.json");
let datasourceName;
export class Onboarding {
private _aggregateHelper = ObjectsRegistry.AggregateHelper;
private _datasources = ObjectsRegistry.DataSources;
private _debuggerHelper = ObjectsRegistry.DebuggerHelper;
public readonly locators = {
back_to_canvas: "#back-to-canvas",
deploy: "#application-publish-btn",
table_widget_card: "#widget-card-draggable-tablewidgetv2",
create_query: "#create-query",
explorer_widget_tab: `#explorer-tab-options [data-value*="widgets"]`,
add_datasources: "#add_datasources",
connect_data_overlay: "#table-overlay-connectdata",
startFromScratchCard: "[data-testid='t--start-from-scratch']",
startFromDataCard: "[data-testid='t--start-from-data']",
seeMoreButtonOnCanvas: `[data-testid="t--canvas-building-block-see-more"]`,
};
completeSignposting() {
cy.get(OnboardingLocator.checklistStatus).should("be.visible");
cy.get(OnboardingLocator.checklistStatus).should("contain", "0 of 5");
this._aggregateHelper
.GetElement(OnboardingLocator.checklistConnectionBtn)
.realHover()
.should("have.css", "cursor", "not-allowed");
this._aggregateHelper.GetHoverNClick(
OnboardingLocator.checklistDatasourceBtn,
0,
true,
);
this._aggregateHelper.AssertElementVisibility(
this._datasources._newDatasourceContainer,
);
this.closeIntroModal();
this._aggregateHelper.AssertElementAbsence(
OnboardingLocator.introModal,
10000,
);
if (Cypress.env("AIRGAPPED")) {
this._datasources.CreateDataSource("Mongo");
cy.get("@dsName").then(($dsName) => {
datasourceName = $dsName;
});
} else {
cy.get(OnboardingLocator.datasourceMock).first().click();
}
cy.wait(1000);
this._aggregateHelper.GetNClick(this._debuggerHelper.locators._helpButton);
cy.get(OnboardingLocator.checklistStatus).should("contain", "1 of 5");
this._aggregateHelper
.GetElement(OnboardingLocator.checklistConnectionBtn)
.realHover()
.should("have.css", "cursor", "not-allowed");
cy.get(OnboardingLocator.checklistActionBtn).should("be.visible");
cy.get(OnboardingLocator.checklistActionBtn).click();
this._datasources.CreateQueryForDS("Movies");
cy.wait(1000);
this._aggregateHelper.GetNClick(this._debuggerHelper.locators._helpButton);
cy.get(OnboardingLocator.checklistStatus).should("contain", "2 of 5");
this._aggregateHelper
.GetElement(OnboardingLocator.checklistActionBtn)
.realHover()
.should("have.css", "cursor", "auto");
cy.get(OnboardingLocator.checklistWidgetBtn).should("be.visible");
cy.get(OnboardingLocator.checklistWidgetBtn).click();
cy.get(OnboardingLocator.widgetSidebar).should("be.visible");
(cy as any).dragAndDropToCanvas("textwidget", { x: 400, y: 400 });
this._aggregateHelper.GetNClick(this._debuggerHelper.locators._helpButton);
cy.get(OnboardingLocator.checklistStatus).should("contain", "3 of 5");
this._aggregateHelper
.GetElement(OnboardingLocator.checklistWidgetBtn)
.realHover()
.should("have.css", "cursor", "auto");
cy.get(OnboardingLocator.checklistConnectionBtn).should("be.visible");
cy.get(OnboardingLocator.checklistConnectionBtn).click();
cy.get(OnboardingLocator.snipingBanner).should("be.visible");
cy.get(OnboardingLocator.snipingTextWidget)
.first()
.trigger("mouseover", { force: true })
.wait(500);
cy.get(OnboardingLocator.widgetName).should("be.visible");
cy.get(OnboardingLocator.widgetName).click();
this._aggregateHelper.GetNClick(this._debuggerHelper.locators._helpButton);
cy.get(OnboardingLocator.checklistStatus).should("contain", "4 of 5");
this._aggregateHelper
.GetElement(OnboardingLocator.checklistConnectionBtn)
.realHover()
.should("have.css", "cursor", "auto");
let open: any;
cy.window().then((window: any) => {
open = window.open;
window.open = Cypress._.noop;
});
cy.get(OnboardingLocator.checklistDeployBtn).should("be.visible");
cy.get(OnboardingLocator.checklistDeployBtn).click();
this._aggregateHelper.AssertElementAbsence(OnboardingLocator.introModal);
this._aggregateHelper.Sleep();
this._aggregateHelper.GetNClick(this._debuggerHelper.locators._helpButton);
this._aggregateHelper.AssertElementExist(
OnboardingLocator.checklistCompletionBanner,
);
cy.window().then((window) => {
window.open = open;
});
}
closeIntroModal() {
cy.get("body").then(($body) => {
if ($body.find(OnboardingLocator.introModalCloseBtn).length) {
this._aggregateHelper.GetNClick(OnboardingLocator.introModalCloseBtn);
}
});
}
skipSignposting() {
cy.get("body").then(($body) => {
if ($body.find(OnboardingLocator.introModalCloseBtn).length) {
cy.wrap(null).then(async () => {
localForage.config({
name: "Appsmith",
});
// return a promise to cy.then() that
// is awaited until it resolves
return localForage.setItem("ENABLE_START_SIGNPOSTING", false);
});
//this._aggregateHelper.RefreshPage();//this is causing CI flakiness, so using below
cy.window().then((win) => {
win.location.reload();
});
}
});
}
}