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