Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cypress snapshot types #34561

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ describe(
});

it("1. Canvas Mode", () => {
anvilSnapshot.triggerInputInvalidState();
anvilSnapshot.verifyCanvasMode("CurrencyInputWidget");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe(
});

it("1. Canvas Mode", () => {
cy.wait(5000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using hardcoded wait times in Cypress tests.

Using cy.wait(5000); can lead to flaky tests and unnecessary delays. Instead, consider waiting for specific conditions or elements to be ready. For example, you can wait for the widget to be visible or for a specific element to appear.

- cy.wait(5000);
+ cy.get('[data-testid="IconButtonWidget"]').should('be.visible');
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cy.wait(5000);
cy.get('[data-testid="IconButtonWidget"]').should('be.visible');

anvilSnapshot.verifyCanvasMode("IconButtonWidget");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ describe(
});

it("1. Canvas Mode", () => {
anvilSnapshot.triggerInputInvalidState();
anvilSnapshot.verifyCanvasMode("InputWidget");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ describe(
});

it("1. Canvas Mode", () => {
anvilSnapshot.triggerInputInvalidState();
anvilSnapshot.verifyCanvasMode("PhoneInputWidget");
});

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Diff not rendered.
Diff not rendered.
Diff not rendered.
26 changes: 13 additions & 13 deletions app/client/cypress/support/Pages/Anvil/AnvilSnapshot.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { agHelper } from "../../Objects/ObjectsCore";
import { ObjectsRegistry } from "../../Objects/Registry";

export class AnvilSnapshot {
Expand All @@ -9,20 +10,24 @@ export class AnvilSnapshot {
exitPreviewMode: ObjectsRegistry.CommonLocators._exitPreviewMode,
canvas: "[data-testid=t--canvas-artboard]",
colorMode: "[data-testid=t--anvil-theme-settings-color-mode]",
appViewerPage: "[data-testid=t--app-viewer-page-body]",
appViewerPage: "[data-testid=t--app-viewer-page]",
propertyPaneSidebar: "[data-testid=t--property-pane-sidebar]",
};

public verifyCanvasMode = async (widgetName: string) => {
this.agHelper
.GetElement(this.locators.canvas)
.matchImageSnapshot(`anvil${widgetName}Canvas`);
.matchImageSnapshot(`anvil${widgetName}Canvas`, {
comparisonMethod: "ssim",
});

this.setTheme("dark");

this.agHelper
.GetElement(this.locators.canvas)
.matchImageSnapshot(`anvil${widgetName}CanvasDark`);
.matchImageSnapshot(`anvil${widgetName}CanvasDark`, {
comparisonMethod: "ssim",
});

this.setTheme("light");
};
Expand All @@ -34,7 +39,9 @@ export class AnvilSnapshot {

this.agHelper
.GetElement(this.locators.canvas)
.matchImageSnapshot(`anvil${widgetName}Preview`);
.matchImageSnapshot(`anvil${widgetName}Preview`, {
comparisonMethod: "ssim",
});

this.exitPreviewMode();
};
Expand All @@ -59,8 +66,9 @@ export class AnvilSnapshot {
this.agHelper
.GetElement(this.locators.appViewerPage)
.matchImageSnapshot(`anvil${widgetName}Deploy${device}`, {
capture: "fullPage",
comparisonMethod: "ssim",
});
agHelper.Sleep(500);
});
};

Expand All @@ -82,12 +90,4 @@ export class AnvilSnapshot {

this.appSettings.ClosePane();
};

public triggerInputInvalidState = () => {
this.enterPreviewMode();
cy.get("input[aria-required=true]").first().type("123");
cy.get("input[aria-required=true]").first().clear();
this.exitPreviewMode();
this.agHelper.GetNClick(this.locators.propertyPaneSidebar);
};
}
2 changes: 2 additions & 0 deletions app/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"g:jest": "cd $INIT_CWD && jest --colors --no-cache --silent --maxWorkers=50%",
"test:unit:ci": "yarn workspaces foreach -tv run test:unit",
"generate:widget": "plop --plopfile generators/index.js",
"generate:anvil-snapshots": "rm -rf cypress/snapshots/Anvil* && npx cypress run --spec cypress/e2e/Regression/ClientSide/Anvil/Widgets/** --browser chrome --reporter cypress-image-snapshot/reporter",
"postinstall": "node cypress/apply-patches.js && yarn init-husky",
"storybook": "yarn workspace @design-system/storybook storybook",
"lint": "eslint --cache ./src && cd ./cypress && eslint -c .eslintrc.json --cache ./",
Expand Down Expand Up @@ -82,6 +83,7 @@
"@tanstack/virtual-core": "^3.0.0-beta.18",
"@tinymce/tinymce-react": "^5.0.0",
"@types/babel__standalone": "^7.1.7",
"@types/cypress-image-snapshot": "^3.1.9",
"@types/d3-geo": "^3.1.0",
"@types/google.maps": "^3.51.0",
"@types/react-page-visibility": "^6.4.1",
Expand Down
1 change: 0 additions & 1 deletion app/client/src/pages/AppViewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ function AppViewer(props: Props) {
<AppViewerBody
$contain={isAutoLayout ? "content" : "strict"}
className={CANVAS_SELECTOR}
data-testid="t--app-viewer-page-body"
hasPages={pages.length > 1}
headerHeight={headerHeight}
ref={focusRef}
Expand Down
8 changes: 8 additions & 0 deletions app/client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10547,6 +10547,13 @@ __metadata:
languageName: node
linkType: hard

"@types/cypress-image-snapshot@npm:^3.1.9":
version: 3.1.9
resolution: "@types/cypress-image-snapshot@npm:3.1.9"
checksum: 8afbeb26c575275d02861cfafde5bfae3a7d25f35d0c18bbc1c70a72b45a8bc021ff73de3b5d4a36c7cb22bc86442fee14308ef096f9650dc5eddd941f923f2f
languageName: node
linkType: hard

"@types/d3-geo@npm:^3.1.0":
version: 3.1.0
resolution: "@types/d3-geo@npm:3.1.0"
Expand Down Expand Up @@ -13128,6 +13135,7 @@ __metadata:
"@tinymce/tinymce-react": ^5.0.0
"@types/babel__standalone": ^7.1.7
"@types/codemirror": ^0.0.96
"@types/cypress-image-snapshot": ^3.1.9
"@types/d3-geo": ^3.1.0
"@types/deep-diff": ^1.0.0
"@types/dom-mediacapture-record": ^1.0.11
Expand Down
Loading