Skip to content

DateCalendar: add unit tests #103676

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

Merged
merged 10 commits into from
May 27, 2025
Merged

DateCalendar: add unit tests #103676

merged 10 commits into from
May 27, 2025

Conversation

ciampo
Copy link
Contributor

@ciampo ciampo commented May 23, 2025

Requires #103675
Partially addresses DS-111

Proposed Changes

Add unit tests for the DateCalendar component

Why are these changes being made?

  • Assess spec compliance
  • Prevent future regressions, especially as we may update the underlying react-day-picker dependency

Working on the tests flagged the inconsistency about the onSelect callback arguments which is fixes in #103675

I will add DateRangeCalendar unit tests in a follow-up PR

Testing Instructions

  • Review unit tests code
  • Make sure unit tests pass

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
    • For UI changes, have we tested the change in various languages (for example, ES, PT, FR, or DE)? The length of text and words vary significantly between languages.
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

Copy link

github-actions bot commented May 23, 2025

@matticbot
Copy link
Contributor

matticbot commented May 23, 2025

This PR modifies the release build for the following Calypso Apps:

For info about this notification, see here: PCYsg-OT6-p2

  • notifications
  • wpcom-block-editor

To test WordPress.com changes, run install-plugin.sh $pluginSlug feat/calendar-unit-tests on your sandbox.

@matticbot
Copy link
Contributor

This PR does not affect the size of JS and CSS bundles shipped to the user's browser.

Generated by performance advisor bot at iscalypsofastyet.com.

@ciampo ciampo self-assigned this May 23, 2025
@ciampo ciampo marked this pull request as ready for review May 23, 2025 15:36
@ciampo ciampo requested a review from a team as a code owner May 23, 2025 15:36
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label May 23, 2025
@ciampo ciampo requested review from mirka and aduth May 23, 2025 15:36
@@ -1,6 +1,8 @@
const path = require( 'path' );
const base = require( '@automattic/calypso-jest' );

process.env.TZ = 'UTC';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is important to make sure that all jest tests run in the UTC timezone, regardless of the machine's local timezone. I wasn't sure whether this file was the best place for it, though — alternatively, we could move it to @automattic/calypso-jest

Copy link
Member

Choose a reason for hiding this comment

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

This looks like a good place. Note that if we want to apply it to client tests, we'll need to add it to the client jest preset too.

@ciampo ciampo force-pushed the feat/calendar-simplify-types branch from 14bf8d6 to 57c9895 Compare May 26, 2025 13:14
@ciampo ciampo force-pushed the feat/calendar-unit-tests branch from 8ae225b to 2ba1280 Compare May 26, 2025 13:15
@ciampo ciampo force-pushed the feat/calendar-simplify-types branch from 57c9895 to 1c3decc Compare May 26, 2025 15:07
Base automatically changed from feat/calendar-simplify-types to trunk May 26, 2025 15:24
@ciampo ciampo force-pushed the feat/calendar-unit-tests branch from 8d7dd48 to 097ce2e Compare May 26, 2025 15:34
Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

This is looking pretty good IMO 👍 Thanks for adding thorough test coverage.

Just a few questions, nothing blocking. Ideally, we'd get rid of the extra dependency if possible.

// earlier by 1 day (from midnight to 10pm the previous day).
expect( getDateCell( today, { selected: true } ) ).toBeVisible();
} );
} );
Copy link
Member

Choose a reason for hiding this comment

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

I wonder how much edge cases we want to support. Like, should we handle daylight savings time transitions correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At least for now, I would ship an initial suite of tests that covers well the majority of use cases.

There are potentially so many edge cases (especially when it comes to time zones, daylight savings, etc) that it would take a considerable amount of time to cover them all, and I'm not sure the effort is worth it for now.

Additionally, I also assume that the underlying react-day-picker component delagates all these calculations to date-fns, meaning that it should be generally reliable.

Happy to add more tests at a later point in time, if needed.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good to me, thanks for confirming!

@@ -1,6 +1,8 @@
const path = require( 'path' );
const base = require( '@automattic/calypso-jest' );

process.env.TZ = 'UTC';
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a good place. Note that if we want to apply it to client tests, we'll need to add it to the client jest preset too.

@ciampo ciampo force-pushed the feat/calendar-unit-tests branch from 097ce2e to feebbc7 Compare May 27, 2025 12:55
@ciampo ciampo merged commit 5a88ff1 into trunk May 27, 2025
11 checks passed
@ciampo ciampo deleted the feat/calendar-unit-tests branch May 27, 2025 13:55
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label May 27, 2025
@ciampo
Copy link
Contributor Author

ciampo commented May 27, 2025

Part 2 (for DateRangeCalendar) here

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

Successfully merging this pull request may close these issues.

3 participants