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

test: fix datepicker tests #37042

Open
wants to merge 3 commits into
base: release
Choose a base branch
from
Open

Conversation

NandanAnantharamu
Copy link
Collaborator

@NandanAnantharamu NandanAnantharamu commented Oct 23, 2024

Summary by CodeRabbit

  • New Features

    • Reactivated the "DatePicker-Date Name validation" test case for improved date validation.
    • Added new Cypress commands for enhanced user interactions and UI validations.
  • Bug Fixes

    • Simplified the setDate command for better date handling.
  • Chores

    • Updated the list of limited tests to include new Datepicker tests.

Warning

Tests have not run on the HEAD 1e8d7ed yet


Wed, 23 Oct 2024 14:26:45 UTC

Copy link
Contributor

coderabbitai bot commented Oct 23, 2024

Walkthrough

The changes in this pull request involve modifications to the Cypress end-to-end testing framework for the DatePicker widget. The main updates include reactivating a previously skipped test case, simplifying the setDate command method, and updating the list of limited tests to include new DatePicker tests. The setDate command now only requires a single parameter, and additional Cypress commands have been introduced or modified to enhance user interactions and validations.

Changes

File Path Change Summary
app/client/cypress/e2e/Regression/ClientSide/Widgets/Datepicker/DatePicker2_spec.js Reactivated the "DatePicker-Date Name validation" test case and simplified the cy.setDate method.
app/client/cypress/limited-tests.txt Removed Fork_Template_spec.js and added DatePicker2_spec.js for limited tests.
app/client/cypress/support/commands.js Updated setDate command to accept only one parameter and added/modified several other commands.

Possibly related PRs

Suggested labels

Bug, ok-to-test, Widgets Product, Table Widget V2, Community Reported

Suggested reviewers

  • ApekshaBhosale
  • sagar-qa007

🎉 In the land of code where tests reside,
The DatePicker's journey takes a joyful ride.
With a click and a change, the dates now align,
Reactivated tests, all working just fine!
So here's to the tweaks, both big and small,
In the world of Cypress, we celebrate all! 🎊


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 457ab98 and 1e8d7ed.

📒 Files selected for processing (1)
  • app/client/cypress/limited-tests.txt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/client/cypress/limited-tests.txt

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 skip-changelog Adding this label to a PR prevents it from being listed in the changelog Test labels Oct 23, 2024
@NandanAnantharamu
Copy link
Collaborator Author

/ci-test-limit

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

🧹 Outside diff range and nitpick comments (3)
app/client/cypress/e2e/Regression/ClientSide/Widgets/Datepicker/DatePicker2_spec.js (3)

Line range hint 22-46: Enhance test reliability with better assertions and selectors.

The reactivated test case needs improvements:

  1. The selector formWidgetsPage.datepickerWidget + " .bp3-input" should use data-* attributes instead
  2. Add multiple assertions to validate both the date value and format

Consider refactoring like this:

- cy.get(formWidgetsPage.datepickerWidget + " .bp3-input").should(
-   "contain.value",
-   nextDay,
- );
+ cy.get('[data-testid="datepicker-input"]').should(($input) => {
+   expect($input.val()).to.equal(nextDay);
+   expect(dayjs($input.val(), "DD/MM/YYYY").isValid()).to.be.true;
+ });

Line range hint 169-171: Remove afterEach block as per coding guidelines.

The coding guidelines specifically mention avoiding afterEach blocks in test cases.

Consider moving the navigation logic into individual test cases or use a different approach for test cleanup.


Line range hint 1-171: Consider implementing skipped test cases.

There are several commented-out test cases that appear to test important functionality:

  • Min/max date validation
  • Default date validation
  • Required field validation

These tests would provide better coverage for the DatePicker widget.

Would you like me to help implement these test cases following the current best practices?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9999c63 and 457ab98.

📒 Files selected for processing (3)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/Datepicker/DatePicker2_spec.js (2 hunks)
  • app/client/cypress/limited-tests.txt (1 hunks)
  • app/client/cypress/support/commands.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
