forked from chartjs/Chart.js
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcore.animations.tests.js
222 lines (191 loc) · 6.37 KB
/
core.animations.tests.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
describe('Chart.animations', function() {
it('should override property collection with property', function() {
const chart = {};
const anims = new Chart.Animations(chart, {
collection1: {
properties: ['property1', 'property2'],
duration: 1000
},
property2: {
duration: 2000
}
});
expect(anims._properties.get('property1')).toEqual(jasmine.objectContaining({duration: 1000}));
expect(anims._properties.get('property2')).toEqual(jasmine.objectContaining({duration: 2000}));
});
it('should ignore duplicate definitions from collections', function() {
const chart = {};
const anims = new Chart.Animations(chart, {
collection1: {
properties: ['property1'],
duration: 1000
},
collection2: {
properties: ['property1', 'property2'],
duration: 2000
}
});
expect(anims._properties.get('property1')).toEqual(jasmine.objectContaining({duration: 1000}));
expect(anims._properties.get('property2')).toEqual(jasmine.objectContaining({duration: 2000}));
});
it('should not animate undefined options key', function() {
const chart = {};
const anims = new Chart.Animations(chart, {value: {duration: 100}, option: {duration: 200}});
const target = {
value: 1,
options: {
option: 2
}
};
expect(anims.update(target, {
options: undefined
})).toBeUndefined();
});
it('should assing options directly, if target does not have previous options', function() {
const chart = {};
const anims = new Chart.Animations(chart, {option: {duration: 200}});
const target = {};
expect(anims.update(target, {options: {option: 1}})).toBeUndefined();
});
it('should clone the target options, if those are shared and new options are not', function() {
const chart = {options: {}};
const anims = new Chart.Animations(chart, {option: {duration: 200}});
const options = {option: 0, $shared: true};
const target = {options};
expect(anims.update(target, {options: {option: 1}})).toBeTrue();
expect(target.options.$shared).not.toBeTrue();
expect(target.options !== options).toBeTrue();
});
it('should assign shared options to target after animations complete', function(done) {
const chart = {
draw: function() {},
options: {}
};
const anims = new Chart.Animations(chart, {value: {duration: 100}, option: {duration: 200}});
const target = {
value: 1,
options: {
option: 2
}
};
const sharedOpts = {option: 10, $shared: true};
expect(anims.update(target, {
options: sharedOpts
})).toBeTrue();
expect(target.options !== sharedOpts).toBeTrue();
Chart.animator.start(chart);
setTimeout(function() {
expect(Chart.animator.running(chart)).toBeFalse();
expect(target.options === sharedOpts).toBeTrue();
Chart.animator.remove(chart);
done();
}, 300);
});
it('should not assign shared options to target when animations are cancelled', function(done) {
const chart = {
draw: function() {},
options: {}
};
const anims = new Chart.Animations(chart, {value: {duration: 100}, option: {duration: 200}});
const target = {
value: 1,
options: {
option: 2
}
};
const sharedOpts = {option: 10, $shared: true};
expect(anims.update(target, {
options: sharedOpts
})).toBeTrue();
expect(target.options !== sharedOpts).toBeTrue();
Chart.animator.start(chart);
setTimeout(function() {
expect(Chart.animator.running(chart)).toBeTrue();
Chart.animator.stop(chart);
expect(Chart.animator.running(chart)).toBeFalse();
setTimeout(function() {
expect(target.options === sharedOpts).toBeFalse();
Chart.animator.remove(chart);
done();
}, 250);
}, 50);
});
it('should assign final shared options to target after animations complete', function(done) {
const chart = {
draw: function() {},
options: {}
};
const anims = new Chart.Animations(chart, {value: {duration: 100}, option: {duration: 200}});
const origOpts = {option: 2};
const target = {
value: 1,
options: origOpts
};
const sharedOpts = {option: 10, $shared: true};
const sharedOpts2 = {option: 20, $shared: true};
expect(anims.update(target, {
options: sharedOpts
})).toBeTrue();
expect(target.options !== sharedOpts).toBeTrue();
Chart.animator.start(chart);
setTimeout(function() {
expect(Chart.animator.running(chart)).toBeTrue();
expect(target.options === origOpts).toBeTrue();
expect(anims.update(target, {
options: sharedOpts2
})).toBeUndefined();
expect(target.options === origOpts).toBeTrue();
setTimeout(function() {
expect(target.options === sharedOpts2).toBeTrue();
Chart.animator.remove(chart);
done();
}, 250);
}, 50);
});
describe('default transitions', function() {
describe('hide', function() {
it('should keep dataset visible through the animation', function(done) {
let count = 0;
window.acquireChart({
type: 'line',
data: {
labels: [0],
datasets: [
{data: [1]},
]
},
options: {
animation: {
duration: 0,
onProgress: (args) => {
if (!args.chart.isDatasetVisible(0) && args.currentStep / args.numSteps < 0.9) {
// while animating, visible should be truthly
// sometimes its not, thats why we check only up to 90% of the animation
expect(args.chart.getDatasetMeta(0).visible).toBeTruthy();
count++;
}
},
onComplete: (args) => {
if (args.chart.isDatasetVisible(0)) {
args.chart.hide(0);
} else {
// and when finished, it should be false
expect(args.chart.getDatasetMeta(0).visible).toBeFalsy();
expect(count).toBeGreaterThan(0);
done();
}
}
},
transitions: {
hide: {
animation: {
duration: 100
}
}
}
}
});
});
});
});
});