DataSourceSettings.test.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import React from 'react';
  2. import { shallow } from 'enzyme';
  3. import { DataSourceSettings, Props } from './DataSourceSettings';
  4. import { DataSource, NavModel } from '../../../types';
  5. import { getMockDataSource } from '../__mocks__/dataSourcesMocks';
  6. import { getMockPlugin } from '../../plugins/__mocks__/pluginMocks';
  7. const setup = (propOverrides?: object) => {
  8. const props: Props = {
  9. navModel: {} as NavModel,
  10. dataSource: getMockDataSource(),
  11. dataSourceMeta: getMockPlugin(),
  12. pageId: 1,
  13. deleteDataSource: jest.fn(),
  14. loadDataSource: jest.fn(),
  15. setDataSourceName: jest.fn(),
  16. updateDataSource: jest.fn(),
  17. };
  18. Object.assign(props, propOverrides);
  19. return shallow(<DataSourceSettings {...props} />);
  20. };
  21. describe('Render', () => {
  22. it('should render component', () => {
  23. const wrapper = setup();
  24. expect(wrapper).toMatchSnapshot();
  25. });
  26. it('should render loader', () => {
  27. const wrapper = setup({
  28. dataSource: {} as DataSource,
  29. });
  30. expect(wrapper).toMatchSnapshot();
  31. });
  32. it('should render beta info text', () => {
  33. const wrapper = setup({
  34. dataSourceMeta: { ...getMockPlugin(), state: 'beta' },
  35. });
  36. expect(wrapper).toMatchSnapshot();
  37. });
  38. it('should render alpha info text', () => {
  39. const wrapper = setup({
  40. dataSourceMeta: { ...getMockPlugin(), state: 'alpha' },
  41. });
  42. expect(wrapper).toMatchSnapshot();
  43. });
  44. it('should render is ready only message', () => {
  45. const wrapper = setup({
  46. dataSource: { ...getMockDataSource(), readOnly: true },
  47. });
  48. expect(wrapper).toMatchSnapshot();
  49. });
  50. });