| 
									
										
										
										
											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-06-08 16:38:52 -07:00
										 |  |  | import {beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit,} from '@angular/core/testing/testing_internal'; | 
					
						
							| 
									
										
										
										
											2015-08-06 13:19:29 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  | import {Component, Type} from '@angular/core'; | 
					
						
							|  |  |  | import {getComponentInfo, parseFields} from '@angular/upgrade/src/metadata'; | 
					
						
							| 
									
										
										
										
											2015-08-06 13:19:29 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							|  |  |  |   describe('upgrade metadata', () => { | 
					
						
							| 
									
										
										
										
											2015-10-01 13:14:59 -07:00
										 |  |  |     it('should extract component selector', () => { | 
					
						
							|  |  |  |       expect(getComponentInfo(ElementNameComponent).selector).toEqual('elementNameDashed'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-08-06 13:19:29 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe('errors', () => { | 
					
						
							|  |  |  |       it('should throw on missing selector', () => { | 
					
						
							| 
									
										
										
										
											2015-10-01 13:14:59 -07:00
										 |  |  |         expect(() => getComponentInfo(AttributeNameComponent)) | 
					
						
							| 
									
										
										
										
											2016-06-22 14:58:57 -07:00
										 |  |  |             .toThrowError('Only selectors matching element names are supported, got: [attr-name]'); | 
					
						
							| 
									
										
										
										
											2015-08-06 13:19:29 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should throw on non element names', () => { | 
					
						
							| 
									
										
										
										
											2015-10-01 13:14:59 -07:00
										 |  |  |         expect(() => getComponentInfo(NoAnnotationComponent)) | 
					
						
							| 
									
										
										
										
											2016-06-22 14:58:57 -07:00
										 |  |  |             .toThrowError('No Directive annotation found on NoAnnotationComponent'); | 
					
						
							| 
									
										
										
										
											2015-08-06 13:19:29 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-10-01 13:14:59 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     describe('parseFields', () => { | 
					
						
							|  |  |  |       it('should process nulls', () => { expect(parseFields(null)).toEqual([]); }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should process values', () => { | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |         expect(parseFields([' name ', ' prop :  attr '])).toEqual([ | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             prop: 'name', | 
					
						
							|  |  |  |             attr: 'name', | 
					
						
							|  |  |  |             bracketAttr: '[name]', | 
					
						
							|  |  |  |             parenAttr: '(name)', | 
					
						
							|  |  |  |             bracketParenAttr: '[(name)]', | 
					
						
							|  |  |  |             onAttr: 'onName', | 
					
						
							|  |  |  |             bindAttr: 'bindName', | 
					
						
							|  |  |  |             bindonAttr: 'bindonName' | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             prop: 'prop', | 
					
						
							|  |  |  |             attr: 'attr', | 
					
						
							|  |  |  |             bracketAttr: '[attr]', | 
					
						
							|  |  |  |             parenAttr: '(attr)', | 
					
						
							|  |  |  |             bracketParenAttr: '[(attr)]', | 
					
						
							|  |  |  |             onAttr: 'onAttr', | 
					
						
							|  |  |  |             bindAttr: 'bindAttr', | 
					
						
							|  |  |  |             bindonAttr: 'bindonAttr' | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         ]); | 
					
						
							| 
									
										
										
										
											2015-10-01 13:14:59 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2015-08-06 13:19:29 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 13:36:48 -08:00
										 |  |  | @Component({selector: 'element-name-dashed', template: ``}) | 
					
						
							| 
									
										
										
										
											2015-08-06 13:19:29 -07:00
										 |  |  | class ElementNameComponent { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 13:36:48 -08:00
										 |  |  | @Component({selector: '[attr-name]', template: ``}) | 
					
						
							| 
									
										
										
										
											2015-08-06 13:19:29 -07:00
										 |  |  | class AttributeNameComponent { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class NoAnnotationComponent {} |