Skip to content

Commit

Permalink
test: add eslint for ut folder and add clip test case
Browse files Browse the repository at this point in the history
  • Loading branch information
erweixin committed Dec 22, 2022
1 parent 9197e05 commit ea7fb34
Show file tree
Hide file tree
Showing 11 changed files with 393 additions and 12 deletions.
196 changes: 196 additions & 0 deletions test/ut/.eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
parser: "@typescript-eslint/parser"
parserOptions:
ecmaVersion: 6
sourceType: module
ecmaFeatures:
modules: true
project: "./test/ut/tsconfig.json"
plugins: ["@typescript-eslint"]
env:
browser: true
node: true
es6: false
jest: true
globals:
jQuery: true
Promise: true
rules:
no-console:
- 2
-
allow:
- "warn"
- "error"
no-constant-condition: 0
comma-dangle: 2
no-debugger: 2
no-dupe-keys: 2
no-empty-character-class: 2
no-ex-assign: 2
no-extra-boolean-cast: 0
no-func-assign: 2
no-inner-declarations: 2
no-invalid-regexp: 2
no-negated-in-lhs: 2
no-obj-calls: 2
no-sparse-arrays: 2
no-unreachable: 2
use-isnan: 2
valid-typeof: 2
block-scoped-var: 0
curly:
- 2
- "all"
eqeqeq:
- 2
- "allow-null"
guard-for-in: 2
no-else-return: 0
no-labels:
- 2
-
allowLoop: true
no-eval: 2
no-extend-native: 2
no-extra-bind: 0
no-implied-eval: 2
no-iterator: 2
no-irregular-whitespace: 2
no-lone-blocks: 2
no-loop-func: 2
no-multi-str: 2
no-native-reassign: 2
no-new-wrappers: 2
no-octal: 2
no-octal-escape: 2
no-proto: 2
no-redeclare: 0
no-self-compare: 2
no-unneeded-ternary: 2
no-with: 2
radix: 2
wrap-iife:
- 2
- "any"
no-delete-var: 2
no-dupe-args: 2
no-duplicate-case: 2
no-label-var: 2
no-shadow-restricted-names: 2
no-undef: 2
no-undef-init: 2
no-use-before-define: 0
brace-style:
- 2
- "stroustrup"
- {}
comma-spacing:
- 2
-
before: false
after: true
comma-style:
- 2
- "last"
new-parens: 2
no-array-constructor: 2
no-multi-spaces:
- 1
-
ignoreEOLComments: true
exceptions:
Property: true
no-new-object: 2
no-spaced-func: 2
no-trailing-spaces: 2
no-extra-parens:
- 2
- "functions"
no-mixed-spaces-and-tabs: 2
one-var:
- 2
- "never"
operator-linebreak:
- 2
- "before"
-
overrides:
"=": "after"
quotes:
- 2
- "single"
semi:
- 2
- "always"
semi-spacing: 2
keyword-spacing: 2
key-spacing:
- 2
-
beforeColon: false
afterColon: true
space-before-function-paren:
- 2
-
anonymous: "always"
named: "never"
space-before-blocks:
- 2
- "always"
computed-property-spacing:
- 2
- "never"
space-in-parens:
- 2
- "never"
space-unary-ops: 2
spaced-comment: 0

max-nested-callbacks:
- 1
- 5
max-depth:
- 1
- 6
max-len:
- 2
- 120
- 4
-
ignoreUrls: true
ignoreComments: true
max-params:
- 1
- 15

space-infix-ops: 2
dot-notation:
- 2
-
allowKeywords: true
allowPattern: "^catch$"

arrow-spacing: 2
constructor-super: 2
no-confusing-arrow:
- 2
-
allowParens: true
no-class-assign: 2
no-const-assign: 2
# no-dupe-class-members: 2
no-this-before-super: 0
no-var: 0
no-duplicate-imports: 2
prefer-rest-params: 0
unicode-bom: 2
max-statements-per-line: 2

no-useless-constructor: 0


"@typescript-eslint/no-unused-vars":
- 1
-
vars: "local"
args: "none"
2 changes: 1 addition & 1 deletion test/ut/spec/animation/ElementAnimation.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Polyline, Rect, init} from '../zrender';
import {Polyline, Rect} from '../zrender';
import Animation from '../../../../src/animation/Animation';

describe('ElementAnimation', function () {
Expand Down
102 changes: 102 additions & 0 deletions test/ut/spec/animation/clip.test.ts
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));
});
});
20 changes: 17 additions & 3 deletions test/ut/spec/core/arrayDiff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,22 @@ import arrayDiff from '../../../../src/core/arrayDiff';
describe('arrayDiff', function () {

it('Basic', function () {
const newArr = [{"name":"类目12"},{"name":"类目13"},{"name":"类目14"},{"name":"类目15"},{"name":"类目16"},{"name":"类目17"}];
const oldArr = [{"name":"类目11"},{"name":"类目12"},{"name":"类目13"},{"name":"类目14"},{"name":"类目15"},{"name":"类目16"}];
const newArr = [
{'name': '类目12'},
{'name': '类目13'},
{'name': '类目14'},
{'name': '类目15'},
{'name': '类目16'},
{'name': '类目17'}
];
const oldArr = [
{'name': '类目11'},
{'name': '类目12'},
{'name': '类目13'},
{'name': '类目14'},
{'name': '类目15'},
{'name': '类目16'}
];

const result = arrayDiff(newArr, oldArr, function (a, b) {
return a.name === b.name;
Expand All @@ -25,7 +39,7 @@ describe('arrayDiff', function () {
const result = arrayDiff([1, 2, 3, 4], [1, 2, 3, 4]);
expect(result[0].added).toBe(false);
expect(result[0].removed).toBe(false);
expect(result[0].indices).toEqual([0, 1, 2, 3])
expect(result[0].indices).toEqual([0, 1, 2, 3]);
});

it('All different array', function () {
Expand Down
19 changes: 19 additions & 0 deletions test/ut/spec/core/matrix.test.ts
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);
});
});
2 changes: 1 addition & 1 deletion test/ut/spec/core/platform.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as platform from '../../../../src/core/platform';

describe('platform', function() {
describe('platform', function () {

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

0 comments on commit ea7fb34

Please sign in to comment.