-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add clip test case and fix eslint error
- Loading branch information
Showing
9 changed files
with
195 additions
and
10 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
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,102 @@ | ||
import Clip from '../../../../src/animation/Clip'; | ||
import easingFuncs from '../../../../src/animation/easing'; | ||
|
||
describe('clip', function () { | ||
const life = 2000; | ||
const interval = 200; | ||
const delay = 300; | ||
/** '2022/12/22 00:42:45' */ | ||
const now = 1671640965219; | ||
it('normal clip call onframe correct', () => { | ||
const onframe = jest.fn(); | ||
const attClip = new Clip({ | ||
life, | ||
onframe | ||
}); | ||
attClip.step(now, 100); | ||
attClip.step(now + interval, 100); | ||
attClip.step(now + interval + life, 100); | ||
expect(onframe).toHaveBeenNthCalledWith(1, 0); | ||
expect(onframe).toHaveBeenNthCalledWith(2, interval / life); | ||
expect(onframe).toHaveBeenNthCalledWith(3, 1); | ||
}); | ||
|
||
it('delay clip call onframe correct', () => { | ||
const onframe = jest.fn(); | ||
|
||
const attClip = new Clip({ | ||
life, | ||
onframe, | ||
delay | ||
}); | ||
attClip.step(now, 100); | ||
attClip.step(now + interval, 100); | ||
attClip.step(now + interval + delay, 100); | ||
expect(onframe).toHaveBeenNthCalledWith(1, 0); | ||
expect(onframe).toHaveBeenNthCalledWith(2, 0); | ||
expect(onframe).toHaveBeenNthCalledWith(3, interval / life); | ||
}); | ||
|
||
it('loop clip call onframe correct', () => { | ||
const onframe = jest.fn(); | ||
const onrestart = jest.fn(); | ||
|
||
const attClip = new Clip({ | ||
life, | ||
onframe, | ||
loop: true, | ||
onrestart | ||
}); | ||
attClip.step(now, 100); | ||
attClip.step(now + interval, 100); | ||
attClip.step(now + interval + life, 100); | ||
attClip.step(now + interval + life + 100, 100); | ||
expect(onframe).toHaveBeenNthCalledWith(1, 0); | ||
expect(onframe).toHaveBeenNthCalledWith(2, interval / life); | ||
expect(onframe).toHaveBeenNthCalledWith(3, 1); | ||
expect(onframe).toHaveBeenNthCalledWith(4, (interval + 100) / life); | ||
expect(onrestart).toBeCalledTimes(1); | ||
}); | ||
|
||
it('clip pause correct', () => { | ||
const onframe = jest.fn(); | ||
const onrestart = jest.fn(); | ||
|
||
const attClip = new Clip({ | ||
life, | ||
onframe, | ||
loop: true, | ||
onrestart | ||
}); | ||
attClip.pause(); | ||
attClip.step(now, interval); | ||
attClip.step(now + interval, interval); | ||
attClip.resume(); | ||
// pause two interval | ||
attClip.step(now + interval + interval + interval, interval); | ||
expect(onframe).toBeCalledTimes(1); | ||
expect(onframe).toHaveBeenNthCalledWith(1, interval / life); | ||
}); | ||
|
||
const buildInEasing = Object.keys(easingFuncs) as Array<keyof typeof easingFuncs>; | ||
|
||
test.each(buildInEasing)('setEasing buildIn %s correct', (easingName) => { | ||
const onframe = jest.fn(); | ||
const onrestart = jest.fn(); | ||
|
||
const attClip = new Clip({ | ||
life, | ||
onframe, | ||
onrestart | ||
}); | ||
attClip.setEasing(easingName); | ||
/** init */ | ||
attClip.step(now, interval); | ||
attClip.step(now + interval, interval); | ||
attClip.step(now + 2 * interval, interval); | ||
expect(onframe).toBeCalledTimes(3); | ||
expect(onframe).toHaveBeenNthCalledWith(1, easingFuncs[easingName](0)); | ||
expect(onframe).toHaveBeenNthCalledWith(2, easingFuncs[easingName](interval / life)); | ||
expect(onframe).toHaveBeenNthCalledWith(3, easingFuncs[easingName](2 * interval / life)); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as matrix from '../../../../src/core/matrix'; | ||
|
||
describe('zrUtil', function () { | ||
const identity = [1, 0, 0, 1, 0, 0]; | ||
it('create', function () { | ||
expect(matrix.create()).toStrictEqual(identity); | ||
}); | ||
it('identity', function () { | ||
const origin = [1, 2, 3, 1, 2, 3]; | ||
matrix.identity(origin); | ||
expect(origin).toStrictEqual(identity); | ||
}); | ||
it('copy', function () { | ||
const origin = [1, 2, 3, 4, 5, 6]; | ||
const target = [0]; | ||
matrix.copy(target, origin); | ||
expect(target).toStrictEqual(origin); | ||
}); | ||
}); |
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
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 |
---|---|---|
|
@@ -19,7 +19,7 @@ describe('Text', function () { | |
stroke: 'blue' | ||
} | ||
} | ||
} | ||
}; | ||
|
||
text.useState('emphasis'); | ||
|
||
|