| 
									
										
										
										
											2016-06-23 09:47:54 -07: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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-27 17:12:25 -07:00
										 |  |  | import {AnimationMetadata, animate, sequence, style, transition, trigger} from '@angular/core'; | 
					
						
							|  |  |  | import {beforeEach, describe, expect, inject, it} from '@angular/core/testing/testing_internal'; | 
					
						
							| 
									
										
										
										
											2016-09-23 16:37:04 -04:00
										 |  |  | import {AnimationCompiler, AnimationEntryCompileResult} from '../../src/animation/animation_compiler'; | 
					
						
							|  |  |  | import {AnimationParser} from '../../src/animation/animation_parser'; | 
					
						
							| 
									
										
										
										
											2016-11-23 09:42:19 -08:00
										 |  |  | import {CompileAnimationEntryMetadata, CompileDirectiveMetadata, CompileTemplateMetadata, CompileTypeMetadata, identifierName} from '../../src/compile_metadata'; | 
					
						
							| 
									
										
										
										
											2016-05-25 12:46:22 -07:00
										 |  |  | import {CompileMetadataResolver} from '../../src/metadata_resolver'; | 
					
						
							| 
									
										
										
										
											2016-11-08 15:45:30 -08:00
										 |  |  | import {ElementSchemaRegistry} from '../../src/schema/element_schema_registry'; | 
					
						
							| 
									
										
										
										
											2016-05-25 12:46:22 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							|  |  |  |   describe('RuntimeAnimationCompiler', () => { | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |     let resolver: CompileMetadataResolver; | 
					
						
							|  |  |  |     let parser: AnimationParser; | 
					
						
							| 
									
										
										
										
											2016-11-08 15:45:30 -08:00
										 |  |  |     beforeEach(inject( | 
					
						
							|  |  |  |         [CompileMetadataResolver, ElementSchemaRegistry], | 
					
						
							|  |  |  |         (res: CompileMetadataResolver, schema: ElementSchemaRegistry) => { | 
					
						
							|  |  |  |           resolver = res; | 
					
						
							|  |  |  |           parser = new AnimationParser(schema); | 
					
						
							|  |  |  |         })); | 
					
						
							| 
									
										
										
										
											2016-05-25 12:46:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-23 16:37:04 -04:00
										 |  |  |     const compiler = new AnimationCompiler(); | 
					
						
							| 
									
										
										
										
											2016-05-25 12:46:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |     const compileAnimations = | 
					
						
							| 
									
										
										
										
											2016-09-23 16:37:04 -04:00
										 |  |  |         (component: CompileDirectiveMetadata): AnimationEntryCompileResult[] => { | 
					
						
							|  |  |  |           const parsedAnimations = parser.parseComponent(component); | 
					
						
							| 
									
										
										
										
											2016-11-23 09:42:19 -08:00
										 |  |  |           return compiler.compile(identifierName(component.type), parsedAnimations); | 
					
						
							| 
									
										
										
										
											2016-08-22 17:18:25 -07:00
										 |  |  |         }; | 
					
						
							| 
									
										
										
										
											2016-05-25 12:46:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |     const compileTriggers = (input: any[]) => { | 
					
						
							|  |  |  |       const entries: CompileAnimationEntryMetadata[] = input.map(entry => { | 
					
						
							|  |  |  |         const animationTriggerData = trigger(entry[0], entry[1]); | 
					
						
							| 
									
										
										
										
											2016-07-11 10:56:47 -07:00
										 |  |  |         return resolver.getAnimationEntryMetadata(animationTriggerData); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2016-05-25 12:46:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |       const component = CompileDirectiveMetadata.create({ | 
					
						
							| 
									
										
										
										
											2016-11-30 10:52:51 -08:00
										 |  |  |         type: {reference: {name: 'myCmp', filePath: ''}, diDeps: [], lifecycleHooks: []}, | 
					
						
							| 
									
										
										
										
											2016-07-11 10:56:47 -07:00
										 |  |  |         template: new CompileTemplateMetadata({animations: entries}) | 
					
						
							| 
									
										
										
										
											2016-05-25 12:46:22 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       return compileAnimations(component); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |     const compileSequence = (seq: AnimationMetadata) => { | 
					
						
							| 
									
										
										
										
											2016-07-11 10:56:47 -07:00
										 |  |  |       return compileTriggers([['myAnimation', [transition('state1 => state2', seq)]]]); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-25 12:46:22 -07:00
										 |  |  |     it('should throw an exception containing all the inner animation parser errors', () => { | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |       const animation = sequence([ | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |         style({'color': 'red'}), animate(1000, style({'font-size': '100px'})), | 
					
						
							|  |  |  |         style({'color': 'blue'}), animate(1000, style(':missing_state')), style({'color': 'gold'}), | 
					
						
							|  |  |  |         animate(1000, style('broken_state')) | 
					
						
							| 
									
										
										
										
											2016-05-25 12:46:22 -07:00
										 |  |  |       ]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |       let capturedErrorMessage: string; | 
					
						
							| 
									
										
										
										
											2016-05-25 12:46:22 -07:00
										 |  |  |       try { | 
					
						
							| 
									
										
										
										
											2016-07-11 10:56:47 -07:00
										 |  |  |         compileSequence(animation); | 
					
						
							| 
									
										
										
										
											2016-05-25 12:46:22 -07:00
										 |  |  |       } catch (e) { | 
					
						
							|  |  |  |         capturedErrorMessage = e.message; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(capturedErrorMessage) | 
					
						
							| 
									
										
										
										
											2016-06-22 14:53:02 -07:00
										 |  |  |           .toMatch(/Unable to apply styles due to missing a state: "missing_state"/g); | 
					
						
							| 
									
										
										
										
											2016-05-25 12:46:22 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(capturedErrorMessage) | 
					
						
							| 
									
										
										
										
											2016-06-22 14:53:02 -07:00
										 |  |  |           .toMatch(/Animation states via styles must be prefixed with a ":"/); | 
					
						
							| 
									
										
										
										
											2016-05-25 12:46:22 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } |