DataSourceSettingsPage.test.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import React from 'react';
  2. import { shallow } from 'enzyme';
  3. import { DataSourceSettingsPage, Props } from './DataSourceSettingsPage';
  4. import { NavModel, DataSourceSettings, DataSourcePlugin, DataSourceConstructor } from '@grafana/ui';
  5. import { getMockDataSource } from '../__mocks__/dataSourcesMocks';
  6. import { getMockPlugin } from '../../plugins/__mocks__/pluginMocks';
  7. import { setDataSourceName, setIsDefault } from '../state/actions';
  8. const pluginMock = new DataSourcePlugin({} as DataSourceConstructor<any>);
  9. const setup = (propOverrides?: object) => {
  10. const props: Props = {
  11. navModel: {} as NavModel,
  12. dataSource: getMockDataSource(),
  13. dataSourceMeta: getMockPlugin(),
  14. pageId: 1,
  15. deleteDataSource: jest.fn(),
  16. loadDataSource: jest.fn(),
  17. setDataSourceName,
  18. updateDataSource: jest.fn(),
  19. setIsDefault,
  20. query: {},
  21. ...propOverrides,
  22. };
  23. return shallow(<DataSourceSettingsPage {...props} />);
  24. };
  25. describe('Render', () => {
  26. it('should render component', () => {
  27. const wrapper = setup();
  28. expect(wrapper).toMatchSnapshot();
  29. });
  30. it('should render loader', () => {
  31. const wrapper = setup({
  32. dataSource: {} as DataSourceSettings,
  33. plugin: pluginMock,
  34. });
  35. expect(wrapper).toMatchSnapshot();
  36. });
  37. it('should render beta info text', () => {
  38. const wrapper = setup({
  39. dataSourceMeta: { ...getMockPlugin(), state: 'beta' },
  40. });
  41. expect(wrapper).toMatchSnapshot();
  42. });
  43. it('should render alpha info text', () => {
  44. const wrapper = setup({
  45. dataSourceMeta: { ...getMockPlugin(), state: 'alpha' },
  46. plugin: pluginMock,
  47. });
  48. expect(wrapper).toMatchSnapshot();
  49. });
  50. it('should render is ready only message', () => {
  51. const wrapper = setup({
  52. dataSource: { ...getMockDataSource(), readOnly: true },
  53. plugin: pluginMock,
  54. });
  55. expect(wrapper).toMatchSnapshot();
  56. });
  57. });