Skip to content

chore: Updating tests to the masking to ensure date formats are covered #3530

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

dpitcock
Copy link
Member

@dpitcock dpitcock commented May 21, 2025

Updating tests to the masking utils

This pull request adds more comprehensive tests for the useMask hook in the masked-input component. The new tests cover the following scenarios:

Date Masks

  • Handling of different date formats (slashed, ISO)
  • Validation and auto-completion for day, month, and year segments
  • Handling of separators in date strings

Time Masks

  • Validation and auto-completion different segments
  • Handling of different separators (:, -, /)
  • Handling of partial time inputs

General Improvements

  • Refactored the test setup to use a more parameterized approach, making it easier to add new mask types in the future
  • Added tests to ensure the correct behavior when the maximum value for a segment is reached
  • Improved the handling of invalid input values, ensuring the hook returns a valid value even when the initial input is invalid

These changes ensure that the useMask hook can handle a wider range of date and time formats, and that the masking functionality is thoroughly tested across various use cases.

Related links, issue #, if available: n/a

How has this been tested?

Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link

codecov bot commented May 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.58%. Comparing base (50922ce) to head (073a267).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3530      +/-   ##
==========================================
+ Coverage   96.54%   96.58%   +0.03%     
==========================================
  Files         805      805              
  Lines       23446    23455       +9     
  Branches     8165     7750     -415     
==========================================
+ Hits        22637    22653      +16     
+ Misses        802      795       -7     
  Partials        7        7              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dpitcock dpitcock requested a review from gethinwebster May 22, 2025 08:23
});
});
describe('getValidValue', () => {
mask.segments.forEach((segment, segmentIndex) => {
Copy link
Member Author

@dpitcock dpitcock May 22, 2025

Choose a reason for hiding this comment

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

This is not the easiest code to read, but I couldn't think of a better way that encompasses a test case for each segment. It looks ugly here, but in the test breakdown it all makes sense

Copy link
Member

Choose a reason for hiding this comment

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

I think overall the test logic here is too complex to be valuable and maintainable in the long term: we almost need tests for the tests... Instead I would suggest trying to create some real-world examples and using those, as that will be much easier to understand and maintain over time.

Copy link
Member

Choose a reason for hiding this comment

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

(if I was adding new functionality, I would have no idea where to start within this test logic to add new tests)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the confirmation. Yea we might even need tests for the tests for the tests... I will do more like I've done below.

@dpitcock dpitcock marked this pull request as ready for review May 22, 2025 09:36
@dpitcock dpitcock requested a review from a team as a code owner May 22, 2025 09:36
@just-boris just-boris removed the request for review from a team May 22, 2025 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants