2016-06-23 12:47:54 -04: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 19:38:52 -04:00
|
|
|
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach,} from '@angular/core/testing/testing_internal';
|
2016-06-23 19:42:25 -04:00
|
|
|
import {browserDetection} from '@angular/platform-browser/testing/browser_util';
|
2015-07-04 13:55:43 -04:00
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
import {DecimalPipe, PercentPipe, CurrencyPipe} from '@angular/common';
|
2015-07-04 13:55:43 -04:00
|
|
|
|
|
|
|
export function main() {
|
2016-02-10 19:54:32 -05: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 18:34:39 -04:00
|
|
|
// Have to restrict to Chrome as IE uses a different formatting
|
|
|
|
if (browserDetection.supportsIntlApi && browserDetection.isChromeDesktop) {
|
2016-06-08 19:38:52 -04:00
|
|
|
describe('DecimalPipe', () => {
|
2016-06-17 13:57:32 -04:00
|
|
|
var pipe: DecimalPipe;
|
2015-07-04 13:55:43 -04:00
|
|
|
|
2016-02-10 19:54:32 -05:00
|
|
|
beforeEach(() => { pipe = new DecimalPipe(); });
|
2015-07-04 13:55:43 -04:00
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
describe('transform', () => {
|
2016-02-10 19:54:32 -05:00
|
|
|
it('should return correct value for numbers', () => {
|
2016-04-22 18:33:32 -04: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 19:54:32 -05:00
|
|
|
});
|
2015-08-06 13:39:02 -04:00
|
|
|
|
2016-07-19 14:27:06 -04:00
|
|
|
it('should support strings', () => {
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not support other objects', () => {
|
|
|
|
expect(() => pipe.transform(new Object())).toThrowError();
|
|
|
|
expect(() => pipe.transform('123abc')).toThrowError();
|
|
|
|
});
|
2016-02-10 19:54:32 -05:00
|
|
|
});
|
2015-08-18 10:16:30 -04:00
|
|
|
});
|
2015-07-04 13:55:43 -04:00
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
describe('PercentPipe', () => {
|
2016-06-17 13:57:32 -04:00
|
|
|
var pipe: PercentPipe;
|
2015-07-04 13:55:43 -04:00
|
|
|
|
2016-02-10 19:54:32 -05:00
|
|
|
beforeEach(() => { pipe = new PercentPipe(); });
|
2015-07-04 13:55:43 -04:00
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
describe('transform', () => {
|
2016-02-10 19:54:32 -05:00
|
|
|
it('should return correct value for numbers', () => {
|
2016-04-22 18:33:32 -04:00
|
|
|
expect(pipe.transform(1.23)).toEqual('123%');
|
|
|
|
expect(pipe.transform(1.2, '.2')).toEqual('120.00%');
|
2016-02-10 19:54:32 -05:00
|
|
|
});
|
2015-08-06 13:39:02 -04:00
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
it('should not support other objects',
|
2016-04-22 18:33:32 -04:00
|
|
|
() => { expect(() => pipe.transform(new Object())).toThrowError(); });
|
2016-02-10 19:54:32 -05:00
|
|
|
});
|
2015-08-18 10:16:30 -04:00
|
|
|
});
|
2015-07-04 13:55:43 -04:00
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
describe('CurrencyPipe', () => {
|
2016-06-17 13:57:32 -04:00
|
|
|
var pipe: CurrencyPipe;
|
2015-07-04 13:55:43 -04:00
|
|
|
|
2016-02-10 19:54:32 -05:00
|
|
|
beforeEach(() => { pipe = new CurrencyPipe(); });
|
2015-07-04 13:55:43 -04:00
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
describe('transform', () => {
|
2016-02-10 19:54:32 -05:00
|
|
|
it('should return correct value for numbers', () => {
|
2016-07-20 21:48:17 -04:00
|
|
|
expect(pipe.transform(123)).toEqual('USD123.00');
|
|
|
|
expect(pipe.transform(12, 'EUR', false, '.1')).toEqual('EUR12.0');
|
|
|
|
expect(pipe.transform(5.1234, 'USD', false, '.0-3')).toEqual('USD5.123');
|
2016-02-10 19:54:32 -05:00
|
|
|
});
|
2015-08-06 13:39:02 -04:00
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
it('should not support other objects',
|
2016-04-22 18:33:32 -04:00
|
|
|
() => { expect(() => pipe.transform(new Object())).toThrowError(); });
|
2016-02-10 19:54:32 -05:00
|
|
|
});
|
2015-08-18 10:16:30 -04:00
|
|
|
});
|
2016-02-10 19:54:32 -05:00
|
|
|
}
|
|
|
|
});
|
2015-07-04 13:55:43 -04:00
|
|
|
}
|