Skip to content

chore: Abstraction of Bottom View in Cypress#37410

Merged
hetunandu merged 1 commit intoreleasefrom
chore/response-test-abstraction
Nov 17, 2024
Merged

chore: Abstraction of Bottom View in Cypress#37410
hetunandu merged 1 commit intoreleasefrom
chore/response-test-abstraction

Conversation

@hetunandu
Copy link
Member

@hetunandu hetunandu commented Nov 15, 2024

Description

Abstract out the Bottom View in cypress tests so that it can be updated in the redesign tasks

Fixes #Issue Number
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.Datasource"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11855858863
Commit: 0cf1b0b
Cypress dashboard.
Tags: @tag.Datasource
Spec:


Fri, 15 Nov 2024 12:48:55 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced a new BottomPane component for improved response type management in tests.
    • Added functionality to switch response types and validate record counts more efficiently.
  • Bug Fixes

    • Enhanced visibility assertions for query responses in various test cases.
  • Documentation

    • Updated documentation to reflect changes in response handling and validation processes.
  • Refactor

    • Streamlined test case logic by centralizing response type switching and record count validation within the BottomPane component.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 15, 2024

Walkthrough

This pull request introduces a new BottomPane component that centralizes the handling of response types in various test cases. The changes involve replacing previous helper methods with calls to the BottomPane methods for switching response types and validating record counts. The modifications affect multiple test files, ensuring that the logic for interacting with API responses is consistent and maintainable across the application.

Changes

File Path Change Summary
app/client/cypress/e2e/Regression/ClientSide/Binding/JSObjectToListWidget_Spec.ts Added import for BottomPane; replaced agHelper method with BottomPane.response.switchResponseType("JSON").
app/client/cypress/e2e/Regression/ClientSide/BugTests/Binding_Bug28287_Spec.ts Added import for BottomPane; modified visibility assertion logic using BottomPane.response.switchToResponseTab().
app/client/cypress/e2e/Regression/ServerSide/OnLoadTests/OnLoadActions_Spec.ts Added import for BottomPane; replaced agHelper.GetNClick with BottomPane.response.switchResponseType("JSON").
app/client/cypress/e2e/Regression/ServerSide/QueryPane/Mongo1_spec.ts Added import for BottomPane; updated assertions for response visibility using BottomPane.response.getResponseTypeSelector().
app/client/cypress/e2e/Regression/ServerSide/QueryPane/Querypane_Mongo_Spec.js Added import for BottomPane; replaced record count checks with BottomPane.response.validateRecordCount.
app/client/cypress/e2e/Regression/ServerSide/QueryPane/S3_1_spec.js Added import for BottomPane; replaced agHelper.GetNClick calls with BottomPane.response.switchResponseType().
app/client/cypress/support/Pages/DataSources.ts Added import for BottomPane; modified RunQueryNVerifyResponseViews to utilize BottomPane methods for visibility checks.
app/client/cypress/support/Pages/IDE/BottomPane/Response.ts Introduced Response class with methods for managing response tab interactions and validations.
app/client/cypress/support/Pages/IDE/BottomPane/index.ts Added BottomPane class with a response property that initializes the Response class.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TestCase
    participant BottomPane
    participant Response

    User->>TestCase: Trigger test case
    TestCase->>BottomPane: switchResponseType("JSON")
    BottomPane->>Response: switchToResponseTab()
    Response->>Response: Click response tab
    BottomPane->>Response: getResponseTypeSelector("JSON")
    Response-->>TestCase: Return response type selector
    TestCase->>TestCase: Assert response visibility
Loading

Possibly related PRs

  • feat: Collapsible Bottom View #33441: This PR also involves the BottomPane component, specifically modifying how response types are handled in tests, which is directly related to the changes made in the main PR regarding the use of BottomPane.response.switchResponseType("JSON").

Suggested labels

Task, skip-changelog, IDE Pod, Query & JS Pod, Integrations Pod General, Widgets & Accelerators Pod

Suggested reviewers

  • AmanAgarwal041
  • albinAppsmith
  • ApekshaBhosale
  • sagar-qa007

Poem

In the realm of code where tests do play,
A BottomPane emerged to light the way.
With selectors and switches, so neat and fine,
API responses now flow in a line.
So let’s raise a cheer for this change so bold,
In the world of widgets, new stories unfold! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Nov 15, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🧹 Outside diff range and nitpick comments (13)
app/client/cypress/support/Pages/IDE/BottomPane/index.ts (1)

3-9: Add JSDoc documentation for the BottomPane class

Consider adding documentation to describe the class's purpose and usage in Cypress tests.

+/**
+ * BottomPane represents the bottom panel in the IDE
+ * Used for managing response-related interactions in Cypress tests
+ */
 class BottomPane {
   public readonly response: Response;

   constructor() {
     this.response = new Response();
   }
 }
app/client/cypress/support/Pages/IDE/BottomPane/Response.ts (1)

17-19: Implement record count validation method

The TODO comment indicates pending implementation. This could block test coverage for response validation.

Would you like me to help create a GitHub issue to track this implementation task or provide a suggested implementation?

app/client/cypress/e2e/Regression/ClientSide/Binding/JSObjectToListWidget_Spec.ts (2)

Line range hint 45-47: Critical: Update test patterns to follow Cypress guidelines

Several patterns in the test need to be updated:

  1. Replace cy.wait("@postExecute") with proper route aliases and intercept patterns
  2. Use data-* attributes instead of direct selectors
  3. Group related assertions using expect().to.satisfy() for better error reporting

Example refactor for the assertions:

- cy.wait("@postExecute").then((interception: any) => {
-   valueToTest = JSON.stringify(interception.response.body.data.body[0].name).replace(/['"]+/g, "");
-   cy.get(_.locators._textWidgetInDeployed)
-     .first()
-     .invoke("text")
-     .then((text) => {
-       expect(text).to.equal((valueToTest as string).trimEnd());
-     });
- });
+ cy.intercept('POST', '**/postExecute').as('apiResponse');
+ cy.wait('@apiResponse').then((interception: any) => {
+   const expectedValue = JSON.stringify(interception.response.body.data.body[0].name).replace(/['"]+/g, "");
+   cy.get('[data-cy=deployed-text-widget]')
+     .first()
+     .should('satisfy', ($el) => {
+       const text = $el.text().trim();
+       expect(text).to.equal(expectedValue);
+       return true;
+     });
+ });

Also applies to: 84-86


Line range hint 71-97: Improve test maintainability and readability

The test contains repetitive navigation checks and magic numbers. Consider:

  1. Extracting page navigation assertions into a helper function
  2. Defining constants for expected widget counts
  3. Breaking down the long test case into smaller, focused ones

Example refactor:

// Define constants
const ITEMS_PER_PAGE = 6;
const TOTAL_ITEMS = 20;

// Extract helper function
const assertPageNavigation = (pageNumber: number, expectedItems: number) => {
  _.table.AssertPageNumber_List(pageNumber);
  _.agHelper.AssertElementLength(_.locators._textWidgetInDeployed, expectedItems);
};

// Use in test
it("3. Validate pagination with updated spacing", () => {
  // Setup
  EditorNavigation.SelectEntityByName("List1", EntityType.Widget);
  _.propPane.MoveToTab("Style");
  _.propPane.UpdatePropertyFieldValue("Item Spacing (px)", "50");
  
  // Deploy and verify initial state
  _.deployMode.DeployApp(_.locators._textWidgetInDeployed);
  assertPageNavigation(1, ITEMS_PER_PAGE);
  
  // Navigate forward
  _.table.NavigateToNextPage_List();
  assertPageNavigation(2, ITEMS_PER_PAGE);
  
  // ... continue with other navigation checks
});
app/client/cypress/e2e/Regression/ServerSide/OnLoadTests/OnLoadActions_Spec.ts (3)

Line range hint 113-113: Remove explicit sleep and use proper wait conditions

Replace agHelper.Sleep(5000) with proper wait conditions. Explicit sleeps can make tests flaky and are against our coding guidelines.

Consider using:

-agHelper.Sleep(5000); //for all api's to ccomplete call!
+cy.wait("@getConsolidatedData").should("have.property", "response");

Line range hint 62-64: Consider extracting API URLs to configuration

The hardcoded URLs with port 5001 should be moved to a configuration file for better maintainability.

Consider creating a config file:

// config/apiEndpoints.ts
export const API_ENDPOINTS = {
  QUOTES: "http://host.docker.internal:5001/v1/favqs/qotd",
  ACTIVITY: "http://host.docker.internal:5001/v1/boredapi/activity",
  GENDERIZE: "http://host.docker.internal:5001/v1/genderize/sampledata"
};

Also applies to: 71-74, 80-83


Line range hint 121-157: Extract response validation logic

The duplicate response validation logic should be extracted into a helper function to improve maintainability and reduce code duplication.

Consider creating a helper:

const validateLayoutActions = (layoutActions: any[]) => {
  const [randomFlora, randomUser, inspiringQuotes, genderize, suggestions] = 
    layoutActions.map(action => action[0]);
    
  expect(randomFlora.name).to.eq("RandomFlora");
  expect(randomUser.name).to.eq("RandomUser");
  expect(inspiringQuotes.name).to.eq("InspiringQuotes");
  expect(genderize.name).to.eq("Genderize");
  expect(suggestions.name).to.eq("Suggestions");
};

Also applies to: 175-204

app/client/cypress/e2e/Regression/ServerSide/QueryPane/Querypane_Mongo_Spec.js (4)

Line range hint 33-38: Remove commented afterEach blocks

These commented-out afterEach blocks should be removed as they contain cy.pause() which is against our coding guidelines.

-    // afterEach(function() {
-    //   if (this.currentTest.state === "failed") {
-    //     Cypress.runner.stop();
-    //   }
-    // });
-
-    // afterEach(() => {
-    //   if (queryName)
-    //     cy.actionContextMenuByEntityName(queryName);
-    // });

Line range hint 264-275: Remove commented selector verification

The commented-out selector verification code should be removed.

-      // cy.get(generatePage.updateBtn)
-      //   .closest("button")
-      //   .then((selector) => {
-      //     cy.get(selector)
-      //       .invoke("attr", "class")
-      //       .then((classes) => {
-      //         cy.log("classes are:" + classes);
-      //         expect(classes).not.contain("bp3-disabled");
-      //       });
-      //   });

Line range hint 492-509: Remove commented update document test cases

Large blocks of commented-out test cases for update document operations should be removed.

-      // //Update document - All matching documents
-      // cy.validateNSelectDropdown("Command", "Find document(s)", "Update document(s)");
-      // cy.typeValueNValidate("{_id: {$gte:2}}", "Query");
-      // cy.typeValueNValidate("{$set:{ 'Frõ': 'InActive'}}", "Update");
-      // cy.validateNSelectDropdown("Limit", "Single document", "All matching documents");
-      // cy.runQuery()
-      // cy.wait("@postExecute").then(({ response }) => {
-      //   expect(response.body.data.body.nModified).to.eq(2);
-      // });
-
-      // //Verify Updation Successful:
-      // cy.validateNSelectDropdown("Command", "Update document(s)", "Find document(s)");
-      // cy.runQuery()
-      // cy.wait("@postExecute").then(({ response }) => {
-      //   expect(response.body.data.body[0].Frõ).to.eq('InActive');
-      // });

Line range hint 551-554: Remove commented query validation code

Remove the commented-out code for query validation.

-      // cy.typeValueNValidate(
-      //   "{_id : {$lte: 3 }}",
-      //   formControls.mongoDeleteDocumentsQuery,
-      // );
app/client/cypress/e2e/Regression/ServerSide/QueryPane/Mongo1_spec.ts (1)

Replace Sleep() calls with proper Cypress wait mechanisms

The test has unnecessary Sleep() calls that should be replaced with Cypress's built-in wait mechanisms. Specifically:

  • Replace agHelper.Sleep(2000) before RunQuery() with proper form value stabilization check
  • Replace agHelper.Sleep(4000) after RunQuery() with cy.wait('@postExecute') since the test already uses @postExecute alias

Example locations:

  • Line ~430: agHelper.Sleep(2000); //for documents value to settle!
  • Line ~431: agHelper.Sleep(4000); //for capturing right response!
🔗 Analysis chain

Line range hint 1-1000: Verify sleep duration necessity

The test contains multiple instances of agHelper.Sleep() with hardcoded durations. While sometimes necessary, sleep commands can make tests flaky and slow.

Let's analyze the sleep usage:

Consider replacing Sleep() calls with Cypress's built-in retry-ability and waiting mechanisms:

  • Use cy.wait('@aliasName') for network requests
  • Use cy.should('condition') for UI elements
  • Use cy.waitUntil() for complex conditions

Let me analyze the sleep usage further to provide a more complete verification.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all Sleep() calls and their durations

echo "Analyzing Sleep() calls in the test file:"
rg -A 1 "Sleep\(" app/client/cypress/e2e/Regression/ServerSide/QueryPane/Mongo1_spec.ts

Length of output: 593


Script:

#!/bin/bash
# Check for existing Cypress wait/intercept patterns
rg -B 2 -A 2 "@postExecute|@trigger|@getDatasourceStructure|@replaceLayoutWithCRUDPage" app/client/cypress/e2e/Regression/ServerSide/QueryPane/Mongo1_spec.ts

Length of output: 3497

app/client/cypress/support/Pages/DataSources.ts (1)

1141-1152: LGTM: Good refactoring of response validation

The changes improve code organization by:

  1. Using the new BottomPane.response methods for response type validation
  2. Centralizing record count validation logic

Consider extracting the response type constants ("TABLE", "JSON", "RAW") to an enum or constants object to avoid magic strings:

enum ResponseType {
  TABLE = "TABLE",
  JSON = "JSON",
  RAW = "RAW"
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between aa8b153 and 0cf1b0b.

📒 Files selected for processing (9)
  • app/client/cypress/e2e/Regression/ClientSide/Binding/JSObjectToListWidget_Spec.ts (2 hunks)
  • app/client/cypress/e2e/Regression/ClientSide/BugTests/Binding_Bug28287_Spec.ts (2 hunks)
  • app/client/cypress/e2e/Regression/ServerSide/OnLoadTests/OnLoadActions_Spec.ts (6 hunks)
  • app/client/cypress/e2e/Regression/ServerSide/QueryPane/Mongo1_spec.ts (10 hunks)
  • app/client/cypress/e2e/Regression/ServerSide/QueryPane/Querypane_Mongo_Spec.js (6 hunks)
  • app/client/cypress/e2e/Regression/ServerSide/QueryPane/S3_1_spec.js (2 hunks)
  • app/client/cypress/support/Pages/DataSources.ts (2 hunks)
  • app/client/cypress/support/Pages/IDE/BottomPane/Response.ts (1 hunks)
  • app/client/cypress/support/Pages/IDE/BottomPane/index.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (9)
app/client/cypress/e2e/Regression/ClientSide/Binding/JSObjectToListWidget_Spec.ts (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
app/client/cypress/e2e/Regression/ClientSide/BugTests/Binding_Bug28287_Spec.ts (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
app/client/cypress/e2e/Regression/ServerSide/OnLoadTests/OnLoadActions_Spec.ts (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
app/client/cypress/e2e/Regression/ServerSide/QueryPane/Mongo1_spec.ts (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
app/client/cypress/e2e/Regression/ServerSide/QueryPane/Querypane_Mongo_Spec.js (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
app/client/cypress/e2e/Regression/ServerSide/QueryPane/S3_1_spec.js (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
app/client/cypress/support/Pages/DataSources.ts (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
app/client/cypress/support/Pages/IDE/BottomPane/Response.ts (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
app/client/cypress/support/Pages/IDE/BottomPane/index.ts (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
🔇 Additional comments (14)
app/client/cypress/support/Pages/IDE/BottomPane/index.ts (1)

11-11: Verify singleton usage across test files

The singleton pattern implementation looks correct. Let's verify its usage to ensure there are no duplicate instantiations.

✅ Verification successful

Singleton pattern implementation verified - no duplicate instantiations found

The verification confirms proper singleton usage:

  • Single instantiation at app/client/cypress/support/Pages/IDE/BottomPane/index.ts
  • All other files correctly import the singleton instance via default import
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any direct instantiations of BottomPane class
# Expect: Only the default export should create an instance

# Search for new BottomPane() instances
rg "new BottomPane\(\)" --type ts

# Search for class imports to ensure they're using the default export
rg "import.*BottomPane.*from.*BottomPane" --type ts

Length of output: 848

app/client/cypress/e2e/Regression/ClientSide/BugTests/Binding_Bug28287_Spec.ts (1)

47-51: LGTM! Good use of the BottomPane component

The refactoring to use BottomPane improves code maintainability and follows best practices by:

  • Using proper component abstraction
  • Following data-* selector patterns
  • Making assertions more readable
app/client/cypress/e2e/Regression/ClientSide/Binding/JSObjectToListWidget_Spec.ts (1)

5-6: LGTM: BottomPane abstraction improves maintainability

The introduction of BottomPane and its usage for response type switching aligns well with the PR's objective of abstracting the Bottom View.

Also applies to: 22-22

app/client/cypress/e2e/Regression/ServerSide/OnLoadTests/OnLoadActions_Spec.ts (2)

16-16: LGTM: Clean import addition

The BottomPane import is properly placed with other IDE-related imports.


59-59: LGTM: Consistent usage of BottomPane abstraction

The replacement of direct response type switching with the BottomPane abstraction is consistent across all instances, improving maintainability.

Also applies to: 68-68, 77-77, 86-86, 166-166

app/client/cypress/e2e/Regression/ServerSide/QueryPane/Querypane_Mongo_Spec.js (4)

20-20: LGTM: Clean import of BottomPane component

The import statement follows the project's import organization pattern.


74-74: LGTM: Consistent use of BottomPane for record count validation

The changes standardize the way record counts are validated across different test cases using the new BottomPane component.

Also applies to: 96-96, 104-104, 112-112, 134-134, 148-148


436-436: LGTM: Record count validation in non-ASCII test case

The validation is correctly placed after the find operation in the non-ASCII test case.


71-73: 🛠️ Refactor suggestion

Remove commented code blocks

Several instances of commented-out code should be removed to improve maintainability.

-      // cy.get(".CodeMirror textarea")
-      //   .first()
-      //   .focus()
-      //   .type(`{"find": "listingAndReviews","limit": 10}`, {
-      //     parseSpecialCharSequences: false,
-      //   });
-      // cy.EvaluateCurrentValue(`{"find": "listingAndReviews","limit": 10}`);

Likely invalid or redundant comment.

app/client/cypress/e2e/Regression/ServerSide/QueryPane/S3_1_spec.js (3)

3-3: LGTM!

The import statement is correctly placed and follows the project's import conventions.


194-195: LGTM!

The response type switching using the new BottomPane component is implemented correctly.


Line range hint 1-650: Remove explicit wait times and use Cypress best practices

The test file contains multiple instances of explicit waits (cy.wait) with hardcoded timeouts. This is against Cypress best practices and can make tests flaky.

Consider these improvements:

  1. Replace cy.wait(3000) with built-in Cypress assertions
  2. Instead of cy.wait('@postExecute'), use cy.intercept() with proper routing and assertions
  3. Remove cy.setQueryTimeout(30000) and use Cypress's retry-ability

Example refactor:

- cy.wait(3000);
- cy.wait('@postExecute')
+ cy.intercept('POST', '/api/v1/actions/execute').as('postExecute');
+ cy.get('@postExecute').should('have.nested.property', 'response.body.data.isExecutionSuccess', true);

Let's scan for all wait instances in the codebase:

app/client/cypress/e2e/Regression/ServerSide/QueryPane/Mongo1_spec.ts (1)

19-19: LGTM: Import statement is correctly placed

The import of BottomPane from the IDE directory is properly structured.

app/client/cypress/support/Pages/DataSources.ts (1)

14-14: LGTM: Clean import of BottomPane component

The addition of the BottomPane import aligns with the abstraction of bottom view functionality.

Comment on lines +1 to +2
class Response {
private ResponseTab = "//button[@data-testid='t--tab-RESPONSE_TAB']";
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Replace XPath selector with data- attribute selector*

The XPath selector usage violates our coding guidelines. Use data-* attributes for more maintainable selectors.

class Response {
-  private ResponseTab = "//button[@data-testid='t--tab-RESPONSE_TAB']";
+  private ResponseTab = "[data-testid='t--tab-RESPONSE_TAB']";
📝 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
class Response {
private ResponseTab = "//button[@data-testid='t--tab-RESPONSE_TAB']";
class Response {
private ResponseTab = "[data-testid='t--tab-RESPONSE_TAB']";

Comment on lines +4 to +6
public switchToResponseTab(): void {
cy.xpath(this.ResponseTab).click({ force: true });
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid force clicks and XPath in Cypress commands

Force clicks can make tests brittle and mask underlying issues. Consider adding proper wait conditions or element visibility checks.

  public switchToResponseTab(): void {
-    cy.xpath(this.ResponseTab).click({ force: true });
+    cy.get(this.ResponseTab)
+      .should('be.visible')
+      .click();
  }

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +12 to +15
public switchResponseType(type: string): void {
this.switchToResponseTab();
cy.xpath(this.getResponseTypeSelector(type)).click({ force: true });
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve response type switching reliability

Similar to the tab switching, avoid force clicks and use proper wait conditions.

  public switchResponseType(type: string): void {
    this.switchToResponseTab();
-    cy.xpath(this.getResponseTypeSelector(type)).click({ force: true });
+    cy.get(this.getResponseTypeSelector(type))
+      .should('be.visible')
+      .click();
  }

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +8 to +10
public getResponseTypeSelector(type: string): string {
return `//div[@data-testid='t--response-tab-segmented-control']//span[text()='${type}']`;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use data attributes for response type selection

String interpolation in selectors is fragile. Consider using data attributes with specific values for each type.

  public getResponseTypeSelector(type: string): string {
-    return `//div[@data-testid='t--response-tab-segmented-control']//span[text()='${type}']`;
+    return `[data-testid='t--response-type-${type.toLowerCase()}']`;
  }

Committable suggestion skipped: line range outside the PR's diff.

@@ -43,7 +44,11 @@ describe(

EditorNavigation.SelectEntityByName(queryName, EntityType.Query);

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove agHelper.Sleep(1000)

Replace the sleep with proper Cypress wait commands or assertions to ensure the page has loaded.

Apply this change:

- agHelper.Sleep(1000);
+ cy.waitUntil(() => EditorNavigation.isEntityPresent(queryName, EntityType.Query));

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +433 to +438
agHelper.AssertElementVisibility(
BottomPane.response.getResponseTypeSelector("JSON"),
);
agHelper.AssertElementVisibility(
BottomPane.response.getResponseTypeSelector("RAW"),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider extracting repeated assertions into a helper function

The same response type selector assertions are repeated across multiple test cases. This violates the DRY principle and makes maintenance harder.

Consider creating a helper function in the test utilities:

// In support/Objects/ObjectsCore.ts
export const assertResponseTypeSelectors = () => {
  agHelper.AssertElementVisibility(
    BottomPane.response.getResponseTypeSelector("JSON")
  );
  agHelper.AssertElementVisibility(
    BottomPane.response.getResponseTypeSelector("RAW")
  );
};

// In the test file
assertResponseTypeSelectors();

Also applies to: 470-475, 517-522, 559-564, 590-595, 623-628, 660-665, 685-690, 722-727

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants