@@ -141,39 +141,61 @@ exports["Animation"] = {
141
141
this . animation . enqueue ( this . segment . long ) ;
142
142
143
143
setTimeout ( function ( ) {
144
+ // calledAt is a property on temporal tasks
144
145
test . ok ( this . animation . playLoop . calledAt ) ;
145
146
} . bind ( this ) , 3000 ) ;
146
147
147
148
setTimeout ( function ( ) {
149
+ // interval is the timer on our fallback
148
150
test . ok ( this . animation . playLoop . interval ) ;
149
151
this . animation . stop ( ) ;
150
152
test . done ( ) ;
151
153
} . bind ( this ) , 6000 ) ;
152
154
153
155
} ,
154
156
155
- synchronousSegments : function ( test ) {
157
+ synchronousNextOnTemporal : function ( test ) {
156
158
159
+ var startTime = Date . now ( ) ;
157
160
this . animation = new Animation ( this . servos ) ;
161
+ test . expect ( 2 ) ;
158
162
159
- test . expect ( 3 ) ;
160
-
161
- this . animation . enqueue ( this . segment . long ) ;
162
- this . animation . enqueue ( this . segment . short ) ;
163
+ var segment = Object . assign ( { } , this . segment . short ) ;
164
+ segment . fps = 200 ;
165
+ segment . oncomplete = ( ) => {
166
+ test . equal ( Math . abs ( Date . now ( ) - startTime - 500 ) <= 10 , true ) ;
167
+ } ;
168
+ this . animation . enqueue ( segment ) ;
163
169
164
- setTimeout ( function ( ) {
165
- test . ok ( Math . abs ( this . animation . progress - 0.5 ) < 0.05 ) ;
166
- } . bind ( this ) , 3500 ) ;
170
+ segment . oncomplete = ( ) => {
171
+ test . equal ( Math . abs ( Date . now ( ) - startTime - 1000 ) <= 10 , true ) ;
172
+ test . done ( ) ;
173
+ } ;
174
+ this . animation . enqueue ( segment ) ;
167
175
168
- setTimeout ( function ( ) {
169
- test . ok ( Math . abs ( this . animation . progress - 0.5 ) < 0.51 ) ;
170
- } . bind ( this ) , 7350 ) ;
176
+ } ,
177
+
178
+ synchronousNextOnFallback : function ( test ) {
171
179
172
- setTimeout ( function ( ) {
173
- test . ok ( Math . abs ( this . animation . progress ) === 1 ) ;
174
- test . done ( ) ;
175
- } . bind ( this ) , 7700 ) ;
180
+ var startTime = Date . now ( ) ;
181
+ this . animation = new Animation ( this . servos ) ;
182
+ test . expect ( 2 ) ;
176
183
184
+ var segment = Object . assign ( { } , this . segment . long ) ;
185
+ segment . fps = 200 ;
186
+ segment . oncomplete = ( ) => {
187
+ test . equal ( Math . abs ( Date . now ( ) - startTime - 7000 ) <= 10 , true ) ;
188
+ } ;
189
+ this . animation . enqueue ( segment ) ;
190
+
191
+ segment = Object . assign ( { } , this . segment . short ) ;
192
+ segment . fps = 200 ;
193
+ segment . oncomplete = ( ) => {
194
+ test . equal ( Math . abs ( Date . now ( ) - startTime - 7500 ) <= 10 , true ) ;
195
+ test . done ( ) ;
196
+ } ;
197
+ this . animation . enqueue ( segment ) ;
198
+
177
199
} ,
178
200
179
201
/*
@@ -185,71 +207,29 @@ exports["Animation"] = {
185
207
*/
186
208
roundedPi : function ( test ) {
187
209
this . animation = new Animation ( this . servos ) ;
188
- test . expect ( 2 ) ;
210
+ test . expect ( 1 ) ;
189
211
190
- var complete = false ;
191
212
var tempSegment = this . segment . short ;
192
213
193
214
tempSegment . easing = "inSine" ;
194
215
tempSegment . progress = 0.5 ;
195
216
196
- tempSegment . oncomplete = function ( ) {
197
- complete = true ;
198
- } ;
199
-
200
- this . animation . enqueue ( tempSegment ) ;
201
-
202
- setTimeout ( function ( ) {
217
+ tempSegment . oncomplete = ( ) => {
203
218
test . ok ( this . animation . progress === 1 ) ;
204
- test . ok ( complete === true ) ;
205
219
test . done ( ) ;
206
- } . bind ( this ) , 300 ) ;
207
-
208
- }
209
-
210
- } ;
211
-
212
-
213
- exports [ "Animation - Looping" ] = {
214
- setUp : function ( done ) {
215
- this . sandbox = sinon . sandbox . create ( ) ;
216
-
217
- this . play = this . sandbox . stub ( Animation . prototype , "play" ) ;
218
-
219
- this . animation = new Animation ( { } ) ;
220
- this . chain = {
221
- result : [ ] ,
222
- "@@render" : function ( args ) {
223
- this . result = this . result . concat ( args ) ;
224
- } ,
225
- "@@normalize" : function ( keyFrames ) {
226
- var last = [ 50 , 0 , - 20 ] ;
227
-
228
- // If user passes null as the first element in keyFrames use current position
229
- if ( keyFrames [ 0 ] === null ) {
230
- keyFrames [ 0 ] = {
231
- position : last
232
- } ;
233
- }
234
-
235
- return keyFrames ;
236
- }
237
220
} ;
238
221
239
- done ( ) ;
240
- } ,
222
+ this . animation . enqueue ( tempSegment ) ;
241
223
242
- tearDown : function ( done ) {
243
- this . sandbox . restore ( ) ;
244
- done ( ) ;
245
224
} ,
246
225
247
226
loopFunction : function ( test ) {
248
- test . expect ( 34 ) ;
227
+ test . expect ( 33 ) ;
249
228
250
- this . animation = new Animation ( this . chain ) ;
229
+ this . animation = new Animation ( this . servos ) ;
230
+
251
231
this . animation . playLoop = {
252
- stop : this . sandbox . spy ( ) ,
232
+ stop : this . sandbox . spy ( )
253
233
} ;
254
234
this . progress = 1 ;
255
235
this . clock = this . sandbox . useFakeTimers ( ) ;
@@ -259,6 +239,7 @@ exports["Animation - Looping"] = {
259
239
this . calculateProgress = this . sandbox . stub ( this . animation , "calculateProgress" , function ( ) {
260
240
this . animation . progress = this . progress ;
261
241
this . animation . loopback = this . progress ;
242
+ this . animation . normalizedKeyFrames = [ [ 0 , 1 ] ] ;
262
243
return this . progress ;
263
244
} . bind ( this ) ) ;
264
245
this . findIndices = this . sandbox . stub ( this . animation , "findIndices" ) . returns ( { left : 2 , right : 3 } ) ;
@@ -308,7 +289,6 @@ exports["Animation - Looping"] = {
308
289
test . equal ( this . findIndices . callCount , 5 ) ;
309
290
test . equal ( this . tweenedValue . callCount , 5 ) ;
310
291
311
-
312
292
this . animation . loop = true ;
313
293
this . animation . progress = 1 ;
314
294
this . animation . loopback = 1 ;
@@ -362,22 +342,18 @@ exports["Animation - Looping"] = {
362
342
this . animation . loopback = 1 ;
363
343
this . animation . metronomic = false ;
364
344
this . animation . reverse = false ;
365
- this . animation . segments . push ( 1 , 2 , 3 ) ;
366
345
this . animation . loopFunction ( { calledAt : 1 } ) ;
367
346
368
347
test . equal ( this . stop . callCount , 1 ) ;
369
- test . equal ( this . next . callCount , 1 ) ;
370
348
test . equal ( this . calculateProgress . callCount , 10 ) ;
371
349
test . equal ( this . findIndices . callCount , 10 ) ;
372
350
test . equal ( this . tweenedValue . callCount , 10 ) ;
373
351
374
- this . animation . oncomplete = function ( ) {
375
- test . done ( ) ;
376
- } ;
377
-
378
352
this . animation . loopFunction ( { calledAt : 1 } ) ;
379
353
380
354
test . equal ( this . animation . target [ "@@render" ] . callCount , 11 ) ;
381
- } ,
355
+
356
+ test . done ( ) ;
357
+ }
382
358
383
359
} ;
0 commit comments