mirror of
https://github.com/apache/superset.git
synced 2024-09-06 13:57:40 -04:00
fix failing time-specific test
This commit is contained in:
parent
bb14f86664
commit
3eeb8ab9cc
@ -22,6 +22,9 @@ import { render, screen, waitFor } from 'spec/helpers/testing-library';
|
|||||||
import userEvent from '@testing-library/user-event';
|
import userEvent from '@testing-library/user-event';
|
||||||
import TimezoneSelector from './index';
|
import TimezoneSelector from './index';
|
||||||
|
|
||||||
|
jest.useFakeTimers('modern');
|
||||||
|
jest.setSystemTime(new Date('2022-01-01'));
|
||||||
|
|
||||||
jest.spyOn(moment.tz, 'guess').mockReturnValue('America/New_York');
|
jest.spyOn(moment.tz, 'guess').mockReturnValue('America/New_York');
|
||||||
|
|
||||||
const getSelectOptions = () =>
|
const getSelectOptions = () =>
|
||||||
@ -69,15 +72,10 @@ it('can select a timezone values and returns canonical value', async () => {
|
|||||||
});
|
});
|
||||||
expect(searchInput).toBeInTheDocument();
|
expect(searchInput).toBeInTheDocument();
|
||||||
userEvent.click(searchInput);
|
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
|
// selected option ranks first
|
||||||
const options = await getSelectOptions();
|
const options = await getSelectOptions();
|
||||||
expect(options[0]).toHaveTextContent(selectedTimezone);
|
expect(options[0]).toHaveTextContent('GMT -05:00 (Eastern Standard Time)');
|
||||||
|
|
||||||
// others are ranked by offset
|
// others are ranked by offset
|
||||||
expect(options[1]).toHaveTextContent('GMT -11:00 (Pacific/Pago_Pago)');
|
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
|
// search for mountain time
|
||||||
await userEvent.type(searchInput, 'mou', { delay: 10 });
|
await userEvent.type(searchInput, 'mou', { delay: 10 });
|
||||||
|
|
||||||
const findTitle = isDaylight
|
const selectOption = await screen.findByTitle(
|
||||||
? 'GMT -06:00 (Mountain Daylight Time)'
|
'GMT -07:00 (Mountain Standard Time)',
|
||||||
: 'GMT -07:00 (Mountain Standard Time)';
|
);
|
||||||
const selectOption = await screen.findByTitle(findTitle);
|
|
||||||
expect(selectOption).toBeInTheDocument();
|
expect(selectOption).toBeInTheDocument();
|
||||||
userEvent.click(selectOption);
|
userEvent.click(selectOption);
|
||||||
expect(onTimezoneChange).toHaveBeenCalledTimes(1);
|
expect(onTimezoneChange).toHaveBeenCalledTimes(1);
|
||||||
|
Loading…
Reference in New Issue
Block a user