2016-04-12 12:40:37 -04:00
|
|
|
import {
|
|
|
|
ddescribe,
|
|
|
|
describe,
|
|
|
|
it,
|
|
|
|
iit,
|
|
|
|
xit,
|
|
|
|
expect,
|
|
|
|
beforeEach,
|
2016-04-28 20:50:03 -04:00
|
|
|
afterEach
|
|
|
|
} from '@angular/core/testing/testing_internal';
|
|
|
|
import {browserDetection} from '@angular/platform-browser/testing';
|
2015-07-04 14:04:54 -04:00
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
import {DatePipe} from '@angular/common';
|
|
|
|
import {DateWrapper} from '../../src/facade/lang';
|
|
|
|
import {PipeResolver} from '@angular/compiler/src/pipe_resolver';
|
2015-07-04 14:04:54 -04:00
|
|
|
|
|
|
|
export function main() {
|
2016-04-12 12:40:37 -04:00
|
|
|
describe("DatePipe", () => {
|
2016-06-08 18:45:15 -04:00
|
|
|
var date: any /** TODO #9100 */;
|
|
|
|
var pipe: any /** TODO #9100 */;
|
2015-07-04 14:04:54 -04:00
|
|
|
|
|
|
|
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); });
|
2016-03-28 10:14:32 -04:00
|
|
|
it("should support ISO string",
|
|
|
|
() => { expect(pipe.supports("2015-06-15T21:43:11Z")).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);
|
2016-03-28 10:14:32 -04:00
|
|
|
expect(pipe.supports("")).toBe(false);
|
2015-07-04 14:04:54 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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', () => {
|
2016-04-22 18:33:32 -04:00
|
|
|
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-08-18 10:16:30 -04:00
|
|
|
});
|
2015-07-04 14:04:54 -04:00
|
|
|
|
2015-08-18 10:16:30 -04:00
|
|
|
it('should format common multi component patterns', () => {
|
2016-05-26 15:06:29 -04:00
|
|
|
expect(pipe.transform(date, 'E, M/d/y')).toEqual('Mon, 6/15/2015');
|
|
|
|
expect(pipe.transform(date, 'E, M/d')).toEqual('Mon, 6/15');
|
|
|
|
expect(pipe.transform(date, 'MMM d')).toEqual('Jun 15');
|
|
|
|
expect(pipe.transform(date, 'dd/MM/yyyy')).toEqual('15/06/2015');
|
|
|
|
expect(pipe.transform(date, 'MM/dd/yyyy')).toEqual('06/15/2015');
|
2016-04-22 18:33:32 -04:00
|
|
|
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');
|
2016-05-26 15:06:29 -04:00
|
|
|
expect(pipe.transform(date, 'jm')).toEqual('9:43');
|
2015-08-18 10:16:30 -04:00
|
|
|
});
|
2015-07-04 14:04:54 -04:00
|
|
|
|
2015-08-18 10:16:30 -04:00
|
|
|
it('should format with pattern aliases', () => {
|
2016-04-22 18:33:32 -04:00
|
|
|
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');
|
2016-05-26 15:06:29 -04:00
|
|
|
expect(pipe.transform(date, 'dd/MM/yyyy')).toEqual('15/06/2015');
|
|
|
|
expect(pipe.transform(date, 'MM/dd/yyyy')).toEqual('06/15/2015');
|
2016-04-22 18:33:32 -04:00
|
|
|
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-08-18 10:16:30 -04:00
|
|
|
});
|
2015-07-04 14:04:54 -04:00
|
|
|
});
|
2015-08-18 10:16:30 -04:00
|
|
|
}
|
2015-07-04 14:04:54 -04:00
|
|
|
});
|
|
|
|
}
|