Skip to content

Commit 374b99d

Browse files
committed
[ML] Fix SelectInterval tests.
1 parent 743f963 commit 374b99d

3 files changed

Lines changed: 40 additions & 17 deletions

File tree

x-pack/legacy/plugins/ml/public/application/components/controls/select_interval/select_interval.test.tsx

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,51 @@
55
*/
66

77
import React from 'react';
8-
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
8+
import { act } from 'react-dom/test-utils';
9+
import { MemoryRouter } from 'react-router-dom';
10+
import { mount } from 'enzyme';
11+
12+
import { EuiSelect } from '@elastic/eui';
13+
914
import { SelectInterval } from './select_interval';
1015

1116
describe('SelectInterval', () => {
1217
test('creates correct initial selected value', () => {
13-
const wrapper = shallowWithIntl(<SelectInterval />);
14-
const defaultSelectedValue = wrapper.props().interval.val;
18+
const wrapper = mount(
19+
<MemoryRouter>
20+
<SelectInterval />
21+
</MemoryRouter>
22+
);
23+
const select = wrapper.find(EuiSelect);
1524

25+
const defaultSelectedValue = select.props().value;
1626
expect(defaultSelectedValue).toBe('auto');
1727
});
1828

19-
test('currently selected value is updated correctly on click', () => {
20-
const wrapper = shallowWithIntl(<SelectInterval />);
21-
const select = wrapper.first().shallow();
22-
23-
const defaultSelectedValue = wrapper.props().interval.val;
29+
test('currently selected value is updated correctly on click', done => {
30+
const wrapper = mount(
31+
<MemoryRouter>
32+
<SelectInterval />
33+
</MemoryRouter>
34+
);
35+
const select = wrapper.find(EuiSelect).first();
36+
const defaultSelectedValue = select.props().value;
2437
expect(defaultSelectedValue).toBe('auto');
2538

26-
select.simulate('change', { target: { value: 'day' } });
27-
const updatedSelectedValue = wrapper.props().interval.val;
28-
expect(updatedSelectedValue).toBe('day');
39+
const onChange = select.props().onChange;
40+
41+
act(() => {
42+
if (onChange !== undefined) {
43+
onChange({ target: { value: 'day' } } as React.ChangeEvent<HTMLSelectElement>);
44+
}
45+
});
46+
47+
setImmediate(() => {
48+
wrapper.update();
49+
const updatedSelect = wrapper.find(EuiSelect).first();
50+
const updatedSelectedValue = updatedSelect.props().value;
51+
expect(updatedSelectedValue).toBe('day');
52+
done();
53+
});
2954
});
3055
});

x-pack/legacy/plugins/ml/public/application/components/controls/select_interval/select_interval.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function optionValueToInterval(value: string) {
5858
return interval;
5959
}
6060

61-
const TABLE_INTERVAL_DEFAULT = OPTIONS[0].value;
61+
const TABLE_INTERVAL_DEFAULT = optionValueToInterval('auto');
6262
const TABLE_INTERVAL_APP_STATE_NAME = 'mlSelectInterval';
6363

6464
export const useTableInterval = () => {

x-pack/legacy/plugins/ml/public/application/components/controls/select_severity/select_severity.test.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import React from 'react';
88
import { act } from 'react-dom/test-utils';
9-
import { MemoryRouter, Route } from 'react-router-dom';
9+
import { MemoryRouter } from 'react-router-dom';
1010
import { mount } from 'enzyme';
1111

1212
import { EuiSuperSelect } from '@elastic/eui';
@@ -64,10 +64,8 @@ describe('SelectSeverity', () => {
6464

6565
test('state for currently selected value is updated correctly on click', done => {
6666
const wrapper = mount(
67-
<MemoryRouter initialEntries={['page']}>
68-
<Route path="page">
69-
<SelectSeverity />
70-
</Route>
67+
<MemoryRouter>
68+
<SelectSeverity />
7169
</MemoryRouter>
7270
);
7371

0 commit comments

Comments
 (0)