Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Commit

Permalink
Test if time_range uses uiSettings to get commonlyUsedRanges
Browse files Browse the repository at this point in the history
  • Loading branch information
iget-esoares committed Apr 5, 2021
1 parent 193846b commit 4c9a549
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ReportSettings } from '../report_settings';
import 'babel-polyfill';
import 'regenerator-runtime';
import httpClientMock from '../../../../../test/httpMockClient';
import uiSettingsMock from '../../../../../test/uiSettingsMock';
import { configure, mount, shallow } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import { act } from 'react-dom/test-utils';
Expand Down Expand Up @@ -103,6 +104,7 @@ describe('<ReportSettings /> panel', () => {
const { container } = render(
<ReportSettings
edit={false}
uiSettings={uiSettingsMock}
reportDefinitionRequest={emptyRequest}
httpClientProps={httpClientMock}
timeRange={timeRange}
Expand Down Expand Up @@ -147,6 +149,7 @@ describe('<ReportSettings /> panel', () => {
const { container } = render(
<ReportSettings
edit={true}
uiSettings={uiSettingsMock}
reportDefinitionRequest={emptyRequest}
httpClientProps={httpClientMock}
timeRange={timeRange}
Expand Down Expand Up @@ -192,6 +195,7 @@ describe('<ReportSettings /> panel', () => {
const { container } = render(
<ReportSettings
edit={true}
uiSettings={uiSettingsMock}
reportDefinitionRequest={emptyRequest}
httpClientProps={httpClientMock}
timeRange={timeRange}
Expand Down Expand Up @@ -240,6 +244,7 @@ describe('<ReportSettings /> panel', () => {
const { container } = render(
<ReportSettings
edit={true}
uiSettings={uiSettingsMock}
reportDefinitionRequest={emptyRequest}
httpClientProps={httpClientMock}
timeRange={timeRange}
Expand Down Expand Up @@ -288,6 +293,7 @@ describe('<ReportSettings /> panel', () => {
const { container } = render(
<ReportSettings
edit={true}
uiSettings={uiSettingsMock}
reportDefinitionRequest={emptyRequest}
httpClientProps={httpClientMock}
timeRange={timeRange}
Expand Down Expand Up @@ -336,6 +342,7 @@ describe('<ReportSettings /> panel', () => {
const { container } = render(
<ReportSettings
edit={true}
uiSettings={uiSettingsMock}
reportDefinitionRequest={emptyRequest}
httpClientProps={httpClientMock}
timeRange={timeRange}
Expand All @@ -347,7 +354,7 @@ describe('<ReportSettings /> panel', () => {
expect(container.firstChild).toMatchSnapshot();
await act(() => promise);
});


test('dashboard create from in-context', async () => {
window = Object.create(window);
Expand Down Expand Up @@ -392,6 +399,7 @@ describe('<ReportSettings /> panel', () => {
const { container } = render(
<ReportSettings
edit={false}
uiSettings={uiSettingsMock}
reportDefinitionRequest={emptyRequest}
httpClientProps={httpClientMock}
timeRange={timeRange}
Expand Down Expand Up @@ -450,6 +458,7 @@ describe('<ReportSettings /> panel', () => {
const { container } = render(
<ReportSettings
edit={false}
uiSettings={uiSettingsMock}
reportDefinitionRequest={emptyRequest}
httpClientProps={httpClientMock}
timeRange={timeRange}
Expand Down Expand Up @@ -510,6 +519,7 @@ describe('<ReportSettings /> panel', () => {
const { container } = render(
<ReportSettings
edit={false}
uiSettings={uiSettingsMock}
reportDefinitionRequest={emptyRequest}
httpClientProps={httpClientMock}
timeRange={timeRange}
Expand Down Expand Up @@ -558,6 +568,7 @@ describe('<ReportSettings /> panel', () => {
const component = shallow(
<ReportSettings
edit={false}
uiSettings={uiSettingsMock}
reportDefinitionRequest={emptyRequest}
httpClientProps={httpClientMock}
timeRange={timeRange}
Expand Down Expand Up @@ -606,6 +617,7 @@ describe('<ReportSettings /> panel', () => {
const component = mount(
<ReportSettings
edit={false}
uiSettings={uiSettingsMock}
reportDefinitionRequest={emptyRequest}
httpClientProps={httpClientMock}
timeRange={timeRange}
Expand All @@ -624,7 +636,7 @@ describe('<ReportSettings /> panel', () => {

act(() => {
comboBox.props().onChange([{ value: 'test', label: 'test' }]);
});
});
component.update();

await act(() => promise);
Expand Down Expand Up @@ -663,6 +675,7 @@ describe('<ReportSettings /> panel', () => {
const component = mount(
<ReportSettings
edit={false}
uiSettings={uiSettingsMock}
reportDefinitionRequest={emptyRequest}
httpClientProps={httpClientMock}
timeRange={timeRange}
Expand Down Expand Up @@ -692,6 +705,7 @@ describe('<ReportSettings /> panel', () => {
const { container } = render(
<ReportSettings
edit={false}
uiSettings={uiSettingsMock}
reportDefinitionRequest={emptyRequest}
httpClientProps={httpClientMock}
timeRange={timeRange}
Expand All @@ -703,4 +717,45 @@ describe('<ReportSettings /> panel', () => {
expect(container.firstChild).toMatchSnapshot();
await act(() => promise);
});

test('load commonlyUsedRanges from uiSettings service', async () => {
const promise = Promise.resolve();
uiSettingsMock.get = jest.fn((key) => [
{
from: 'now/d',
to: 'now/d',
display: 'Foo'
}
]);

const component = mount(
<ReportSettings
edit={false}
uiSettings={uiSettingsMock}
reportDefinitionRequest={emptyRequest}
httpClientProps={httpClientMock}
timeRange={timeRange}
showSettingsReportNameError={true}
showTimeRangeError={true}
/>
);
await act(() => promise);

const superDatePicker = component.find('EuiSuperDatePicker').at(0);

expect(superDatePicker.prop('commonlyUsedRanges')).toEqual(
[
{
start: 'now/d',
end: 'now/d',
label: 'Foo'
}
]
);

expect(uiSettingsMock.get.mock.calls.length).toBeGreaterThan(0);
expect(uiSettingsMock.get.mock.calls[0][0]).toBe('timepicker:quickRanges');

await act(() => promise);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
EuiGlobalToastList,
EuiSuperDatePicker,
} from '@elastic/eui';
import { UI_SETTINGS } from '../../../../../../src/plugins/data/common';

export function TimeRangeSelect(props) {
const {
Expand Down Expand Up @@ -194,7 +193,7 @@ export function TimeRangeSelect(props) {
};

const commonlyUsedRanges = uiSettings!
.get(UI_SETTINGS.TIMEPICKER_QUICK_RANGES)
.get('timepicker:quickRanges')
.map(({ from, to, display }: { from: string; to: string; display: string }) => {
return {
start: from,
Expand Down
20 changes: 20 additions & 0 deletions kibana-reports/test/uiSettingsMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

const uiSettingsMock = jest.fn();

uiSettingsMock.get = jest.fn((key) => ([]));

export default uiSettingsMock;

0 comments on commit 4c9a549

Please sign in to comment.