Skip to content

Commit

Permalink
test: fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienIzz committed Sep 18, 2024
1 parent 502355c commit 2e977e6
Show file tree
Hide file tree
Showing 5 changed files with 340 additions and 541 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('SpatialNavigationVirtualizedGrid', () => {
<DefaultFocus>
<SpatialNavigationVirtualizedGrid
renderItem={renderItem}
data={createDataArray(19)}
data={createDataArray(28)}
itemHeight={100}
numberOfColumns={3}
testID="test-grid"
Expand All @@ -54,7 +54,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');
Expand All @@ -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', () => {
Expand All @@ -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();

Expand All @@ -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', () => {
Expand Down
Loading

0 comments on commit 2e977e6

Please sign in to comment.