import { act } from 'react-dom/test-utils' ; import { TestBed } from '@kbn/test/jest' ; import { Phase } from '../../../../common/types' ; import { createFormToggleAction } from './form_toggle_action' ; export const createSearchableSnapshotActions = ( testBed , phase ) => { const { exists , find , component } = testBed ; const fieldSelector = `searchableSnapshotField-${ phase }` ; const licenseCalloutSelector = `${ fieldSelector }.searchableSnapshotDisabledDueToLicense` ; const toggleSelector = `${ fieldSelector }.searchableSnapshotToggle` ; const toggleSearchableSnapshot = createFormToggleAction ( testBed , toggleSelector ) ; return { searchableSnapshotDisabledDueToLicense : ( ) => exists ( licenseCalloutSelector ) && find ( toggleSelector ) . props ( ) . disabled === true , searchableSnapshotsExists : ( ) => exists ( fieldSelector ) , toggleSearchableSnapshot , setSearchableSnapshot : async ( value ) => { if ( ! exists ( `searchableSnapshotField-${ phase }.searchableSnapshotCombobox` ) ) { await toggleSearchableSnapshot ( ) ; } act ( ( ) => { find ( `searchableSnapshotField-${ phase }.searchableSnapshotCombobox` ) . simulate ( 'change' , [ { label : value } , ] ) ; } ) ; component . update ( ) ; } , } ; } ;