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 14:04:54 -04:00
|
|
|
|
2015-11-18 18:55:43 -05:00
|
|
|
import {DatePipe} from 'angular2/common';
|
2015-11-06 20:34:07 -05:00
|
|
|
import {DateWrapper} from 'angular2/src/facade/lang';
|
2016-01-06 17:13:44 -05:00
|
|
|
import {PipeResolver} from 'angular2/src/compiler/pipe_resolver';
|
2015-07-04 14:04:54 -04:00
|
|
|
|
|
|
|
export function main() {
|
2016-04-12 12:40:37 -04:00
|
|
|
describe("DatePipe", () => {
|
2015-07-04 14:04:54 -04:00
|
|
|
var date;
|
|
|
|
var pipe;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
date = DateWrapper.create(2015, 6, 15, 21, 43, 11);
|
|
|
|
pipe = new DatePipe();
|
|
|
|
});
|
|
|
|
|
2015-10-27 19:37:08 -04:00
|
|
|
it('should be marked as pure',
|
|
|
|
() => { expect(new PipeResolver().resolve(DatePipe).pure).toEqual(true); });
|
2015-10-27 15:43:34 -04:00
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
describe("supports", () => {
|
|
|
|
it("should support date", () => { expect(pipe.supports(date)).toBe(true); });
|
|
|
|
it("should support int", () => { expect(pipe.supports(123456789)).toBe(true); });
|
2015-07-04 14:04:54 -04:00
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
it("should not support other objects", () => {
|
2015-07-04 14:04:54 -04:00
|
|
|
expect(pipe.supports(new Object())).toBe(false);
|
|
|
|
expect(pipe.supports(null)).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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) {
|
2016-04-12 12:40:37 -04:00
|
|
|
describe("transform", () => {
|
2015-08-18 10:16:30 -04:00
|
|
|
it('should format each component correctly', () => {
|
|
|
|
expect(pipe.transform(date, ['y'])).toEqual('2015');
|
|
|
|
expect(pipe.transform(date, ['yy'])).toEqual('15');
|
|
|
|
expect(pipe.transform(date, ['M'])).toEqual('6');
|
|
|
|
expect(pipe.transform(date, ['MM'])).toEqual('06');
|
|
|
|
expect(pipe.transform(date, ['MMM'])).toEqual('Jun');
|
|
|
|
expect(pipe.transform(date, ['MMMM'])).toEqual('June');
|
|
|
|
expect(pipe.transform(date, ['d'])).toEqual('15');
|
|
|
|
expect(pipe.transform(date, ['E'])).toEqual('Mon');
|
|
|
|
expect(pipe.transform(date, ['EEEE'])).toEqual('Monday');
|
|
|
|
expect(pipe.transform(date, ['H'])).toEqual('21');
|
|
|
|
expect(pipe.transform(date, ['j'])).toEqual('9 PM');
|
|
|
|
expect(pipe.transform(date, ['m'])).toEqual('43');
|
|
|
|
expect(pipe.transform(date, ['s'])).toEqual('11');
|
|
|
|
});
|
2015-07-04 14:04:54 -04:00
|
|
|
|
2015-08-18 10:16:30 -04:00
|
|
|
it('should format common multi component patterns', () => {
|
|
|
|
expect(pipe.transform(date, ['yMEd'])).toEqual('Mon, 6/15/2015');
|
|
|
|
expect(pipe.transform(date, ['MEd'])).toEqual('Mon, 6/15');
|
|
|
|
expect(pipe.transform(date, ['MMMd'])).toEqual('Jun 15');
|
|
|
|
expect(pipe.transform(date, ['yMMMMEEEEd'])).toEqual('Monday, June 15, 2015');
|
|
|
|
expect(pipe.transform(date, ['jms'])).toEqual('9:43:11 PM');
|
|
|
|
expect(pipe.transform(date, ['ms'])).toEqual('43:11');
|
|
|
|
});
|
2015-07-04 14:04:54 -04:00
|
|
|
|
2015-08-18 10:16:30 -04:00
|
|
|
it('should format with pattern aliases', () => {
|
|
|
|
expect(pipe.transform(date, ['medium'])).toEqual('Jun 15, 2015, 9:43:11 PM');
|
|
|
|
expect(pipe.transform(date, ['short'])).toEqual('6/15/2015, 9:43 PM');
|
|
|
|
expect(pipe.transform(date, ['fullDate'])).toEqual('Monday, June 15, 2015');
|
|
|
|
expect(pipe.transform(date, ['longDate'])).toEqual('June 15, 2015');
|
|
|
|
expect(pipe.transform(date, ['mediumDate'])).toEqual('Jun 15, 2015');
|
|
|
|
expect(pipe.transform(date, ['shortDate'])).toEqual('6/15/2015');
|
|
|
|
expect(pipe.transform(date, ['mediumTime'])).toEqual('9:43:11 PM');
|
|
|
|
expect(pipe.transform(date, ['shortTime'])).toEqual('9:43 PM');
|
|
|
|
});
|
2015-07-04 14:04:54 -04:00
|
|
|
});
|
2015-08-18 10:16:30 -04:00
|
|
|
}
|
2015-07-04 14:04:54 -04:00
|
|
|
});
|
|
|
|
}
|