DataSourceSettings.test.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. setIsDefault: jest.fn(),
  18. };
  19. Object.assign(props, propOverrides);
  20. return shallow(<DataSourceSettings {...props} />);
  21. };
  22. describe('Render', () => {
  23. it('should render component', () => {
  24. const wrapper = setup();
  25. expect(wrapper).toMatchSnapshot();
  26. });
  27. it('should render loader', () => {
  28. const wrapper = setup({
  29. dataSource: {} as DataSource,
  30. });
  31. expect(wrapper).toMatchSnapshot();
  32. });
  33. it('should render beta info text', () => {
  34. const wrapper = setup({
  35. dataSourceMeta: { ...getMockPlugin(), state: 'beta' },
  36. });
  37. expect(wrapper).toMatchSnapshot();
  38. });
  39. it('should render alpha info text', () => {
  40. const wrapper = setup({
  41. dataSourceMeta: { ...getMockPlugin(), state: 'alpha' },
  42. });
  43. expect(wrapper).toMatchSnapshot();
  44. });
  45. it('should render is ready only message', () => {
  46. const wrapper = setup({
  47. dataSource: { ...getMockDataSource(), readOnly: true },
  48. });
  49. expect(wrapper).toMatchSnapshot();
  50. });
  51. });