2022-04-22 08:33:13 -05:00
|
|
|
import { render, screen } from '@testing-library/react';
|
2019-10-25 09:43:20 -05:00
|
|
|
import React from 'react';
|
2022-04-22 08:33:13 -05:00
|
|
|
import selectEvent from 'react-select-event';
|
|
|
|
|
2019-10-25 09:43:20 -05:00
|
|
|
import { ElasticDetails } from './ElasticDetails';
|
|
|
|
import { createDefaultConfigOptions } from './mocks';
|
|
|
|
|
|
|
|
describe('ElasticDetails', () => {
|
2022-01-12 03:19:10 -06:00
|
|
|
describe('Max concurrent Shard Requests', () => {
|
|
|
|
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();
|
|
|
|
});
|
2019-10-25 09:43:20 -05:00
|
|
|
|
2022-01-12 03:19:10 -06:00
|
|
|
it('should not render "Max concurrent Shard Requests" if version < 5.6.0', () => {
|
|
|
|
render(<ElasticDetails onChange={() => {}} value={createDefaultConfigOptions({ esVersion: '5.0.0' })} />);
|
|
|
|
expect(screen.queryByLabelText('Max concurrent Shard Requests')).not.toBeInTheDocument();
|
|
|
|
});
|
2019-10-25 09:43:20 -05:00
|
|
|
});
|
|
|
|
|
2022-01-12 03:19:10 -06:00
|
|
|
it('should change database on interval change when not set explicitly', async () => {
|
2019-10-25 09:43:20 -05:00
|
|
|
const onChangeMock = jest.fn();
|
2022-01-12 03:19:10 -06:00
|
|
|
render(<ElasticDetails onChange={onChangeMock} value={createDefaultConfigOptions()} />);
|
|
|
|
const selectEl = screen.getByLabelText('Pattern');
|
2019-10-25 09:43:20 -05:00
|
|
|
|
2022-01-12 03:19:10 -06:00
|
|
|
await selectEvent.select(selectEl, 'Daily', { container: document.body });
|
|
|
|
|
|
|
|
expect(onChangeMock).toHaveBeenLastCalledWith(
|
|
|
|
expect.objectContaining({
|
|
|
|
database: '[logstash-]YYYY.MM.DD',
|
|
|
|
jsonData: expect.objectContaining({ interval: 'Daily' }),
|
|
|
|
})
|
|
|
|
);
|
2019-10-25 09:43:20 -05:00
|
|
|
});
|
|
|
|
|
2022-01-12 03:19:10 -06:00
|
|
|
it('should change database on interval change if pattern is from example', async () => {
|
2019-10-25 09:43:20 -05:00
|
|
|
const onChangeMock = jest.fn();
|
|
|
|
const options = createDefaultConfigOptions();
|
|
|
|
options.database = '[logstash-]YYYY.MM.DD.HH';
|
2022-01-12 03:19:10 -06:00
|
|
|
render(<ElasticDetails onChange={onChangeMock} value={options} />);
|
|
|
|
const selectEl = screen.getByLabelText('Pattern');
|
2019-10-25 09:43:20 -05:00
|
|
|
|
2022-01-12 03:19:10 -06:00
|
|
|
await selectEvent.select(selectEl, 'Monthly', { container: document.body });
|
2019-10-25 09:43:20 -05:00
|
|
|
|
2022-01-12 03:19:10 -06:00
|
|
|
expect(onChangeMock).toHaveBeenLastCalledWith(
|
|
|
|
expect.objectContaining({
|
|
|
|
database: '[logstash-]YYYY.MM',
|
|
|
|
jsonData: expect.objectContaining({ interval: 'Monthly' }),
|
|
|
|
})
|
|
|
|
);
|
2019-10-25 09:43:20 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('version change', () => {
|
2022-05-05 09:16:34 -05:00
|
|
|
const testCases = [{ version: '7.10+', maxConcurrentShardRequests: 6, expectedMaxConcurrentShardRequests: 6 }];
|
2019-10-25 09:43:20 -05:00
|
|
|
|
2021-01-20 00:59:48 -06:00
|
|
|
testCases.forEach((tc) => {
|
2022-01-12 03:19:10 -06:00
|
|
|
const onChangeMock = jest.fn();
|
|
|
|
it(`sets maxConcurrentShardRequests=${tc.expectedMaxConcurrentShardRequests} if version=${tc.version},`, async () => {
|
|
|
|
render(
|
|
|
|
<ElasticDetails
|
|
|
|
onChange={onChangeMock}
|
|
|
|
value={createDefaultConfigOptions({
|
2019-10-25 09:43:20 -05:00
|
|
|
maxConcurrentShardRequests: tc.maxConcurrentShardRequests,
|
2022-05-05 09:16:34 -05:00
|
|
|
esVersion: '7.0.0',
|
2022-01-12 03:19:10 -06:00
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const selectEl = screen.getByLabelText('ElasticSearch version');
|
2019-10-25 09:43:20 -05:00
|
|
|
|
2022-01-12 03:19:10 -06:00
|
|
|
await selectEvent.select(selectEl, tc.version, { container: document.body });
|
2019-10-25 09:43:20 -05:00
|
|
|
|
2022-01-12 03:19:10 -06:00
|
|
|
expect(onChangeMock).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({
|
|
|
|
jsonData: expect.objectContaining({ maxConcurrentShardRequests: tc.expectedMaxConcurrentShardRequests }),
|
|
|
|
})
|
2019-10-25 09:43:20 -05:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|