This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
elasticsearch_settings.test.jsx
88 lines (82 loc) · 2.79 KB
/
elasticsearch_settings.test.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {shallow} from 'enzyme';
import SaveButton from 'components/save_button';
import ElasticSearchSettings from 'components/admin_console/elasticsearch_settings.jsx';
jest.mock('actions/admin_actions.jsx', () => {
return {
elasticsearchPurgeIndexes: jest.fn(),
elasticsearchTest: (config, success) => success(),
};
});
describe('components/ElasticSearchSettings', () => {
test('should match snapshot, disabled', () => {
const config = {
ElasticsearchSettings: {
ConnectionUrl: 'test',
SkipTLSVerification: false,
Username: 'test',
Password: 'test',
Sniff: false,
EnableIndexing: false,
EnableSearching: false,
EnableAutocomplete: false,
},
};
const wrapper = shallow(
<ElasticSearchSettings
config={config}
/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, enabled', () => {
const config = {
ElasticsearchSettings: {
ConnectionUrl: 'test',
SkipTLSVerification: false,
Username: 'test',
Password: 'test',
Sniff: false,
EnableIndexing: true,
EnableSearching: false,
EnableAutocomplete: false,
},
};
const wrapper = shallow(
<ElasticSearchSettings
config={config}
/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should maintain save disable until is tested', () => {
const config = {
ElasticsearchSettings: {
ConnectionUrl: 'test',
SkipTLSVerification: false,
Username: 'test',
Password: 'test',
Sniff: false,
EnableIndexing: false,
EnableSearching: false,
EnableAutocomplete: false,
},
};
const wrapper = shallow(
<ElasticSearchSettings
config={config}
/>,
);
expect(wrapper.find(SaveButton).prop('disabled')).toBe(true);
wrapper.instance().handleSettingChanged('enableIndexing', true);
expect(wrapper.find(SaveButton).prop('disabled')).toBe(true);
const instance = wrapper.instance();
instance.doSubmit = jest.fn();
const success = jest.fn();
instance.doTestConfig(success);
expect(success).toBeCalled();
expect(wrapper.find(SaveButton).prop('disabled')).toBe(false);
});
});