@@ -81,7 +81,7 @@ export var test_CancellingAnimation = function (done) {
81
81
// # Cancelling animation
82
82
// ``` JavaScript
83
83
var animation1 = label . createAnimation ( { translate : { x : 100 , y : 100 } } ) ;
84
- animation1 . play ( ) . finished
84
+ animation1 . play ( )
85
85
. then ( ( ) => {
86
86
////console.log("Animation finished");
87
87
// <hide>
@@ -145,51 +145,51 @@ export var test_ChainingAnimations = function (done) {
145
145
// </snippet>
146
146
}
147
147
148
- // export var test_ReusingAnimations = function (done) {
149
- // var mainPage: pageModule.Page;
150
- // var label: labelModule.Label;
151
- // var pageFactory = function (): pageModule.Page {
152
- // label = new labelModule.Label();
153
- // label.text = "label";
154
- // var stackLayout = new stackLayoutModule.StackLayout();
155
- // stackLayout.addChild(label);
156
- // mainPage = new pageModule.Page();
157
- // mainPage.content = stackLayout;
158
- // return mainPage;
159
- // };
160
-
161
- // helper.navigate(pageFactory);
162
- // TKUnit.waitUntilReady(() => { return label.isLoaded });
163
-
164
- // // <snippet module="ui/animation" title="animation">
165
- // // # Reusing animations
166
- // // ``` JavaScript
167
- // var animation1 = label.createAnimation({ translate: { x: 100, y: 100 } });
168
- // var animation2 = label.createAnimation({ translate: { x: 0, y: 0 } });
169
-
170
- // animation1.play().finished
171
- // .then(() => animation1 .play().finished )
172
- // .then(() => animation1.play().finished )
173
- // .then(() => animation2.play().finished )
174
- // .then(() => animation1.play().finished )
175
- // .then(() => animation2.play().finished )
176
- // .then(() => {
177
- // ////console.log("Animation finished");
178
- // // <hide>
179
- // helper.goBack();
180
- // done();
181
- // // </hide>
182
- // })
183
- // .catch((e) => {
184
- // console.log(e.message);
185
- // // <hide>
186
- // helper.goBack();
187
- // done(e);
188
- // // </hide>
189
- // });
190
- // // ```
191
- // // </snippet>
192
- // }
148
+ export var test_ReusingAnimations = function ( done ) {
149
+ var mainPage : pageModule . Page ;
150
+ var label : labelModule . Label ;
151
+ var pageFactory = function ( ) : pageModule . Page {
152
+ label = new labelModule . Label ( ) ;
153
+ label . text = "label" ;
154
+ var stackLayout = new stackLayoutModule . StackLayout ( ) ;
155
+ stackLayout . addChild ( label ) ;
156
+ mainPage = new pageModule . Page ( ) ;
157
+ mainPage . content = stackLayout ;
158
+ return mainPage ;
159
+ } ;
160
+
161
+ helper . navigate ( pageFactory ) ;
162
+ TKUnit . waitUntilReady ( ( ) => { return label . isLoaded } ) ;
163
+
164
+ // <snippet module="ui/animation" title="animation">
165
+ // # Reusing animations
166
+ // ``` JavaScript
167
+ var animation1 = label . createAnimation ( { translate : { x : 100 , y : 100 } } ) ;
168
+ var animation2 = label . createAnimation ( { translate : { x : 0 , y : 0 } } ) ;
169
+
170
+ animation1 . play ( )
171
+ . then ( ( ) => animation2 . play ( ) )
172
+ . then ( ( ) => animation1 . play ( ) )
173
+ . then ( ( ) => animation2 . play ( ) )
174
+ . then ( ( ) => animation1 . play ( ) )
175
+ . then ( ( ) => animation2 . play ( ) )
176
+ . then ( ( ) => {
177
+ ////console.log("Animation finished");
178
+ // <hide>
179
+ helper . goBack ( ) ;
180
+ done ( ) ;
181
+ // </hide>
182
+ } )
183
+ . catch ( ( e ) => {
184
+ console . log ( e . message ) ;
185
+ // <hide>
186
+ helper . goBack ( ) ;
187
+ done ( e ) ;
188
+ // </hide>
189
+ } ) ;
190
+ // ```
191
+ // </snippet>
192
+ }
193
193
194
194
export var test_AnimatingMultipleViews = function ( done ) {
195
195
var mainPage : pageModule . Page ;
@@ -223,7 +223,7 @@ export var test_AnimatingMultipleViews = function (done) {
223
223
{ target : label3 , translate : { x : 200 , y : 200 } , duration : 1000 , delay : 666 } ,
224
224
] ;
225
225
var a = new animation . Animation ( animations ) ;
226
- a . play ( ) . finished
226
+ a . play ( )
227
227
. then ( ( ) => {
228
228
////console.log("Animations finished");
229
229
// <hide>
@@ -404,10 +404,13 @@ export var test_AnimationsAreAlwaysPlayed = function (done) {
404
404
var animation1 = label . createAnimation ( { opacity : 0 } ) ;
405
405
var animation2 = label . createAnimation ( { opacity : 1 } ) ;
406
406
407
- animation1 . play ( ) . finished
408
- . then ( ( ) => animation2 . play ( ) . finished )
407
+ animation1 . play ( )
408
+ . then ( ( ) => {
409
+ TKUnit . assert ( label . opacity === 0 , `Label opacity should be 0 after first animation, actual value is ${ label . opacity } .` ) ;
410
+ return animation2 . play ( )
411
+ } )
409
412
. then ( ( ) => {
410
- TKUnit . assert ( label . opacity === 1 , `Label opacity expected vaue is 1 , actual value is ${ label . opacity } .` ) ;
413
+ TKUnit . assert ( label . opacity === 1 , `Label opacity should be 1 after second animation , actual value is ${ label . opacity } .` ) ;
411
414
helper . goBack ( ) ;
412
415
done ( ) ;
413
416
} )
@@ -417,3 +420,65 @@ export var test_AnimationsAreAlwaysPlayed = function (done) {
417
420
done ( e ) ;
418
421
} ) ;
419
422
}
423
+
424
+ export var test_PlayPromiseIsResolvedWhenAnimationFinishes = function ( done ) {
425
+ var mainPage : pageModule . Page ;
426
+ var label : labelModule . Label ;
427
+ var pageFactory = function ( ) : pageModule . Page {
428
+ label = new labelModule . Label ( ) ;
429
+ label . text = "label" ;
430
+ var stackLayout = new stackLayoutModule . StackLayout ( ) ;
431
+ stackLayout . addChild ( label ) ;
432
+ mainPage = new pageModule . Page ( ) ;
433
+ mainPage . content = stackLayout ;
434
+ return mainPage ;
435
+ } ;
436
+
437
+ helper . navigate ( pageFactory ) ;
438
+ TKUnit . waitUntilReady ( ( ) => { return label . isLoaded } ) ;
439
+
440
+ var animation = label . createAnimation ( { opacity : 0 , duration : 1000 } ) ;
441
+
442
+ animation . play ( )
443
+ . then ( function onResolved ( ) {
444
+ TKUnit . assert ( animation . isPlaying === false , "Animation.isPlaying should be false when animation play promise is resolved." ) ;
445
+ helper . goBack ( ) ;
446
+ done ( ) ;
447
+ } , function onRejected ( e ) {
448
+ TKUnit . assert ( 1 === 2 , "Animation play promise should be resolved, not rejected." ) ;
449
+ helper . goBack ( ) ;
450
+ done ( e ) ;
451
+ } ) ;
452
+ }
453
+
454
+ export var test_PlayPromiseIsRejectedWhenAnimationIsCancelled = function ( done ) {
455
+ var mainPage : pageModule . Page ;
456
+ var label : labelModule . Label ;
457
+ var pageFactory = function ( ) : pageModule . Page {
458
+ label = new labelModule . Label ( ) ;
459
+ label . text = "label" ;
460
+ var stackLayout = new stackLayoutModule . StackLayout ( ) ;
461
+ stackLayout . addChild ( label ) ;
462
+ mainPage = new pageModule . Page ( ) ;
463
+ mainPage . content = stackLayout ;
464
+ return mainPage ;
465
+ } ;
466
+
467
+ helper . navigate ( pageFactory ) ;
468
+ TKUnit . waitUntilReady ( ( ) => { return label . isLoaded } ) ;
469
+
470
+ var animation = label . createAnimation ( { opacity : 0 , duration : 1000 } ) ;
471
+
472
+ animation . play ( )
473
+ . then ( function onResolved ( ) {
474
+ TKUnit . assert ( 1 === 2 , "Animation play promise should be rejected, not resolved." ) ;
475
+ helper . goBack ( ) ;
476
+ done ( ) ;
477
+ } , function onRejected ( e ) {
478
+ TKUnit . assert ( animation . isPlaying === false , "Animation.isPlaying should be false when animation play promise is rejected." ) ;
479
+ helper . goBack ( ) ;
480
+ done ( ) ;
481
+ } ) ;
482
+
483
+ animation . cancel ( ) ;
484
+ }
0 commit comments