DataSourceSettingsPage.test.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. plugin: pluginMock,
  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. plugin: pluginMock,
  41. });
  42. expect(wrapper).toMatchSnapshot();
  43. });
  44. it('should render alpha info text', () => {
  45. const wrapper = setup({
  46. dataSourceMeta: { ...getMockPlugin(), state: 'alpha' },
  47. plugin: pluginMock,
  48. });
  49. expect(wrapper).toMatchSnapshot();
  50. });
  51. it('should render is ready only message', () => {
  52. const wrapper = setup({
  53. dataSource: { ...getMockDataSource(), readOnly: true },
  54. plugin: pluginMock,
  55. });
  56. expect(wrapper).toMatchSnapshot();
  57. });
  58. });