2016-04-12 12:40:37 -04:00
|
|
|
import {
|
|
|
|
ddescribe,
|
|
|
|
describe,
|
|
|
|
it,
|
|
|
|
iit,
|
|
|
|
xit,
|
|
|
|
expect,
|
|
|
|
beforeEach,
|
|
|
|
afterEach,
|
|
|
|
browserDetection
|
|
|
|
} from 'angular2/testing_internal';
|
2015-07-04 13:55:43 -04:00
|
|
|
|
2015-11-18 18:55:43 -05:00
|
|
|
import {DecimalPipe, PercentPipe, CurrencyPipe} from 'angular2/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
|
|
|
|
if (browserDetection.supportsIntlApi) {
|
2016-04-12 12:40:37 -04:00
|
|
|
describe("DecimalPipe", () => {
|
2016-02-10 19:54:32 -05:00
|
|
|
var pipe;
|
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-04-12 12:40:37 -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');
|
2015-08-07 14:41:38 -04:00
|
|
|
|
2016-04-22 18:33:32 -04:00
|
|
|
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-04-12 12:40:37 -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-04-12 12:40:37 -04:00
|
|
|
describe("PercentPipe", () => {
|
2016-02-10 19:54:32 -05:00
|
|
|
var pipe;
|
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-04-12 12:40:37 -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-04-12 12:40:37 -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-04-12 12:40:37 -04:00
|
|
|
describe("CurrencyPipe", () => {
|
2016-02-10 19:54:32 -05:00
|
|
|
var pipe;
|
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-04-12 12:40:37 -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(123)).toEqual('USD123');
|
|
|
|
expect(pipe.transform(12, 'EUR', false, '.2')).toEqual('EUR12.00');
|
2016-02-10 19:54:32 -05:00
|
|
|
});
|
2015-08-06 13:39:02 -04:00
|
|
|
|
2016-04-12 12:40:37 -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
|
|
|
}
|