DataSourcesListPage.test.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import React from 'react';
  2. import { shallow } from 'enzyme';
  3. import { DataSourcesListPage, Props } from './DataSourcesListPage';
  4. import { NavModel } from 'app/types';
  5. import { DataSourceSettings } from '@grafana/ui/src/types';
  6. import { LayoutModes } from '../../core/components/LayoutSelector/LayoutSelector';
  7. import { getMockDataSources } from './__mocks__/dataSourcesMocks';
  8. import { setDataSourcesSearchQuery, setDataSourcesLayoutMode } from './state/actions';
  9. const setup = (propOverrides?: object) => {
  10. const props: Props = {
  11. dataSources: [] as DataSourceSettings[],
  12. layoutMode: LayoutModes.Grid,
  13. loadDataSources: jest.fn(),
  14. navModel: {
  15. main: {
  16. text: 'Configuration',
  17. },
  18. node: {
  19. text: 'Data Sources',
  20. },
  21. } as NavModel,
  22. dataSourcesCount: 0,
  23. searchQuery: '',
  24. setDataSourcesSearchQuery,
  25. setDataSourcesLayoutMode,
  26. hasFetched: false,
  27. };
  28. Object.assign(props, propOverrides);
  29. return shallow(<DataSourcesListPage {...props} />);
  30. };
  31. describe('Render', () => {
  32. it('should render component', () => {
  33. const wrapper = setup();
  34. expect(wrapper).toMatchSnapshot();
  35. });
  36. it('should render action bar and datasources', () => {
  37. const wrapper = setup({
  38. dataSources: getMockDataSources(5),
  39. dataSourcesCount: 5,
  40. hasFetched: true,
  41. });
  42. expect(wrapper).toMatchSnapshot();
  43. });
  44. });