2019-10-25 22:43:20 +08:00
|
|
|
import { mount, shallow } from 'enzyme';
|
2022-04-22 21:33:13 +08:00
|
|
|
import React from 'react';
|
|
|
|
|
|
2019-10-25 22:43:20 +08:00
|
|
|
import { DataSourceHttpSettings } from '@grafana/ui';
|
2022-04-22 21:33:13 +08:00
|
|
|
|
|
|
|
|
import { ConfigEditor } from './ConfigEditor';
|
2019-10-25 22:43:20 +08:00
|
|
|
import { ElasticDetails } from './ElasticDetails';
|
|
|
|
|
import { LogsConfig } from './LogsConfig';
|
|
|
|
|
import { createDefaultConfigOptions } from './mocks';
|
|
|
|
|
|
|
|
|
|
describe('ConfigEditor', () => {
|
|
|
|
|
it('should render without error', () => {
|
|
|
|
|
mount(<ConfigEditor onOptionsChange={() => {}} options={createDefaultConfigOptions()} />);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should render all parts of the config', () => {
|
|
|
|
|
const wrapper = shallow(<ConfigEditor onOptionsChange={() => {}} options={createDefaultConfigOptions()} />);
|
|
|
|
|
expect(wrapper.find(DataSourceHttpSettings).length).toBe(1);
|
|
|
|
|
expect(wrapper.find(ElasticDetails).length).toBe(1);
|
|
|
|
|
expect(wrapper.find(LogsConfig).length).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should set defaults', () => {
|
|
|
|
|
const options = createDefaultConfigOptions();
|
2020-12-04 22:29:40 +08:00
|
|
|
// @ts-ignore
|
2019-10-25 22:43:20 +08:00
|
|
|
delete options.jsonData.esVersion;
|
2020-12-04 22:29:40 +08:00
|
|
|
// @ts-ignore
|
2019-10-25 22:43:20 +08:00
|
|
|
delete options.jsonData.timeField;
|
|
|
|
|
delete options.jsonData.maxConcurrentShardRequests;
|
|
|
|
|
|
|
|
|
|
expect.assertions(3);
|
|
|
|
|
|
|
|
|
|
mount(
|
|
|
|
|
<ConfigEditor
|
2021-01-20 14:59:48 +08:00
|
|
|
onOptionsChange={(options) => {
|
2021-05-11 16:44:00 +08:00
|
|
|
expect(options.jsonData.esVersion).toBe('5.0.0');
|
2019-10-25 22:43:20 +08:00
|
|
|
expect(options.jsonData.timeField).toBe('@timestamp');
|
|
|
|
|
expect(options.jsonData.maxConcurrentShardRequests).toBe(256);
|
|
|
|
|
}}
|
|
|
|
|
options={options}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not apply default if values are set', () => {
|
2021-05-11 16:44:00 +08:00
|
|
|
const onChange = jest.fn();
|
2019-10-25 22:43:20 +08:00
|
|
|
|
2021-05-11 16:44:00 +08:00
|
|
|
mount(<ConfigEditor onOptionsChange={onChange} options={createDefaultConfigOptions()} />);
|
|
|
|
|
|
|
|
|
|
expect(onChange).toHaveBeenCalledTimes(0);
|
2019-10-25 22:43:20 +08:00
|
|
|
});
|
|
|
|
|
});
|