PromucFlow_constructor/app/client/cypress/support/Pages/AssertHelper.ts
Aishwarya-U-R 515e28a6f1
test: Cypress | Added Dynamic checks for Flaky fix + Cypress upgrade (#30840)
## Description
- This PR does below:
-
cypress/e2e/Regression/ClientSide/Templates/Fork_Template_To_App_spec.js
(to .ts with flaky fix)
- cypress/e2e/Sanity/Datasources/SMTPDatasource_spec.js (multiple runs,
no fix was needed, removed from skipped list)
- Cypress upgrade from 13.6.1 to 13.6.4
- cypress/e2e/Regression/ClientSide/EmbedSettings/EmbedSettings_spec.js
(flaky fix)
- cypress/e2e/Regression/ServerSide/QueryPane/S3_1_spec.js (6th test -
flaky fix)
- assertHelper.WaitForNetworkCall() - reduced wait timeout
- deployHelper.DeployApp() added dynamic checks
- cypress/e2e/Regression/ClientSide/Git/GitSync/SwitchBranches_spec.js
(removed redundant before hook to fix flakyness)
- cypress/e2e/Regression/ClientSide/Git/GitImport/GitImport_spec.js
(removed redundant before hook to fix flakyness)

#### 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

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

- **New Features**
- Introduced functionality for forking a template to the current app and
adding selected pages from a template.
- **Bug Fixes**
- Enhanced test stability by replacing sleep calls with dynamic wait
conditions.
- Improved test reliability and performance by adjusting waiting
conditions for network calls and element assertions.
- **Tests**
- Updated the list of Cypress tests to include new scenarios and remove
outdated ones.
- Added new end-to-end tests for template forking and embed settings
validation.
- **Chores**
- Optimized test support files and functions for better code maintenance
and readability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-02-02 16:01:59 +05:30

161 lines
4.4 KiB
TypeScript

import "cypress-wait-until";
export const EntityItems = {
Page: 0,
Query: 1,
Api: 2,
JSObject: 3,
Widget: 4,
Datasource: 5,
} as const;
export type EntityItemsType = (typeof EntityItems)[keyof typeof EntityItems];
export class AssertHelper {
public _modifierKey = Cypress.platform === "darwin" ? "meta" : "ctrl";
public isMac = Cypress.platform === "darwin";
public Sleep(timeout = 1000) {
cy.wait(timeout);
}
public AssertDocumentReady() {
cy.waitUntil(() =>
cy.document().should((doc) => {
expect(doc.readyState).to.equal("complete");
}),
);
cy.waitUntil(() =>
cy
.window({ timeout: Cypress.config().pageLoadTimeout })
.then((win) => expect(win).haveOwnProperty("onload")),
);
}
public AssertDelete(entityType: EntityItemsType) {
let networkCall = "";
switch (entityType) {
case EntityItems.Api:
case EntityItems.Query:
networkCall = "deleteAction";
break;
case EntityItems.Widget:
networkCall = "updateLayout";
break;
case EntityItems.JSObject:
networkCall = "deleteJSCollection";
this.AssertContains("deleted successfully");
break;
case EntityItems.Datasource:
networkCall = "deleteDatasource";
break;
case EntityItems.Page:
networkCall = "deletePage";
break;
default:
networkCall && this.AssertNetworkStatus(networkCall);
}
}
public GetAliasName(aliasName: string) {
aliasName = aliasName.startsWith("@") ? aliasName : "@" + aliasName;
return aliasName;
}
public WaitForNetworkCall(aliasName: string, responseTimeout = 100000) {
// cy.wait(aliasName).then(($apiCall: any) => {
// expect($apiCall.response.body.responseMeta.status).to.eq(expectedStatus);
// });
this.Sleep(); //wait a bit to avoid flaky tests
return cy
.wait(this.GetAliasName(aliasName), { timeout: responseTimeout })
.then((interceptions) => {
return cy
.get(this.GetAliasName(aliasName), { timeout: responseTimeout })
.its("response");
});
}
public AssertNetworkStatus(
aliasName: string,
expectedStatus: number | number[] = 200,
waitForNetworkCall = true,
) {
if (waitForNetworkCall) {
// If waitForNetworkCall is true, then use the response from WaitForNetworkCall call
return this.WaitForNetworkCall(aliasName).then((response: any) =>
this.processNetworkStatus(response, expectedStatus),
);
} else {
// If interception is not available, directly get the alias & use it
return cy
.get(this.GetAliasName(aliasName))
.its("response")
.then((interception: any) =>
this.processNetworkStatus(interception, expectedStatus),
);
}
}
private processNetworkStatus(
response: any,
expectedStatus: number | number[],
) {
const responseStatus = Number(response.body.responseMeta.status);
const expectedStatusArray = Array.isArray(expectedStatus)
? expectedStatus
: [expectedStatus];
expect(expectedStatusArray).to.include(responseStatus);
return responseStatus;
}
public AssertNetworkResponseData(
aliasName: string,
waitForNetworkCall = true,
) {
if (waitForNetworkCall) {
// If waitForNetworkCall is true, then use the interception from received call
this.WaitForNetworkCall(aliasName).then((interception: any) => {
this.processNetworkResponseData(interception);
});
} else {
// If interception is not available, directly get the alias & use it
cy.get(this.GetAliasName(aliasName))
.its("response")
.then((interception: any) => {
this.processNetworkResponseData(interception);
});
}
}
private processNetworkResponseData(response: any) {
expect(response.body.data).to.not.be.empty;
}
public AssertNetworkExecutionSuccess(
aliasName: string,
expectedRes = true,
waitForNetworkCall = true,
) {
waitForNetworkCall && this.WaitForNetworkCall(aliasName);
cy.get(aliasName)
.its("response.body.data.isExecutionSuccess")
.should("eq", expectedRes);
}
public AssertContains(
text: string | RegExp,
exists: "exist" | "not.exist" | "be.visible" = "exist",
selector?: string,
) {
if (selector) {
return cy.contains(selector, text).should(exists);
}
return cy.contains(text).should(exists);
}
}