| 
									
										
										
										
											2017-02-23 08:51:00 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2017-02-23 08:51:00 -08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * 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'; | 
					
						
							| 
									
										
										
										
											2021-02-21 14:17:53 +01:00
										 |  |  | import {BrowserAnimationsModule, NoopAnimationsModule} from '@angular/platform-browser/animations'; | 
					
						
							| 
									
										
										
										
											2017-02-23 08:51:00 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-21 14:17:53 +01:00
										 |  |  | describe('NoopAnimationsModule', () => { | 
					
						
							|  |  |  |   beforeEach(() => { | 
					
						
							|  |  |  |     TestBed.configureTestingModule({imports: [NoopAnimationsModule]}); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   noopAnimationTests(); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe('BrowserAnimationsModule with disableAnimations = true', () => { | 
					
						
							|  |  |  |   beforeEach(() => { | 
					
						
							|  |  |  |     TestBed.configureTestingModule( | 
					
						
							|  |  |  |         {imports: [BrowserAnimationsModule.withConfig({disableAnimations: true})]}); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   noopAnimationTests(); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function noopAnimationTests() { | 
					
						
							|  |  |  |   it('should flush and fire callbacks when the zone becomes stable', (async) => { | 
					
						
							|  |  |  |     // This test is only meant to be run inside the browser.
 | 
					
						
							|  |  |  |     if (isNode) { | 
					
						
							|  |  |  |       async(); | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-02-23 08:51:00 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-21 14:17:53 +01:00
										 |  |  |     @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; | 
					
						
							| 
									
										
										
										
											2018-12-06 15:57:52 -08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2021-02-21 14:17:53 +01:00
										 |  |  |       onDone(event: any) { | 
					
						
							|  |  |  |         this.doneEvent = event; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-12-05 14:39:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-21 14:17:53 +01:00
										 |  |  |     TestBed.configureTestingModule({declarations: [Cmp]}); | 
					
						
							| 
									
										
										
										
											2017-02-23 08:51:00 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-21 14:17:53 +01:00
										 |  |  |     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(); | 
					
						
							| 
									
										
										
										
											2018-12-06 15:57:52 -08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2021-02-21 14:17:53 +01:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2017-02-23 08:51:00 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-21 14:17:53 +01:00
										 |  |  |   it('should handle leave animation callbacks even if the element is destroyed in the process', | 
					
						
							|  |  |  |      (async) => { | 
					
						
							|  |  |  |        // This test is only meant to be run inside the browser.
 | 
					
						
							|  |  |  |        if (isNode) { | 
					
						
							|  |  |  |          async(); | 
					
						
							|  |  |  |          return; | 
					
						
							|  |  |  |        } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |        @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; | 
					
						
							| 
									
										
										
										
											2018-12-06 15:57:52 -08:00
										 |  |  |          } | 
					
						
							| 
									
										
										
										
											2021-02-21 14:17:53 +01:00
										 |  |  |        } | 
					
						
							| 
									
										
										
										
											2017-02-23 09:41:00 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-21 14:17:53 +01:00
										 |  |  |        TestBed.configureTestingModule({declarations: [Cmp]}); | 
					
						
							|  |  |  |        const engine = TestBed.inject(ɵAnimationEngine); | 
					
						
							|  |  |  |        const fixture = TestBed.createComponent(Cmp); | 
					
						
							|  |  |  |        const cmp = fixture.componentInstance; | 
					
						
							| 
									
										
										
										
											2017-02-23 09:41:00 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-21 14:17:53 +01:00
										 |  |  |        cmp.exp = true; | 
					
						
							|  |  |  |        fixture.detectChanges(); | 
					
						
							|  |  |  |        fixture.whenStable().then(() => { | 
					
						
							|  |  |  |          cmp.startEvent = null; | 
					
						
							|  |  |  |          cmp.doneEvent = null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          cmp.exp = false; | 
					
						
							| 
									
										
										
										
											2018-12-06 15:57:52 -08:00
										 |  |  |          fixture.detectChanges(); | 
					
						
							|  |  |  |          fixture.whenStable().then(() => { | 
					
						
							| 
									
										
										
										
											2021-02-21 14:17:53 +01:00
										 |  |  |            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(); | 
					
						
							| 
									
										
										
										
											2018-12-06 15:57:52 -08:00
										 |  |  |          }); | 
					
						
							|  |  |  |        }); | 
					
						
							| 
									
										
										
										
											2021-02-21 14:17:53 +01:00
										 |  |  |      }); | 
					
						
							| 
									
										
										
										
											2017-02-23 08:51:00 -08:00
										 |  |  | } |