From c276ecf7e6e9cc40656028f2ea69e1f2555d66c9 Mon Sep 17 00:00:00 2001 From: Suvish Varghese Thoovamalayil <suvisht@thoughtworks.com> Date: Thu, 08 Feb 2018 20:56:08 +0100 Subject: [PATCH] Allow specifying viewDate as a prop, fixes #468 --- test/tests.spec.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 49 insertions(+), 0 deletions(-) diff --git a/test/tests.spec.js b/test/tests.spec.js index 883f7ca..c156400 100644 --- a/test/tests.spec.js +++ b/test/tests.spec.js @@ -1174,4 +1174,53 @@ }); }); + + describe('with viewDate', () => { + it('date value', () => { + const date = new Date(2000, 0, 15, 2, 2, 2, 2), + strDate = moment(date).format('MMMM YYYY'), + component = utils.createDatetime({ viewDate: date }); + expect(utils.getViewDateValue(component)).toEqual(strDate); + }); + + it('moment value', () => { + const date = new Date(2000, 0, 15, 2, 2, 2, 2), + mDate = moment(date), + strDate = mDate.format('MMMM YYYY'), + component = utils.createDatetime({ viewDate: mDate }); + expect(utils.getViewDateValue(component)).toEqual(strDate); + }); + + it('string value', () => { + const date = new Date(2000, 0, 15, 2, 2, 2, 2), + mDate = moment(date), + strDate = mDate.format('L') + ' ' + mDate.format('LT'), + expectedStrDate = mDate.format('MMMM YYYY'), + component = utils.createDatetime({ viewDate: strDate }); + expect(utils.getViewDateValue(component)).toEqual(expectedStrDate); + }); + + it('UTC value from UTC string', () => { + const date = new Date(2000, 0, 15, 2, 2, 2, 2), + momentDateUTC = moment.utc(date), + strDateUTC = momentDateUTC.format('L') + ' ' + momentDateUTC.format('LT'), + expectedStrDate = momentDateUTC.format('MMMM YYYY'), + component = utils.createDatetime({ viewDate: strDateUTC, utc: true }); + expect(utils.getViewDateValue(component)).toEqual(expectedStrDate); + }); + + it('invalid string value', () => { + const strDate = 'invalid string', + expectedStrDate = moment().format('MMMM YYYY'), + component = utils.createDatetime({ viewDate: strDate }); + expect(utils.getViewDateValue(component)).toEqual(expectedStrDate); + }); + + it('invalid moment object', () => { + const mDate = moment(null), + expectedStrDate = moment().format('MMMM YYYY'), + component = utils.createDatetime({ viewDate: mDate }); + expect(utils.getViewDateValue(component)).toEqual(expectedStrDate); + }); + }); }); -- Gitblit v1.9.3