| 
									
										
										
										
											2015-08-07 11:41:38 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   ddescribe, | 
					
						
							|  |  |  |   xdescribe, | 
					
						
							|  |  |  |   describe, | 
					
						
							|  |  |  |   it, | 
					
						
							|  |  |  |   iit, | 
					
						
							|  |  |  |   xit, | 
					
						
							|  |  |  |   expect, | 
					
						
							|  |  |  |   beforeEach, | 
					
						
							|  |  |  |   afterEach | 
					
						
							| 
									
										
										
										
											2015-10-13 00:29:13 -07:00
										 |  |  | } from 'angular2/testing_internal'; | 
					
						
							| 
									
										
										
										
											2015-08-07 11:41:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-17 10:09:23 -08:00
										 |  |  | import {Injector, Inject, provide, Pipe, PipeTransform, OnDestroy} from 'angular2/core'; | 
					
						
							| 
									
										
										
										
											2015-08-07 11:41:38 -07:00
										 |  |  | import {ProtoPipes, Pipes} from 'angular2/src/core/pipes/pipes'; | 
					
						
							| 
									
										
										
										
											2015-10-10 22:11:13 -07:00
										 |  |  | import {PipeProvider} from 'angular2/src/core/pipes/pipe_provider'; | 
					
						
							| 
									
										
										
										
											2015-08-07 11:41:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-17 10:09:23 -08:00
										 |  |  | class PipeA implements PipeTransform, OnDestroy { | 
					
						
							| 
									
										
										
										
											2015-08-07 11:41:38 -07:00
										 |  |  |   transform(a, b) {} | 
					
						
							| 
									
										
										
										
											2015-11-17 10:09:23 -08:00
										 |  |  |   ngOnDestroy() {} | 
					
						
							| 
									
										
										
										
											2015-08-07 11:41:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-17 10:09:23 -08:00
										 |  |  | class PipeB implements PipeTransform, OnDestroy { | 
					
						
							| 
									
										
										
										
											2015-08-07 11:41:38 -07:00
										 |  |  |   dep; | 
					
						
							|  |  |  |   constructor(@Inject("dep") dep: any) { this.dep = dep; } | 
					
						
							|  |  |  |   transform(a, b) {} | 
					
						
							| 
									
										
										
										
											2015-11-17 10:09:23 -08:00
										 |  |  |   ngOnDestroy() {} | 
					
						
							| 
									
										
										
										
											2015-08-07 11:41:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							|  |  |  |   describe("Pipes", () => { | 
					
						
							|  |  |  |     var injector; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-12 11:30:34 -07:00
										 |  |  |     beforeEach(() => { | 
					
						
							|  |  |  |       injector = Injector.resolveAndCreate([provide('dep', {useValue: 'dependency'})]); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-08-07 11:41:38 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should instantiate a pipe', () => { | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |       var proto = | 
					
						
							| 
									
										
										
										
											2015-10-10 22:11:13 -07:00
										 |  |  |           ProtoPipes.fromProviders([PipeProvider.createFromType(PipeA, new Pipe({name: 'a'}))]); | 
					
						
							| 
									
										
										
										
											2015-08-07 11:41:38 -07:00
										 |  |  |       var pipes = new Pipes(proto, injector); | 
					
						
							| 
									
										
										
										
											2015-09-08 09:17:58 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(pipes.get("a").pipe).toBeAnInstanceOf(PipeA); | 
					
						
							| 
									
										
										
										
											2015-08-07 11:41:38 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should throw when no pipe found', () => { | 
					
						
							| 
									
										
										
										
											2015-10-10 22:11:13 -07:00
										 |  |  |       var proto = ProtoPipes.fromProviders([]); | 
					
						
							| 
									
										
										
										
											2015-08-07 11:41:38 -07:00
										 |  |  |       var pipes = new Pipes(proto, injector); | 
					
						
							|  |  |  |       expect(() => pipes.get("invalid")).toThrowErrorWith("Cannot find pipe 'invalid'"); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should inject dependencies from the provided injector', () => { | 
					
						
							| 
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 |  |  |       var proto = | 
					
						
							| 
									
										
										
										
											2015-10-10 22:11:13 -07:00
										 |  |  |           ProtoPipes.fromProviders([PipeProvider.createFromType(PipeB, new Pipe({name: 'b'}))]); | 
					
						
							| 
									
										
										
										
											2015-08-07 11:41:38 -07:00
										 |  |  |       var pipes = new Pipes(proto, injector); | 
					
						
							| 
									
										
										
										
											2015-09-08 09:17:58 -07:00
										 |  |  |       expect((<any>pipes.get("b").pipe).dep).toEqual("dependency"); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should cache pure pipes', () => { | 
					
						
							| 
									
										
										
										
											2015-10-10 22:11:13 -07:00
										 |  |  |       var proto = ProtoPipes.fromProviders( | 
					
						
							|  |  |  |           [PipeProvider.createFromType(PipeA, new Pipe({name: 'a', pure: true}))]); | 
					
						
							| 
									
										
										
										
											2015-09-08 09:17:58 -07:00
										 |  |  |       var pipes = new Pipes(proto, injector); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(pipes.get("a").pure).toEqual(true); | 
					
						
							|  |  |  |       expect(pipes.get("a")).toBe(pipes.get("a")); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should NOT cache impure pipes', () => { | 
					
						
							| 
									
										
										
										
											2015-10-10 22:11:13 -07:00
										 |  |  |       var proto = ProtoPipes.fromProviders( | 
					
						
							|  |  |  |           [PipeProvider.createFromType(PipeA, new Pipe({name: 'a', pure: false}))]); | 
					
						
							| 
									
										
										
										
											2015-09-08 09:17:58 -07:00
										 |  |  |       var pipes = new Pipes(proto, injector); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(pipes.get("a").pure).toEqual(false); | 
					
						
							|  |  |  |       expect(pipes.get("a")).not.toBe(pipes.get("a")); | 
					
						
							| 
									
										
										
										
											2015-08-07 11:41:38 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } |