-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure cursor pauses correctly during each action.
- Loading branch information
1 parent
be00e9f
commit ad463f6
Showing
6 changed files
with
135 additions
and
34 deletions.
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
91 changes: 91 additions & 0 deletions
91
packages/typeit/__tests__/helpers/setCursorAnimation.test.js
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,91 @@ | ||
import setCursorAnimation from "../../src/helpers/setCursorAnimation"; | ||
import * as beforePaint from "../../src/helpers/beforePaint"; | ||
|
||
let cursor; | ||
let mockAnimate; | ||
let mockPause; | ||
let mockPlay; | ||
let beforePaintSpy; | ||
|
||
beforeEach(() => { | ||
setHTML`<span class='ti-cursor' data-ti-animation-id="123abc">|</span>`; | ||
|
||
cursor = document.querySelector(".ti-cursor"); | ||
|
||
beforePaintSpy = jest | ||
.spyOn(beforePaint, "default") | ||
.mockImplementation((cb) => { | ||
return cb(); | ||
}); | ||
mockPause = jest.fn(); | ||
mockPlay = jest.fn(); | ||
mockAnimate = jest.fn(() => { | ||
return { | ||
pause: mockPause, | ||
play: mockPlay, | ||
}; | ||
}); | ||
|
||
cursor.animate = mockAnimate; | ||
}); | ||
|
||
describe("setting correct options", () => { | ||
it("sets correct defaults", () => { | ||
setCursorAnimation({ cursor }); | ||
|
||
expect(mockAnimate).toBeCalledTimes(1); | ||
expect(mockAnimate).toBeCalledWith( | ||
[{ opacity: 0 }, { opacity: 0 }, { opacity: 1 }], | ||
{ | ||
iterations: Infinity, | ||
easing: "steps(2, start)", | ||
fill: "forwards", | ||
} | ||
); | ||
}); | ||
|
||
it("takes custom options", () => { | ||
setCursorAnimation({ | ||
cursor, | ||
frames: [{ height: "10px" }, { height: "50px" }], | ||
timingOptions: { | ||
iterations: 3, | ||
easing: "linear", | ||
fill: "backwards", | ||
}, | ||
}); | ||
|
||
expect(mockAnimate).toBeCalledTimes(1); | ||
expect(mockAnimate).toBeCalledWith( | ||
[ | ||
{ | ||
height: "10px", | ||
}, | ||
{ | ||
height: "50px", | ||
}, | ||
], | ||
{ | ||
iterations: 3, | ||
easing: "linear", | ||
fill: "backwards", | ||
} | ||
); | ||
}); | ||
}); | ||
|
||
describe("initial behavior", () => { | ||
it("pauses and then plays after repaint", () => { | ||
let animation = setCursorAnimation({ cursor }); | ||
|
||
expect(mockPause).toHaveBeenCalledTimes(1); | ||
expect(mockPlay).toHaveBeenCalledTimes(1); | ||
expect(beforePaintSpy).toHaveBeenCalledTimes(2); | ||
}); | ||
|
||
it("sets correct animation ID", () => { | ||
let animation = setCursorAnimation({ cursor }); | ||
|
||
expect(animation.id).toEqual("123abc"); | ||
}); | ||
}); |
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
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
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
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