import React from "react" ; import { Props , withMaxItems , WithMaxItemsProps , DragAndDropResult } from "./withMaxItems" ; import { mount , ReactWrapper } from "enzyme" ; describe ( "withMaxItems" , ( ) => { it ( "Should split items in chunks according to the maxItems props" , ( ) => { const items = [ { id : "id0" } , { id : "id1" } , { id : "id2" } ] ; const dragAndDropResult = { source : { id : "id1" , index : 0 } , destination : { id : "id0" , index : 0 } } ; const Component = ( { onDragEnd } ) => ( < div onClick = { ( ) => onDragEnd ( dragAndDropResult ) } />); const createId = jest . fn ( ) . mockReturnValueOnce ( "id0" ) . mockReturnValueOnce ( "id1" ) ; const props = { items , maxItems : 2 , onDragEnd : jest . fn ( ) } ; const ComponentWithMaxItems = withMaxItems ( Component , createId ) ; const wrapper = mount ( < ComponentWithMaxItems { ... props } / > ) ; wrapper . simulate ( "click" ) ; expect ( props . onDragEnd ) . toHaveBeenCalledWith ( 2 , 0 ) ; } ) ; } ) ;