2015-08-18 10:16:30 -04:00
|
|
|
import {
|
|
|
|
ddescribe,
|
|
|
|
describe,
|
|
|
|
it,
|
|
|
|
iit,
|
|
|
|
xit,
|
|
|
|
expect,
|
|
|
|
beforeEach,
|
|
|
|
afterEach,
|
2015-08-24 09:41:36 -04:00
|
|
|
browserDetection
|
2015-10-13 03:29:13 -04:00
|
|
|
} 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() {
|
2015-08-18 10:16:30 -04:00
|
|
|
// TODO(mlaval): enable tests when Intl API is no longer used, see
|
|
|
|
// https://github.com/angular/angular/issues/3333
|
2015-08-24 09:41:36 -04:00
|
|
|
if (browserDetection.supportsIntlApi) {
|
2015-08-18 10:16:30 -04:00
|
|
|
describe("DecimalPipe", () => {
|
|
|
|
var pipe;
|
2015-07-04 13:55:43 -04:00
|
|
|
|
2015-08-18 10:16:30 -04:00
|
|
|
beforeEach(() => { pipe = new DecimalPipe(); });
|
2015-07-04 13:55:43 -04:00
|
|
|
|
2015-08-18 10:16:30 -04:00
|
|
|
describe("transform", () => {
|
|
|
|
it('should return correct value for numbers', () => {
|
|
|
|
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
|
|
|
|
2015-08-18 10:16:30 -04:00
|
|
|
expect(pipe.transform(1.123456, ['3.4-5'])).toEqual('001.12346');
|
|
|
|
expect(pipe.transform(1.1234, [])).toEqual('1.123');
|
|
|
|
});
|
2015-08-06 13:39:02 -04:00
|
|
|
|
2015-08-18 10:16:30 -04:00
|
|
|
it("should not support other objects",
|
|
|
|
() => { expect(() => pipe.transform(new Object(), [])).toThrowError(); });
|
|
|
|
});
|
2015-07-04 13:55:43 -04:00
|
|
|
});
|
|
|
|
|
2015-08-18 10:16:30 -04:00
|
|
|
describe("PercentPipe", () => {
|
|
|
|
var pipe;
|
2015-07-04 13:55:43 -04:00
|
|
|
|
2015-08-18 10:16:30 -04:00
|
|
|
beforeEach(() => { pipe = new PercentPipe(); });
|
2015-07-04 13:55:43 -04:00
|
|
|
|
2015-08-18 10:16:30 -04:00
|
|
|
describe("transform", () => {
|
|
|
|
it('should return correct value for numbers', () => {
|
|
|
|
expect(pipe.transform(1.23, [])).toEqual('123%');
|
|
|
|
expect(pipe.transform(1.2, ['.2'])).toEqual('120.00%');
|
|
|
|
});
|
2015-08-06 13:39:02 -04:00
|
|
|
|
2015-08-18 10:16:30 -04:00
|
|
|
it("should not support other objects",
|
|
|
|
() => { expect(() => pipe.transform(new Object(), [])).toThrowError(); });
|
|
|
|
});
|
2015-07-04 13:55:43 -04:00
|
|
|
});
|
|
|
|
|
2015-08-18 10:16:30 -04:00
|
|
|
describe("CurrencyPipe", () => {
|
|
|
|
var pipe;
|
2015-07-04 13:55:43 -04:00
|
|
|
|
2015-08-18 10:16:30 -04:00
|
|
|
beforeEach(() => { pipe = new CurrencyPipe(); });
|
2015-07-04 13:55:43 -04:00
|
|
|
|
2015-08-18 10:16:30 -04:00
|
|
|
describe("transform", () => {
|
|
|
|
it('should return correct value for numbers', () => {
|
|
|
|
expect(pipe.transform(123, [])).toEqual('USD123');
|
|
|
|
expect(pipe.transform(12, ['EUR', false, '.2'])).toEqual('EUR12.00');
|
|
|
|
});
|
2015-08-06 13:39:02 -04:00
|
|
|
|
2015-08-18 10:16:30 -04:00
|
|
|
it("should not support other objects",
|
|
|
|
() => { expect(() => pipe.transform(new Object(), [])).toThrowError(); });
|
|
|
|
});
|
2015-07-04 13:55:43 -04:00
|
|
|
});
|
2015-08-18 10:16:30 -04:00
|
|
|
}
|
2015-07-04 13:55:43 -04:00
|
|
|
}
|