| 
									
										
										
										
											2015-02-05 13:08:05 -08:00
										 |  |  | import {describe, iit, it, expect, beforeEach} from 'angular2/test_lib'; | 
					
						
							|  |  |  | import {Key, KeyRegistry} from 'angular2/di'; | 
					
						
							| 
									
										
										
										
											2014-09-30 14:56:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-07 10:34:07 -04:00
										 |  |  | export function main() { | 
					
						
							| 
									
										
										
										
											2014-09-30 14:56:33 -04:00
										 |  |  |   describe("key", function () { | 
					
						
							| 
									
										
										
										
											2014-11-06 10:55:34 -08:00
										 |  |  |     var registry; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-20 15:17:06 -04:00
										 |  |  |     beforeEach(function () { | 
					
						
							| 
									
										
										
										
											2014-11-06 10:55:34 -08:00
										 |  |  |       registry = new KeyRegistry(); | 
					
						
							| 
									
										
										
										
											2014-10-20 15:17:06 -04:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-30 14:56:33 -04:00
										 |  |  |     it('should be equal to another key if type is the same', function () { | 
					
						
							| 
									
										
										
										
											2014-11-06 10:55:34 -08:00
										 |  |  |       expect(registry.get('car')).toBe(registry.get('car')); | 
					
						
							| 
									
										
										
										
											2014-09-30 14:56:33 -04:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should not be equal to another key if types are different', function () { | 
					
						
							| 
									
										
										
										
											2014-11-06 10:55:34 -08:00
										 |  |  |       expect(registry.get('car')).not.toBe(registry.get('porsche')); | 
					
						
							| 
									
										
										
										
											2014-09-30 14:56:33 -04:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2014-10-10 16:31:27 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should return the passed in key', function () { | 
					
						
							| 
									
										
										
										
											2014-11-06 10:55:34 -08:00
										 |  |  |       expect(registry.get(registry.get('car'))).toBe(registry.get('car')); | 
					
						
							| 
									
										
										
										
											2014-10-10 16:31:27 -04:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2014-10-20 15:17:06 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     describe("metadata", function () { | 
					
						
							|  |  |  |       it("should assign metadata to a key", function () { | 
					
						
							| 
									
										
										
										
											2014-11-06 10:55:34 -08:00
										 |  |  |         var key = registry.get('car'); | 
					
						
							| 
									
										
										
										
											2014-10-20 15:17:06 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         Key.setMetadata(key, "meta"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(key.metadata).toEqual("meta"); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it("should allow assigning the same metadata twice", function () { | 
					
						
							| 
									
										
										
										
											2014-11-06 10:55:34 -08:00
										 |  |  |         var key = registry.get('car'); | 
					
						
							| 
									
										
										
										
											2014-10-20 15:17:06 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         Key.setMetadata(key, "meta"); | 
					
						
							|  |  |  |         Key.setMetadata(key, "meta"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(key.metadata).toEqual("meta"); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it("should throw when assigning different metadata", function () { | 
					
						
							| 
									
										
										
										
											2014-11-06 10:55:34 -08:00
										 |  |  |         var key = registry.get('car'); | 
					
						
							| 
									
										
										
										
											2014-10-20 15:17:06 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         Key.setMetadata(key, "meta1"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(() => Key.setMetadata(key, "meta2")).toThrowError(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2014-09-30 14:56:33 -04:00
										 |  |  |   }); | 
					
						
							|  |  |  | } |