app/client/cypress/e2e/Regression/ClientSide/Widgets/Datepicker/DatePicker2_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/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/support/commands.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.
🔇 Additional comments (1)
app/client/cypress/limited-tests.txt (1)

2-4: LGTM! Verify test paths exist.

The DatePicker test specifications have been correctly added to the limited tests configuration.

Let's verify these test files exist:

✅ Verification successful

Based on the script results, I can generate the final response since all test files were successfully found in the repository.

All DatePicker test paths verified ✓

All three test specifications added to the limited tests configuration exist in the correct locations within the repository.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the specified test files
# Expected: All files should exist in the repository

for test_path in \
    "cypress/e2e/Regression/ClientSide/Widgets/Datepicker/DatePicker2_spec.js" \
    "cypress/e2e/Regression/ClientSide/Binding/DatePicker_Text_spec.js" \
    "cypress/e2e/Regression/ClientSide/Widgets/Datepicker/DatePicker_With_Switch_spec.js"
do
    if ! fd -p "$test_path" app/client; then
        echo "Warning: Test file not found: $test_path"
    fi
done

Length of output: 1279

*/
cy.setDate(1, "ddd MMM DD YYYY");
cy.setDate(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Update required: setDate command usage is inconsistent with implementation

The current implementation of setDate only accepts a single parameter for days offset, but there are multiple occurrences in the codebase where it's called with two parameters. This needs to be fixed:

  • DatePicker_With_Switch_spec.js: Uses setDate(1, "ddd MMM DD YYYY")
  • DatePicker_Text_spec.js: Two instances using setDate(1, "ddd MMM DD YYYY")

These calls need to be updated to match the current implementation which only accepts the days offset parameter.

🔗 Analysis chain

Verify the impact of simplified setDate command.

The setDate command has been simplified to use a single parameter. Ensure this change is consistent with the command implementation.


Let me check the implementation of the setDate command to verify if the simplified usage is correct.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all usages of setDate command to verify consistency
rg "cy\.setDate\(" --type js

Length of output: 889


Script:

#!/bin/bash
# Search for the implementation of setDate command
rg -A 10 "Cypress\.Commands\.add\(['\"]setDate" --type js

Length of output: 941

Comment on lines +527 to +529
Cypress.Commands.add("setDate", (date) => {
const expDate = dayjs().add(date, "days").format("dddd, MMMM DD");
cy.get(`.react-datepicker__day[aria-label^="Choose ${expDate}"]`).click();
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 making the date format configurable.

The hardcoded date format "dddd, MMMM DD" reduces flexibility. Consider keeping the format parameter to support different date formats across tests.

-Cypress.Commands.add("setDate", (date) => {
+Cypress.Commands.add("setDate", (date, dateFormat = "dddd, MMMM DD") => {
   const expDate = dayjs()
     .add(date, "days")
-    .format("dddd, MMMM DD");
+    .format(dateFormat);
   cy.get(`.react-datepicker__day[aria-label^="Choose ${expDate}"]`).click();
});
📝 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
Cypress.Commands.add("setDate", (date) => {
const expDate = dayjs().add(date, "days").format("dddd, MMMM DD");
cy.get(`.react-datepicker__day[aria-label^="Choose ${expDate}"]`).click();
Cypress.Commands.add("setDate", (date, dateFormat = "dddd, MMMM DD") => {
const expDate = dayjs().add(date, "days").format(dateFormat);
cy.get(`.react-datepicker__day[aria-label^="Choose ${expDate}"]`).click();

@NandanAnantharamu
Copy link
Collaborator Author

/ci-test-limit-count run_count=25

Copy link

Copy link

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

Copy link

Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11482044903.
Cypress dashboard: Click here!
The following are new failures, please fix them before merging the PR:
To know the list of identified flaky tests - Refer here

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip-changelog Adding this label to a PR prevents it from being listed in the changelog Test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant