Skip to content

Commit

Permalink
fix(#7399): DatePicker.test fails with daylight savings change (#7401)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
majornista authored Nov 20, 2024
1 parent 52bf91b commit 9170093
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/@react-spectrum/datepicker/test/DatePicker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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}');
Expand Down Expand Up @@ -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 () {
Expand Down

1 comment on commit 9170093

@rspbot
Copy link

@rspbot rspbot commented on 9170093 Nov 20, 2024

Choose a reason for hiding this comment

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

Please sign in to comment.