import React from 'react' ; import { mount } from '@cypress/react' ; import HoverVideoPlayer from 'react-hover-video-player' ; import { makeMockVideoSrc } from '../utils' ; describe ( 'onHoverStart and onHoverEnd callbacks' , ( ) => { it ( 'Fires onHoverStart callback correctly' , ( ) => { const onHoverStart = cy . stub ( ) . as ( 'onHoverStart' ) ; mount ( < HoverVideoPlayer videoSrc = { makeMockVideoSrc ( ) } onHoverStart = { onHoverStart } / > ) ; cy . get ( '@onHoverStart' ) . should ( 'not.have.been.called' ) ; cy . triggerEventOnPlayer ( 'mouseenter' ) ; cy . get ( '@onHoverStart' ) . should ( 'have.been.calledOnce' ) ; cy . triggerEventOnPlayer ( 'mouseleave' ) ; cy . get ( '@onHoverStart' ) . should ( 'have.been.calledOnce' ) ; cy . triggerEventOnPlayer ( 'touchstart' ) ; cy . get ( '@onHoverStart' ) . should ( 'have.been.calledTwice' ) ; } ) ; it ( 'Fires onHoverEnd callback correctly' , ( ) => { const onHoverEnd = cy . stub ( ) . as ( 'onHoverEnd' ) ; mount ( < HoverVideoPlayer videoSrc = { makeMockVideoSrc ( ) } onHoverEnd = { onHoverEnd } / > ) ; cy . triggerEventOnPlayer ( 'mouseenter' ) ; cy . get ( '@onHoverEnd' ) . should ( 'not.have.been.called' ) ; cy . triggerEventOnPlayer ( 'mouseleave' ) ; cy . get ( '@onHoverEnd' ) . should ( 'have.been.calledOnce' ) ; cy . triggerEventOnPlayer ( 'touchstart' ) ; cy . get ( '@onHoverEnd' ) . should ( 'have.been.calledOnce' ) ; cy . document ( ) . then ( ( doc ) => { doc . body . dispatchEvent ( new TouchEvent ( 'touchstart' , { bubbles : true , } ) ) ; } ) ; cy . get ( '@onHoverEnd' ) . should ( 'have.been.calledTwice' ) ; } ) ; it ( 'Fires hover state callbacks correctly when both are provided' , ( ) => { const onHoverStart = cy . stub ( ) . as ( 'onHoverStart' ) ; const onHoverEnd = cy . stub ( ) . as ( 'onHoverEnd' ) ; mount ( < HoverVideoPlayer videoSrc = { makeMockVideoSrc ( ) } onHoverStart = { onHoverStart } onHoverEnd = { onHoverEnd } / > ) ; cy . get ( '@onHoverStart' ) . should ( 'not.have.been.called' ) ; cy . get ( '@onHoverEnd' ) . should ( 'not.have.been.called' ) ; cy . triggerEventOnPlayer ( 'mouseenter' ) ; cy . get ( '@onHoverStart' ) . should ( 'have.been.calledOnce' ) ; cy . get ( '@onHoverEnd' ) . should ( 'not.have.been.called' ) ; cy . triggerEventOnPlayer ( 'mouseleave' ) ; cy . get ( '@onHoverEnd' ) . should ( 'have.been.calledOnce' ) ; cy . get ( '@onHoverStart' ) . should ( 'have.been.calledOnce' ) ; } ) ; } ) ;