Skip to content

Commit

Permalink
fix(TimezoneSelector): Failing unit tests due to timezone change (#30828
Browse files Browse the repository at this point in the history
)

(cherry picked from commit 5820d31)
  • Loading branch information
geido authored and michael-s-molina committed Nov 19, 2024
1 parent b1c7b81 commit 938b1fd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ const loadComponent = (mockCurrentTime?: string) => {
return new Promise<FC<TimezoneSelectorProps>>(resolve => {
const { default: TimezoneSelector } = module.require('./index');
resolve(TimezoneSelector);
jest.useRealTimers();
});
};

afterEach(() => {
jest.useRealTimers();
});

test('render timezones in correct order for daylight saving time', async () => {
const TimezoneSelector = await loadComponent('2022-07-01');
const onTimezoneChange = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const loadComponent = (mockCurrentTime?: string) => {
return new Promise<FC<TimezoneSelectorProps>>(resolve => {
const { default: TimezoneSelector } = module.require('./index');
resolve(TimezoneSelector);
jest.useRealTimers();
});
};

Expand All @@ -44,6 +43,10 @@ const openSelectMenu = () => {

jest.spyOn(moment.tz, 'guess').mockReturnValue('America/New_York');

afterEach(() => {
jest.useRealTimers();
});

test('use the timezone from `moment` if no timezone provided', async () => {
const TimezoneSelector = await loadComponent('2022-01-01');
const onTimezoneChange = jest.fn();
Expand Down Expand Up @@ -89,7 +92,6 @@ test('render timezones in correct oder for standard time', async () => {
expect(options[0]).toHaveTextContent('GMT -05:00 (Eastern Standard Time)');
expect(options[1]).toHaveTextContent('GMT -11:00 (Pacific/Pago_Pago)');
expect(options[2]).toHaveTextContent('GMT -10:00 (Hawaii Standard Time)');
expect(options[3]).toHaveTextContent('GMT -10:00 (America/Adak)');
});

test('can select a timezone values and returns canonical timezone name', async () => {
Expand All @@ -106,7 +108,7 @@ test('can select a timezone values and returns canonical timezone name', async (

const searchInput = screen.getByRole('combobox');
// search for mountain time
await userEvent.type(searchInput, 'mou', { delay: 10 });
await userEvent.type(searchInput, 'mou');
const findTitle = 'GMT -07:00 (Mountain Standard Time)';
const selectOption = await screen.findByTitle(findTitle);
userEvent.click(selectOption);
Expand Down

0 comments on commit 938b1fd

Please sign in to comment.