-
Notifications
You must be signed in to change notification settings - Fork 4.6k
feat: add cypress tests for drag and drop building blocks #33036
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 19 commits
3d10db4
be509fd
5f53f7d
4e84de9
d34ab5d
6c76fc0
fbf2da8
1435ce3
4b77394
b348574
bc4cafb
6e9baea
1dd0e9a
8cfa49c
e8d2ef0
813c3b4
6c10107
38eb5ac
922e49e
df26919
cc3da8a
0ce8f9b
8ad615e
5d92b68
60a0982
3364deb
b33c48b
0d68b72
7aca7b9
a0d47c8
b6b81df
029e189
6ce3de9
c05dcbb
9575d97
d679225
ae4ae11
0d7683d
b9b2b61
791f542
f1f27d3
2b8f502
0a9bd72
f99d714
ea02ee1
07eaa5e
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,158 @@ | ||
| import { featureFlagIntercept } from "../../../../support/Objects/FeatureFlags"; | ||
| import { | ||
| entityExplorer, | ||
| agHelper, | ||
| } from "../../../../support/Objects/ObjectsCore"; | ||
|
|
||
| const commonlocators = require("../../../../locators/commonlocators.json"); | ||
|
|
||
| // Taken from here appsmith/app/client/src/constants/WidgetConstants.tsx | ||
| const MAX_BUILDING_BLOCKS_TO_DISPLAY = 9; | ||
|
|
||
| describe( | ||
| "Building blocks explorer tests", | ||
| { | ||
| tags: ["@tag.IDE", "@tag.Widget"], | ||
| }, | ||
| () => { | ||
| it("1. Building blocks tag is visible and open by default", () => { | ||
| featureFlagIntercept({ release_drag_drop_building_blocks_enabled: true }); | ||
| agHelper | ||
| .GetElement(`${entityExplorer._widgetTagBuildingBlocks}`) | ||
| .each(($widgetTag) => { | ||
| const widgetsInThisTag: string[] = []; | ||
| cy.wrap($widgetTag) | ||
| .find(entityExplorer._widgetCardTitle) | ||
| .each(($widgetName) => { | ||
| const value = $widgetName.text(); | ||
| widgetsInThisTag.push(value); | ||
| }) | ||
| .then(() => { | ||
| expect(widgetsInThisTag).to.have.length.gt(1); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| it("2. If widgets are more than 9, see more button should be visible", () => { | ||
| featureFlagIntercept({ release_drag_drop_building_blocks_enabled: true }); | ||
| let widgetsInThisTag: string[] = []; | ||
|
|
||
| agHelper | ||
| .GetElement(`${entityExplorer._widgetTagBuildingBlocks}`) | ||
| .each(($widgetTag) => { | ||
| cy.wrap($widgetTag) | ||
| .find(entityExplorer._widgetCardTitle) | ||
| .each(($widgetName) => { | ||
| const value = $widgetName.text(); | ||
| widgetsInThisTag.push(value); | ||
| }); | ||
| }); | ||
|
|
||
| if (widgetsInThisTag.length > MAX_BUILDING_BLOCKS_TO_DISPLAY) { | ||
| cy.get(entityExplorer._widgetSeeMoreButton).should("be.visible"); | ||
| } | ||
|
Comment on lines
+36
to
+
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. Address the variable scope issue to prevent potential test failures. The variable |
||
| }); | ||
|
|
||
| it("3. Should not show the 'See More' button if widgets are less than 9", () => { | ||
| featureFlagIntercept({ release_drag_drop_building_blocks_enabled: true }); | ||
|
|
||
| // Array to store the names of widgets found | ||
| const widgetsInThisTag: string[] = []; | ||
|
|
||
| // Find and iterate over each widget card title within the specified tag | ||
| cy.get(entityExplorer._widgetTagBuildingBlocks) | ||
| .find(entityExplorer._widgetCardTitle) | ||
| .each(($widgetName) => { | ||
| // Extract the text of each widget title | ||
| const value = $widgetName.text().trim(); | ||
| widgetsInThisTag.push(value); | ||
| }) | ||
| .then(() => { | ||
| // After collecting widget names, assert based on the count | ||
| if (widgetsInThisTag.length < MAX_BUILDING_BLOCKS_TO_DISPLAY) { | ||
| // If less than 9 widgets, ensure the 'See More' button does not exist | ||
| cy.get(entityExplorer._widgetSeeMoreButton).should("not.exist"); | ||
| } else { | ||
| // If 9 or more widgets, ensure the 'See More' button exists | ||
| cy.get(entityExplorer._widgetSeeMoreButton).should("exist"); | ||
| } | ||
|
Comment on lines
+56
to
+
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. Refactor to remove redundant conditions. The conditions in lines 73 and 77 are redundant since they are mutually exclusive and handled in the same |
||
| }); | ||
| }); | ||
|
|
||
| it("4. Clicking on 'See More' button should show all widgets, and 'See Less' should show max 9 widgets", () => { | ||
| featureFlagIntercept({ release_drag_drop_building_blocks_enabled: true }); | ||
|
|
||
| let widgetsInThisTag: string[] = []; | ||
|
|
||
| // Get all building blocks before attempting to click "See More" | ||
| cy.get(entityExplorer._widgetTagBuildingBlocks) | ||
| .each(($widgetTag) => { | ||
| cy.wrap($widgetTag) | ||
| .find(entityExplorer._widgetCardTitle) | ||
| .each(($widgetName) => { | ||
| const value = $widgetName.text().trim(); | ||
| widgetsInThisTag.push(value); | ||
| }); | ||
| }) | ||
| .then(() => { | ||
| // Check if there are fewer than 9 widgets | ||
| if (widgetsInThisTag.length < MAX_BUILDING_BLOCKS_TO_DISPLAY) { | ||
| // No need to click "See More" if there are already fewer than 9 widgets | ||
| cy.get(entityExplorer._widgetSeeMoreButton).should("not.exist"); | ||
| } else { | ||
| // Click the "See More" button for each widget tag | ||
| cy.get(entityExplorer._widgetTagsList).each(($widgetTag) => { | ||
| cy.wrap($widgetTag) | ||
| .find(entityExplorer._widgetSeeMoreButton) | ||
| .should("exist") | ||
| .click({ force: true }); | ||
| }); | ||
| } | ||
|
|
||
| // Get all building blocks after attempting to click "See More" | ||
| let widgetsInThisTagAfterSeeMore: string[] = []; | ||
| cy.get(entityExplorer._widgetTagBuildingBlocks) | ||
| .each(($widgetTag) => { | ||
| cy.wrap($widgetTag) | ||
| .find(entityExplorer._widgetCardTitle) | ||
| .each(($widgetName) => { | ||
| const value = $widgetName.text().trim(); | ||
| widgetsInThisTagAfterSeeMore.push(value); | ||
| }); | ||
| }) | ||
| .then(() => { | ||
| // Assert that the number of widgets after potentially clicking "See More" is correct | ||
| expect(widgetsInThisTagAfterSeeMore.length).to.be.greaterThan( | ||
| widgetsInThisTag.length, | ||
| ); | ||
| }); | ||
|
|
||
| // Click the same "See More" button again to simulate "See Less" | ||
| cy.get(entityExplorer._widgetTagsList).each(($widgetTag) => { | ||
| cy.wrap($widgetTag) | ||
| .find(entityExplorer._widgetSeeMoreButton) | ||
| .should("exist") // Check if the button still exists (now interpreted as "See Less") | ||
| .click({ force: true }); | ||
| }); | ||
|
|
||
| // Get all building blocks after clicking "See Less" | ||
| let widgetsInThisTagAfterSeeLess: string[] = []; | ||
| cy.get(entityExplorer._widgetTagBuildingBlocks) | ||
| .each(($widgetTag) => { | ||
| cy.wrap($widgetTag) | ||
| .find(entityExplorer._widgetCardTitle) | ||
| .each(($widgetName) => { | ||
| const value = $widgetName.text().trim(); | ||
| widgetsInThisTagAfterSeeLess.push(value); | ||
| }); | ||
| }) | ||
| .then(() => { | ||
| // Assert that the number of widgets after clicking "See Less" is back to original count | ||
| expect(widgetsInThisTagAfterSeeLess.length).to.equal( | ||
| widgetsInThisTag.length, | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
| }, | ||
| ); | ||
Uh oh!
There was an error while loading. Please reload this page.