DataSourceSettingsPage.test.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. const setup = (propOverrides?: object) => {
  9. const props: Props = {
  10. navModel: {} as NavModel,
  11. dataSource: getMockDataSource(),
  12. dataSourceMeta: getMockPlugin(),
  13. pageId: 1,
  14. deleteDataSource: jest.fn(),
  15. loadDataSource: jest.fn(),
  16. setDataSourceName: jest.fn(),
  17. updateDataSource: jest.fn(),
  18. setIsDefault: jest.fn(),
  19. };
  20. Object.assign(props, propOverrides);
  21. return shallow(<DataSourceSettingsPage {...props} />);
  22. };
  23. describe('Render', () => {
  24. it('should render component', () => {
  25. const wrapper = setup();
  26. expect(wrapper).toMatchSnapshot();
  27. });
  28. it('should render loader', () => {
  29. const wrapper = setup({
  30. dataSource: {} as DataSourceSettings,
  31. });
  32. expect(wrapper).toMatchSnapshot();
  33. });
  34. it('should render beta info text', () => {
  35. const wrapper = setup({
  36. dataSourceMeta: { ...getMockPlugin(), state: 'beta' },
  37. });
  38. expect(wrapper).toMatchSnapshot();
  39. });
  40. it('should render alpha info text', () => {
  41. const wrapper = setup({
  42. dataSourceMeta: { ...getMockPlugin(), state: 'alpha' },
  43. });
  44. expect(wrapper).toMatchSnapshot();
  45. });
  46. it('should render is ready only message', () => {
  47. const wrapper = setup({
  48. dataSource: { ...getMockDataSource(), readOnly: true },
  49. });
  50. expect(wrapper).toMatchSnapshot();
  51. });
  52. });