import { splitItems } from "./splitItems" ; import { Chunk } from "../withMaxItems" ; describe ( "splitItems" , ( ) => { it ( "should split items according to maxItems (less items than maxItems)" , ( ) => { const maxItems = 4 ; const items = [ { id : "0" } , { id : "1" } , { id : "2" } ] ; const createId = jest . fn ( ) . mockReturnValue ( "id" ) ; const actual = splitItems ( maxItems , items , createId ) ; const expected = [ { id : "id" , items : [ { id : "0" } , { id : "1" } , { id : "2" } ] } ] ; expect ( actual ) . toEqual ( expected ) ; } ) ; it ( "should split items according to maxItems (as many items as maxItems)" , ( ) => { const maxItems = 4 ; const items = [ { id : "0" } , { id : "1" } , { id : "2" } , { id : "3" } ] ; const createId = jest . fn ( ) . mockReturnValue ( "id" ) ; const actual = splitItems ( maxItems , items , createId ) ; const expected = [ { id : "id" , items : [ { id : "0" } , { id : "1" } , { id : "2" } , { id : "3" } ] } ] ; expect ( actual ) . toEqual ( expected ) ; } ) ; it ( "should split items according to maxItems (more items than maxItems)" , ( ) => { const maxItems = 4 ; const items = [ { id : "0" } , { id : "1" } , { id : "2" } , { id : "3" } , { id : "4" } ] ; const createId = jest . fn ( ) . mockReturnValueOnce ( "id0" ) . mockReturnValueOnce ( "id1" ) ; const actual = splitItems ( maxItems , items , createId ) ; const expected = [ { id : "id0" , items : [ { id : "0" } , { id : "1" } , { id : "2" } , { id : "3" } ] } , { id : "id1" , items : [ { id : "4" } ] } ] ; expect ( actual ) . toEqual ( expected ) ; } ) ; } ) ;