Skip to content

Commit ea7fb34

Browse files
committed
test: add eslint for ut folder and add clip test case
1 parent 9197e05 commit ea7fb34

File tree

11 files changed

+393
-12
lines changed

11 files changed

+393
-12
lines changed

test/ut/.eslintrc.yaml

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
parser: "@typescript-eslint/parser"
2+
parserOptions:
3+
ecmaVersion: 6
4+
sourceType: module
5+
ecmaFeatures:
6+
modules: true
7+
project: "./test/ut/tsconfig.json"
8+
plugins: ["@typescript-eslint"]
9+
env:
10+
browser: true
11+
node: true
12+
es6: false
13+
jest: true
14+
globals:
15+
jQuery: true
16+
Promise: true
17+
rules:
18+
no-console:
19+
- 2
20+
-
21+
allow:
22+
- "warn"
23+
- "error"
24+
no-constant-condition: 0
25+
comma-dangle: 2
26+
no-debugger: 2
27+
no-dupe-keys: 2
28+
no-empty-character-class: 2
29+
no-ex-assign: 2
30+
no-extra-boolean-cast: 0
31+
no-func-assign: 2
32+
no-inner-declarations: 2
33+
no-invalid-regexp: 2
34+
no-negated-in-lhs: 2
35+
no-obj-calls: 2
36+
no-sparse-arrays: 2
37+
no-unreachable: 2
38+
use-isnan: 2
39+
valid-typeof: 2
40+
block-scoped-var: 0
41+
curly:
42+
- 2
43+
- "all"
44+
eqeqeq:
45+
- 2
46+
- "allow-null"
47+
guard-for-in: 2
48+
no-else-return: 0
49+
no-labels:
50+
- 2
51+
-
52+
allowLoop: true
53+
no-eval: 2
54+
no-extend-native: 2
55+
no-extra-bind: 0
56+
no-implied-eval: 2
57+
no-iterator: 2
58+
no-irregular-whitespace: 2
59+
no-lone-blocks: 2
60+
no-loop-func: 2
61+
no-multi-str: 2
62+
no-native-reassign: 2
63+
no-new-wrappers: 2
64+
no-octal: 2
65+
no-octal-escape: 2
66+
no-proto: 2
67+
no-redeclare: 0
68+
no-self-compare: 2
69+
no-unneeded-ternary: 2
70+
no-with: 2
71+
radix: 2
72+
wrap-iife:
73+
- 2
74+
- "any"
75+
no-delete-var: 2
76+
no-dupe-args: 2
77+
no-duplicate-case: 2
78+
no-label-var: 2
79+
no-shadow-restricted-names: 2
80+
no-undef: 2
81+
no-undef-init: 2
82+
no-use-before-define: 0
83+
brace-style:
84+
- 2
85+
- "stroustrup"
86+
- {}
87+
comma-spacing:
88+
- 2
89+
-
90+
before: false
91+
after: true
92+
comma-style:
93+
- 2
94+
- "last"
95+
new-parens: 2
96+
no-array-constructor: 2
97+
no-multi-spaces:
98+
- 1
99+
-
100+
ignoreEOLComments: true
101+
exceptions:
102+
Property: true
103+
no-new-object: 2
104+
no-spaced-func: 2
105+
no-trailing-spaces: 2
106+
no-extra-parens:
107+
- 2
108+
- "functions"
109+
no-mixed-spaces-and-tabs: 2
110+
one-var:
111+
- 2
112+
- "never"
113+
operator-linebreak:
114+
- 2
115+
- "before"
116+
-
117+
overrides:
118+
"=": "after"
119+
quotes:
120+
- 2
121+
- "single"
122+
semi:
123+
- 2
124+
- "always"
125+
semi-spacing: 2
126+
keyword-spacing: 2
127+
key-spacing:
128+
- 2
129+
-
130+
beforeColon: false
131+
afterColon: true
132+
space-before-function-paren:
133+
- 2
134+
-
135+
anonymous: "always"
136+
named: "never"
137+
space-before-blocks:
138+
- 2
139+
- "always"
140+
computed-property-spacing:
141+
- 2
142+
- "never"
143+
space-in-parens:
144+
- 2
145+
- "never"
146+
space-unary-ops: 2
147+
spaced-comment: 0
148+
149+
max-nested-callbacks:
150+
- 1
151+
- 5
152+
max-depth:
153+
- 1
154+
- 6
155+
max-len:
156+
- 2
157+
- 120
158+
- 4
159+
-
160+
ignoreUrls: true
161+
ignoreComments: true
162+
max-params:
163+
- 1
164+
- 15
165+
166+
space-infix-ops: 2
167+
dot-notation:
168+
- 2
169+
-
170+
allowKeywords: true
171+
allowPattern: "^catch$"
172+
173+
arrow-spacing: 2
174+
constructor-super: 2
175+
no-confusing-arrow:
176+
- 2
177+
-
178+
allowParens: true
179+
no-class-assign: 2
180+
no-const-assign: 2
181+
# no-dupe-class-members: 2
182+
no-this-before-super: 0
183+
no-var: 0
184+
no-duplicate-imports: 2
185+
prefer-rest-params: 0
186+
unicode-bom: 2
187+
max-statements-per-line: 2
188+
189+
no-useless-constructor: 0
190+
191+
192+
"@typescript-eslint/no-unused-vars":
193+
- 1
194+
-
195+
vars: "local"
196+
args: "none"

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 () {

test/ut/spec/animation/clip.test.ts

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);

0 commit comments

Comments
 (0)