ConfigEditor.test.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. import { mount } from 'enzyme';
  2. import React from 'react';
  3. import { DataSourceHttpSettings } from '@grafana/ui';
  4. import { createDefaultConfigOptions } from '../mocks';
  5. import { ConfigEditor } from './ConfigEditor';
  6. import { DerivedFields } from './DerivedFields';
  7. describe('ConfigEditor', () => {
  8. it('should render without error', () => {
  9. mount(<ConfigEditor onOptionsChange={() => {}} options={createDefaultConfigOptions()} />);
  10. });
  11. it('should render the right sections', () => {
  12. const wrapper = mount(<ConfigEditor onOptionsChange={() => {}} options={createDefaultConfigOptions()} />);
  13. expect(wrapper.find(DataSourceHttpSettings).length).toBe(1);
  14. expect(wrapper.find({ label: 'Maximum lines' }).length).toBe(1);
  15. expect(wrapper.find(DerivedFields).length).toBe(1);
  16. });
  17. it('should pass correct data to onChange', () => {
  18. const onChangeMock = jest.fn();
  19. const wrapper = mount(<ConfigEditor onOptionsChange={onChangeMock} options={createDefaultConfigOptions()} />);
  20. const inputWrapper = wrapper.find({ label: 'Maximum lines' }).find('input');
  21. (inputWrapper.getDOMNode() as any).value = 42;
  22. inputWrapper.simulate('change');
  23. expect(onChangeMock.mock.calls[0][0].jsonData.maxLines).toBe('42');
  24. });
  25. });