adobe / react-spectrum

A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
https://react-spectrum.adobe.com
Apache License 2.0
13.1k stars 1.14k forks source link

DatePicker.test throws error after deleting a defaultValue in DT/ST when current timeZone is ST/DT #7399

Closed majornista closed 1 week ago

majornista commented 1 week ago

Provide a general summary of the issue here

The following test fails when the defaultValue timeZone's daylight savings/standard time does not match the current timeZone's standard/daylight savings time.

https://github.com/adobe/react-spectrum/blob/f33288c867e305341b63b4ec88e55bc566ae115e/packages/%40react-spectrum/datepicker/test/DatePicker.test.js#L1897-L1932

πŸ€” Expected Behavior?

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.

😯 Current Behavior

The test is written to always expect "PDT" Pacific Daylight Savings Time, which means it will fail when we're on standard time.

https://github.com/adobe/react-spectrum/blob/f33288c867e305341b63b4ec88e55bc566ae115e/packages/%40react-spectrum/datepicker/test/DatePicker.test.js#L1931

πŸ’ Possible Solution

Use the timeZoneName for the current date time.

      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}`);

πŸ”¦ Context

No response

πŸ–₯️ Steps to Reproduce

Run yarn test packages/@react-spectrum/datepicker/test/DatePicker.test.js from the first Sunday in November to the second Sunday in March.

Version

@react-spectrum/datepicker@3.10.3

What browsers are you seeing the problem on?

Firefox, Chrome, Safari, Microsoft Edge

If other, please specify.

No response

What operating system are you using?

MacOS

🧒 Your Company/Team

Adobe/Accessibility

πŸ•· Tracking Issue

No response