PromucFlow_constructor/app/client/cypress/support/Pages/AssertHelper.ts
Aishwarya-U-R 959fdce6ac
test: Cypress | Flaky fixes (#24508)
## Description
- This PR improves the sign up method to work even if telemetry related
details are not asked at start
- Also alters the Commit message based on the repository/workflow or
push runs
 - Improves DragDropWidgetNVerify()
 - Fixes flaky TableV2/Inline_editing_spec.js spec with TS methods
 - Improved EditTableCell()
 - Skipping deleting apps during local runs for debugging purpose
 - Fixes PropertyPane_Search_spec.ts
- Fixed ever flaky AppNavigationWithMultiplePages_spec,
AppNavigationWithAutoLayout_spec

#### 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:
- [ ] Added `Test Plan Approved` label after changes were reviewed
2023-06-17 00:10:10 +05:30

96 lines
2.6 KiB
TypeScript

import "cypress-wait-until";
import { ObjectsRegistry } from "../Objects/Registry";
import { ReusableHelper } from "../Objects/ReusableHelper";
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 extends ReusableHelper {
private locator = ObjectsRegistry.CommonLocators;
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().then((doc) => doc.readyState === "complete"),
cy.document().should((doc) => {
expect(doc.readyState).to.equal("complete");
}),
);
cy.window().should("have.property", "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 AssertNetworkStatus(aliasName: string, expectedStatus = 200) {
// cy.wait(aliasName).then(($apiCall: any) => {
// expect($apiCall.response.body.responseMeta.status).to.eq(expectedStatus);
// });
// cy.wait(aliasName).should(
// "have.nested.property",
// "response.body.responseMeta.status",
// expectedStatus,
// );
this.Sleep(); //Wait a bit for call to finish!
aliasName = aliasName.startsWith("@") ? aliasName : "@" + aliasName;
cy.wait(aliasName);
cy.get(aliasName)
.its("response.body.responseMeta.status")
.should("eq", expectedStatus);
//To improve below:
// cy.wait(aliasName, { timeout: timeout }).should((response: any) => {
// expect(response.status).to.be.oneOf([expectedStatus]);
// });
}
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);
}
}