| 
									
										
										
										
											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-06-08 16:38:52 -07:00
										 |  |  | import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach,} from '@angular/core/testing/testing_internal'; | 
					
						
							| 
									
										
										
										
											2016-06-23 16:42:25 -07:00
										 |  |  | import {browserDetection} from '@angular/platform-browser/testing/browser_util'; | 
					
						
							| 
									
										
										
										
											2015-07-04 22:25:43 +04:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  | import {DecimalPipe, PercentPipe, CurrencyPipe} from '@angular/common'; | 
					
						
							| 
									
										
										
										
											2015-07-04 22:25:43 +04:30
										 |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							| 
									
										
										
										
											2016-02-10 16:54:32 -08:00
										 |  |  |   describe('Number pipes', () => { | 
					
						
							|  |  |  |     // TODO(mlaval): enable tests when Intl API is no longer used, see
 | 
					
						
							|  |  |  |     // https://github.com/angular/angular/issues/3333
 | 
					
						
							| 
									
										
										
										
											2016-06-17 15:34:39 -07:00
										 |  |  |     // Have to restrict to Chrome as IE uses a different formatting
 | 
					
						
							|  |  |  |     if (browserDetection.supportsIntlApi && browserDetection.isChromeDesktop) { | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |       describe('DecimalPipe', () => { | 
					
						
							| 
									
										
										
										
											2016-06-17 10:57:32 -07:00
										 |  |  |         var pipe: DecimalPipe; | 
					
						
							| 
									
										
										
										
											2015-07-04 22:25:43 +04:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-10 16:54:32 -08:00
										 |  |  |         beforeEach(() => { pipe = new DecimalPipe(); }); | 
					
						
							| 
									
										
										
										
											2015-07-04 22:25:43 +04:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |         describe('transform', () => { | 
					
						
							| 
									
										
										
										
											2016-02-10 16:54:32 -08:00
										 |  |  |           it('should return correct value for numbers', () => { | 
					
						
							| 
									
										
										
										
											2016-04-22 15:33:32 -07:00
										 |  |  |             expect(pipe.transform(12345)).toEqual('12,345'); | 
					
						
							|  |  |  |             expect(pipe.transform(123, '.2')).toEqual('123.00'); | 
					
						
							|  |  |  |             expect(pipe.transform(1, '3.')).toEqual('001'); | 
					
						
							|  |  |  |             expect(pipe.transform(1.1, '3.4-5')).toEqual('001.1000'); | 
					
						
							|  |  |  |             expect(pipe.transform(1.123456, '3.4-5')).toEqual('001.12346'); | 
					
						
							|  |  |  |             expect(pipe.transform(1.1234)).toEqual('1.123'); | 
					
						
							| 
									
										
										
										
											2016-02-10 16:54:32 -08:00
										 |  |  |           }); | 
					
						
							| 
									
										
										
										
											2015-08-06 10:39:02 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |           it('should not support other objects', | 
					
						
							| 
									
										
										
										
											2016-04-22 15:33:32 -07:00
										 |  |  |              () => { expect(() => pipe.transform(new Object())).toThrowError(); }); | 
					
						
							| 
									
										
										
										
											2016-02-10 16:54:32 -08:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2015-08-18 16:16:30 +02:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2015-07-04 22:25:43 +04:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |       describe('PercentPipe', () => { | 
					
						
							| 
									
										
										
										
											2016-06-17 10:57:32 -07:00
										 |  |  |         var pipe: PercentPipe; | 
					
						
							| 
									
										
										
										
											2015-07-04 22:25:43 +04:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-10 16:54:32 -08:00
										 |  |  |         beforeEach(() => { pipe = new PercentPipe(); }); | 
					
						
							| 
									
										
										
										
											2015-07-04 22:25:43 +04:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |         describe('transform', () => { | 
					
						
							| 
									
										
										
										
											2016-02-10 16:54:32 -08:00
										 |  |  |           it('should return correct value for numbers', () => { | 
					
						
							| 
									
										
										
										
											2016-04-22 15:33:32 -07:00
										 |  |  |             expect(pipe.transform(1.23)).toEqual('123%'); | 
					
						
							|  |  |  |             expect(pipe.transform(1.2, '.2')).toEqual('120.00%'); | 
					
						
							| 
									
										
										
										
											2016-02-10 16:54:32 -08:00
										 |  |  |           }); | 
					
						
							| 
									
										
										
										
											2015-08-06 10:39:02 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |           it('should not support other objects', | 
					
						
							| 
									
										
										
										
											2016-04-22 15:33:32 -07:00
										 |  |  |              () => { expect(() => pipe.transform(new Object())).toThrowError(); }); | 
					
						
							| 
									
										
										
										
											2016-02-10 16:54:32 -08:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2015-08-18 16:16:30 +02:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2015-07-04 22:25:43 +04:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |       describe('CurrencyPipe', () => { | 
					
						
							| 
									
										
										
										
											2016-06-17 10:57:32 -07:00
										 |  |  |         var pipe: CurrencyPipe; | 
					
						
							| 
									
										
										
										
											2015-07-04 22:25:43 +04:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-10 16:54:32 -08:00
										 |  |  |         beforeEach(() => { pipe = new CurrencyPipe(); }); | 
					
						
							| 
									
										
										
										
											2015-07-04 22:25:43 +04:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |         describe('transform', () => { | 
					
						
							| 
									
										
										
										
											2016-02-10 16:54:32 -08:00
										 |  |  |           it('should return correct value for numbers', () => { | 
					
						
							| 
									
										
										
										
											2016-04-22 15:33:32 -07:00
										 |  |  |             expect(pipe.transform(123)).toEqual('USD123'); | 
					
						
							|  |  |  |             expect(pipe.transform(12, 'EUR', false, '.2')).toEqual('EUR12.00'); | 
					
						
							| 
									
										
										
										
											2016-06-17 15:15:15 -07:00
										 |  |  |             expect(pipe.transform(5.123, 'USD', false, '.0-2')).toEqual('USD5.12'); | 
					
						
							| 
									
										
										
										
											2016-02-10 16:54:32 -08:00
										 |  |  |           }); | 
					
						
							| 
									
										
										
										
											2015-08-06 10:39:02 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |           it('should not support other objects', | 
					
						
							| 
									
										
										
										
											2016-04-22 15:33:32 -07:00
										 |  |  |              () => { expect(() => pipe.transform(new Object())).toThrowError(); }); | 
					
						
							| 
									
										
										
										
											2016-02-10 16:54:32 -08:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2015-08-18 16:16:30 +02:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2016-02-10 16:54:32 -08:00
										 |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2015-07-04 22:25:43 +04:30
										 |  |  | } |