import React from 'react' ; import { mount as enzymeMount , ReactWrapper } from 'enzyme' ; import { keys } from '@elastic/eui' ; import { ServicesProvider , SharedUXServices } from '../../services' ; import { servicesFactory } from '../../services/mocks' ; import { ExitFullScreenButton } from './exit_full_screen_button' ; describe ( '<ExitFullScreenButton />' , ( ) => { let services ; let mount ; beforeEach ( ( ) => { services = servicesFactory ( ) ; mount = ( element ) => enzymeMount ( < ServicesProvider { ... services } > { element } < /ServicesProvider>); } ) ; afterEach ( ( ) => { jest . resetAllMocks ( ) ; } ) ; test ( 'is rendered' , ( ) => { const component = mount ( < ExitFullScreenButton onExit = { jest . fn ( ) } / > ) ; expect ( component ) . toMatchSnapshot ( ) ; } ) ; test ( 'passing `false` to toggleChrome does not toggle chrome' , ( ) => { const component = mount ( < ExitFullScreenButton onExit = { jest . fn ( ) } toggleChrome = { false } / > ) ; expect ( services . platform . setIsFullscreen ) . toHaveBeenCalledTimes ( 0 ) ; component . unmount ( ) ; expect ( services . platform . setIsFullscreen ) . toHaveBeenCalledTimes ( 0 ) ; } ) ; describe ( 'onExit' , ( ) => { const onExitHandler = jest . fn ( ) ; let component ; beforeEach ( ( ) => { component = mount ( < ExitFullScreenButton onExit = { onExitHandler } toggleChrome = { true } / > ) ; } ) ; test ( 'is called when the button is pressed' , ( ) => { expect ( services . platform . setIsFullscreen ) . toHaveBeenLastCalledWith ( false ) ; component . find ( 'button' ) . simulate ( 'click' ) ; expect ( onExitHandler ) . toHaveBeenCalledTimes ( 1 ) ; component . unmount ( ) ; expect ( services . platform . setIsFullscreen ) . toHaveBeenLastCalledWith ( true ) ; } ) ; test ( 'is called when the ESC key is pressed' , ( ) => { expect ( services . platform . setIsFullscreen ) . toHaveBeenLastCalledWith ( false ) ; const escapeKeyEvent = new KeyboardEvent ( 'keydown' , { key : keys . ESCAPE } as any ) ; document . dispatchEvent ( escapeKeyEvent ) ; expect ( onExitHandler ) . toHaveBeenCalledTimes ( 1 ) ; component . unmount ( ) ; expect ( services . platform . setIsFullscreen ) . toHaveBeenLastCalledWith ( true ) ; } ) ; } ) ; } ) ;