ElasticDetails.test.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { render, screen } from '@testing-library/react';
  2. import React from 'react';
  3. import selectEvent from 'react-select-event';
  4. import { ElasticDetails } from './ElasticDetails';
  5. import { createDefaultConfigOptions } from './mocks';
  6. describe('ElasticDetails', () => {
  7. describe('Max concurrent Shard Requests', () => {
  8. it('should render "Max concurrent Shard Requests" if version >= 5.6.0', () => {
  9. render(<ElasticDetails onChange={() => {}} value={createDefaultConfigOptions({ esVersion: '5.6.0' })} />);
  10. expect(screen.getByLabelText('Max concurrent Shard Requests')).toBeInTheDocument();
  11. });
  12. it('should not render "Max concurrent Shard Requests" if version < 5.6.0', () => {
  13. render(<ElasticDetails onChange={() => {}} value={createDefaultConfigOptions({ esVersion: '5.0.0' })} />);
  14. expect(screen.queryByLabelText('Max concurrent Shard Requests')).not.toBeInTheDocument();
  15. });
  16. });
  17. it('should change database on interval change when not set explicitly', async () => {
  18. const onChangeMock = jest.fn();
  19. render(<ElasticDetails onChange={onChangeMock} value={createDefaultConfigOptions()} />);
  20. const selectEl = screen.getByLabelText('Pattern');
  21. await selectEvent.select(selectEl, 'Daily', { container: document.body });
  22. expect(onChangeMock).toHaveBeenLastCalledWith(
  23. expect.objectContaining({
  24. database: '[logstash-]YYYY.MM.DD',
  25. jsonData: expect.objectContaining({ interval: 'Daily' }),
  26. })
  27. );
  28. });
  29. it('should change database on interval change if pattern is from example', async () => {
  30. const onChangeMock = jest.fn();
  31. const options = createDefaultConfigOptions();
  32. options.database = '[logstash-]YYYY.MM.DD.HH';
  33. render(<ElasticDetails onChange={onChangeMock} value={options} />);
  34. const selectEl = screen.getByLabelText('Pattern');
  35. await selectEvent.select(selectEl, 'Monthly', { container: document.body });
  36. expect(onChangeMock).toHaveBeenLastCalledWith(
  37. expect.objectContaining({
  38. database: '[logstash-]YYYY.MM',
  39. jsonData: expect.objectContaining({ interval: 'Monthly' }),
  40. })
  41. );
  42. });
  43. describe('version change', () => {
  44. const testCases = [{ version: '7.10+', maxConcurrentShardRequests: 6, expectedMaxConcurrentShardRequests: 6 }];
  45. testCases.forEach((tc) => {
  46. const onChangeMock = jest.fn();
  47. it(`sets maxConcurrentShardRequests=${tc.expectedMaxConcurrentShardRequests} if version=${tc.version},`, async () => {
  48. render(
  49. <ElasticDetails
  50. onChange={onChangeMock}
  51. value={createDefaultConfigOptions({
  52. maxConcurrentShardRequests: tc.maxConcurrentShardRequests,
  53. esVersion: '7.0.0',
  54. })}
  55. />
  56. );
  57. const selectEl = screen.getByLabelText('ElasticSearch version');
  58. await selectEvent.select(selectEl, tc.version, { container: document.body });
  59. expect(onChangeMock).toHaveBeenCalledWith(
  60. expect.objectContaining({
  61. jsonData: expect.objectContaining({ maxConcurrentShardRequests: tc.expectedMaxConcurrentShardRequests }),
  62. })
  63. );
  64. });
  65. });
  66. });
  67. });