Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje committed Aug 1, 2024
1 parent 02d96b1 commit 59c8519
Show file tree
Hide file tree
Showing 8 changed files with 4,410 additions and 58,741 deletions.
63,065 changes: 4,357 additions & 58,708 deletions superset-frontend/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion superset-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
"@svgr/webpack": "^8.1.0",
"@testing-library/dom": "^7.29.4",
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/react": "^11.2.0",
"@testing-library/react": "^12.1.5",
"@testing-library/react-hooks": "^5.1.3",
"@testing-library/user-event": "^12.7.0",
"@types/classnames": "^2.2.10",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@superset-ui/core": "*",
"@testing-library/dom": "^7.29.4",
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/react": "^11.2.0",
"@testing-library/react": "^12.1.5",
"@testing-library/react-hooks": "^5.0.3",
"@testing-library/user-event": "^12.7.0",
"ace-builds": "^1.4.14",
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/packages/superset-ui-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"@emotion/styled": "^11.3.0",
"@testing-library/dom": "^7.29.4",
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/react": "^11.2.0",
"@testing-library/react": "^12.1.5",
"@testing-library/user-event": "^12.7.0",
"@types/react": "*",
"@types/react-loadable": "*",
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/plugins/plugin-chart-table/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@superset-ui/core": "*",
"@testing-library/dom": "^7.29.4",
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/react": "^11.2.0",
"@testing-library/react": "^12.1.5",
"@testing-library/react-hooks": "^5.0.3",
"@testing-library/user-event": "^12.7.0",
"@types/classnames": "*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
FrameComponentProps,
} from 'src/explore/components/controls/DateFilterControl/types';
import { ExplorePageState } from 'src/explore/types';
import Loading from 'src/components/Loading';

export function CustomFrame(props: FrameComponentProps) {
const { customRange, matchedFlag } = customTimeRangeDecode(props.value);
Expand Down Expand Up @@ -134,7 +135,7 @@ export function CustomFrame(props: FrameComponentProps) {
}, [datePickerLocale, localFromFlaskBabel]);

if (datePickerLocale === null) {
return null;
return <Loading position="inline-centered" />;
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
import thunk from 'redux-thunk';
import { Provider } from 'react-redux';
import configureStore from 'redux-mock-store';
import { render, screen } from 'spec/helpers/testing-library';
import {
render,
screen,
waitForElementToBeRemoved,
waitFor,
} from 'spec/helpers/testing-library';
import userEvent from '@testing-library/user-event';
import { CustomFrame } from '../components';

Expand All @@ -44,12 +49,14 @@ const emptyStore = mockStore({});
// case when common.locale is populated with invalid locale
const invalidStore = mockStore({ common: { locale: 'invalid_locale' } });

test('renders with default props', () => {
test('renders with default props', async () => {
render(
<Provider store={store}>
<CustomFrame onChange={jest.fn()} value={emptyValue} />
</Provider>,
);
expect(screen.getByLabelText('Loading')).toBeVisible();
await waitForElementToBeRemoved(() => screen.queryByLabelText('Loading'));
expect(screen.getByText('Configure custom time range')).toBeInTheDocument();
expect(screen.getByText('Relative Date/Time')).toBeInTheDocument();
expect(screen.getByRole('spinbutton')).toBeInTheDocument();
Expand Down Expand Up @@ -106,88 +113,96 @@ test('renders since and until with specific date/time with invalid locale', () =
expect(screen.getAllByRole('img', { name: 'calendar' }).length).toBe(2);
});

test('renders since and until with specific date/time', () => {
test('renders since and until with specific date/time', async () => {
render(
<Provider store={store}>
<CustomFrame onChange={jest.fn()} value={specificValue} />
</Provider>,
);
await waitForElementToBeRemoved(() => screen.queryByLabelText('Loading'));
expect(screen.getAllByText('Specific Date/Time').length).toBe(2);
expect(screen.getAllByRole('img', { name: 'calendar' }).length).toBe(2);
});

test('renders since and until with relative date/time', () => {
test('renders since and until with relative date/time', async () => {
render(
<Provider store={store}>
<CustomFrame onChange={jest.fn()} value={relativeNowValue} />
</Provider>,
);
await waitForElementToBeRemoved(() => screen.queryByLabelText('Loading'));
expect(screen.getAllByText('Relative Date/Time').length).toBe(2);
expect(screen.getAllByRole('spinbutton').length).toBe(2);
expect(screen.getByText('Days Before')).toBeInTheDocument();
expect(screen.getByText('Days After')).toBeInTheDocument();
});

test('renders since and until with Now option', () => {
test('renders since and until with Now option', async () => {
render(
<Provider store={store}>
<CustomFrame onChange={jest.fn()} value={nowValue} />
</Provider>,
);
await waitForElementToBeRemoved(() => screen.queryByLabelText('Loading'));
expect(screen.getAllByText('Now').length).toBe(2);
});

test('renders since and until with Midnight option', () => {
test('renders since and until with Midnight option', async () => {
render(
<Provider store={store}>
<CustomFrame onChange={jest.fn()} value={todayValue} />
</Provider>,
);
await waitForElementToBeRemoved(() => screen.queryByLabelText('Loading'));
expect(screen.getAllByText('Midnight').length).toBe(2);
});

test('renders anchor with now option', () => {
test('renders anchor with now option', async () => {
render(
<Provider store={store}>
<CustomFrame onChange={jest.fn()} value={relativeNowValue} />
</Provider>,
);
await waitForElementToBeRemoved(() => screen.queryByLabelText('Loading'));
expect(screen.getByText('Anchor to')).toBeInTheDocument();
expect(screen.getByRole('radio', { name: 'NOW' })).toBeInTheDocument();
expect(screen.getByRole('radio', { name: 'Date/Time' })).toBeInTheDocument();
expect(screen.queryByPlaceholderText('Select date')).not.toBeInTheDocument();
});

test('renders anchor with date/time option', () => {
test('renders anchor with date/time option', async () => {
render(
<Provider store={store}>
<CustomFrame onChange={jest.fn()} value={relativeTodayValue} />
</Provider>,
);
await waitForElementToBeRemoved(() => screen.queryByLabelText('Loading'));
expect(screen.getByText('Anchor to')).toBeInTheDocument();
expect(screen.getByRole('radio', { name: 'NOW' })).toBeInTheDocument();
expect(screen.getByRole('radio', { name: 'Date/Time' })).toBeInTheDocument();
expect(screen.getByPlaceholderText('Select date')).toBeInTheDocument();
});

test('triggers onChange when the anchor changes', () => {
test('triggers onChange when the anchor changes', async () => {
const onChange = jest.fn();
render(
<Provider store={store}>
<CustomFrame onChange={onChange} value={relativeNowValue} />
</Provider>,
);
await waitForElementToBeRemoved(() => screen.queryByLabelText('Loading'));
userEvent.click(screen.getByRole('radio', { name: 'Date/Time' }));
expect(onChange).toHaveBeenCalled();
});

test('triggers onChange when the value changes', () => {
test('triggers onChange when the value changes', async () => {
const onChange = jest.fn();
render(
<Provider store={store}>
<CustomFrame onChange={onChange} value={emptyValue} />
</Provider>,
);
await waitForElementToBeRemoved(() => screen.queryByLabelText('Loading'));
userEvent.click(screen.getByRole('img', { name: 'up' }));
expect(onChange).toHaveBeenCalled();
});
Expand All @@ -199,6 +214,7 @@ test('triggers onChange when the mode changes', async () => {
<CustomFrame onChange={onChange} value={todayNowValue} />
</Provider>,
);
await waitForElementToBeRemoved(() => screen.queryByLabelText('Loading'));
userEvent.click(screen.getByTitle('Midnight'));
expect(await screen.findByTitle('Relative Date/Time')).toBeInTheDocument();
userEvent.click(screen.getByTitle('Relative Date/Time'));
Expand All @@ -207,7 +223,7 @@ test('triggers onChange when the mode changes', async () => {
await screen.findByText('Configure custom time range'),
).toBeInTheDocument();
userEvent.click(screen.getAllByTitle('Specific Date/Time')[1]);
expect(onChange).toHaveBeenCalledTimes(2);
await waitFor(() => expect(onChange).toHaveBeenCalledTimes(2));
});

test('triggers onChange when the grain changes', async () => {
Expand All @@ -217,13 +233,14 @@ test('triggers onChange when the grain changes', async () => {
<CustomFrame onChange={onChange} value={relativeNowValue} />
</Provider>,
);
await waitForElementToBeRemoved(() => screen.queryByLabelText('Loading'));
userEvent.click(screen.getByText('Days Before'));
expect(await screen.findByText('Weeks Before')).toBeInTheDocument();
userEvent.click(screen.getByText('Weeks Before'));
userEvent.click(screen.getByText('Days After'));
expect(await screen.findByText('Weeks After')).toBeInTheDocument();
userEvent.click(screen.getByText('Weeks After'));
expect(onChange).toHaveBeenCalledTimes(2);
await waitFor(() => expect(onChange).toHaveBeenCalledTimes(2));
});

test('triggers onChange when the date changes', async () => {
Expand All @@ -233,6 +250,7 @@ test('triggers onChange when the date changes', async () => {
<CustomFrame onChange={onChange} value={specificValue} />
</Provider>,
);
await waitForElementToBeRemoved(() => screen.queryByLabelText('Loading'));
const inputs = screen.getAllByPlaceholderText('Select date');
userEvent.click(inputs[0]);
userEvent.click(screen.getAllByText('Now')[0]);
Expand All @@ -241,7 +259,7 @@ test('triggers onChange when the date changes', async () => {
expect(onChange).toHaveBeenCalledTimes(2);
});

test('should translate Date Picker', () => {
test('should translate Date Picker', async () => {
const onChange = jest.fn();
const store = mockStore({
common: { locale: 'fr' },
Expand All @@ -251,6 +269,7 @@ test('should translate Date Picker', () => {
<CustomFrame onChange={onChange} value={specificValue} />
</Provider>,
);
await waitForElementToBeRemoved(() => screen.queryByLabelText('Loading'));
userEvent.click(screen.getAllByRole('img', { name: 'calendar' })[0]);
expect(screen.getByText('2021')).toBeInTheDocument();
expect(screen.getByText('lu')).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,21 @@ export const SEVEN_DAYS_AGO = moment()
export const MIDNIGHT = moment().utc().startOf('day').format(MOMENT_FORMAT);

export const LOCALE_MAPPING = {
en: () => import('antd/es/date-picker/locale/en_US'),
fr: () => import('antd/es/date-picker/locale/fr_FR'),
es: () => import('antd/es/date-picker/locale/es_ES'),
it: () => import('antd/es/date-picker/locale/it_IT'),
zh: () => import('antd/es/date-picker/locale/zh_CN'),
ja: () => import('antd/es/date-picker/locale/ja_JP'),
de: () => import('antd/es/date-picker/locale/de_DE'),
pt: () => import('antd/es/date-picker/locale/pt_PT'),
pt_BR: () => import('antd/es/date-picker/locale/pt_BR'),
ru: () => import('antd/es/date-picker/locale/ru_RU'),
ko: () => import('antd/es/date-picker/locale/ko_KR'),
sk: () => import('antd/es/date-picker/locale/sk_SK'),
sl: () => import('antd/es/date-picker/locale/sl_SI'),
nl: () => import('antd/es/date-picker/locale/nl_NL'),
pl: () => import('antd/es/date-picker/locale/pl_PL'),
en: () => import('antd/lib/date-picker/locale/en_US'),
fr: () => import('antd/lib/date-picker/locale/fr_FR'),
es: () => import('antd/lib/date-picker/locale/es_ES'),
it: () => import('antd/lib/date-picker/locale/it_IT'),
zh: () => import('antd/lib/date-picker/locale/zh_CN'),
ja: () => import('antd/lib/date-picker/locale/ja_JP'),
de: () => import('antd/lib/date-picker/locale/de_DE'),
pt: () => import('antd/lib/date-picker/locale/pt_PT'),
pt_BR: () => import('antd/lib/date-picker/locale/pt_BR'),
ru: () => import('antd/lib/date-picker/locale/ru_RU'),
ko: () => import('antd/lib/date-picker/locale/ko_KR'),
sk: () => import('antd/lib/date-picker/locale/sk_SK'),
sl: () => import('antd/lib/date-picker/locale/sl_SI'),
nl: () => import('antd/lib/date-picker/locale/nl_NL'),
pl: () => import('antd/lib/date-picker/locale/pl_PL'),
};

export enum DateFilterTestKey {
Expand Down

0 comments on commit 59c8519

Please sign in to comment.