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

feat: Enhance date validation logic and add tests for timePrecision in DatePickerWidget2 #37218

Merged
merged 7 commits into from
Nov 7, 2024

Conversation

rahulbarwal
Copy link
Contributor

@rahulbarwal rahulbarwal commented Nov 5, 2024

Description

Problem

The DatePickerWidget2 component had incomplete date validation logic, allowing incorrect dates to be selected, and lacked comprehensive testing for time precision.

Root cause

The date validation logic did not accurately account for time precision, and the testing was limited, making it difficult to ensure the component's correctness.

Solution

This PR enhances the date validation logic in DatePickerWidget2 to provide better granularity checks based on the timePrecision property, and adds comprehensive tests to ensure correct date handling across boundaries for different timePrecision settings. This PR handles...

  • Enhanced date validation logic to accurately account for time precision.
  • Comprehensive testing to ensure correct date handling for all possible input combinations.

Fixes #37083
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.Datepicker"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11702221741
Commit: 306373a
Cypress dashboard.
Tags: @tag.Datepicker
Spec:


Wed, 06 Nov 2024 11:32:28 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced date validation logic in the DatePickerWidget2 for improved accuracy based on time precision.
  • Tests

    • Introduced comprehensive test cases for the isValidDate function, covering various scenarios related to time precision, ensuring robust validation against defined date ranges.

Copy link
Contributor

coderabbitai bot commented Nov 5, 2024

Walkthrough

The changes in this pull request primarily involve the isValidDate function within the DatePickerWidget2. The validation logic has been restructured to utilize a switch statement based on the timePrecision property, allowing for more precise date validation. Additionally, new test cases have been added to cover various scenarios related to the timePrecision values, ensuring comprehensive testing of the date validation logic.

Changes

File Path Change Summary
app/client/src/widgets/DatePickerWidget2/widget/derived.js Modified the isValidDate function to enhance date validation logic based on timePrecision.
app/client/src/widgets/DatePickerWidget2/widget/derived.test.js Added new test cases for isValidDate to validate behavior across different timePrecision values.

Assessment against linked issues

Objective Addressed Explanation
The form should be valid and the Submit button enabled when today's date is selected (37083)

Possibly related PRs

Suggested labels

JSON Form, Test

Suggested reviewers

  • ApekshaBhosale
  • sagar-qa007

🎉 In the DatePicker's realm, changes unfold,
With logic refined, and precision bold.
Each date now dances, with tests all around,
Validations enhanced, new checks abound!
So let’s pick a date, with joy and with cheer,
For the form is now ready, the submit button near! 🌟


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 Bug Something isn't working Community Reported issues reported by community members Date Picker Widget High This issue blocks a user from building or impacts a lot of users Needs Triaging Needs attention from maintainers to triage Production Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets labels Nov 5, 2024
@rahulbarwal rahulbarwal self-assigned this Nov 5, 2024
@github-actions github-actions bot added Enhancement New feature or request and removed Bug Something isn't working labels Nov 5, 2024
@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

@rahulbarwal rahulbarwal added the ok-to-test Required label for CI label Nov 5, 2024
@github-actions github-actions bot added the Bug Something isn't working label Nov 5, 2024
Copy link

github-actions bot commented Nov 5, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11679324581.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 37218.
recreate: .

@github-actions github-actions bot removed the Bug Something isn't working label Nov 5, 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: 3

🧹 Outside diff range and nitpick comments (1)
app/client/src/widgets/DatePickerWidget2/widget/derived.test.js (1)

105-118: Consider adding boundary test cases for minute precision.

While the current test verifies that seconds don't affect validation, consider adding edge cases where the minute is exactly at the boundary.

+ it("should pass when selectedDate minute exactly matches maxDate", () => {
+   const { isValidDate } = derivedProperty;
+   const input = {
+     isRequired: true,
+     maxDate: "2021-12-01T05:49:00.000Z",
+     minDate: "2021-12-01T05:48:00.000Z",
+     selectedDate: "2021-12-01T05:49:00.000Z",
+     timePrecision: "minute",
+   };
+   expect(isValidDate(input, moment, _)).toStrictEqual(true);
+ });
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6660bd9 and 3e590f4.

📒 Files selected for processing (2)
  • app/client/src/widgets/DatePickerWidget2/widget/derived.js (1 hunks)
  • app/client/src/widgets/DatePickerWidget2/widget/derived.test.js (1 hunks)
🔇 Additional comments (2)
app/client/src/widgets/DatePickerWidget2/widget/derived.test.js (2)

89-103: LGTM! Good test coverage for minute precision.

The test effectively validates that dates with incorrect minute values are rejected.


150-207: LGTM! Comprehensive test coverage for 'None' precision.

The test suite thoroughly covers all scenarios for date validation without time precision:

  • Exact matches with min/max dates
  • Valid dates within range
  • Invalid dates outside range

Copy link

github-actions bot commented Nov 5, 2024

Deploy-Preview-URL: https://ce-37218.dp.appsmith.com

