DataSourceSettingsPage.test.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 } 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 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. };
  21. Object.assign(props, propOverrides);
  22. return shallow(<DataSourceSettingsPage {...props} />);
  23. };
  24. describe('Render', () => {
  25. it('should render component', () => {
  26. const wrapper = setup();
  27. expect(wrapper).toMatchSnapshot();
  28. });
  29. it('should render loader', () => {
  30. const wrapper = setup({
  31. dataSource: {} as DataSourceSettings,
  32. });
  33. expect(wrapper).toMatchSnapshot();
  34. });
  35. it('should render beta info text', () => {
  36. const wrapper = setup({
  37. dataSourceMeta: { ...getMockPlugin(), state: 'beta' },
  38. });
  39. expect(wrapper).toMatchSnapshot();
  40. });
  41. it('should render alpha info text', () => {
  42. const wrapper = setup({
  43. dataSourceMeta: { ...getMockPlugin(), state: 'alpha' },
  44. });
  45. expect(wrapper).toMatchSnapshot();
  46. });
  47. it('should render is ready only message', () => {
  48. const wrapper = setup({
  49. dataSource: { ...getMockDataSource(), readOnly: true },
  50. });
  51. expect(wrapper).toMatchSnapshot();
  52. });
  53. });