DataSourceSettingsPage.test.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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, dataSourceLoaded } 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. dataSourceLoaded,
  27. query: {},
  28. ...propOverrides,
  29. };
  30. return shallow(<DataSourceSettingsPage {...props} />);
  31. };
  32. describe('Render', () => {
  33. it('should render component', () => {
  34. const wrapper = setup();
  35. expect(wrapper).toMatchSnapshot();
  36. });
  37. it('should render loader', () => {
  38. const wrapper = setup({
  39. dataSource: {} as DataSourceSettings,
  40. plugin: pluginMock,
  41. });
  42. expect(wrapper).toMatchSnapshot();
  43. });
  44. it('should render beta info text', () => {
  45. const wrapper = setup({
  46. dataSourceMeta: { ...getMockPlugin(), state: 'beta' },
  47. });
  48. expect(wrapper).toMatchSnapshot();
  49. });
  50. it('should render alpha info text', () => {
  51. const wrapper = setup({
  52. dataSourceMeta: { ...getMockPlugin(), state: 'alpha' },
  53. plugin: pluginMock,
  54. });
  55. expect(wrapper).toMatchSnapshot();
  56. });
  57. it('should render is ready only message', () => {
  58. const wrapper = setup({
  59. dataSource: { ...getMockDataSource(), readOnly: true },
  60. plugin: pluginMock,
  61. });
  62. expect(wrapper).toMatchSnapshot();
  63. });
  64. });