DataSourcesListPage.test.tsx 1.4 KB

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