@@ -290,6 +290,138 @@ describe('computeTranslation for virtualized list with stick-to-end scroll behav
290290 } ) ;
291291} ) ;
292292
293+ describe ( 'computeTranslation for virtualized list with stick-to-center scroll behavior' , ( ) => {
294+ const scrollBehavior = 'stick-to-center' ;
295+
296+ it ( 'should not scroll if currentlyFocusedItemIndex < numberOfItemsVisibleOnScreen' , ( ) => {
297+ const expectedResult = computeTranslation ( {
298+ itemSizeInPx,
299+ currentlyFocusedItemIndex : 3 ,
300+ numberOfItemsVisibleOnScreen : 4 ,
301+ nbMaxOfItems : 11 ,
302+ scrollBehavior : scrollBehavior ,
303+ data,
304+ listSizeInPx : 40 ,
305+ maxPossibleLeftAlignedIndex : 7 ,
306+ maxPossibleRightAlignedIndex : 3 ,
307+ } ) ;
308+
309+ expect ( expectedResult ) . toEqual ( - 0 ) ;
310+ } ) ;
311+
312+ it ( 'should not scroll if currentlyFocusedItemIndex < numberOfItemsVisibleOnScreen with dynamic sizes' , ( ) => {
313+ const expectedResult = computeTranslation ( {
314+ itemSizeInPx : itemSizeInPxFunction ,
315+ currentlyFocusedItemIndex : 3 ,
316+ numberOfItemsVisibleOnScreen : 4 ,
317+ nbMaxOfItems : 11 ,
318+ scrollBehavior : scrollBehavior ,
319+ data,
320+ listSizeInPx : 40 ,
321+ maxPossibleLeftAlignedIndex : 7 ,
322+ maxPossibleRightAlignedIndex : 3 ,
323+ } ) ;
324+
325+ expect ( expectedResult ) . toEqual ( - 0 ) ;
326+ } ) ;
327+
328+ it ( 'should end-align focused item' , ( ) => {
329+ const expectedResult = computeTranslation ( {
330+ itemSizeInPx,
331+ currentlyFocusedItemIndex : 6 ,
332+ numberOfItemsVisibleOnScreen : 4 ,
333+ nbMaxOfItems : 11 ,
334+ scrollBehavior : scrollBehavior ,
335+ data,
336+ listSizeInPx : 40 ,
337+ maxPossibleLeftAlignedIndex : 7 ,
338+ maxPossibleRightAlignedIndex : 3 ,
339+ } ) ;
340+
341+ expect ( expectedResult ) . toEqual ( - 30 ) ;
342+ } ) ;
343+
344+ it ( 'should end-align focused item with dynamic sizes' , ( ) => {
345+ const expectedResult = computeTranslation ( {
346+ itemSizeInPx : itemSizeInPxFunction ,
347+ currentlyFocusedItemIndex : 6 ,
348+ numberOfItemsVisibleOnScreen : 4 ,
349+ nbMaxOfItems : 11 ,
350+ scrollBehavior : scrollBehavior ,
351+ data,
352+ listSizeInPx : 40 ,
353+ maxPossibleLeftAlignedIndex : 7 ,
354+ maxPossibleRightAlignedIndex : 3 ,
355+ } ) ;
356+
357+ expect ( expectedResult ) . toEqual ( - 60 ) ;
358+ } ) ;
359+
360+ it ( 'should end-align last element if focused' , ( ) => {
361+ const expectedResult = computeTranslation ( {
362+ itemSizeInPx,
363+ currentlyFocusedItemIndex : 10 ,
364+ numberOfItemsVisibleOnScreen : 4 ,
365+ nbMaxOfItems : 11 ,
366+ scrollBehavior : scrollBehavior ,
367+ data,
368+ listSizeInPx : 40 ,
369+ maxPossibleLeftAlignedIndex : 7 ,
370+ maxPossibleRightAlignedIndex : 3 ,
371+ } ) ;
372+
373+ expect ( expectedResult ) . toEqual ( - 70 ) ;
374+ } ) ;
375+
376+ it ( 'should end-align last element if focused with dynamic sizes' , ( ) => {
377+ const expectedResult = computeTranslation ( {
378+ itemSizeInPx : itemSizeInPxFunction ,
379+ currentlyFocusedItemIndex : 10 ,
380+ numberOfItemsVisibleOnScreen : 4 ,
381+ nbMaxOfItems : 11 ,
382+ scrollBehavior : scrollBehavior ,
383+ data,
384+ listSizeInPx : 40 ,
385+ maxPossibleLeftAlignedIndex : 7 ,
386+ maxPossibleRightAlignedIndex : 3 ,
387+ } ) ;
388+
389+ expect ( expectedResult ) . toEqual ( - 120 ) ;
390+ } ) ;
391+
392+ it ( 'should start-align first element if numberOfItems <= numberOfVisibleItemsOnScreen' , ( ) => {
393+ const expectedResult = computeTranslation ( {
394+ itemSizeInPx,
395+ currentlyFocusedItemIndex : 1 ,
396+ numberOfItemsVisibleOnScreen : 4 ,
397+ nbMaxOfItems : 3 ,
398+ scrollBehavior : scrollBehavior ,
399+ data,
400+ listSizeInPx : 40 ,
401+ maxPossibleLeftAlignedIndex : 7 ,
402+ maxPossibleRightAlignedIndex : 3 ,
403+ } ) ;
404+
405+ expect ( expectedResult ) . toEqual ( - 0 ) ;
406+ } ) ;
407+
408+ it ( 'should start-align first element if numberOfItems <= numberOfVisibleItemsOnScreen with dynamic sizes' , ( ) => {
409+ const expectedResult = computeTranslation ( {
410+ itemSizeInPx : itemSizeInPxFunction ,
411+ currentlyFocusedItemIndex : 1 ,
412+ numberOfItemsVisibleOnScreen : 4 ,
413+ nbMaxOfItems : 3 ,
414+ scrollBehavior : scrollBehavior ,
415+ data : data . slice ( 0 , 2 ) ,
416+ listSizeInPx : 40 ,
417+ maxPossibleLeftAlignedIndex : 0 ,
418+ maxPossibleRightAlignedIndex : 2 ,
419+ } ) ;
420+
421+ expect ( expectedResult ) . toEqual ( - 0 ) ;
422+ } ) ;
423+ } ) ;
424+
293425describe ( 'computeTranslation for virtualized list with jumping scroll behavior' , ( ) => {
294426 const scrollBehavior = 'jump-on-scroll' ;
295427
0 commit comments