…dability and early returns on optional selections
@github-actions github-actions bot added the Bug Something isn't working label Nov 5, 2024
…emoving unused vars and consolidating comparison settings
@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

github-actions bot commented Nov 5, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11681629187.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 37218.
recreate: .

@github-actions github-actions bot removed the Bug Something isn't working label Nov 5, 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: 3

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3e590f4 and 6da8ec5.

📒 Files selected for processing (1)
  • app/client/src/widgets/DatePickerWidget2/widget/derived.js (1 hunks)
🔇 Additional comments (1)
app/client/src/widgets/DatePickerWidget2/widget/derived.js (1)

2-18: LGTM! Clean implementation of early returns

The early validation checks and function signature cleanup improve code clarity.

Copy link

github-actions bot commented Nov 5, 2024

Deploy-Preview-URL: https://ce-37218.dp.appsmith.com

jsartisan
jsartisan previously approved these changes Nov 5, 2024
@github-actions github-actions bot added the Bug Something isn't working label Nov 6, 2024
@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

github-actions bot commented Nov 6, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11702159642.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 37218.
recreate: .

…g unnecessary timePrecision checks for min/max dates
@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

github-actions bot commented Nov 6, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11702215554.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 37218.
recreate: .

@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

github-actions bot commented Nov 6, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11702241917.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 37218.
recreate: .

@github-actions github-actions bot removed the Bug Something isn't working label Nov 6, 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: 1

🧹 Outside diff range and nitpick comments (1)
app/client/src/widgets/DatePickerWidget2/widget/derived.js (1)

18-33: Document default case behavior.

While the default case is handled during initialization as mentioned in past discussions, it would be helpful to add a comment explaining this behavior for future maintainers.

Add a comment above the switch statement:

+    // Note: Default values for granularity and inclusivity are handled during component initialization
     switch (props.timePrecision) {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6da8ec5 and 306373a.

📒 Files selected for processing (1)
  • app/client/src/widgets/DatePickerWidget2/widget/derived.js (1 hunks)
🧰 Additional context used
📓 Learnings (1)
app/client/src/widgets/DatePickerWidget2/widget/derived.js (1)
Learnt from: rahulbarwal
PR: appsmithorg/appsmith#37218
File: app/client/src/widgets/DatePickerWidget2/widget/derived.js:20-34
Timestamp: 2024-11-05T11:23:44.713Z
Learning: In the `DatePickerWidget2`'s `isValidDate` function, the default case for `timePrecision` is handled during initialization, so no additional default case is necessary in the switch statement.
🔇 Additional comments (3)
app/client/src/widgets/DatePickerWidget2/widget/derived.js (3)

4-5: LGTM! Good use of early return pattern.

The early validation check simplifies the control flow and improves readability.


14-16: LGTM! Proper handling of required field validation.

The logic correctly handles the case when no date is selected based on the isRequired flag.


35-45: LGTM! Proper date range validation with inclusive comparisons.

The use of isSameOrAfter and isSameOrBefore correctly addresses the validation issues mentioned in #37083, ensuring consistent behavior when selecting today's date.

Copy link

github-actions bot commented Nov 6, 2024

Deploy-Preview-URL: https://ce-37218.dp.appsmith.com

@rahulbarwal rahulbarwal merged commit 0c406b0 into release Nov 7, 2024
45 checks passed
@rahulbarwal rahulbarwal deleted the rahulbarwal/issue37083 branch November 7, 2024 05:55
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Nov 20, 2024
…n DatePickerWidget2 (appsmithorg#37218)

## Description
<ins>Problem</ins>

The DatePickerWidget2 component had incomplete date validation logic,
allowing incorrect dates to be selected, and lacked comprehensive
testing for time precision.

<ins>Root cause</ins>

The date validation logic did not accurately account for time precision,
and the testing was limited, making it difficult to ensure the
component's correctness.

<ins>Solution</ins>

This PR enhances the date validation logic in DatePickerWidget2 to
provide better granularity checks based on the timePrecision property,
and adds comprehensive tests to ensure correct date handling across
boundaries for different timePrecision settings. This PR handles...

- Enhanced date validation logic to accurately account for time
precision.
- Comprehensive testing to ensure correct date handling for all possible
input combinations.

Fixes appsmithorg#37083
_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.Datepicker"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11702221741>
> Commit: 306373a
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11702221741&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Datepicker`
> Spec:
> <hr>Wed, 06 Nov 2024 11:32:28 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Enhanced date validation logic in the DatePickerWidget2 for improved
accuracy based on time precision.

- **Tests**
- Introduced comprehensive test cases for the `isValidDate` function,
covering various scenarios related to time precision, ensuring robust
validation against defined date ranges.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Reported issues reported by community members Date Picker Widget Enhancement New feature or request High This issue blocks a user from building or impacts a lot of users Needs Triaging Needs attention from maintainers to triage ok-to-test Required label for CI Production Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: DatePicker widget validation invalid within a Form when Min date is today and current day selected
2 participants