diff --git a/packages/lib/src/spatial-navigation/components/virtualizedGrid/SpatialNavigationVirtualizedGrid.test.tsx b/packages/lib/src/spatial-navigation/components/virtualizedGrid/SpatialNavigationVirtualizedGrid.test.tsx index e3e7099c..b167d8c0 100644 --- a/packages/lib/src/spatial-navigation/components/virtualizedGrid/SpatialNavigationVirtualizedGrid.test.tsx +++ b/packages/lib/src/spatial-navigation/components/virtualizedGrid/SpatialNavigationVirtualizedGrid.test.tsx @@ -38,7 +38,7 @@ describe('SpatialNavigationVirtualizedGrid', () => { { expect(screen).toMatchSnapshot(); const listElement = component.getByTestId(gridTestId); - expect(listElement).toHaveStyle({ height: 700 }); + expect(listElement).toHaveStyle({ height: 1000 }); expect(screen.getByText('button 1')).toBeTruthy(); expectButtonToHaveFocus(component, 'button 1'); @@ -72,7 +72,13 @@ describe('SpatialNavigationVirtualizedGrid', () => { expect(screen.getByText('button 13')).toBeTruthy(); expect(screen.getByText('button 14')).toBeTruthy(); expect(screen.getByText('button 15')).toBeTruthy(); - expect(screen.queryByText('button 16')).toBeFalsy(); + expect(screen.getByText('button 16')).toBeTruthy(); + expect(screen.getByText('button 17')).toBeTruthy(); + expect(screen.getByText('button 18')).toBeTruthy(); + expect(screen.getByText('button 19')).toBeTruthy(); + expect(screen.getByText('button 20')).toBeTruthy(); + expect(screen.getByText('button 21')).toBeTruthy(); + expect(screen.queryByText('button 22')).toBeFalsy(); }); it('handles correctly RIGHT & DOWN and RENDERS new elements accordingly while deleting elements that are too far from scroll when on stick to start scroll', () => { @@ -82,7 +88,7 @@ describe('SpatialNavigationVirtualizedGrid', () => { const listElement = component.getByTestId(gridTestId); expectListToHaveScroll(listElement, 0); - expect(listElement).toHaveStyle({ height: 700 }); + expect(listElement).toHaveStyle({ height: 1000 }); testRemoteControlManager.handleRight(); @@ -102,70 +108,69 @@ describe('SpatialNavigationVirtualizedGrid', () => { expect(screen.getByText('button 13')).toBeTruthy(); expect(screen.getByText('button 14')).toBeTruthy(); expect(screen.getByText('button 15')).toBeTruthy(); - expect(screen.queryByText('button 16')).toBeFalsy(); + expect(screen.getByText('button 16')).toBeTruthy(); + expect(screen.getByText('button 17')).toBeTruthy(); + expect(screen.getByText('button 18')).toBeTruthy(); + expect(screen.getByText('button 19')).toBeTruthy(); + expect(screen.getByText('button 20')).toBeTruthy(); + expect(screen.getByText('button 21')).toBeTruthy(); + expect(screen.queryByText('button 22')).toBeFalsy(); testRemoteControlManager.handleDown(); expectListToHaveScroll(listElement, -100); - - expect(screen.getByText('button 1')).toBeTruthy(); - expect(screen.getByText('button 2')).toBeTruthy(); - expect(screen.getByText('button 3')).toBeTruthy(); - expect(screen.getByText('button 4')).toBeTruthy(); - expect(screen.getByText('button 5')).toBeTruthy(); expectButtonToHaveFocus(component, 'button 5'); - expect(screen.getByText('button 6')).toBeTruthy(); - expect(screen.getByText('button 7')).toBeTruthy(); - expect(screen.getByText('button 8')).toBeTruthy(); - expect(screen.getByText('button 9')).toBeTruthy(); - expect(screen.getByText('button 10')).toBeTruthy(); - expect(screen.getByText('button 11')).toBeTruthy(); - expect(screen.getByText('button 12')).toBeTruthy(); - expect(screen.getByText('button 13')).toBeTruthy(); - expect(screen.getByText('button 14')).toBeTruthy(); - expect(screen.getByText('button 15')).toBeTruthy(); - expect(screen.queryByText('button 16')).toBeFalsy(); testRemoteControlManager.handleDown(); expectListToHaveScroll(listElement, -200); + expectButtonToHaveFocus(component, 'button 8'); + + testRemoteControlManager.handleDown(); + expectListToHaveScroll(listElement, -300); + expectButtonToHaveFocus(component, 'button 11'); expect(screen.queryByText('button 1')).toBeFalsy(); expect(screen.queryByText('button 2')).toBeFalsy(); expect(screen.queryByText('button 3')).toBeFalsy(); expect(screen.getByText('button 4')).toBeTruthy(); - expect(screen.getByText('button 5')).toBeTruthy(); - expect(screen.getByText('button 6')).toBeTruthy(); + + testRemoteControlManager.handleDown(); + expectListToHaveScroll(listElement, -400); + expectButtonToHaveFocus(component, 'button 14'); + + expect(screen.queryByText('button 4')).toBeFalsy(); + expect(screen.queryByText('button 5')).toBeFalsy(); + expect(screen.queryByText('button 6')).toBeFalsy(); expect(screen.getByText('button 7')).toBeTruthy(); - expect(screen.getByText('button 8')).toBeTruthy(); - expectButtonToHaveFocus(component, 'button 8'); - expect(screen.getByText('button 9')).toBeTruthy(); - expect(screen.getByText('button 10')).toBeTruthy(); - expect(screen.getByText('button 11')).toBeTruthy(); - expect(screen.getByText('button 12')).toBeTruthy(); - expect(screen.getByText('button 13')).toBeTruthy(); - expect(screen.getByText('button 14')).toBeTruthy(); - expect(screen.getByText('button 15')).toBeTruthy(); - expect(screen.getByText('button 16')).toBeTruthy(); - expect(screen.getByText('button 17')).toBeTruthy(); - expect(screen.getByText('button 18')).toBeTruthy(); - expect(screen.queryByText('button 19')).toBeFalsy(); - expect(screen).toMatchSnapshot(); + testRemoteControlManager.handleDown(); + expectListToHaveScroll(listElement, -500); + expectButtonToHaveFocus(component, 'button 17'); + + expect(screen.queryByText('button 7')).toBeFalsy(); + expect(screen.queryByText('button 8')).toBeFalsy(); + expect(screen.queryByText('button 9')).toBeFalsy(); + expect(screen.getByText('button 10')).toBeTruthy(); testRemoteControlManager.handleDown(); - expectListToHaveScroll(listElement, -300); - expectButtonToHaveFocus(component, 'button 11'); + expectListToHaveScroll(listElement, -600); + expectButtonToHaveFocus(component, 'button 20'); + + expect(screen.queryByText('button 7')).toBeFalsy(); + expect(screen.queryByText('button 8')).toBeFalsy(); + expect(screen.queryByText('button 9')).toBeFalsy(); + expect(screen.getByText('button 10')).toBeTruthy(); testRemoteControlManager.handleDown(); - expectListToHaveScroll(listElement, -400); - expectButtonToHaveFocus(component, 'button 14'); + expectListToHaveScroll(listElement, -700); + expectButtonToHaveFocus(component, 'button 23'); testRemoteControlManager.handleDown(); - expectListToHaveScroll(listElement, -400); - expectButtonToHaveFocus(component, 'button 17'); + expectListToHaveScroll(listElement, -700); + expectButtonToHaveFocus(component, 'button 26'); testRemoteControlManager.handleDown(); - expectListToHaveScroll(listElement, -400); - expectButtonToHaveFocus(component, 'button 19'); + expectListToHaveScroll(listElement, -700); + expectButtonToHaveFocus(component, 'button 28'); }); it('handles correctly RIGHT & DOWN and RENDERS new elements accordingly while deleting elements that are too far from scroll when on stick to end scroll', () => { diff --git a/packages/lib/src/spatial-navigation/components/virtualizedGrid/SpatialNavigationVirtualizedGrid.test.tsx.snap b/packages/lib/src/spatial-navigation/components/virtualizedGrid/SpatialNavigationVirtualizedGrid.test.tsx.snap index f37a4985..ffbe2415 100644 --- a/packages/lib/src/spatial-navigation/components/virtualizedGrid/SpatialNavigationVirtualizedGrid.test.tsx.snap +++ b/packages/lib/src/spatial-navigation/components/virtualizedGrid/SpatialNavigationVirtualizedGrid.test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`SpatialNavigationVirtualizedGrid handles correctly RIGHT & DOWN and RENDERS new elements accordingly while deleting elements that are too far from scroll when on stick to start scroll 1`] = ` +exports[`SpatialNavigationVirtualizedGrid renders the correct number of item 1`] = ` - - - - - button 4 - - - - - - - button 5 - - - - - - - button 6 - - - - - - - - button 7 - - - - - - button 8 - - - - - - - button 9 - - - - - - - - - - - button 10 + button 1 - button 11 + button 2 - button 12 + button 3 @@ -362,7 +144,7 @@ exports[`SpatialNavigationVirtualizedGrid handles correctly RIGHT & DOWN and REN "position": "absolute", "transform": [ { - "translateY": 400, + "translateY": 100, }, ], } @@ -380,8 +162,8 @@ exports[`SpatialNavigationVirtualizedGrid handles correctly RIGHT & DOWN and REN > - button 13 + button 4 - button 14 + button 5 - button 15 + button 6 @@ -471,7 +253,7 @@ exports[`SpatialNavigationVirtualizedGrid handles correctly RIGHT & DOWN and REN "position": "absolute", "transform": [ { - "translateY": 500, + "translateY": 200, }, ], } @@ -489,64 +271,8 @@ exports[`SpatialNavigationVirtualizedGrid handles correctly RIGHT & DOWN and REN > - - button 16 - - - - - - - button 17 - - - - - - button 18 - - - - - - - - -`; - -exports[`SpatialNavigationVirtualizedGrid renders the correct number of item 1`] = ` - - - - - - - - - button 1 + button 7 - button 2 + button 8 - button 3 + button 9 @@ -722,7 +362,7 @@ exports[`SpatialNavigationVirtualizedGrid renders the correct number of item 1`] "position": "absolute", "transform": [ { - "translateY": 100, + "translateY": 300, }, ], } @@ -740,8 +380,8 @@ exports[`SpatialNavigationVirtualizedGrid renders the correct number of item 1`] > - button 4 + button 10 - button 5 + button 11 - button 6 + button 12 @@ -831,7 +471,7 @@ exports[`SpatialNavigationVirtualizedGrid renders the correct number of item 1`] "position": "absolute", "transform": [ { - "translateY": 200, + "translateY": 400, }, ], } @@ -849,8 +489,8 @@ exports[`SpatialNavigationVirtualizedGrid renders the correct number of item 1`] > - button 7 + button 13 - button 8 + button 14 - button 9 + button 15 @@ -940,7 +580,7 @@ exports[`SpatialNavigationVirtualizedGrid renders the correct number of item 1`] "position": "absolute", "transform": [ { - "translateY": 300, + "translateY": 500, }, ], } @@ -958,8 +598,8 @@ exports[`SpatialNavigationVirtualizedGrid renders the correct number of item 1`] > - button 10 + button 16 - button 11 + button 17 - button 12 + button 18 @@ -1049,7 +689,7 @@ exports[`SpatialNavigationVirtualizedGrid renders the correct number of item 1`] "position": "absolute", "transform": [ { - "translateY": 400, + "translateY": 600, }, ], } @@ -1067,8 +707,8 @@ exports[`SpatialNavigationVirtualizedGrid renders the correct number of item 1`] > - button 13 + button 19 - button 14 + button 20 - button 15 + button 21 diff --git a/packages/lib/src/spatial-navigation/components/virtualizedList/SpatialNavigationVirtualizedList.test.tsx b/packages/lib/src/spatial-navigation/components/virtualizedList/SpatialNavigationVirtualizedList.test.tsx index 2fe3ea2f..3684b941 100644 --- a/packages/lib/src/spatial-navigation/components/virtualizedList/SpatialNavigationVirtualizedList.test.tsx +++ b/packages/lib/src/spatial-navigation/components/virtualizedList/SpatialNavigationVirtualizedList.test.tsx @@ -119,7 +119,13 @@ describe('SpatialNavigationVirtualizedList', () => { expect(button5).toBeTruthy(); const button6 = screen.queryByText('button 6'); - expect(button6).toBeFalsy(); + expect(button6).toBeTruthy(); + + const button7 = screen.queryByText('button 7'); + expect(button7).toBeTruthy(); + + const button8 = screen.queryByText('button 8'); + expect(button8).toBeFalsy(); }); it('handles correctly RIGHT and RENDERS new elements accordingly while deleting elements that are too far from scroll', async () => { @@ -138,17 +144,17 @@ describe('SpatialNavigationVirtualizedList', () => { expectListToHaveScroll(listElement, -100); expect(screen.getByText('button 1')).toBeTruthy(); - expect(screen.getByText('button 5')).toBeTruthy(); - expect(screen.queryByText('button 6')).toBeFalsy(); + expect(screen.getByText('button 7')).toBeTruthy(); + expect(screen.queryByText('button 8')).toBeFalsy(); testRemoteControlManager.handleRight(); expectButtonToHaveFocus(component, 'button 3'); expectListToHaveScroll(listElement, -200); - expect(screen.queryByText('button 1')).toBeFalsy(); + expect(screen.getByText('button 1')).toBeTruthy(); expect(screen.getByText('button 2')).toBeTruthy(); - expect(screen.getByText('button 6')).toBeTruthy(); - expect(screen.queryByText('button 7')).toBeFalsy(); + expect(screen.getByText('button 7')).toBeTruthy(); + expect(screen.queryByText('button 8')).toBeFalsy(); expect(screen).toMatchSnapshot(); @@ -156,10 +162,11 @@ describe('SpatialNavigationVirtualizedList', () => { expectButtonToHaveFocus(component, 'button 4'); expectListToHaveScroll(listElement, -300); - expect(screen.queryByText('button 2')).toBeFalsy(); + expect(screen.queryByText('button 1')).toBeFalsy(); + expect(screen.getByText('button 2')).toBeTruthy(); expect(screen.getByText('button 3')).toBeTruthy(); - expect(screen.getByText('button 7')).toBeTruthy(); - expect(screen.queryByText('button 8')).toBeFalsy(); + expect(screen.getByText('button 8')).toBeTruthy(); + expect(screen.queryByText('button 9')).toBeFalsy(); testRemoteControlManager.handleRight(); expectButtonToHaveFocus(component, 'button 5'); @@ -215,26 +222,28 @@ describe('SpatialNavigationVirtualizedList', () => { expectListToHaveScroll(listElement, -100); expect(screen.getByText('button 1')).toBeTruthy(); - expect(screen.getByText('button 5')).toBeTruthy(); - expect(screen.queryByText('button 6')).toBeFalsy(); + expect(screen.getByText('button 7')).toBeTruthy(); + expect(screen.queryByText('button 8')).toBeFalsy(); testRemoteControlManager.handleRight(); expectButtonToHaveFocus(component, 'button 3'); expectListToHaveScroll(listElement, -200); - expect(screen.queryByText('button 1')).toBeFalsy(); + expect(screen.getByText('button 1')).toBeTruthy(); expect(screen.getByText('button 2')).toBeTruthy(); - expect(screen.getByText('button 6')).toBeTruthy(); - expect(screen.queryByText('button 7')).toBeFalsy(); + expect(screen.getByText('button 7')).toBeTruthy(); + expect(screen.queryByText('button 8')).toBeFalsy(); testRemoteControlManager.handleRight(); expectButtonToHaveFocus(component, 'button 4'); expectListToHaveScroll(listElement, -300); - expect(screen.queryByText('button 2')).toBeFalsy(); + expect(screen.queryByText('button 1')).toBeFalsy(); + expect(screen.getByText('button 2')).toBeTruthy(); expect(screen.getByText('button 3')).toBeTruthy(); expect(screen.getByText('button 7')).toBeTruthy(); - expect(screen.queryByText('button 8')).toBeFalsy(); + expect(screen.getByText('button 8')).toBeTruthy(); + expect(screen.queryByText('button 9')).toBeFalsy(); testRemoteControlManager.handleRight(); expectButtonToHaveFocus(component, 'button 5'); @@ -344,33 +353,33 @@ describe('SpatialNavigationVirtualizedList', () => { expectListToHaveScroll(listElement, 0); expect(screen.getByText('button 1')).toBeTruthy(); - expect(screen.getByText('button 5')).toBeTruthy(); - expect(screen.queryByText('button 6')).toBeFalsy(); + expect(screen.getByText('button 7')).toBeTruthy(); + expect(screen.queryByText('button 8')).toBeFalsy(); testRemoteControlManager.handleRight(); expectButtonToHaveFocus(component, 'button 3'); expectListToHaveScroll(listElement, 0); expect(screen.getByText('button 1')).toBeTruthy(); - expect(screen.getByText('button 5')).toBeTruthy(); - expect(screen.queryByText('button 6')).toBeFalsy(); + expect(screen.getByText('button 7')).toBeTruthy(); + expect(screen.queryByText('button 8')).toBeFalsy(); testRemoteControlManager.handleRight(); expectButtonToHaveFocus(component, 'button 4'); expectListToHaveScroll(listElement, -100); expect(screen.getByText('button 1')).toBeTruthy(); - expect(screen.getByText('button 5')).toBeTruthy(); - expect(screen.queryByText('button 6')).toBeFalsy(); + expect(screen.getByText('button 7')).toBeTruthy(); + expect(screen.queryByText('button 8')).toBeFalsy(); testRemoteControlManager.handleRight(); expectButtonToHaveFocus(component, 'button 5'); expectListToHaveScroll(listElement, -200); - expect(screen.queryByText('button 1')).toBeFalsy(); + expect(screen.getByText('button 1')).toBeTruthy(); expect(screen.getByText('button 2')).toBeTruthy(); - expect(screen.getByText('button 6')).toBeTruthy(); - expect(screen.queryByText('button 7')).toBeFalsy(); + expect(screen.getByText('button 7')).toBeTruthy(); + expect(screen.queryByText('button 8')).toBeFalsy(); testRemoteControlManager.handleRight(); expectButtonToHaveFocus(component, 'button 6'); @@ -500,26 +509,25 @@ describe('SpatialNavigationVirtualizedList', () => { expectListToHaveScroll(listElement, -100); expect(screen.getByText('button 1')).toBeTruthy(); - expect(screen.getByText('button 5')).toBeTruthy(); - expect(screen.queryByText('button 6')).toBeFalsy(); + expect(screen.getByText('button 7')).toBeTruthy(); + expect(screen.queryByText('button 8')).toBeFalsy(); testRemoteControlManager.handleRight(); expectButtonToHaveFocus(component, 'button 3'); expectListToHaveScroll(listElement, -300); - expect(screen.queryByText('button 1')).toBeFalsy(); - expect(screen.getByText('button 2')).toBeTruthy(); - expect(screen.getByText('button 6')).toBeTruthy(); - expect(screen.queryByText('button 7')).toBeFalsy(); + expect(screen.getByText('button 1')).toBeTruthy(); + expect(screen.getByText('button 7')).toBeTruthy(); + expect(screen.queryByText('button 8')).toBeFalsy(); testRemoteControlManager.handleRight(); expectButtonToHaveFocus(component, 'button 4'); expectListToHaveScroll(listElement, -400); - expect(screen.queryByText('button 2')).toBeFalsy(); - expect(screen.getByText('button 3')).toBeTruthy(); - expect(screen.getByText('button 7')).toBeTruthy(); - expect(screen.queryByText('button 8')).toBeFalsy(); + expect(screen.queryByText('button 1')).toBeFalsy(); + expect(screen.getByText('button 2')).toBeTruthy(); + expect(screen.getByText('button 8')).toBeTruthy(); + expect(screen.queryByText('button 9')).toBeFalsy(); }); it('handles correctly different item sizes on stick to end scroll', async () => { @@ -549,33 +557,33 @@ describe('SpatialNavigationVirtualizedList', () => { expectListToHaveScroll(listElement, 0); expect(screen.getByText('button 1')).toBeTruthy(); - expect(screen.getByText('button 5')).toBeTruthy(); - expect(screen.queryByText('button 6')).toBeFalsy(); + expect(screen.getByText('button 7')).toBeTruthy(); + expect(screen.queryByText('button 8')).toBeFalsy(); testRemoteControlManager.handleRight(); expectButtonToHaveFocus(component, 'button 3'); expectListToHaveScroll(listElement, -100); - expect(screen.getByText('button 1')).toBeTruthy(); - expect(screen.getByText('button 5')).toBeTruthy(); - expect(screen.queryByText('button 6')).toBeFalsy(); - testRemoteControlManager.handleRight(); expectButtonToHaveFocus(component, 'button 4'); expectListToHaveScroll(listElement, -300); - expect(screen.getByText('button 1')).toBeTruthy(); - expect(screen.getByText('button 5')).toBeTruthy(); - expect(screen.queryByText('button 6')).toBeFalsy(); - testRemoteControlManager.handleRight(); expectButtonToHaveFocus(component, 'button 5'); expectListToHaveScroll(listElement, -400); + expect(screen.getByText('button 1')).toBeTruthy(); + expect(screen.getByText('button 7')).toBeTruthy(); + expect(screen.queryByText('button 8')).toBeFalsy(); + + testRemoteControlManager.handleRight(); + expectButtonToHaveFocus(component, 'button 6'); + expectListToHaveScroll(listElement, -600); + expect(screen.queryByText('button 1')).toBeFalsy(); - expect(screen.getByText('button 5')).toBeTruthy(); - expect(screen.getByText('button 5')).toBeTruthy(); - expect(screen.queryByText('button 7')).toBeFalsy(); + expect(screen.getByText('button 2')).toBeTruthy(); + expect(screen.getByText('button 8')).toBeTruthy(); + expect(screen.queryByText('button 9')).toBeFalsy(); }); it('jumps to first element on go to first button press', async () => { diff --git a/packages/lib/src/spatial-navigation/components/virtualizedList/SpatialNavigationVirtualizedList.test.tsx.snap b/packages/lib/src/spatial-navigation/components/virtualizedList/SpatialNavigationVirtualizedList.test.tsx.snap index 4462e6d2..f24e65d4 100644 --- a/packages/lib/src/spatial-navigation/components/virtualizedList/SpatialNavigationVirtualizedList.test.tsx.snap +++ b/packages/lib/src/spatial-navigation/components/virtualizedList/SpatialNavigationVirtualizedList.test.tsx.snap @@ -28,6 +28,46 @@ exports[`SpatialNavigationVirtualizedList handles correctly RIGHT and RENDERS ne testID="test-list" > + + + + button 1 + + + + + + + button 7 + + + @@ -461,6 +541,86 @@ exports[`SpatialNavigationVirtualizedList renders the correct number of item 1`] + + + + button 6 + + + + + + + button 7 + + + diff --git a/packages/lib/src/spatial-navigation/components/virtualizedList/helpers/getRange.test.ts b/packages/lib/src/spatial-navigation/components/virtualizedList/helpers/getRange.test.ts index f29b0c17..5070859b 100644 --- a/packages/lib/src/spatial-navigation/components/virtualizedList/helpers/getRange.test.ts +++ b/packages/lib/src/spatial-navigation/components/virtualizedList/helpers/getRange.test.ts @@ -58,18 +58,4 @@ describe('getRange for custom virtualized list', () => { expect(expectedResult).toEqual(result); expect(console.error).toHaveBeenCalledTimes(1); }); - - it('should throw an error if the numberOfRenderedItems is inferior to the numberOfItemsVisibleOnScreen + 2', () => { - const input = new Array(30).fill(1); - - expect(() => - getRange({ - data: input, - currentlyFocusedItemIndex: 5, - numberOfRenderedItems: 6, - numberOfItemsVisibleOnScreen: 8, - scrollBehavior: 'stick-to-start', - }), - ).toThrowError(); - }); });