Skip to content

Commit

Permalink
fix failing time-specific test
Browse files Browse the repository at this point in the history
  • Loading branch information
suddjian committed Mar 14, 2022
1 parent bb14f86 commit 3eeb8ab
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import { render, screen, waitFor } from 'spec/helpers/testing-library';
import userEvent from '@testing-library/user-event';
import TimezoneSelector from './index';

jest.useFakeTimers('modern');
jest.setSystemTime(new Date('2022-01-01'));

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

const getSelectOptions = () =>
Expand Down Expand Up @@ -69,15 +72,10 @@ it('can select a timezone values and returns canonical value', async () => {
});
expect(searchInput).toBeInTheDocument();
userEvent.click(searchInput);
const isDaylight = moment(moment.now()).isDST();

const selectedTimezone = isDaylight
? 'GMT -04:00 (Eastern Daylight Time)'
: 'GMT -05:00 (Eastern Standard Time)';

// selected option ranks first
const options = await getSelectOptions();
expect(options[0]).toHaveTextContent(selectedTimezone);
expect(options[0]).toHaveTextContent('GMT -05:00 (Eastern Standard Time)');

// others are ranked by offset
expect(options[1]).toHaveTextContent('GMT -11:00 (Pacific/Pago_Pago)');
Expand All @@ -87,10 +85,9 @@ it('can select a timezone values and returns canonical value', async () => {
// search for mountain time
await userEvent.type(searchInput, 'mou', { delay: 10 });

const findTitle = isDaylight
? 'GMT -06:00 (Mountain Daylight Time)'
: 'GMT -07:00 (Mountain Standard Time)';
const selectOption = await screen.findByTitle(findTitle);
const selectOption = await screen.findByTitle(
'GMT -07:00 (Mountain Standard Time)',
);
expect(selectOption).toBeInTheDocument();
userEvent.click(selectOption);
expect(onTimezoneChange).toHaveBeenCalledTimes(1);
Expand Down

0 comments on commit 3eeb8ab

Please sign in to comment.