mirror of https://github.com/apache/superset.git
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 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);
|
||||
|
|
Loading…
Reference in New Issue