mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
This commit is contained in:
parent
e6c44e02cb
commit
2258fbf878
@ -39,6 +39,12 @@ const store = mockStore({
|
|||||||
common: { locale: 'en' },
|
common: { locale: 'en' },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// case when common.locale is not populated
|
||||||
|
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', () => {
|
||||||
render(
|
render(
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
@ -53,6 +59,54 @@ test('renders with default props', () => {
|
|||||||
expect(screen.getByRole('img', { name: 'calendar' })).toBeInTheDocument();
|
expect(screen.getByRole('img', { name: 'calendar' })).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('renders with empty store', () => {
|
||||||
|
render(
|
||||||
|
<Provider store={emptyStore}>
|
||||||
|
<CustomFrame onChange={jest.fn()} value={emptyValue} />
|
||||||
|
</Provider>,
|
||||||
|
);
|
||||||
|
expect(screen.getByText('Configure custom time range')).toBeInTheDocument();
|
||||||
|
expect(screen.getByText('Relative Date/Time')).toBeInTheDocument();
|
||||||
|
expect(screen.getByRole('spinbutton')).toBeInTheDocument();
|
||||||
|
expect(screen.getByText('Days Before')).toBeInTheDocument();
|
||||||
|
expect(screen.getByText('Specific Date/Time')).toBeInTheDocument();
|
||||||
|
expect(screen.getByRole('img', { name: 'calendar' })).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('renders since and until with specific date/time with default locale', () => {
|
||||||
|
render(
|
||||||
|
<Provider store={emptyStore}>
|
||||||
|
<CustomFrame onChange={jest.fn()} value={specificValue} />
|
||||||
|
</Provider>,
|
||||||
|
);
|
||||||
|
expect(screen.getAllByText('Specific Date/Time').length).toBe(2);
|
||||||
|
expect(screen.getAllByRole('img', { name: 'calendar' }).length).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('renders with invalid locale', () => {
|
||||||
|
render(
|
||||||
|
<Provider store={invalidStore}>
|
||||||
|
<CustomFrame onChange={jest.fn()} value={emptyValue} />
|
||||||
|
</Provider>,
|
||||||
|
);
|
||||||
|
expect(screen.getByText('Configure custom time range')).toBeInTheDocument();
|
||||||
|
expect(screen.getByText('Relative Date/Time')).toBeInTheDocument();
|
||||||
|
expect(screen.getByRole('spinbutton')).toBeInTheDocument();
|
||||||
|
expect(screen.getByText('Days Before')).toBeInTheDocument();
|
||||||
|
expect(screen.getByText('Specific Date/Time')).toBeInTheDocument();
|
||||||
|
expect(screen.getByRole('img', { name: 'calendar' })).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('renders since and until with specific date/time with invalid locale', () => {
|
||||||
|
render(
|
||||||
|
<Provider store={invalidStore}>
|
||||||
|
<CustomFrame onChange={jest.fn()} value={specificValue} />
|
||||||
|
</Provider>,
|
||||||
|
);
|
||||||
|
expect(screen.getAllByText('Specific Date/Time').length).toBe(2);
|
||||||
|
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', () => {
|
||||||
render(
|
render(
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
|
@ -110,9 +110,15 @@ export function CustomFrame(props: FrameComponentProps) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const localFromFlaskBabel =
|
// check if there is a locale defined for explore
|
||||||
useSelector((state: ExplorePageState) => state.common.locale) || 'en';
|
const localFromFlaskBabel = useSelector(
|
||||||
const currentLocale = locales[LOCALE_MAPPING[localFromFlaskBabel]].DatePicker;
|
(state: ExplorePageState) => state?.common?.locale,
|
||||||
|
);
|
||||||
|
// An undefined datePickerLocale is acceptable if no match is found in the LOCALE_MAPPING[localFromFlaskBabel] lookup
|
||||||
|
// and will fall back to antd's default locale when the antd DataPicker's prop locale === undefined
|
||||||
|
// This also protects us from the case where state is populated with a locale that antd locales does not recognize
|
||||||
|
const datePickerLocale =
|
||||||
|
locales[LOCALE_MAPPING[localFromFlaskBabel]]?.DatePicker;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div data-test="custom-frame">
|
<div data-test="custom-frame">
|
||||||
@ -141,7 +147,7 @@ export function CustomFrame(props: FrameComponentProps) {
|
|||||||
onChange('sinceDatetime', datetime.format(MOMENT_FORMAT))
|
onChange('sinceDatetime', datetime.format(MOMENT_FORMAT))
|
||||||
}
|
}
|
||||||
allowClear={false}
|
allowClear={false}
|
||||||
locale={currentLocale}
|
locale={datePickerLocale}
|
||||||
/>
|
/>
|
||||||
</Row>
|
</Row>
|
||||||
)}
|
)}
|
||||||
@ -194,7 +200,7 @@ export function CustomFrame(props: FrameComponentProps) {
|
|||||||
onChange('untilDatetime', datetime.format(MOMENT_FORMAT))
|
onChange('untilDatetime', datetime.format(MOMENT_FORMAT))
|
||||||
}
|
}
|
||||||
allowClear={false}
|
allowClear={false}
|
||||||
locale={currentLocale}
|
locale={datePickerLocale}
|
||||||
/>
|
/>
|
||||||
</Row>
|
</Row>
|
||||||
)}
|
)}
|
||||||
@ -252,7 +258,7 @@ export function CustomFrame(props: FrameComponentProps) {
|
|||||||
}
|
}
|
||||||
allowClear={false}
|
allowClear={false}
|
||||||
className="control-anchor-to-datetime"
|
className="control-anchor-to-datetime"
|
||||||
locale={currentLocale}
|
locale={datePickerLocale}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
)}
|
)}
|
||||||
|
Loading…
Reference in New Issue
Block a user