import React from 'react' ; import { shallowWithIntl } from '@kbn/test/jest' ; import { FullTimeRangeSelector } from './index' ; import type { Query } from 'src/plugins/data/public' ; import type { DataView } from '../../../../../../../src/plugins/data_views/public' ; const mockSetFullTimeRange = jest . fn ( ( indexPattern , query ) => true ) ; jest . mock ( './full_time_range_selector_service' , ( ) => ( { setFullTimeRange : ( indexPattern , query ) => mockSetFullTimeRange ( indexPattern , query ) , } ) ) ; jest . mock ( '../../contexts/ml/use_storage' , ( ) => { return { useStorage : jest . fn ( ( ) => 'exclude-frozen' ) , } ; } ) ; describe ( 'FullTimeRangeSelector' , ( ) => { const dataView = { id : '0844fc70-5ab5-11e9-935e-836737467b0f' , fields : [ ] , title : 'test-data-view' , timeFieldName : '@timestamp' , } as unknown as DataView ; const query = { language : 'kuery' , query : 'region:us-east-1' , } ; const requiredProps = { dataView , query , } ; test ( 'renders the selector' , ( ) => { const props = { ... requiredProps , disabled : false , } ; const wrapper = shallowWithIntl ( < FullTimeRangeSelector { ... props } / > ) ; expect ( wrapper ) . toMatchSnapshot ( ) ; } ) ; test ( 'calls setFullTimeRange on clicking button' , ( ) => { const props = { ... requiredProps , disabled : false , } ; const wrapper = shallowWithIntl ( < FullTimeRangeSelector { ... props } / > ) ; wrapper . find ( 'EuiButton' ) . simulate ( 'click' ) ; expect ( mockSetFullTimeRange ) . toHaveBeenCalled ( ) ; } ) ; } ) ;