|
|
|
@ -62,11 +62,15 @@ function setup( |
|
|
|
|
) { |
|
|
|
|
const { element, events } = getMockElement(startPosition); |
|
|
|
|
|
|
|
|
|
function scrollTo(position: number) { |
|
|
|
|
function scrollTo(position: number, timeStamp?: number) { |
|
|
|
|
element.scrollTop = position; |
|
|
|
|
|
|
|
|
|
act(() => { |
|
|
|
|
events['scroll'](new Event('scroll')); |
|
|
|
|
const event = new Event('scroll'); |
|
|
|
|
if (timeStamp) { |
|
|
|
|
jest.spyOn(event, 'timeStamp', 'get').mockReturnValue(timeStamp); |
|
|
|
|
} |
|
|
|
|
events['scroll'](event); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// When scrolling top, we wait for the user to reach the top, and then for a new scrolling event
|
|
|
|
@ -153,7 +157,8 @@ describe('InfiniteScroll', () => { |
|
|
|
|
|
|
|
|
|
expect(await screen.findByTestId('contents')).toBeInTheDocument(); |
|
|
|
|
|
|
|
|
|
scrollTo(endPosition); |
|
|
|
|
scrollTo(endPosition - 1, 1); |
|
|
|
|
scrollTo(endPosition, 600); |
|
|
|
|
|
|
|
|
|
expect(loadMoreMock).toHaveBeenCalled(); |
|
|
|
|
expect(await screen.findByTestId('Spinner')).toBeInTheDocument(); |
|
|
|
@ -177,7 +182,8 @@ describe('InfiniteScroll', () => { |
|
|
|
|
|
|
|
|
|
expect(await screen.findByTestId('contents')).toBeInTheDocument(); |
|
|
|
|
|
|
|
|
|
wheel(deltaY); |
|
|
|
|
wheel(deltaY, 1); |
|
|
|
|
wheel(deltaY, 600); |
|
|
|
|
|
|
|
|
|
expect(loadMoreMock).toHaveBeenCalled(); |
|
|
|
|
expect(await screen.findByTestId('Spinner')).toBeInTheDocument(); |
|
|
|
@ -192,7 +198,8 @@ describe('InfiniteScroll', () => { |
|
|
|
|
element.clientHeight = 40; |
|
|
|
|
element.scrollHeight = element.clientHeight; |
|
|
|
|
|
|
|
|
|
scrollTo(40); |
|
|
|
|
scrollTo(39, 1); |
|
|
|
|
scrollTo(40, 600); |
|
|
|
|
|
|
|
|
|
expect(loadMoreMock).not.toHaveBeenCalled(); |
|
|
|
|
expect(screen.queryByTestId('Spinner')).not.toBeInTheDocument(); |
|
|
|
@ -207,7 +214,8 @@ describe('InfiniteScroll', () => { |
|
|
|
|
|
|
|
|
|
expect(await screen.findByTestId('contents')).toBeInTheDocument(); |
|
|
|
|
|
|
|
|
|
scrollTo(endPosition); |
|
|
|
|
scrollTo(endPosition - 1, 1); |
|
|
|
|
scrollTo(endPosition, 600); |
|
|
|
|
|
|
|
|
|
expect(loadMoreMock).toHaveBeenCalledWith({ |
|
|
|
|
from: rows[rows.length - 1].timeEpochMs, |
|
|
|
@ -224,7 +232,8 @@ describe('InfiniteScroll', () => { |
|
|
|
|
|
|
|
|
|
expect(await screen.findByTestId('contents')).toBeInTheDocument(); |
|
|
|
|
|
|
|
|
|
scrollTo(endPosition); |
|
|
|
|
scrollTo(endPosition - 1, 1); |
|
|
|
|
scrollTo(endPosition, 600); |
|
|
|
|
|
|
|
|
|
expect(loadMoreMock).toHaveBeenCalledWith({ |
|
|
|
|
from: absoluteRange.from, |
|
|
|
@ -246,7 +255,8 @@ describe('InfiniteScroll', () => { |
|
|
|
|
|
|
|
|
|
expect(await screen.findByTestId('contents')).toBeInTheDocument(); |
|
|
|
|
|
|
|
|
|
scrollTo(endPosition); |
|
|
|
|
scrollTo(endPosition - 1, 1); |
|
|
|
|
scrollTo(endPosition, 600); |
|
|
|
|
|
|
|
|
|
expect(loadMoreMock).not.toHaveBeenCalled(); |
|
|
|
|
expect(screen.queryByTestId('Spinner')).not.toBeInTheDocument(); |
|
|
|
@ -269,7 +279,8 @@ describe('InfiniteScroll', () => { |
|
|
|
|
|
|
|
|
|
expect(await screen.findByTestId('contents')).toBeInTheDocument(); |
|
|
|
|
|
|
|
|
|
scrollTo(endPosition); |
|
|
|
|
scrollTo(endPosition - 1, 1); |
|
|
|
|
scrollTo(endPosition, 600); |
|
|
|
|
|
|
|
|
|
expect(loadMoreMock).not.toHaveBeenCalled(); |
|
|
|
|
expect(screen.queryByTestId('Spinner')).not.toBeInTheDocument(); |
|
|
|
|