DataSourceSettingsPage.test.tsx 2.0 KB

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