From 3eeb8ab9cc5db155a30d08b81fd697af1fcaf6ea Mon Sep 17 00:00:00 2001 From: David Aaron Suddjian Date: Mon, 14 Mar 2022 16:34:38 -0700 Subject: [PATCH] fix failing time-specific test --- .../TimezoneSelector/TimezoneSelector.test.tsx | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx b/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx index 035cff842c..27f05ce496 100644 --- a/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx +++ b/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx @@ -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 = () => @@ -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)'); @@ -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);