From 71bde5758b174c17ff9ae4875c391a26e421d114 Mon Sep 17 00:00:00 2001 From: Michael Jordan Date: Tue, 19 Nov 2024 17:04:43 -0500 Subject: [PATCH] fix(#7399): DatePicker.test fails with daylight savings change If the defaultValue is on daylight savings time and the user clears the value while in a time zone on standard time, the DatePicker's time zone will change to standard time. I think this is the correct behavior, however, the test is written to always expect "PDT" Pacific Daylight Savings Time, which means it will fail when we're on standard time. --- .../datepicker/test/DatePicker.test.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/@react-spectrum/datepicker/test/DatePicker.test.js b/packages/@react-spectrum/datepicker/test/DatePicker.test.js index 968c7a1eb08..2c4511b8e3f 100644 --- a/packages/@react-spectrum/datepicker/test/DatePicker.test.js +++ b/packages/@react-spectrum/datepicker/test/DatePicker.test.js @@ -12,7 +12,7 @@ import {act, fireEvent, pointerMap, render as render_, waitFor, within} from '@react-spectrum/test-utils-internal'; import {Button} from '@react-spectrum/button'; -import {CalendarDate, CalendarDateTime, EthiopicCalendar, getLocalTimeZone, JapaneseCalendar, parseZonedDateTime, toCalendarDateTime, today} from '@internationalized/date'; +import {CalendarDate, CalendarDateTime, DateFormatter, EthiopicCalendar, getLocalTimeZone, JapaneseCalendar, parseZonedDateTime, toCalendarDateTime, today} from '@internationalized/date'; import {DatePicker} from '../'; import {Form} from '@react-spectrum/form'; import {Provider} from '@react-spectrum/provider'; @@ -584,7 +584,7 @@ describe('DatePicker', function () { let month = parts.find(p => p.type === 'month').value; let day = parts.find(p => p.type === 'day').value; let year = parts.find(p => p.type === 'year').value; - + expectPlaceholder(combobox, `${month}/${day}/${year}, 12:00 AM`); await user.keyboard('{ArrowRight}'); @@ -1928,7 +1928,17 @@ describe('DatePicker', function () { await user.tab(); await user.keyboard('{Backspace}'); - expectPlaceholder(combobox, 'mm/dd/yyyy, ––:–– AM PDT'); + let timeZoneName = + new DateFormatter('en-US', + { + timeZone: 'America/Los_Angeles', + timeZoneName: 'short' + }) + .formatToParts(new Date()) + .find(p => p.type === 'timeZoneName') + .value; + + expectPlaceholder(combobox, `mm/dd/yyyy, ––:–– AM ${timeZoneName}`); }); it('should keep timeZone from defaultValue when date and time are cleared then set', async function () {