DataSourceSettingsPage.test.tsx 1.9 KB

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