ConfigEditor.test.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { mount, shallow } from 'enzyme';
  2. import React from 'react';
  3. import { DataSourceHttpSettings } from '@grafana/ui';
  4. import { ConfigEditor } from './ConfigEditor';
  5. import { ElasticDetails } from './ElasticDetails';
  6. import { LogsConfig } from './LogsConfig';
  7. import { createDefaultConfigOptions } from './mocks';
  8. describe('ConfigEditor', () => {
  9. it('should render without error', () => {
  10. mount(<ConfigEditor onOptionsChange={() => {}} options={createDefaultConfigOptions()} />);
  11. });
  12. it('should render all parts of the config', () => {
  13. const wrapper = shallow(<ConfigEditor onOptionsChange={() => {}} options={createDefaultConfigOptions()} />);
  14. expect(wrapper.find(DataSourceHttpSettings).length).toBe(1);
  15. expect(wrapper.find(ElasticDetails).length).toBe(1);
  16. expect(wrapper.find(LogsConfig).length).toBe(1);
  17. });
  18. it('should set defaults', () => {
  19. const options = createDefaultConfigOptions();
  20. // @ts-ignore
  21. delete options.jsonData.esVersion;
  22. // @ts-ignore
  23. delete options.jsonData.timeField;
  24. delete options.jsonData.maxConcurrentShardRequests;
  25. expect.assertions(3);
  26. mount(
  27. <ConfigEditor
  28. onOptionsChange={(options) => {
  29. expect(options.jsonData.esVersion).toBe('5.0.0');
  30. expect(options.jsonData.timeField).toBe('@timestamp');
  31. expect(options.jsonData.maxConcurrentShardRequests).toBe(256);
  32. }}
  33. options={options}
  34. />
  35. );
  36. });
  37. it('should not apply default if values are set', () => {
  38. const onChange = jest.fn();
  39. mount(<ConfigEditor onOptionsChange={onChange} options={createDefaultConfigOptions()} />);
  40. expect(onChange).toHaveBeenCalledTimes(0);
  41. });
  42. });