Skip to content

Commit 6c95827

Browse files
committed
新增Animation ut review by songym
1 parent d6516ed commit 6c95827

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import { Clip } from '../../../../src/common/overlay/levelRenderer/Clip';
2+
import { Animation } from '../../../../src/common/overlay/levelRenderer/Animation';
3+
import { SmicStar } from '../../../../src/common/overlay/levelRenderer/SmicStar';
4+
5+
6+
describe('Animation', () => {
7+
it('constructor', () => {
8+
var animation = new Animation({});
9+
expect(animation).not.toBeNull();
10+
expect(animation._time).toEqual(0);
11+
});
12+
13+
it('add,remove', () => {
14+
var animation = new Animation();
15+
var star = new SmicStar({
16+
style: {
17+
x: 200,
18+
y: 100,
19+
r: 150,
20+
n: 5,
21+
text: '五角星'
22+
}
23+
});
24+
var options = {
25+
target: star
26+
};
27+
var clip = new Clip(options);
28+
animation.add(clip);
29+
expect(animation._clips.length).toEqual(1);
30+
animation.remove(clip)
31+
expect(animation._clips.length).toEqual(0);
32+
});
33+
34+
it('start,stop', () => {
35+
var animation = new Animation();
36+
var star = new SmicStar({
37+
style: {
38+
x: 200,
39+
y: 100,
40+
r: 150,
41+
n: 5,
42+
text: '五角星'
43+
}
44+
});
45+
var options = {
46+
target: star
47+
};
48+
var clip = new Clip(options);
49+
animation.add(clip);
50+
animation.start();
51+
expect(animation._running).toEqual(true);
52+
animation.stop();
53+
expect(animation._running).toEqual(false);
54+
});
55+
56+
it('animation', () => {
57+
var animation = new Animation();
58+
var obj = {
59+
x: 100,
60+
y: 100
61+
};
62+
var star = new SmicStar({
63+
style: {
64+
x: 200,
65+
y: 100,
66+
r: 150,
67+
n: 5,
68+
text: '五角星'
69+
}
70+
});
71+
var animator = animation.animate(obj)
72+
.when(1000, {
73+
x: 500,
74+
y: 500
75+
})
76+
.when(2000, {
77+
x: 100,
78+
y: 100
79+
});
80+
animator.start('spline')
81+
82+
animation._clips[0].onframe(star, 0.5);
83+
animation._clips[0].ondestroy();
84+
animator.stop();
85+
expect(animation._running).toEqual(false);
86+
});
87+
88+
it('_update', () => {
89+
var animation = new Animation();
90+
var star = new SmicStar({
91+
style: {
92+
x: 200,
93+
y: 100,
94+
r: 150,
95+
n: 5,
96+
text: '五角星'
97+
}
98+
});
99+
var options = {
100+
target: star
101+
};
102+
var clip = new Clip(options);
103+
clip._needsRemove = true;
104+
animation.add(clip);
105+
spyOn(animation, 'dispatch').and.callThrough();
106+
animation._update();
107+
expect(animation.dispatch).toHaveBeenCalled();
108+
});
109+
110+
it('_catmullRomInterpolateArray,_interpolateArray,_cloneValue,_catmullRomInterpolate', () => {
111+
var p0 = new Array("1");
112+
var p1 = new Array("2");
113+
var p2 = new Array("3");
114+
var p3 = new Array("4");
115+
var out = new Array();
116+
var t = 1;
117+
var t2 = 1;
118+
var t3 = 1;
119+
var arrDim = 1;
120+
var percent = 0.3;
121+
Animation._catmullRomInterpolateArray(p0, p1, p2, p3, t, t2, t3, out, arrDim);
122+
expect(out.length).toBe(1);
123+
Animation._interpolateArray(p0, p1, percent, out, arrDim)
124+
expect(out[0]).toBe('0.31');
125+
126+
p0 = [];
127+
p0[0] = [1, 2]
128+
p1 = [];
129+
p1[0] = [1, 2]
130+
p2 = [];
131+
p2[0] = [1, 2];
132+
p3 = [];
133+
p3[0] = [1, 2]
134+
arrDim = 2;
135+
out[0] = new Array();
136+
Animation._catmullRomInterpolateArray(p0, p1, p2, p3, t, t2, t3, out, arrDim);
137+
expect(out[0][0]).toBe(1);
138+
Animation._interpolateArray(p0, p1, percent, out, arrDim)
139+
expect(out[0][0]).toBe(1);
140+
var result = Animation._cloneValue(out);
141+
expect(result[0].length).toBe(2);
142+
});
143+
144+
it('rgba2String', () => {
145+
var rgba = new Array(25, 255, 255);
146+
expect(Animation.rgba2String(rgba)).toEqual("rgba(25,255,255)");
147+
});
148+
149+
})

test/test-main-common.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ import './common/commontypes/geometry/LinearRingSpec.js';
118118
import './common/overlay/feature/ShapeFactorySpec.js';
119119
import './common/overlay/levelRenderer/AreaSpec.js';
120120
import './common/overlay/levelRenderer/ClipSpec.js';
121+
import './common/overlay/levelRenderer/AnimationSpec.js';
121122
import './common/overlay/levelRenderer/ColorSpec.js';
122123
import './common/overlay/levelRenderer/ComputeBoundingBoxSpec';
123124
import './common/overlay/levelRenderer/CurveSpec.js';

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy