| 
									
										
										
										
											2015-06-18 15:40:12 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   ddescribe, | 
					
						
							| 
									
										
										
										
											2015-08-06 10:39:02 -07:00
										 |  |  |   xdescribe, | 
					
						
							| 
									
										
										
										
											2015-06-18 15:40:12 -07:00
										 |  |  |   describe, | 
					
						
							|  |  |  |   it, | 
					
						
							|  |  |  |   iit, | 
					
						
							|  |  |  |   xit, | 
					
						
							|  |  |  |   expect, | 
					
						
							|  |  |  |   beforeEach, | 
					
						
							| 
									
										
										
										
											2015-08-06 10:39:02 -07:00
										 |  |  |   afterEach | 
					
						
							| 
									
										
										
										
											2015-06-18 15:40:12 -07:00
										 |  |  | } from 'angular2/test_lib'; | 
					
						
							| 
									
										
										
										
											2015-02-12 14:56:41 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-09 13:08:33 -07:00
										 |  |  | import {Injector, bind} from 'angular2/di'; | 
					
						
							| 
									
										
										
										
											2015-07-09 10:34:51 -07:00
										 |  |  | import {Pipes} from 'angular2/src/change_detection/pipes/pipes'; | 
					
						
							| 
									
										
										
										
											2015-08-06 10:39:02 -07:00
										 |  |  | import {Pipe} from 'angular2/src/change_detection/pipes/pipe'; | 
					
						
							| 
									
										
										
										
											2015-02-12 14:56:41 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-06 10:39:02 -07:00
										 |  |  | class APipe implements Pipe { | 
					
						
							|  |  |  |   transform(a, b) {} | 
					
						
							|  |  |  |   onDestroy() {} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-06-18 15:40:12 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-06 10:39:02 -07:00
										 |  |  | class AnotherPipe implements Pipe { | 
					
						
							|  |  |  |   transform(a, b) {} | 
					
						
							|  |  |  |   onDestroy() {} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-06-18 15:40:12 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-06 10:39:02 -07:00
										 |  |  | export function main() { | 
					
						
							|  |  |  |   describe("pipe registry", () => { | 
					
						
							|  |  |  |     var injector; | 
					
						
							| 
									
										
										
										
											2015-06-18 15:40:12 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-06 10:39:02 -07:00
										 |  |  |     beforeEach(() => { injector = Injector.resolveAndCreate([]); }); | 
					
						
							| 
									
										
										
										
											2015-06-18 15:40:12 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-06 10:39:02 -07:00
										 |  |  |     it("should instantiate a pipe", () => { | 
					
						
							|  |  |  |       var r = new Pipes({"type": APipe}, injector); | 
					
						
							|  |  |  |       expect(r.get("type", null)).toBeAnInstanceOf(APipe); | 
					
						
							| 
									
										
										
										
											2015-06-18 15:40:12 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-06 10:39:02 -07:00
										 |  |  |     it("should instantiate a new pipe every time", () => { | 
					
						
							|  |  |  |       var r = new Pipes({"type": APipe}, injector); | 
					
						
							|  |  |  |       var p1 = r.get("type", null); | 
					
						
							|  |  |  |       var p2 = r.get("type", null); | 
					
						
							|  |  |  |       expect(p1).not.toBe(p2); | 
					
						
							| 
									
										
										
										
											2015-02-12 14:56:41 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it("should throw when no matching type", () => { | 
					
						
							| 
									
										
										
										
											2015-08-06 10:39:02 -07:00
										 |  |  |       var r = new Pipes({}, null); | 
					
						
							|  |  |  |       expect(() => r.get("unknown", null)).toThrowError(`Cannot find pipe 'unknown'.`); | 
					
						
							| 
									
										
										
										
											2015-02-12 14:56:41 -08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-07-09 13:08:33 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-17 13:26:26 -07:00
										 |  |  |     describe('.create()', () => { | 
					
						
							|  |  |  |       it("should create a new Pipes object", () => { | 
					
						
							| 
									
										
										
										
											2015-08-06 10:39:02 -07:00
										 |  |  |         var pipes = Pipes.create({'pipe': APipe}, null); | 
					
						
							|  |  |  |         expect(pipes.config).toEqual({'pipe': APipe}); | 
					
						
							| 
									
										
										
										
											2015-07-17 13:26:26 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-06 10:39:02 -07:00
										 |  |  |       it("should merge pipes config", () => { | 
					
						
							|  |  |  |         var pipes1 = Pipes.create({'pipe': APipe, 'pipe1': APipe}, null); | 
					
						
							|  |  |  |         var pipes2 = Pipes.create({'pipe': AnotherPipe, 'pipe2': AnotherPipe}, null, pipes1); | 
					
						
							| 
									
										
										
										
											2015-07-17 13:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-06 10:39:02 -07:00
										 |  |  |         expect(pipes2.config).toEqual({'pipe': AnotherPipe, 'pipe1': APipe, 'pipe2': AnotherPipe}); | 
					
						
							| 
									
										
										
										
											2015-07-17 13:26:26 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-06 10:39:02 -07:00
										 |  |  |       it("should not change parent's config", () => { | 
					
						
							|  |  |  |         var pipes1 = Pipes.create({'pipe': APipe, 'pipe1': APipe}, null); | 
					
						
							|  |  |  |         Pipes.create({'pipe': AnotherPipe, 'pipe2': AnotherPipe}, null, pipes1); | 
					
						
							| 
									
										
										
										
											2015-07-17 13:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-06 10:39:02 -07:00
										 |  |  |         expect(pipes1.config).toEqual({'pipe': APipe, 'pipe1': APipe}); | 
					
						
							| 
									
										
										
										
											2015-07-17 13:26:26 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe(".extend()", () => { | 
					
						
							|  |  |  |       it('should create a factory that prepend new pipes to old', () => { | 
					
						
							| 
									
										
										
										
											2015-08-06 10:39:02 -07:00
										 |  |  |         var pipes1 = Pipes.create({'pipe': APipe, 'pipe1': APipe}, null); | 
					
						
							|  |  |  |         var binding = Pipes.extend({'pipe': AnotherPipe, 'pipe2': AnotherPipe}); | 
					
						
							|  |  |  |         var pipes: Pipes = binding.toFactory(pipes1, injector); | 
					
						
							| 
									
										
										
										
											2015-07-09 13:08:33 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-06 10:39:02 -07:00
										 |  |  |         expect(pipes.config).toEqual({'pipe': AnotherPipe, 'pipe1': APipe, 'pipe2': AnotherPipe}); | 
					
						
							| 
									
										
										
										
											2015-07-09 13:08:33 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-17 13:26:26 -07:00
										 |  |  |       it('should throw if calling extend when creating root injector', () => { | 
					
						
							| 
									
										
										
										
											2015-08-06 10:39:02 -07:00
										 |  |  |         var injector = Injector.resolveAndCreate([Pipes.extend({'pipe': APipe})]); | 
					
						
							| 
									
										
										
										
											2015-07-17 13:26:26 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(() => injector.get(Pipes)) | 
					
						
							| 
									
										
										
										
											2015-07-23 18:00:19 -07:00
										 |  |  |             .toThrowErrorWith("Cannot extend Pipes without a parent injector"); | 
					
						
							| 
									
										
										
										
											2015-07-17 13:26:26 -07:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2015-07-09 13:08:33 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-02-12 14:56:41 -08:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2015-07-09 13:08:33 -07:00
										 |  |  | } |