Skip to content

Commit 71d2eef

Browse files
committed
test: add clip test case and fix eslint error
1 parent 0ddd8a0 commit 71d2eef

File tree

9 files changed

+195
-10
lines changed

9 files changed

+195
-10
lines changed

test/ut/spec/animation/ElementAnimation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Polyline, Rect, init} from '../zrender';
1+
import {Polyline, Rect} from '../zrender';
22
import Animation from '../../../../src/animation/Animation';
33

44
describe('ElementAnimation', function () {
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import Clip from '../../../../src/animation/Clip';
2+
import easingFuncs from '../../../../src/animation/easing';
3+
4+
describe('clip', function () {
5+
const life = 2000;
6+
const interval = 200;
7+
const delay = 300;
8+
/** '2022/12/22 00:42:45' */
9+
const now = 1671640965219;
10+
it('normal clip call onframe correct', () => {
11+
const onframe = jest.fn();
12+
const attClip = new Clip({
13+
life,
14+
onframe
15+
});
16+
attClip.step(now, 100);
17+
attClip.step(now + interval, 100);
18+
attClip.step(now + interval + life, 100);
19+
expect(onframe).toHaveBeenNthCalledWith(1, 0);
20+
expect(onframe).toHaveBeenNthCalledWith(2, interval / life);
21+
expect(onframe).toHaveBeenNthCalledWith(3, 1);
22+
});
23+
24+
it('delay clip call onframe correct', () => {
25+
const onframe = jest.fn();
26+
27+
const attClip = new Clip({
28+
life,
29+
onframe,
30+
delay
31+
});
32+
attClip.step(now, 100);
33+
attClip.step(now + interval, 100);
34+
attClip.step(now + interval + delay, 100);
35+
expect(onframe).toHaveBeenNthCalledWith(1, 0);
36+
expect(onframe).toHaveBeenNthCalledWith(2, 0);
37+
expect(onframe).toHaveBeenNthCalledWith(3, interval / life);
38+
});
39+
40+
it('loop clip call onframe correct', () => {
41+
const onframe = jest.fn();
42+
const onrestart = jest.fn();
43+
44+
const attClip = new Clip({
45+
life,
46+
onframe,
47+
loop: true,
48+
onrestart
49+
});
50+
attClip.step(now, 100);
51+
attClip.step(now + interval, 100);
52+
attClip.step(now + interval + life, 100);
53+
attClip.step(now + interval + life + 100, 100);
54+
expect(onframe).toHaveBeenNthCalledWith(1, 0);
55+
expect(onframe).toHaveBeenNthCalledWith(2, interval / life);
56+
expect(onframe).toHaveBeenNthCalledWith(3, 1);
57+
expect(onframe).toHaveBeenNthCalledWith(4, (interval + 100) / life);
58+
expect(onrestart).toBeCalledTimes(1);
59+
});
60+
61+
it('clip pause correct', () => {
62+
const onframe = jest.fn();
63+
const onrestart = jest.fn();
64+
65+
const attClip = new Clip({
66+
life,
67+
onframe,
68+
loop: true,
69+
onrestart
70+
});
71+
attClip.pause();
72+
attClip.step(now, interval);
73+
attClip.step(now + interval, interval);
74+
attClip.resume();
75+
// pause two interval
76+
attClip.step(now + interval + interval + interval, interval);
77+
expect(onframe).toBeCalledTimes(1);
78+
expect(onframe).toHaveBeenNthCalledWith(1, interval / life);
79+
});
80+
81+
const buildInEasing = Object.keys(easingFuncs) as Array<keyof typeof easingFuncs>;
82+
83+
test.each(buildInEasing)('setEasing buildIn %s correct', (easingName) => {
84+
const onframe = jest.fn();
85+
const onrestart = jest.fn();
86+
87+
const attClip = new Clip({
88+
life,
89+
onframe,
90+
onrestart
91+
});
92+
attClip.setEasing(easingName);
93+
/** init */
94+
attClip.step(now, interval);
95+
attClip.step(now + interval, interval);
96+
attClip.step(now + 2 * interval, interval);
97+
expect(onframe).toBeCalledTimes(3);
98+
expect(onframe).toHaveBeenNthCalledWith(1, easingFuncs[easingName](0));
99+
expect(onframe).toHaveBeenNthCalledWith(2, easingFuncs[easingName](interval / life));
100+
expect(onframe).toHaveBeenNthCalledWith(3, easingFuncs[easingName](2 * interval / life));
101+
});
102+
});

test/ut/spec/core/arrayDiff.test.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,22 @@ import arrayDiff from '../../../../src/core/arrayDiff';
33
describe('arrayDiff', function () {
44

55
it('Basic', function () {
6-
const newArr = [{"name":"类目12"},{"name":"类目13"},{"name":"类目14"},{"name":"类目15"},{"name":"类目16"},{"name":"类目17"}];
7-
const oldArr = [{"name":"类目11"},{"name":"类目12"},{"name":"类目13"},{"name":"类目14"},{"name":"类目15"},{"name":"类目16"}];
6+
const newArr = [
7+
{'name': '类目12'},
8+
{'name': '类目13'},
9+
{'name': '类目14'},
10+
{'name': '类目15'},
11+
{'name': '类目16'},
12+
{'name': '类目17'}
13+
];
14+
const oldArr = [
15+
{'name': '类目11'},
16+
{'name': '类目12'},
17+
{'name': '类目13'},
18+
{'name': '类目14'},
19+
{'name': '类目15'},
20+
{'name': '类目16'}
21+
];
822

923
const result = arrayDiff(newArr, oldArr, function (a, b) {
1024
return a.name === b.name;
@@ -25,7 +39,7 @@ describe('arrayDiff', function () {
2539
const result = arrayDiff([1, 2, 3, 4], [1, 2, 3, 4]);
2640
expect(result[0].added).toBe(false);
2741
expect(result[0].removed).toBe(false);
28-
expect(result[0].indices).toEqual([0, 1, 2, 3])
42+
expect(result[0].indices).toEqual([0, 1, 2, 3]);
2943
});
3044

3145
it('All different array', function () {

test/ut/spec/core/matrix.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as matrix from '../../../../src/core/matrix';
2+
3+
describe('zrUtil', function () {
4+
const identity = [1, 0, 0, 1, 0, 0];
5+
it('create', function () {
6+
expect(matrix.create()).toStrictEqual(identity);
7+
});
8+
it('identity', function () {
9+
const origin = [1, 2, 3, 1, 2, 3];
10+
matrix.identity(origin);
11+
expect(origin).toStrictEqual(identity);
12+
});
13+
it('copy', function () {
14+
const origin = [1, 2, 3, 4, 5, 6];
15+
const target = [0];
16+
matrix.copy(target, origin);
17+
expect(target).toStrictEqual(origin);
18+
});
19+
});

test/ut/spec/core/platform.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as platform from '../../../../src/core/platform';
22

3-
describe('platform', function() {
3+
describe('platform', function () {
44

55
it('Default font should be correct', function () {
66
expect(platform.DEFAULT_FONT_SIZE).toBe(12);

test/ut/spec/core/util.test.ts

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as zrUtil from '../../../../src/core/util';
22

3-
describe('zrUtil', function() {
3+
describe('zrUtil', function () {
44

55
describe('merge', function () {
66

@@ -147,4 +147,54 @@ describe('zrUtil', function() {
147147
});
148148

149149
});
150-
});
150+
151+
describe('each', function () {
152+
153+
it('array base', function () {
154+
const basicArray = ['z', 'r', 'e', 'n', 'd', 'e', 'r'];
155+
const target: string[] = [];
156+
const thisObject = {
157+
count: 0
158+
};
159+
const cb = jest.fn(function (char, index) {
160+
this.count++;
161+
target[index] = char + 'E';
162+
});
163+
zrUtil.each(basicArray, cb, thisObject);
164+
expect(cb).toBeCalledTimes(basicArray.length);
165+
new Array(basicArray.length).forEach((_, index) => {
166+
expect(cb).toHaveBeenNthCalledWith(index + 1, basicArray[index], index, basicArray);
167+
});
168+
expect(target).toEqual(['zE', 'rE', 'eE', 'nE', 'dE', 'eE', 'rE']);
169+
expect(thisObject.count).toBe(7);
170+
});
171+
172+
it('object base', function () {
173+
const basicObject = {
174+
name: 'zRender',
175+
version: '5.4.1'
176+
};
177+
const ObjectKeys = Object.keys(basicObject);
178+
const ObjectKeysLength = ObjectKeys.length;
179+
const ObjectValues = Object.values(basicObject);
180+
const target: Partial<typeof basicObject> = {};
181+
const thisObject = {
182+
count: 0
183+
};
184+
const cb = jest.fn(function (value: string, key: keyof typeof basicObject) {
185+
this.count++;
186+
target[key] = value + 'E';
187+
});
188+
zrUtil.each(basicObject, cb, thisObject);
189+
expect(cb).toBeCalledTimes(ObjectKeysLength);
190+
new Array(ObjectKeysLength).forEach((_, index) => {
191+
expect(cb).toHaveBeenNthCalledWith(index + 1, ObjectValues[index], ObjectKeys[index], basicObject);
192+
});
193+
expect(target).toEqual({
194+
name: 'zRenderE',
195+
version: '5.4.1E'
196+
});
197+
expect(thisObject.count).toBe(2);
198+
});
199+
});
200+
});

test/ut/spec/graphic/Group.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Group, Path, Image as ZImage, Element} from '../zrender';
1+
import {Group, Element} from '../zrender';
22

33
describe('Group', function () {
44

test/ut/spec/graphic/Path.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ describe('Path', function () {
194194
// TODO textContent
195195
});
196196

197-
it('Path#useStates. Mutiple states should be merged properly', function () {
197+
it('Path#useStates. Multiple states should be merged properly', function () {
198198
const rect = createRectForStateTest();
199199

200200
rect.states = {

test/ut/spec/graphic/Text.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('Text', function () {
1919
stroke: 'blue'
2020
}
2121
}
22-
}
22+
};
2323

2424
text.useState('emphasis');
2525

0 commit comments

Comments
 (0)