-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import DocumentScrollParent from "../../scrollHandler/documentScrollParent"; | ||
|
||
afterEach(() => { | ||
jest.useRealTimers(); | ||
}); | ||
|
||
describe("checkHorizontalScrolling", () => { | ||
it("scrolls to the left when pageX is near the left edge", () => { | ||
jest.useFakeTimers(); | ||
const scrollBy = jest.fn(); | ||
window.scrollBy = scrollBy; | ||
|
||
const refreshHitAreas = jest.fn(); | ||
const treeElement = document.createElement("div"); | ||
|
||
const documentScrollParent = new DocumentScrollParent({ | ||
refreshHitAreas, | ||
treeElement, | ||
}); | ||
|
||
documentScrollParent.checkHorizontalScrolling(10); | ||
|
||
expect(scrollBy).not.toHaveBeenCalled(); | ||
jest.advanceTimersByTime(50); | ||
expect(scrollBy).toHaveBeenCalledWith({ | ||
behavior: "instant", | ||
left: -20, | ||
top: 0, | ||
}); | ||
}); | ||
|
||
it("stops scrolling when pageX is moved from the left edge", () => { | ||
jest.useFakeTimers(); | ||
const scrollBy = jest.fn(); | ||
window.scrollBy = scrollBy; | ||
|
||
const refreshHitAreas = jest.fn(); | ||
const treeElement = document.createElement("div"); | ||
|
||
const documentScrollParent = new DocumentScrollParent({ | ||
refreshHitAreas, | ||
treeElement, | ||
}); | ||
|
||
documentScrollParent.checkHorizontalScrolling(10); | ||
|
||
expect(scrollBy).not.toHaveBeenCalled(); | ||
jest.advanceTimersByTime(50); | ||
expect(scrollBy).toHaveBeenCalledWith({ | ||
behavior: "instant", | ||
left: -20, | ||
top: 0, | ||
}); | ||
|
||
documentScrollParent.checkHorizontalScrolling(100); | ||
jest.advanceTimersByTime(50); | ||
|
||
expect(scrollBy).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters