| 
									
										
										
										
											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-04-28 17:50:03 -07:00
										 |  |  | import {I18nSelectPipe} from '@angular/common'; | 
					
						
							|  |  |  | import {PipeResolver} from '@angular/compiler/src/pipe_resolver'; | 
					
						
							| 
									
										
										
										
											2016-02-26 10:02:52 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |   describe('I18nSelectPipe', () => { | 
					
						
							| 
									
										
										
										
											2016-11-04 14:49:53 -07:00
										 |  |  |     const pipe: I18nSelectPipe = new I18nSelectPipe(); | 
					
						
							|  |  |  |     const mapping = {'male': 'Invite him.', 'female': 'Invite her.', 'other': 'Invite them.'}; | 
					
						
							| 
									
										
										
										
											2016-02-26 10:02:52 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should be marked as pure', | 
					
						
							|  |  |  |        () => { expect(new PipeResolver().resolve(I18nSelectPipe).pure).toEqual(true); }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |     describe('transform', () => { | 
					
						
							| 
									
										
										
										
											2016-11-04 14:49:53 -07:00
										 |  |  |       it('should return the "male" text if value is "male"', () => { | 
					
						
							|  |  |  |         const val = pipe.transform('male', mapping); | 
					
						
							| 
									
										
										
										
											2016-02-26 10:02:52 -08:00
										 |  |  |         expect(val).toEqual('Invite him.'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-04 14:49:53 -07:00
										 |  |  |       it('should return the "female" text if value is "female"', () => { | 
					
						
							|  |  |  |         const val = pipe.transform('female', mapping); | 
					
						
							| 
									
										
										
										
											2016-02-26 10:02:52 -08:00
										 |  |  |         expect(val).toEqual('Invite her.'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-04 14:49:53 -07:00
										 |  |  |       it('should return the "other" text if value is neither "male" nor "female"', | 
					
						
							|  |  |  |          () => { expect(pipe.transform('Anything else', mapping)).toEqual('Invite them.'); }); | 
					
						
							| 
									
										
										
										
											2016-02-26 10:02:52 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-04 14:49:53 -07:00
										 |  |  |       it('should return an empty text if value is null or undefined', () => { | 
					
						
							|  |  |  |         expect(pipe.transform(null, mapping)).toEqual(''); | 
					
						
							|  |  |  |         expect(pipe.transform(void 0, mapping)).toEqual(''); | 
					
						
							| 
									
										
										
										
											2016-02-26 10:02:52 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-04 14:49:53 -07:00
										 |  |  |       it('should throw on bad arguments', | 
					
						
							| 
									
										
										
										
											2016-06-17 10:57:32 -07:00
										 |  |  |          () => { expect(() => pipe.transform('male', <any>'hey')).toThrowError(); }); | 
					
						
							| 
									
										
										
										
											2016-02-26 10:02:52 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } |