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: Fixed Bug29566 spec with list widget #36260

Merged
merged 4 commits into from
Sep 12, 2024
Merged

Conversation

sagar-qa007
Copy link
Contributor

@sagar-qa007 sagar-qa007 commented Sep 11, 2024

Description

Root Cause Analysis (RCA):

The test case in BugTests/Bug29566_Spec.ts has become flaky due to its dependency on a third-party API call (https://api.jsonbin.io/v3/b/). As experienced automation engineers, we understand that relying on third-party services can introduce instability and lead to frequent test failures. In this particular case, the dependency was tightly coupled with the test logic, and updating the data was not a viable solution.

Solution:

Upon assessing the situation, I determined that refactoring the existing test would take significantly longer than rewriting it from scratch. Therefore, I chose the rewriting approach to prioritize time efficiency. The test flow has been updated while maintaining the same assertions for data validation. Additionally, I have incorporated an extra assertion to verify the data after a page reload to further enhance the robustness of the test.

Fixes #36259

Automation

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

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/10816309843
Commit: 2be906c
Cypress dashboard.
Tags: @tag.Sanity
Spec:


Wed, 11 Sep 2024 17:34:50 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced testing for the list widget to ensure it populates correctly on page load, addressing Bug 29566.
    • Introduced dynamic data sourcing for more accurate test scenarios.
  • Bug Fixes

    • Updated test cases to reflect changes in functionality and validate correct data display.
  • Documentation

    • Renamed test case for clarity regarding the specific bug being addressed.
  • Chores

    • Updated the limited tests configuration to focus on the new bug test instead of a template test.

@sagar-qa007 sagar-qa007 added the ok-to-test Required label for CI label Sep 11, 2024
Copy link
Contributor

coderabbitai bot commented Sep 11, 2024

Walkthrough

The changes involve significant modifications to a Cypress test file, specifically Bug29566_Spec.ts, which now utilizes a PostgreSQL data source for fetching user data instead of relying on hardcoded JavaScript objects. The test case has been renamed for clarity, and it includes new assertions to validate the list widget's population with the fetched data. Additionally, the entry in limited-tests.txt has been updated to reflect this new focus on the bug test. Furthermore, a new test file, ListWidgetOnPageLoad_Spec.ts, has been introduced to ensure comprehensive testing of the list widget's functionality.

Changes

File(s) Change Summary
app/client/cypress/e2e/Regression/ClientSide/BugTests/Bug29566_Spec.ts, app/client/cypress/e2e/Regression/ClientSide/BugTests/ListWidgetOnPageLoad_Spec.ts Removed hardcoded JavaScript objects, introduced PostgreSQL data source, renamed test case, added assertions, and created a new test suite for list widget functionality.
app/client/cypress/limited-tests.txt Updated entry from Fork_Template_spec.js to Bug29566_Spec.ts, changing the focus of limited tests.

Assessment against linked issues

Objective Addressed Explanation
Fix the test case. (#36259)

🎉 In the world of code, changes unfold,
A test reborn, with stories told.
From static roots to dynamic flows,
The list widget now proudly shows!
With PostgreSQL's grace, it fetches with ease,
A bug's defeat, a developer's breeze! 🌟


Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 69873bf and 2be906c.

Files selected for processing (1)
  • app/client/cypress/e2e/Regression/ClientSide/BugTests/ListWidgetOnPageLoad_Spec.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/client/cypress/e2e/Regression/ClientSide/BugTests/ListWidgetOnPageLoad_Spec.ts

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

@sagar-qa007 sagar-qa007 added the Bug Something isn't working label Sep 11, 2024
@sagar-qa007
Copy link
Contributor Author

/ci-test-limit-count run_count=20

Copy link

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: 0

Outside diff range and nitpick comments (1)
app/client/cypress/e2e/Regression/ClientSide/BugTests/Bug29566_Spec.ts (1)

21-54: Excellent work on the test case!

The test case follows a clear and logical flow, covering the essential aspects of the bug being tested. Here's a breakdown of the test case:

  1. Set up the data source and query.
  2. Navigate through the editor and configure the widget.
  3. Deploy the app and assert the widget's behavior.
  4. Reload the page and re-assert the widget's behavior.

The test case is well-structured and effectively tests the list widget's behavior on page load.

A few suggestions for improvement:

  1. Consider extracting the repeated assertions into a separate function to improve readability and maintainability.
  2. Add comments to explain the purpose of each section of the test case, making it easier for other developers to understand the test's flow.

Here's an example of how you can extract the repeated assertions into a separate function:

function assertWidgetText(locator: string, expectedTexts: string[]) {
  agHelper.AssertElementLength(locator, expectedTexts.length);
  agHelper.GetText(locator).then((texts: string[]) => {
    expect(texts).to.deep.equal(expectedTexts);
  });
}

Then, you can use this function in the test case:

agHelper
  .GetText(locators._widgetInCanvas("textwidget") + " span")
  .then((initialTexts: string[]) => {
    deployMode.DeployApp();
    assertWidgetText(locators._textWidgetInDeployed, initialTexts);
    agHelper.CypressReload();
    assertWidgetText(locators._textWidgetInDeployed, initialTexts);
  });
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 228af86 and 2c369f4.

Files selected for processing (2)
  • app/client/cypress/e2e/Regression/ClientSide/BugTests/Bug29566_Spec.ts (1 hunks)
  • app/client/cypress/limited-tests.txt (1 hunks)
Additional context used
Path-based instructions (2)
app/client/cypress/limited-tests.txt (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/Bug29566_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.
Additional comments not posted (5)
app/client/cypress/limited-tests.txt (1)

2-2: Good choice for limited tests! 👍

Focusing the limited tests on Bug29566_Spec.ts aligns well with the PR objective of fixing the flaky test in that file. This change ensures that the problematic test gets adequate attention during the CI/CD process.

app/client/cypress/e2e/Regression/ClientSide/BugTests/Bug29566_Spec.ts (4)

1-14: Great job organizing the imports!

The new imports for dataSources, deployMode, locators, propPane, EditorNavigation, AppSidebar, AppSidebarButton, EntityType, PageLeftPane, and PagePaneSegment are well-structured and indicate a clear understanding of the test's requirements.

Importing these modules from the appropriate locations will help keep the test code clean and maintainable.


16-19: Excellent setup in the before hook!

Adding the DSL using agHelper.AddDsl("Listv2/simpleList") in the before hook is a great way to ensure that the necessary setup is performed before running the test case.

This approach helps keep the test case focused on the specific scenario being tested and improves the overall organization of the test file.


37-38: Great job using locator variables!

Using locator variables like locators._widgetInCanvas("textwidget") and locators._textWidgetInDeployed instead of plain strings is a best practice in Cypress testing.

This approach helps maintain consistency and makes the test code more readable and maintainable. It also makes it easier to update the locators if the application's structure changes in the future.

Keep up the good work!

Also applies to: 40-40, 42-43, 47-47


44-45: Excellent use of multiple assertions!

Using multiple assertions for the expect statements, such as comparing the deployed texts with the initial texts, is a best practice in Cypress testing.

This approach ensures that the test case covers all the necessary conditions and provides more informative error messages if an assertion fails. It also makes the test case more robust and less likely to produce false positives.

Great job implementing this best practice!

Also applies to: 51-52

Copy link

Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/10814867598.
Cypress dashboard url: Click here!
All cypress tests have passed 🎉🎉🎉

***** Repeat Run Summary ***** Total Tests with repeat: 20 Total Passed: 20 Total Failed: 0 Total Skipped: 0 *****************************

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: 0

Outside diff range and nitpick comments (1)
app/client/cypress/e2e/Regression/ClientSide/BugTests/ListWidgetOnPageLoad_Spec.ts (1)

1-55: Great test case! Here are a few suggestions to make it even better:

  1. Use the actual data source name instead of relying on the @dsName alias, which is not defined in this file. This will make the test case more self-contained and easier to understand.

  2. Use cy.reload() instead of agHelper.CypressReload() for reloading the page. cy.reload() is a standard Cypress command and is more idiomatic.

  3. Consider moving the data source creation and query configuration to a before hook. This way, it will be executed only once for all test cases in this file, making the tests faster and more efficient.

For example:

before(() => {
  agHelper.AddDsl("Listv2/simpleList");
  dataSources.CreateDataSource("Postgres");
  dataSources.CreateQueryAfterDSSaved(
    "SELECT id,name FROM public.users LIMIT 10;",
  );
  dataSources.ToggleUsePreparedStatement(false);
  dataSources.RunQuery();
});

it("1. List widget gets populated on page load. Bug: 29566", function () {
  // Rest of the test case...
  cy.reload();
  // ...
});

Other than that, the test case follows many of the best practices for Cypress tests, such as using locator variables, data-* attributes for selectors, performing multiple assertions, and avoiding duplication and unnecessary delays. Well done!

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2c369f4 and 69873bf.

Files selected for processing (1)
  • app/client/cypress/e2e/Regression/ClientSide/BugTests/ListWidgetOnPageLoad_Spec.ts (1 hunks)
Additional context used
Path-based instructions (1)
app/client/cypress/e2e/Regression/ClientSide/BugTests/ListWidgetOnPageLoad_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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working ok-to-test Required label for CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants