import React from 'react' ; import { shallow } from 'enzyme' ; import { EuiButtonIcon , EuiButtonIconColor } from '@elastic/eui' ; import { ResultActions } from './result_actions' ; describe ( 'ResultActions' , ( ) => { const actions = [ { title : 'Hide' , onClick : jest . fn ( ) , iconType : 'eyeClosed' , iconColor : 'danger' as EuiButtonIconColor , } , { title : 'Bookmark' , onClick : jest . fn ( ) , iconType : 'starFilled' , iconColor : undefined , } , ] ; const wrapper = shallow ( < ResultActions actions = { actions } / > ) ; const buttons = wrapper . find ( EuiButtonIcon ) ; it ( 'renders an action button for each action passed' , ( ) => { expect ( buttons ) . toHaveLength ( 2 ) ; } ) ; it ( 'passes icon props correctly' , ( ) => { expect ( buttons . first ( ) . prop ( 'iconType' ) ) . toEqual ( 'eyeClosed' ) ; expect ( buttons . first ( ) . prop ( 'color' ) ) . toEqual ( 'danger' ) ; expect ( buttons . last ( ) . prop ( 'iconType' ) ) . toEqual ( 'starFilled' ) ; expect ( buttons . last ( ) . prop ( 'color' ) ) . toEqual ( 'primary' ) ; } ) ; it ( 'passes click events' , ( ) => { buttons . first ( ) . simulate ( 'click' ) ; expect ( actions [ 0 ] . onClick ) . toHaveBeenCalled ( ) ; buttons . last ( ) . simulate ( 'click' ) ; expect ( actions [ 1 ] . onClick ) . toHaveBeenCalled ( ) ; } ) ; } ) ;