import { setMockActions , setMockValues } from '../../../__mocks__/kea_logic' ; import '../../../__mocks__/shallow_useeffect.mock' ; import '../../__mocks__/engine_logic.mock' ; import React from 'react' ; import { shallow } from 'enzyme' ; import { getPageHeaderActions } from '../../../test_helpers' ; import { AddSourceEnginesButton , AddSourceEnginesModal , SourceEnginesTable } from './components' ; import { SourceEngines } from '.' ; describe ( 'SourceEngines' , ( ) => { const MOCK_ACTIONS = { fetchIndexedEngines : jest . fn ( ) , fetchSourceEngines : jest . fn ( ) , } ; const MOCK_VALUES = { myRole : { canManageMetaEngineSourceEngines : true , } , dataLoading : false , isModalOpen : false , } ; beforeEach ( ( ) => { jest . clearAllMocks ( ) ; setMockValues ( MOCK_VALUES ) ; setMockActions ( MOCK_ACTIONS ) ; } ) ; it ( 'renders and calls a function to initialize data' , ( ) => { const wrapper = shallow ( < SourceEngines />); expect ( wrapper . find ( SourceEnginesTable ) ) . toHaveLength ( 1 ) ; expect ( MOCK_ACTIONS . fetchIndexedEngines ) . toHaveBeenCalled ( ) ; expect ( MOCK_ACTIONS . fetchSourceEngines ) . toHaveBeenCalled ( ) ; } ) ; it ( 'renders the add source engines modal' , ( ) => { setMockValues ( { ... MOCK_VALUES , isModalOpen : true , } ) ; const wrapper = shallow ( < SourceEngines />); expect ( wrapper . find ( AddSourceEnginesModal ) ) . toHaveLength ( 1 ) ; } ) ; describe ( 'page actions' , ( ) => { it ( 'contains a button to add source engines' , ( ) => { const wrapper = shallow ( < SourceEngines />); expect ( getPageHeaderActions ( wrapper ) . find ( AddSourceEnginesButton ) ) . toHaveLength ( 1 ) ; } ) ; it ( 'hides the add source engines button if the user does not have permissions' , ( ) => { setMockValues ( { ... MOCK_VALUES , myRole : { canManageMetaEngineSourceEngines : false , } , } ) ; const wrapper = shallow ( < SourceEngines />); expect ( getPageHeaderActions ( wrapper ) . find ( AddSourceEnginesButton ) ) . toHaveLength ( 0 ) ; } ) ; } ) ; } ) ;