|
|
@ -1,92 +1,89 @@ |
|
|
|
import React from 'react'; |
|
|
|
import React from 'react'; |
|
|
|
import { last } from 'lodash'; |
|
|
|
|
|
|
|
import { mount } from 'enzyme'; |
|
|
|
|
|
|
|
import { ElasticDetails } from './ElasticDetails'; |
|
|
|
import { ElasticDetails } from './ElasticDetails'; |
|
|
|
import { createDefaultConfigOptions } from './mocks'; |
|
|
|
import { createDefaultConfigOptions } from './mocks'; |
|
|
|
import { LegacyForms } from '@grafana/ui'; |
|
|
|
import { render, screen } from '@testing-library/react'; |
|
|
|
const { Select } = LegacyForms; |
|
|
|
import selectEvent from 'react-select-event'; |
|
|
|
|
|
|
|
|
|
|
|
describe('ElasticDetails', () => { |
|
|
|
describe('ElasticDetails', () => { |
|
|
|
it('should render without error', () => { |
|
|
|
describe('Max concurrent Shard Requests', () => { |
|
|
|
mount(<ElasticDetails onChange={() => {}} value={createDefaultConfigOptions()} />); |
|
|
|
it('should render "Max concurrent Shard Requests" if version >= 5.6.0', () => { |
|
|
|
|
|
|
|
render(<ElasticDetails onChange={() => {}} value={createDefaultConfigOptions({ esVersion: '5.6.0' })} />); |
|
|
|
|
|
|
|
expect(screen.getByLabelText('Max concurrent Shard Requests')).toBeInTheDocument(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should render "Max concurrent Shard Requests" if version high enough', () => { |
|
|
|
it('should not render "Max concurrent Shard Requests" if version < 5.6.0', () => { |
|
|
|
const wrapper = mount(<ElasticDetails onChange={() => {}} value={createDefaultConfigOptions()} />); |
|
|
|
render(<ElasticDetails onChange={() => {}} value={createDefaultConfigOptions({ esVersion: '5.0.0' })} />); |
|
|
|
expect(wrapper.find('input[aria-label="Max concurrent Shard Requests input"]').length).toBe(1); |
|
|
|
expect(screen.queryByLabelText('Max concurrent Shard Requests')).not.toBeInTheDocument(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should not render "Max concurrent Shard Requests" if version is low', () => { |
|
|
|
|
|
|
|
const options = createDefaultConfigOptions(); |
|
|
|
|
|
|
|
options.jsonData.esVersion = '5.0.0'; |
|
|
|
|
|
|
|
const wrapper = mount(<ElasticDetails onChange={() => {}} value={options} />); |
|
|
|
|
|
|
|
expect(wrapper.find('input[aria-label="Max concurrent Shard Requests input"]').length).toBe(0); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should change database on interval change when not set explicitly', () => { |
|
|
|
it('should change database on interval change when not set explicitly', async () => { |
|
|
|
const onChangeMock = jest.fn(); |
|
|
|
const onChangeMock = jest.fn(); |
|
|
|
const wrapper = mount(<ElasticDetails onChange={onChangeMock} value={createDefaultConfigOptions()} />); |
|
|
|
render(<ElasticDetails onChange={onChangeMock} value={createDefaultConfigOptions()} />); |
|
|
|
const selectEl = wrapper.find({ label: 'Pattern' }).find(Select); |
|
|
|
const selectEl = screen.getByLabelText('Pattern'); |
|
|
|
selectEl.props().onChange({ value: 'Daily', label: 'Daily' }, { action: 'select-option', option: undefined }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(onChangeMock.mock.calls[0][0].jsonData.interval).toBe('Daily'); |
|
|
|
await selectEvent.select(selectEl, 'Daily', { container: document.body }); |
|
|
|
expect(onChangeMock.mock.calls[0][0].database).toBe('[logstash-]YYYY.MM.DD'); |
|
|
|
|
|
|
|
|
|
|
|
expect(onChangeMock).toHaveBeenLastCalledWith( |
|
|
|
|
|
|
|
expect.objectContaining({ |
|
|
|
|
|
|
|
database: '[logstash-]YYYY.MM.DD', |
|
|
|
|
|
|
|
jsonData: expect.objectContaining({ interval: 'Daily' }), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should change database on interval change if pattern is from example', () => { |
|
|
|
it('should change database on interval change if pattern is from example', async () => { |
|
|
|
const onChangeMock = jest.fn(); |
|
|
|
const onChangeMock = jest.fn(); |
|
|
|
const options = createDefaultConfigOptions(); |
|
|
|
const options = createDefaultConfigOptions(); |
|
|
|
options.database = '[logstash-]YYYY.MM.DD.HH'; |
|
|
|
options.database = '[logstash-]YYYY.MM.DD.HH'; |
|
|
|
const wrapper = mount(<ElasticDetails onChange={onChangeMock} value={options} />); |
|
|
|
render(<ElasticDetails onChange={onChangeMock} value={options} />); |
|
|
|
|
|
|
|
const selectEl = screen.getByLabelText('Pattern'); |
|
|
|
|
|
|
|
|
|
|
|
const selectEl = wrapper.find({ label: 'Pattern' }).find(Select); |
|
|
|
await selectEvent.select(selectEl, 'Monthly', { container: document.body }); |
|
|
|
selectEl.props().onChange({ value: 'Monthly', label: 'Monthly' }, { action: 'select-option', option: undefined }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(onChangeMock.mock.calls[0][0].jsonData.interval).toBe('Monthly'); |
|
|
|
expect(onChangeMock).toHaveBeenLastCalledWith( |
|
|
|
expect(onChangeMock.mock.calls[0][0].database).toBe('[logstash-]YYYY.MM'); |
|
|
|
expect.objectContaining({ |
|
|
|
|
|
|
|
database: '[logstash-]YYYY.MM', |
|
|
|
|
|
|
|
jsonData: expect.objectContaining({ interval: 'Monthly' }), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('version change', () => { |
|
|
|
describe('version change', () => { |
|
|
|
const testCases = [ |
|
|
|
const testCases = [ |
|
|
|
{ version: '5.0.0', expectedMaxConcurrentShardRequests: 256 }, |
|
|
|
{ version: '5.x', expectedMaxConcurrentShardRequests: 256 }, |
|
|
|
{ version: '5.0.0', maxConcurrentShardRequests: 50, expectedMaxConcurrentShardRequests: 50 }, |
|
|
|
{ version: '5.x', maxConcurrentShardRequests: 50, expectedMaxConcurrentShardRequests: 50 }, |
|
|
|
{ version: '5.6.0', expectedMaxConcurrentShardRequests: 256 }, |
|
|
|
{ version: '5.6+', expectedMaxConcurrentShardRequests: 256 }, |
|
|
|
{ version: '5.6.0', maxConcurrentShardRequests: 256, expectedMaxConcurrentShardRequests: 256 }, |
|
|
|
{ version: '5.6+', maxConcurrentShardRequests: 256, expectedMaxConcurrentShardRequests: 256 }, |
|
|
|
{ version: '5.6.0', maxConcurrentShardRequests: 5, expectedMaxConcurrentShardRequests: 256 }, |
|
|
|
{ version: '5.6+', maxConcurrentShardRequests: 5, expectedMaxConcurrentShardRequests: 256 }, |
|
|
|
{ version: '5.6.0', maxConcurrentShardRequests: 200, expectedMaxConcurrentShardRequests: 200 }, |
|
|
|
{ version: '5.6+', maxConcurrentShardRequests: 200, expectedMaxConcurrentShardRequests: 200 }, |
|
|
|
{ version: '7.0.0', expectedMaxConcurrentShardRequests: 5 }, |
|
|
|
{ version: '7.0+', expectedMaxConcurrentShardRequests: 5 }, |
|
|
|
{ version: '7.0.0', maxConcurrentShardRequests: 256, expectedMaxConcurrentShardRequests: 5 }, |
|
|
|
{ version: '7.0+', maxConcurrentShardRequests: 256, expectedMaxConcurrentShardRequests: 5 }, |
|
|
|
{ version: '7.0.0', maxConcurrentShardRequests: 5, expectedMaxConcurrentShardRequests: 5 }, |
|
|
|
{ version: '7.0+', maxConcurrentShardRequests: 5, expectedMaxConcurrentShardRequests: 5 }, |
|
|
|
{ version: '7.0.0', maxConcurrentShardRequests: 6, expectedMaxConcurrentShardRequests: 6 }, |
|
|
|
{ version: '7.0+', maxConcurrentShardRequests: 6, expectedMaxConcurrentShardRequests: 6 }, |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
const onChangeMock = jest.fn(); |
|
|
|
|
|
|
|
const options = createDefaultConfigOptions(); |
|
|
|
|
|
|
|
const wrapper = mount(<ElasticDetails onChange={onChangeMock} value={options} />); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testCases.forEach((tc) => { |
|
|
|
testCases.forEach((tc) => { |
|
|
|
it(`sets maxConcurrentShardRequests = ${tc.maxConcurrentShardRequests} if version = ${tc.version},`, () => { |
|
|
|
const onChangeMock = jest.fn(); |
|
|
|
wrapper.setProps({ |
|
|
|
it(`sets maxConcurrentShardRequests=${tc.expectedMaxConcurrentShardRequests} if version=${tc.version},`, async () => { |
|
|
|
onChange: onChangeMock, |
|
|
|
render( |
|
|
|
value: { |
|
|
|
<ElasticDetails |
|
|
|
...options, |
|
|
|
onChange={onChangeMock} |
|
|
|
jsonData: { |
|
|
|
value={createDefaultConfigOptions({ |
|
|
|
...options.jsonData, |
|
|
|
|
|
|
|
maxConcurrentShardRequests: tc.maxConcurrentShardRequests, |
|
|
|
maxConcurrentShardRequests: tc.maxConcurrentShardRequests, |
|
|
|
}, |
|
|
|
esVersion: '2.0.0', |
|
|
|
}, |
|
|
|
})} |
|
|
|
}); |
|
|
|
/> |
|
|
|
|
|
|
|
|
|
|
|
const selectEl = wrapper.find({ label: 'Version' }).find(Select); |
|
|
|
|
|
|
|
selectEl |
|
|
|
|
|
|
|
.props() |
|
|
|
|
|
|
|
.onChange( |
|
|
|
|
|
|
|
{ value: tc.version, label: tc.version.toString() }, |
|
|
|
|
|
|
|
{ action: 'select-option', option: undefined } |
|
|
|
|
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
expect(last(onChangeMock.mock.calls)[0].jsonData.maxConcurrentShardRequests).toBe( |
|
|
|
const selectEl = screen.getByLabelText('ElasticSearch version'); |
|
|
|
tc.expectedMaxConcurrentShardRequests |
|
|
|
|
|
|
|
|
|
|
|
await selectEvent.select(selectEl, tc.version, { container: document.body }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(onChangeMock).toHaveBeenCalledWith( |
|
|
|
|
|
|
|
expect.objectContaining({ |
|
|
|
|
|
|
|
jsonData: expect.objectContaining({ maxConcurrentShardRequests: tc.expectedMaxConcurrentShardRequests }), |
|
|
|
|
|
|
|
}) |
|
|
|
); |
|
|
|
); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|