DataSourceSettingsPage.test.tsx 2.0 KB

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