Skip to content

Commit

Permalink
[ML] adjust editor test
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Nov 22, 2019
1 parent e7c0183 commit 0542a7f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,40 @@
*/

// Mock the mlJobService that is used for testing custom URLs.
import { UrlConfig } from '../../../../common/types/custom_urls';
import { shallow } from 'enzyme';

jest.mock('../../../services/job_service.js', () => 'mlJobService');

import { shallowWithIntl } from 'test_utils/enzyme_helpers';
import React from 'react';

import { CustomUrlEditor } from './editor';
import {
TIME_RANGE_TYPE,
URL_TYPE
} from './constants';

function prepareTest(customUrl, setEditCustomUrlFn) {
import { TIME_RANGE_TYPE, URL_TYPE } from './constants';
import { CustomUrlSettings } from './utils';
import { IIndexPattern } from '../../../../../../../../src/plugins/data/common/index_patterns';

function prepareTest(customUrl: CustomUrlSettings, setEditCustomUrlFn: (url: UrlConfig) => void) {
const savedCustomUrls = [
{
url_name: 'Show data',
time_range: 'auto',
url_value: 'kibana#/discover?_g=(time:(from:\'$earliest$\',mode:absolute,to:\'$latest$\'))&_a=' +
'(index:e532ba80-b76f-11e8-a9dc-37914a458883,query:(language:lucene,query:\'airline:"$airline$"\'))'
url_value:
"kibana#/discover?_g=(time:(from:'$earliest$',mode:absolute,to:'$latest$'))&_a=" +
'(index:e532ba80-b76f-11e8-a9dc-37914a458883,query:(language:lucene,query:\'airline:"$airline$"\'))',
},
{
url_name: 'Show dashboard',
time_range: '1h',
url_value: 'kibana#/dashboard/52ea8840-bbef-11e8-a04d-b1701b2b977e?_g=' +
'(time:(from:\'$earliest$\',mode:absolute,to:\'$latest$\'))&' +
'_a=(filters:!(),query:(language:lucene,query:\'airline:"$airline$"\'))'
url_value:
'kibana#/dashboard/52ea8840-bbef-11e8-a04d-b1701b2b977e?_g=' +
"(time:(from:'$earliest$',mode:absolute,to:'$latest$'))&" +
'_a=(filters:!(),query:(language:lucene,query:\'airline:"$airline$"\'))',
},
{
url_name: 'Show airline',
time_range: 'auto',
url_value: 'http://airlinecodes.info/airline-code-$airline$'
url_value: 'http://airlinecodes.info/airline-code-$airline$',
},

];

const dashboards = [
Expand All @@ -48,7 +49,7 @@ function prepareTest(customUrl, setEditCustomUrlFn) {
const indexPatterns = [
{ id: 'pattern1', title: 'Index Pattern 1' },
{ id: 'pattern2', title: 'Index Pattern 2' },
];
] as IIndexPattern[];

const queryEntityFieldNames = ['airline'];

Expand All @@ -61,22 +62,16 @@ function prepareTest(customUrl, setEditCustomUrlFn) {
queryEntityFieldNames,
};

const wrapper = shallowWithIntl(
<CustomUrlEditor.WrappedComponent {...props} />
);

return wrapper;
return shallow(<CustomUrlEditor {...props} />);
}


describe('CustomUrlEditor', () => {

const setEditCustomUrl = jest.fn(() => {});
const dashboardUrl = {
label: '',
timeRange: {
type: TIME_RANGE_TYPE.AUTO,
interval: ''
interval: '',
},
type: URL_TYPE.KIBANA_DASHBOARD,
kibanaSettings: {
Expand All @@ -89,7 +84,7 @@ describe('CustomUrlEditor', () => {
label: 'Open Discover',
timeRange: {
type: TIME_RANGE_TYPE.INTERVAL,
interval: ''
interval: '',
},
type: URL_TYPE.KIBANA_DISCOVER,
kibanaSettings: {
Expand All @@ -102,12 +97,12 @@ describe('CustomUrlEditor', () => {
label: 'Show airline',
timeRange: {
type: TIME_RANGE_TYPE.AUTO,
interval: ''
interval: '',
},
type: URL_TYPE.OTHER,
otherUrlSettings: {
urlValue: 'https://www.google.co.uk/search?q=airline+code+$airline$'
}
urlValue: 'https://www.google.co.uk/search?q=airline+code+$airline$',
},
};

test('renders the editor for a new dashboard type URL with no label', () => {
Expand All @@ -118,7 +113,7 @@ describe('CustomUrlEditor', () => {
test('renders the editor for a dashboard type URL with a label', () => {
const dashboardUrlEdit = {
...dashboardUrl,
label: 'Open Dashboard 1'
label: 'Open Dashboard 1',
};
const wrapper = prepareTest(dashboardUrlEdit, setEditCustomUrl);
expect(wrapper).toMatchSnapshot();
Expand All @@ -134,8 +129,8 @@ describe('CustomUrlEditor', () => {
...discoverUrl,
timeRange: {
type: TIME_RANGE_TYPE.INTERVAL,
interval: '1h'
}
interval: '1h',
},
};
const wrapper = prepareTest(discoverUrlEdit, setEditCustomUrl);
expect(wrapper).toMatchSnapshot();
Expand All @@ -149,7 +144,7 @@ describe('CustomUrlEditor', () => {
test('renders the editor for other type of URL with unique label', () => {
const otherUrlEdit = {
...otherUrl,
label: 'View airline'
label: 'View airline',
};
const wrapper = prepareTest(otherUrlEdit, setEditCustomUrl);
expect(wrapper).toMatchSnapshot();
Expand All @@ -162,5 +157,4 @@ describe('CustomUrlEditor', () => {
wrapper.update();
expect(setEditCustomUrl).toHaveBeenCalled();
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export interface CustomUrlSettings {
// Note timeRange is only editable in new URLs for Dashboard and Discover URLs,
// as for other URLs we have no way of knowing how the field will be used in the URL.
timeRange: TimeRange;
kibanaSettings: any;
otherUrlSettings: {
kibanaSettings?: any;
otherUrlSettings?: {
urlValue: string;
};
}
Expand Down

0 comments on commit 0542a7f

Please sign in to comment.