Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add eslint for ut folder and add clip test case #985

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
44 changes: 44 additions & 0 deletions test/ut/spec/animation/Animator.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Animator from '../../../../src/animation/Animator';
import Clip from '../../../../src/animation/Clip';

describe('Animator', function () {
it('valueType number Animator', async () => {
const obj = {
x: 100,
y: 100
};
const duringFn = jest.fn();
const clips: Clip[] = [];
const addClip = jest.fn((t) => clips.push(t));
const attClip = new Animator(obj,
false).during(duringFn);
attClip.animation = {
addClip
} as any;
attClip.when(1000, {
x: 200,
y: 300
}).when(2000, {
x: 300,
y: 500
}).start();
expect(addClip).toBeCalledTimes(1);
clips[0].onframe(0.25);
expect(obj).toStrictEqual({
x: 150,
y: 200
});
clips[0].onframe(0.5);
expect(obj).toStrictEqual({
x: 200,
y: 300
});
clips[0].onframe(0.75);
expect(obj).toStrictEqual({
x: 250,
y: 400
});
expect(duringFn).toBeCalledTimes(3);
});

});
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
130 changes: 130 additions & 0 deletions test/ut/spec/animation/Track.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { Track } from '../../../../src/animation/Animator';

describe('Track', function () {
it('valueType number', async () => {
const obj = {
x: 100
};
const track = new Track('x');
track.addKeyframe(0, 100);
track.addKeyframe(1000, 150);
track.addKeyframe(2000, 300);
track.prepare(2000);
track.step(obj, 0.25);
expect(obj.x).toBe(125);
});

it('valueType 1d array', async () => {
const obj = {
x: [100, 100]
};
const track = new Track('x');
track.addKeyframe(0, [100, 100]);
track.addKeyframe(1000, [150, 200]);
track.addKeyframe(2000, [300, 400]);
track.prepare(2000);
track.step(obj, 0.25);
expect(obj.x).toStrictEqual([125, 150]);
track.step(obj, 0.75);
expect(obj.x).toStrictEqual([225, 300]);
});

it('valueType 2d array', async () => {
const obj = {
x: [[100, 50], [100, 30]]
};
const track = new Track('x');
track.addKeyframe(0, [[100, 50], [100, 30]]);
track.addKeyframe(1000, [[150, 100], [200, 60]]);
track.addKeyframe(2000, [[300, 150], [400, 120]]);
track.prepare(2000);
track.step(obj, 0.25);
expect(obj.x).toStrictEqual([[125, 75], [150, 45]]);
track.step(obj, 0.75);
expect(obj.x).toStrictEqual([[225, 125], [300, 90]]);
});

it('valueType color', async () => {
const obj = {
x: 'rgba(0,0,0,0)'
};
const track = new Track('x');
track.addKeyframe(0, 'rgba(0,0,0,0)');
track.addKeyframe(1000, 'rgba(200,200,200,1)');
track.addKeyframe(2000, 'rgba(100,100,100,0)');
track.prepare(2000);
track.step(obj, 0.25);
expect(obj.x).toStrictEqual('rgba(100,100,100,0.5)');
track.step(obj, 0.75);
expect(obj.x).toStrictEqual('rgba(150,150,150,0.5)');
});

it('valueType linear', async () => {
const obj = {
x: {
type: 'linear',
x: 0,
y: 0,
x2: 1,
y2: 0,
colorStops: [{
offset: 0,
color: '#00f'
}, {
offset: 1,
color: '#f0f'
}]
}
};
const track = new Track('x');
track.addKeyframe(0, {
type: 'linear',
x: 0,
y: 0,
x2: 1,
y2: 1,
colorStops: [{
offset: 0,
color: '#00f'
}, {
offset: 1,
color: '#f0f'
}]
});
track.addKeyframe(1000, {
type: 'linear',
x: 1,
y: 1,
x2: 0,
y2: 0,
colorStops: [{
offset: 0,
color: '#00f'
}, {
offset: 1,
color: '#f0f'
}]
});
track.prepare(1000);
track.step(obj, 0.25);
expect(obj.x).toStrictEqual({
'colorStops': [{'color': 'rgba(0,0,255,1)', 'offset': 0}, {'color': 'rgba(255,0,255,1)', 'offset': 1}],
'global': undefined,
'type': 'linear',
'x': 0.25,
'x2': 0.75,
'y': 0.25,
'y2': 0.75
});
track.step(obj, 0.75);
expect(obj.x).toStrictEqual({
'colorStops': [{'color': 'rgba(0,0,255,1)', 'offset': 0}, {'color': 'rgba(255,0,255,1)', 'offset': 1}],
'global': undefined,
'type': 'linear',
'x': 0.75,
'x2': 0.25,
'y': 0.75,
'y2': 0.25
});
});
});
Loading