| 
									
										
										
										
											2015-06-18 15:40:12 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   ddescribe, | 
					
						
							|  |  |  |   describe, | 
					
						
							|  |  |  |   it, | 
					
						
							|  |  |  |   iit, | 
					
						
							|  |  |  |   xit, | 
					
						
							|  |  |  |   expect, | 
					
						
							|  |  |  |   beforeEach, | 
					
						
							|  |  |  |   afterEach, | 
					
						
							|  |  |  |   SpyPipe, | 
					
						
							|  |  |  |   SpyPipeFactory | 
					
						
							|  |  |  | } from 'angular2/test_lib'; | 
					
						
							| 
									
										
										
										
											2015-02-12 14:56:41 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import {PipeRegistry} from 'angular2/src/change_detection/pipes/pipe_registry'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							|  |  |  |   describe("pipe registry", () => { | 
					
						
							| 
									
										
										
										
											2015-06-18 15:40:12 -07:00
										 |  |  |     var firstPipe; | 
					
						
							|  |  |  |     var secondPipe; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     var firstPipeFactory; | 
					
						
							|  |  |  |     var secondPipeFactory; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     beforeEach(() => { | 
					
						
							|  |  |  |       firstPipe = <any>new SpyPipe(); | 
					
						
							|  |  |  |       secondPipe = <any>new SpyPipe(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       firstPipeFactory = <any>new SpyPipeFactory(); | 
					
						
							|  |  |  |       secondPipeFactory = <any>new SpyPipeFactory(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it("should return an existing pipe if it can support the passed in object", () => { | 
					
						
							|  |  |  |       var r = new PipeRegistry({"type": []}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       firstPipe.spy("supports").andReturn(true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(r.get("type", "some object", null, firstPipe)).toEqual(firstPipe); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it("should call onDestroy on the provided pipe if it cannot support the provided object", | 
					
						
							|  |  |  |        () => { | 
					
						
							|  |  |  |          firstPipe.spy("supports").andReturn(false); | 
					
						
							|  |  |  |          firstPipeFactory.spy("supports").andReturn(true); | 
					
						
							|  |  |  |          firstPipeFactory.spy("create").andReturn(secondPipe); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          var r = new PipeRegistry({"type": [firstPipeFactory]}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          expect(r.get("type", "some object", null, firstPipe)).toEqual(secondPipe); | 
					
						
							|  |  |  |          expect(firstPipe.spy("onDestroy")).toHaveBeenCalled(); | 
					
						
							|  |  |  |        }); | 
					
						
							| 
									
										
										
										
											2015-02-12 14:56:41 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it("should return the first pipe supporting the data type", () => { | 
					
						
							| 
									
										
										
										
											2015-06-18 15:40:12 -07:00
										 |  |  |       firstPipeFactory.spy("supports").andReturn(false); | 
					
						
							|  |  |  |       firstPipeFactory.spy("create").andReturn(firstPipe); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       secondPipeFactory.spy("supports").andReturn(true); | 
					
						
							|  |  |  |       secondPipeFactory.spy("create").andReturn(secondPipe); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       var r = new PipeRegistry({"type": [firstPipeFactory, secondPipeFactory]}); | 
					
						
							| 
									
										
										
										
											2015-02-12 14:56:41 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-18 15:40:12 -07:00
										 |  |  |       expect(r.get("type", "some object")).toBe(secondPipe); | 
					
						
							| 
									
										
										
										
											2015-02-12 14:56:41 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it("should throw when no matching type", () => { | 
					
						
							|  |  |  |       var r = new PipeRegistry({}); | 
					
						
							| 
									
										
										
										
											2015-06-18 15:40:12 -07:00
										 |  |  |       expect(() => r.get("unknown", "some object")) | 
					
						
							| 
									
										
										
										
											2015-05-26 17:12:38 -07:00
										 |  |  |           .toThrowError(`Cannot find 'unknown' pipe supporting object 'some object'`); | 
					
						
							| 
									
										
										
										
											2015-02-12 14:56:41 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it("should throw when no matching pipe", () => { | 
					
						
							| 
									
										
										
										
											2015-05-26 17:12:38 -07:00
										 |  |  |       var r = new PipeRegistry({"type": []}); | 
					
						
							| 
									
										
										
										
											2015-02-12 14:56:41 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-18 15:40:12 -07:00
										 |  |  |       expect(() => r.get("type", "some object")) | 
					
						
							| 
									
										
										
										
											2015-05-26 17:12:38 -07:00
										 |  |  |           .toThrowError(`Cannot find 'type' pipe supporting object 'some object'`); | 
					
						
							| 
									
										
										
										
											2015-02-12 14:56:41 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2015-06-18 15:40:12 -07:00
										 |  |  | } |