| 
									
										
										
										
											2017-02-23 08:51:00 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-02-28 17:49:37 -08:00
										 |  |  | import {animate, style, transition, trigger} from '@angular/animations'; | 
					
						
							| 
									
										
										
										
											2017-05-02 15:45:48 -07:00
										 |  |  | import {ɵAnimationEngine} from '@angular/animations/browser'; | 
					
						
							| 
									
										
										
										
											2017-02-23 08:51:00 -08:00
										 |  |  | import {Component} from '@angular/core'; | 
					
						
							|  |  |  | import {TestBed} from '@angular/core/testing'; | 
					
						
							| 
									
										
										
										
											2017-02-28 17:49:37 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-24 14:47:36 -08:00
										 |  |  | import {NoopAnimationsModule} from '../src/module'; | 
					
						
							| 
									
										
										
										
											2017-02-23 08:51:00 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							| 
									
										
										
										
											2017-02-24 09:36:58 -08:00
										 |  |  |   describe('NoopAnimationsModule', () => { | 
					
						
							| 
									
										
										
										
											2017-02-27 23:08:19 -08:00
										 |  |  |     beforeEach(() => { TestBed.configureTestingModule({imports: [NoopAnimationsModule]}); }); | 
					
						
							| 
									
										
										
										
											2017-02-23 08:51:00 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should flush and fire callbacks when the zone becomes stable', (async) => { | 
					
						
							|  |  |  |       @Component({ | 
					
						
							|  |  |  |         selector: 'my-cmp', | 
					
						
							|  |  |  |         template: | 
					
						
							|  |  |  |             '<div [@myAnimation]="exp" (@myAnimation.start)="onStart($event)" (@myAnimation.done)="onDone($event)"></div>', | 
					
						
							|  |  |  |         animations: [trigger( | 
					
						
							|  |  |  |             'myAnimation', | 
					
						
							|  |  |  |             [transition( | 
					
						
							|  |  |  |                 '* => state', [style({'opacity': '0'}), animate(500, style({'opacity': '1'}))])])], | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       class Cmp { | 
					
						
							|  |  |  |         exp: any; | 
					
						
							|  |  |  |         startEvent: any; | 
					
						
							|  |  |  |         doneEvent: any; | 
					
						
							|  |  |  |         onStart(event: any) { this.startEvent = event; } | 
					
						
							|  |  |  |         onDone(event: any) { this.doneEvent = event; } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       TestBed.configureTestingModule({declarations: [Cmp]}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const fixture = TestBed.createComponent(Cmp); | 
					
						
							|  |  |  |       const cmp = fixture.componentInstance; | 
					
						
							|  |  |  |       cmp.exp = 'state'; | 
					
						
							|  |  |  |       fixture.detectChanges(); | 
					
						
							|  |  |  |       fixture.whenStable().then(() => { | 
					
						
							|  |  |  |         expect(cmp.startEvent.triggerName).toEqual('myAnimation'); | 
					
						
							|  |  |  |         expect(cmp.startEvent.phaseName).toEqual('start'); | 
					
						
							|  |  |  |         expect(cmp.doneEvent.triggerName).toEqual('myAnimation'); | 
					
						
							|  |  |  |         expect(cmp.doneEvent.phaseName).toEqual('done'); | 
					
						
							|  |  |  |         async(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-02-23 09:41:00 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should handle leave animation callbacks even if the element is destroyed in the process', | 
					
						
							|  |  |  |        (async) => { | 
					
						
							|  |  |  |          @Component({ | 
					
						
							|  |  |  |            selector: 'my-cmp', | 
					
						
							|  |  |  |            template: | 
					
						
							|  |  |  |                '<div *ngIf="exp" @myAnimation (@myAnimation.start)="onStart($event)" (@myAnimation.done)="onDone($event)"></div>', | 
					
						
							|  |  |  |            animations: [trigger( | 
					
						
							|  |  |  |                'myAnimation', | 
					
						
							|  |  |  |                [transition( | 
					
						
							|  |  |  |                    ':leave', [style({'opacity': '0'}), animate(500, style({'opacity': '1'}))])])], | 
					
						
							|  |  |  |          }) | 
					
						
							|  |  |  |          class Cmp { | 
					
						
							|  |  |  |            exp: any; | 
					
						
							|  |  |  |            startEvent: any; | 
					
						
							|  |  |  |            doneEvent: any; | 
					
						
							|  |  |  |            onStart(event: any) { this.startEvent = event; } | 
					
						
							|  |  |  |            onDone(event: any) { this.doneEvent = event; } | 
					
						
							|  |  |  |          } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          TestBed.configureTestingModule({declarations: [Cmp]}); | 
					
						
							|  |  |  |          const engine = TestBed.get(ɵAnimationEngine); | 
					
						
							|  |  |  |          const fixture = TestBed.createComponent(Cmp); | 
					
						
							|  |  |  |          const cmp = fixture.componentInstance; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          cmp.exp = true; | 
					
						
							|  |  |  |          fixture.detectChanges(); | 
					
						
							|  |  |  |          fixture.whenStable().then(() => { | 
					
						
							| 
									
										
										
										
											2017-05-02 15:45:48 -07:00
										 |  |  |            cmp.startEvent = null; | 
					
						
							|  |  |  |            cmp.doneEvent = null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            cmp.exp = false; | 
					
						
							|  |  |  |            fixture.detectChanges(); | 
					
						
							|  |  |  |            fixture.whenStable().then(() => { | 
					
						
							|  |  |  |              expect(cmp.startEvent.triggerName).toEqual('myAnimation'); | 
					
						
							|  |  |  |              expect(cmp.startEvent.phaseName).toEqual('start'); | 
					
						
							|  |  |  |              expect(cmp.startEvent.toState).toEqual('void'); | 
					
						
							|  |  |  |              expect(cmp.doneEvent.triggerName).toEqual('myAnimation'); | 
					
						
							|  |  |  |              expect(cmp.doneEvent.phaseName).toEqual('done'); | 
					
						
							|  |  |  |              expect(cmp.doneEvent.toState).toEqual('void'); | 
					
						
							|  |  |  |              async(); | 
					
						
							|  |  |  |            }); | 
					
						
							| 
									
										
										
										
											2017-02-23 09:41:00 -08:00
										 |  |  |          }); | 
					
						
							|  |  |  |        }); | 
					
						
							| 
									
										
										
										
											2017-02-23 08:51:00 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | } |