-
Notifications
You must be signed in to change notification settings - Fork 4.7k
chore: add tests for anvil modal. #34347
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
Changes from 2 commits
ba6956e
36727bc
cc291be
a1b6acd
75d8ffb
bcc4bbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| import { | ||
| agHelper, | ||
| anvilLayout, | ||
| locators, | ||
| propPane, | ||
| } from "../../../../support/Objects/ObjectsCore"; | ||
| import { ANVIL_EDITOR_TEST } from "../../../../support/Constants"; | ||
| import { anvilLocators } from "../../../../support/Pages/Anvil/Locators"; | ||
| import EditorNavigation, { | ||
| EntityType, | ||
| } from "../../../../support/Pages/EditorNavigation"; | ||
|
|
||
| describe( | ||
| `${ANVIL_EDITOR_TEST}: Anvil tests for Modals`, | ||
| { tags: ["@tag.Anvil"] }, | ||
| () => { | ||
| before(() => { | ||
| // Cleanup the canvas before each test | ||
| agHelper.SelectAllWidgets(); | ||
| agHelper.PressDelete(); | ||
| }); | ||
| it("1. Verify opening a modal by clicking on a button", () => { | ||
| // drop a modal widget | ||
| anvilLayout.dnd.DragDropNewAnvilWidgetNVerify( | ||
| anvilLocators.WDSMODAL, | ||
| 10, | ||
| 10, | ||
| { | ||
| skipWidgetSearch: true, | ||
| dropTargetDetails: { | ||
| dropModal: true, | ||
| }, | ||
| }, | ||
| ); | ||
| // press escape and close modal | ||
| agHelper.PressEscape(); | ||
| // add a button | ||
| anvilLayout.dnd.DragDropNewAnvilWidgetNVerify( | ||
| anvilLocators.WDSBUTTON, | ||
| 10, | ||
| 10, | ||
| { | ||
| skipWidgetSearch: true, | ||
| }, | ||
| ); | ||
| propPane.EnterJSContext("onClick", "{{showModal(Modal1.name);}}"); | ||
| agHelper.GetNClick(locators._enterPreviewMode); | ||
| agHelper.GetNClick(anvilLocators.anvilWidgetNameSelector("Button1")); | ||
| agHelper.AssertElementExist( | ||
| anvilLocators.anvilWidgetNameSelector("Modal1"), | ||
| ); | ||
| }); | ||
| it("2. Verify closing a modal using the close icon button", () => { | ||
| agHelper.GetNClick( | ||
| anvilLocators.anvilModalCloseIconButtonSelector("Modal1"), | ||
| ); | ||
| agHelper.AssertElementAbsence( | ||
| anvilLocators.anvilWidgetNameSelector("Modal1"), | ||
| ); | ||
| }); | ||
| it("3. Verify closing a modal by clicking outside the modal area", () => { | ||
| // open modal | ||
| agHelper.GetNClick(anvilLocators.anvilWidgetNameSelector("Button1")); | ||
| agHelper.AssertElementExist( | ||
| anvilLocators.anvilWidgetNameSelector("Modal1"), | ||
| ); | ||
| // click on overlay top position | ||
| agHelper.GetNClick( | ||
| anvilLocators.anvilModalOverlay, | ||
| 0, | ||
| false, | ||
| 500, | ||
| false, | ||
| false, | ||
| "top", | ||
| ); | ||
| agHelper.AssertElementAbsence( | ||
| anvilLocators.anvilWidgetNameSelector("Modal1"), | ||
| ); | ||
| }); | ||
| it("4. Verify closing a modal using the ESC key", () => { | ||
| // open modal | ||
| agHelper.GetNClick(anvilLocators.anvilWidgetNameSelector("Button1")); | ||
| agHelper.AssertElementExist( | ||
| anvilLocators.anvilWidgetNameSelector("Modal1"), | ||
| ); | ||
| // press escape | ||
| agHelper.PressEscape(); | ||
| agHelper.AssertElementAbsence( | ||
| anvilLocators.anvilWidgetNameSelector("Modal1"), | ||
| ); | ||
| agHelper.GetNClick(locators._exitPreviewMode); | ||
| }); | ||
| it("5. verify onClose function of Modal", () => { | ||
| EditorNavigation.SelectEntityByName("Modal1", EntityType.Widget); | ||
| propPane.EnterJSContext("onClose", "{{showAlert('onCloseTest');}}"); | ||
| agHelper.GetNClick(locators._enterPreviewMode); | ||
| //close modal via footer close button | ||
| agHelper.GetNClick( | ||
| anvilLocators.anvilModalFooterCloseButtonSelector("Modal1"), | ||
| ); | ||
| //verify alert | ||
| agHelper.ValidateToastMessage("onCloseTest"); | ||
| agHelper.GetNClick(locators._exitPreviewMode); | ||
| }); | ||
| it("6. Verify onSubmit function on Modal", () => { | ||
| EditorNavigation.SelectEntityByName("Modal1", EntityType.Widget); | ||
| propPane.EnterJSContext("onSubmit", "{{showAlert('onSubmitTest');}}"); | ||
| agHelper.GetNClick(locators._enterPreviewMode); | ||
| //close modal via submit button | ||
| agHelper.GetNClick( | ||
| anvilLocators.anvilModalFooterSubmitButtonSelector("Modal1"), | ||
| ); | ||
| //verify alert | ||
| agHelper.ValidateToastMessage("onSubmitTest"); | ||
| agHelper.GetNClick(locators._exitPreviewMode); | ||
| }); | ||
| it("7. Verify DnD on Modal", () => { | ||
| EditorNavigation.SelectEntityByName("Modal1", EntityType.Widget); | ||
| // add a widget to modal | ||
| anvilLayout.dnd.DragDropNewAnvilWidgetNVerify( | ||
| anvilLocators.WDSBUTTON, | ||
| 10, | ||
| 10, | ||
| { | ||
| skipWidgetSearch: true, | ||
| dropTargetDetails: { | ||
| name: "Modal1", | ||
| }, | ||
| }, | ||
| ); | ||
| // verify newly added button | ||
| agHelper.AssertElementExist( | ||
| anvilLocators.anvilWidgetNameSelector("Button2"), | ||
| ); | ||
| }); | ||
| it("8. Verify different modal sizes", () => { | ||
| // select all widgets and delete | ||
| agHelper.PressEscape(); | ||
| agHelper.SelectAllWidgets(); | ||
| agHelper.PressDelete(); | ||
| // add a modal widget | ||
| anvilLayout.dnd.DragDropNewAnvilWidgetNVerify( | ||
| anvilLocators.WDSMODAL, | ||
| 10, | ||
| 10, | ||
| { | ||
| skipWidgetSearch: true, | ||
| dropTargetDetails: { | ||
| dropModal: true, | ||
| }, | ||
| }, | ||
| ); | ||
| agHelper | ||
| .GetElement(anvilLocators.anvilWidgetNameSelector("Modal1")) | ||
| .matchImageSnapshot("anvil/anvilModalMediumSize"); | ||
| propPane.SelectPropertiesDropDown("size", "Small"); | ||
| agHelper | ||
| .GetElement(anvilLocators.anvilWidgetNameSelector("Modal1")) | ||
| .matchImageSnapshot("anvil/anvilModalSmallSize"); | ||
| propPane.SelectPropertiesDropDown("size", "Large"); | ||
| agHelper | ||
| .GetElement(anvilLocators.anvilWidgetNameSelector("Modal1")) | ||
| .matchImageSnapshot("anvil/anvilModalLargeSize"); | ||
| }); | ||
| }, | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,12 +9,25 @@ const anvilWidgetBasedSelectors = { | |
| anvilWidgetNameSelector: (widgetName: string) => { | ||
| return `[${AnvilDataAttributes.WIDGET_NAME}="${widgetName}"]`; | ||
| }, | ||
| anvilModalOverlay: 'div[data-floating-ui-portal] > div[data-status="open"]', | ||
| anvilSelectedWidget: `${anvilWidgetSelector}[data-selected=true]`, | ||
| anvilWidgetTypeSelector: (widgetType: string) => { | ||
| return `.t--widget-${widgetType}`; | ||
| }, | ||
| }; | ||
|
|
||
| const anvilModalWidgetSelectors = { | ||
| anvilModalCloseIconButtonSelector: (widgetName: string) => { | ||
| return `${anvilWidgetBasedSelectors.anvilWidgetNameSelector(widgetName)} > div > div > button[data-icon-button]`; | ||
| }, | ||
| anvilModalFooterCloseButtonSelector: (widgetName: string) => { | ||
| return `${anvilWidgetBasedSelectors.anvilWidgetNameSelector(widgetName)} > div > div:last-child > button[data-button]:first-child`; | ||
| }, | ||
| anvilModalFooterSubmitButtonSelector: (widgetName: string) => { | ||
| return `${anvilWidgetBasedSelectors.anvilWidgetNameSelector(widgetName)} > div > div:last-child > button[data-button]:last-child`; | ||
| }, | ||
| }; | ||
|
|
||
| // sections and zones based selectors | ||
| const anvilSectionAndZonesBasedSelectors = { | ||
| anvilZoneDistributionValue: "[data-testid=t--anvil-zone-distribution-value]", | ||
|
|
@@ -29,6 +42,8 @@ const anvilSectionAndZonesBasedSelectors = { | |
| // dnd based selectors | ||
| const anvilDnDBasedSelectors = { | ||
| anvilDnDListener: "[data-type=anvil-dnd-listener]", | ||
| anvilDetachedWidgetsDropArena: | ||
| "[data-testid=t--anvil-detached-widgets-drop-arena]", | ||
| mainCanvasSelector: `#${getAnvilCanvasId(MAIN_CONTAINER_WIDGET_ID)}`, | ||
| }; | ||
|
|
||
|
|
@@ -39,12 +54,14 @@ const anvilWidgetsLocators = { | |
| WDSINPUT: "wdsinputwidget", | ||
| WDSSWITCH: "wdsswitchwidget", | ||
| WDSCHECKBOX: "wdscheckboxwidget", | ||
| WDSMODAL: "wdsmodalwidget", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tip Codebase Verification The search results indicate that the new widget type
This suggests that the new widget type Analysis chainAdded a new widget type for modals. Confirm that this widget type is integrated into the widget system and handled appropriately in widget-related logic. Let's address the issue with the The search results show that the new widget type Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify the integration of the new modal widget type.
# Test: Search for the handling of the new widget type. Expect: Proper handling in the widget system logic.
rg --type typescript $'WDSMODAL'
Length of output: 66 Script: #!/bin/bash
# Description: Verify the integration of the new modal widget type.
# Correcting the file type and searching for the handling of the new widget type in TypeScript files.
rg --type-add 'ts:*.ts' --type ts 'WDSMODAL'
Length of output: 335 Script: #!/bin/bash
# Description: Verify the integration of the new modal widget type in the widget system logic.
# Searching for the handling of the new widget type in the entire codebase, excluding test files.
rg --type-add 'ts:*.ts' --type ts 'WDSMODAL' --glob '!**/*spec.ts'
Length of output: 153 |
||
| SECTION: "sectionwidget", | ||
| ZONE: "zonewidget", | ||
| }; | ||
|
|
||
| export const anvilLocators = { | ||
| ...anvilWidgetBasedSelectors, | ||
| ...anvilModalWidgetSelectors, | ||
| ...anvilWidgetsLocators, | ||
| ...anvilSectionAndZonesBasedSelectors, | ||
| ...anvilDnDBasedSelectors, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you use command line to generate these snapshot or used the cytest command?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I ask is if you have used the cytest command, It will always pass the CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
matchImageSnapshotcreates the snapshot the first time in the directory provided if there is no snapshot already present, once the snap is present it will do a diff against the existing snapshot.so when I first ran the test, it created the snapshot and for the next runs it does diff checks against the already generated snapshots.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean how did you generate the snapshots? with headless chrome or regular chrome with cypress? I did with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generated via chromium based electron.