From 739f5706db67dd6dbb2675ddf9e1222a56f044ae Mon Sep 17 00:00:00 2001 From: Shawn Taylor Date: Fri, 24 Mar 2023 11:57:55 -0400 Subject: [PATCH] test(datetime): add tests for parseDate (#27015) --- .../components/datetime/test/parse.spec.ts | 51 ++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/core/src/components/datetime/test/parse.spec.ts b/core/src/components/datetime/test/parse.spec.ts index 73c2aebad9..95b5cf2328 100644 --- a/core/src/components/datetime/test/parse.spec.ts +++ b/core/src/components/datetime/test/parse.spec.ts @@ -1,4 +1,4 @@ -import { clampDate, getPartsFromCalendarDay, parseAmPm, parseMinParts, parseMaxParts } from '../utils/parse'; +import { clampDate, getPartsFromCalendarDay, parseAmPm, parseDate, parseMinParts, parseMaxParts } from '../utils/parse'; describe('getPartsFromCalendarDay()', () => { it('should extract DatetimeParts from a calendar day element', () => { @@ -17,7 +17,54 @@ describe('getPartsFromCalendarDay()', () => { }); }); -// TODO FW-2794: parseDate() +describe('parseDate()', () => { + it('should return undefined when passed undefined', () => { + expect(parseDate(undefined)).toStrictEqual(undefined); + }); + + it('should return undefined when passed null', () => { + expect(parseDate(null)).toStrictEqual(undefined); + }); + + it('should return the correct date object when passed a date', () => { + expect(parseDate('2022-12-15T13:47')).toEqual({ + ampm: 'pm', + day: 15, + hour: 13, + minute: 47, + month: 12, + tzOffset: 0, + year: 2022, + }); + }); + + it('should return the correct time zone offset', () => { + expect(parseDate('2022-12-15T13:47:30-02:00').tzOffset).toEqual(-120); + }); + + it('should parse an array of dates', () => { + expect(parseDate(['2022-12-15T13:47', '2023-03-23T20:19:33.517Z'])).toEqual([ + { + ampm: 'pm', + day: 15, + hour: 13, + minute: 47, + month: 12, + tzOffset: 0, + year: 2022, + }, + { + ampm: 'pm', + day: 23, + hour: 20, + minute: 19, + month: 3, + tzOffset: 0, + year: 2023, + }, + ]); + }); +}); describe('clampDate()', () => { const minParts = {