|
1 |
| -import { Intl } from '@js-temporal/polyfill' |
| 1 | +import { Intl, Temporal } from '@js-temporal/polyfill' |
2 | 2 | import { render } from '@testing-library/react'
|
3 | 3 | import { renderHook } from '@testing-library/react-hooks'
|
4 | 4 | import React from 'react'
|
5 | 5 | import { SupportedCalendar } from '../types'
|
| 6 | +import { formatDate } from '../utils' |
6 | 7 | import localisationHelpers from '../utils/localisationHelpers'
|
7 | 8 | import { useDatePicker, UseDatePickerReturn } from './useDatePicker'
|
8 | 9 |
|
@@ -271,13 +272,21 @@ describe('useDatePicker hook', () => {
|
271 | 272 | })
|
272 | 273 | describe('highlighting today', () => {
|
273 | 274 | const getDayByDate: (
|
274 |
| - calendarWeekDays: { calendarDate: string; isToday: boolean }[][], |
| 275 | + calendarWeekDays: { |
| 276 | + isToday: boolean |
| 277 | + zdt: Temporal.ZonedDateTime |
| 278 | + }[][], |
275 | 279 | dayToFind: string
|
276 | 280 | ) => { calendarDate: string; isToday: boolean }[] = (
|
277 | 281 | calendarWeekDays,
|
278 | 282 | dayToFind
|
279 | 283 | ) => {
|
280 |
| - const days = calendarWeekDays.flatMap((week) => week) |
| 284 | + const days = calendarWeekDays |
| 285 | + .flatMap((week) => week) |
| 286 | + .map((day) => ({ |
| 287 | + ...day, |
| 288 | + calendarDate: formatDate(day.zdt, undefined, 'YYYY-MM-DD'), |
| 289 | + })) |
281 | 290 |
|
282 | 291 | return days.filter((day) => day.calendarDate === dayToFind)
|
283 | 292 | }
|
@@ -485,7 +494,12 @@ describe('clicking a day', () => {
|
485 | 494 |
|
486 | 495 | // find and click the day passed to the calendar
|
487 | 496 | for (let i = 0; i < days.length; i++) {
|
488 |
| - if (days[i].calendarDate === date) { |
| 497 | + const formattedDate = formatDate( |
| 498 | + days[i].zdt, |
| 499 | + undefined, |
| 500 | + 'YYYY-MM-DD' |
| 501 | + ) |
| 502 | + if (formattedDate === date) { |
489 | 503 | days[i].onClick()
|
490 | 504 | break
|
491 | 505 | }
|
|
0 commit comments