-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow cursor animation to be customized.
- Loading branch information
1 parent
4747a0d
commit 79a9e73
Showing
19 changed files
with
3,110 additions
and
3,026 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
118 changes: 118 additions & 0 deletions
118
packages/typeit/__tests__/helpers/processCursorOptions.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,118 @@ | ||
import processCursorOptions from "../../src/helpers/processCursorOptions"; | ||
|
||
describe("a boolean is passed", () => { | ||
it("returns the defaults when it's true", () => { | ||
const result = processCursorOptions(true); | ||
|
||
expect(result).toEqual( | ||
expect.objectContaining({ | ||
autoPause: true, | ||
autoPauseDelay: 500, | ||
animation: expect.anything(), | ||
}) | ||
); | ||
}); | ||
|
||
it("returns false when it's false", () => { | ||
const result = processCursorOptions(false); | ||
|
||
expect(result).toBe(false); | ||
}); | ||
}); | ||
|
||
describe("an object is passed", () => { | ||
describe("autoPause settings", () => { | ||
it("uses defaults", () => { | ||
const result = processCursorOptions({}); | ||
|
||
expect(result.autoPause).toBe(true); | ||
expect(result.autoPauseDelay).toEqual(500); | ||
}); | ||
|
||
it("uses custom values", () => { | ||
const result = processCursorOptions({ | ||
autoPause: false, | ||
autoPauseDelay: 800, | ||
}); | ||
|
||
expect(result.autoPause).toBe(false); | ||
expect(result.autoPauseDelay).toEqual(800); | ||
}); | ||
}); | ||
|
||
describe("animation frames", () => { | ||
it("uses default frames", () => { | ||
const result = processCursorOptions({ | ||
animation: {}, | ||
}); | ||
|
||
expect(result.animation.options.iterations).toEqual(Infinity); | ||
expect(result.animation.frames).toEqual([ | ||
{ opacity: 0 }, | ||
{ opacity: 0 }, | ||
{ opacity: 1 }, | ||
]); | ||
}); | ||
|
||
it("uses custom frames", () => { | ||
const result = processCursorOptions({ | ||
animation: { | ||
frames: [ | ||
{ transform: "rotate(0)" }, | ||
{ transform: "rotate(0)" }, | ||
{ transform: "rotate(1)" }, | ||
], | ||
}, | ||
}); | ||
|
||
expect(result.animation.options.iterations).toEqual(Infinity); | ||
expect(result.animation.frames).toEqual([ | ||
{ transform: "rotate(0)" }, | ||
{ transform: "rotate(0)" }, | ||
{ transform: "rotate(1)" }, | ||
]); | ||
}); | ||
}); | ||
|
||
describe("animation options", () => { | ||
it("it uses defaults", () => { | ||
const result = processCursorOptions({ | ||
animation: { | ||
options: { | ||
// iterations: Infinity, | ||
}, | ||
}, | ||
}); | ||
|
||
expect(result.animation.options).toEqual( | ||
expect.objectContaining({ | ||
iterations: Infinity, | ||
easing: "steps(2, start)", | ||
fill: "forwards", | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
it("it uses custom values", () => { | ||
const result = processCursorOptions({ | ||
animation: { | ||
options: { | ||
iterations: 2, | ||
fill: "backwards", | ||
}, | ||
}, | ||
}); | ||
|
||
expect(result.animation.frames[0]).toEqual({ | ||
opacity: 0, | ||
}); | ||
expect(result.animation.options).toEqual( | ||
expect.objectContaining({ | ||
iterations: 2, | ||
easing: "steps(2, start)", | ||
fill: "backwards", | ||
}) | ||
); | ||
}); | ||
}); |
Oops, something went wrong.