import '../../../__mocks__/shallow_useeffect.mock' ; import { setMockValues , setMockActions } from '../../../__mocks__/kea_logic' ; import React from 'react' ; import { shallow } from 'enzyme' ; import { EuiSwitch , EuiConfirmModal } from '@elastic/eui' ; import { UnsavedChangesPrompt } from '../../../shared/unsaved_changes_prompt' ; import { getPageHeaderActions } from '../../../test_helpers' ; import { Security } from './security' ; describe ( 'Security' , ( ) => { const initializeSourceRestrictions = jest . fn ( ) ; const updatePrivateSourcesEnabled = jest . fn ( ) ; const updateRemoteEnabled = jest . fn ( ) ; const updateRemoteSource = jest . fn ( ) ; const updateStandardEnabled = jest . fn ( ) ; const updateStandardSource = jest . fn ( ) ; const saveSourceRestrictions = jest . fn ( ) ; const resetState = jest . fn ( ) ; const mockValues = { isEnabled : true , remote : { isEnabled : true , contentSources : [ ] } , standard : { isEnabled : true , contentSources : [ ] } , dataLoading : false , unsavedChanges : false , hasPlatinumLicense : true , } ; beforeEach ( ( ) => { setMockValues ( mockValues ) ; setMockActions ( { initializeSourceRestrictions , updatePrivateSourcesEnabled , updateRemoteEnabled , updateRemoteSource , updateStandardEnabled , updateStandardSource , saveSourceRestrictions , resetState , } ) ; } ) ; it ( 'renders' , ( ) => { setMockValues ( { ... mockValues , hasPlatinumLicense : false } ) ; const wrapper = shallow ( < Security />); expect ( wrapper . find ( UnsavedChangesPrompt ) ) . toHaveLength ( 1 ) ; expect ( wrapper . find ( EuiSwitch ) . prop ( 'disabled' ) ) . toEqual ( true ) ; } ) ; it ( 'does not disable switch on Platinum license' , ( ) => { const wrapper = shallow ( < Security />); expect ( wrapper . find ( EuiSwitch ) . prop ( 'disabled' ) ) . toEqual ( false ) ; } ) ; it ( 'handles switch click' , ( ) => { const wrapper = shallow ( < Security />); const privateSourcesSwitch = wrapper . find ( EuiSwitch ) ; const event = { target : { checked : true } } ; privateSourcesSwitch . prop ( 'onChange' ) ( event as any ) ; expect ( updatePrivateSourcesEnabled ) . toHaveBeenCalled ( ) ; } ) ; it ( 'handles confirmModal submission' , ( ) => { setMockValues ( { ... mockValues , unsavedChanges : true } ) ; const wrapper = shallow ( < Security />); const headerActions = getPageHeaderActions ( wrapper ) ; headerActions . find ( '[data-test-subj="SaveSettingsButton"]' ) . prop ( 'onClick' ) ! ( { } as any ) ; const modal = wrapper . find ( EuiConfirmModal ) ; modal . prop ( 'onConfirm' ) ! ( { } as any ) ; expect ( saveSourceRestrictions ) . toHaveBeenCalled ( ) ; } ) ; } ) ;