/
feature.rendering.js
117 lines (110 loc) · 3.4 KB
/
feature.rendering.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import Easycanvas from 'src/index.js';
import constants from 'karma/case.constant.js';
var $canvas = document.createElement('canvas');
$canvas.width = 888;
$canvas.height = 888;
document.body.appendChild($canvas);
var $Painter = new Easycanvas.Painter();
$Painter.register($canvas);
$Painter.start();
var sprite1;
Easycanvas.ImgLoader(constants.png30px, function (img) {
sprite1 = $Painter.add({
name: '0',
content: {
img: img,
},
style: {
left: 100, top: 100,
locate: 'lt',
opacity: 0.5,
rotate: 40,
},
events: {
click: function () {
console.log(3);
}
},
children: [
{
name: '1',
content: {
img: img,
},
style: {
left: 500, top: 0,
zIndex: 1,
opacity: 0.5,
locate: 'center',
},
events: {
eIndex: -3,
click: function () {
console.log(1);
}
}
},
{
name: '2',
// inherit: ['opacity'],
content: {
img: img,
},
style: {
left: 0, top: 500, // 实际100, 600
opacity: 1,
zIndex: 2,
locate: 'lt', // 原始中心115, 615
scale: 5 // 实际宽高150,x40~190,y540~690
},
events: {
eIndex: -31,
click: function () {
console.log(2);
}
}
},
{
name: '3',
content: {
img: img,
},
style: {
left: 500, top: 500,
opacity: 0.7,
zIndex: 3,
locate: 'center',
},
events: {
eIndex: -31,
click: function () {
console.log(3);
this.style.opacity = 0;
}
}
},
],
});
});
describe('Feature.rendering Test.', function () {
it('Basic props inherit correctly.', function (done) {
let getRenderStyle = function (props) {
return [
props.cutLeft, props.cutTop, props.cutWidth, props.cutHeight,
props.left, props.top, props.width, props.height,
].join(',');
};
setTimeout(() => {
$Painter.$children.forEach((i) => {
console.log(i.$origin.name);
});
expect($Painter.$children.length).toBe(6);
expect($Painter.$children[1].type).toBe('img');
expect(getRenderStyle($Painter.$children[1].props)).toBe('0,0,30,30,100,100,30,30');
expect($Painter.$children[3].settings.rotate).toBe(undefined);
expect($Painter.$children[2].settings.rotate).toBe(undefined);
expect(getRenderStyle($Painter.$children[3].props)).toBe('0,0,30,30,40,540,150,150');
done();
}, constants.waitForUpdateTime);
});
});