|
| 1 | +import {getCalendarDateString} from '../services'; |
| 2 | + |
| 3 | +describe('services', function () { |
| 4 | + describe('getCalendarDateString()', function () { |
| 5 | + const timestamp = 1585561899000; |
| 6 | + const expectedFormattedDate = '2020-03-30'; |
| 7 | + const throwMessage = 'Invalid Date'; |
| 8 | + const epochDate = '1970-01-01'; |
| 9 | + |
| 10 | + it('should return undefined for undefined date', function () { |
| 11 | + expect(getCalendarDateString()).toEqual(undefined); |
| 12 | + }); |
| 13 | + |
| 14 | + it('should return same date for dashed date string', function () { |
| 15 | + expect(getCalendarDateString('2020-03-30')).toEqual(expectedFormattedDate); |
| 16 | + }); |
| 17 | + |
| 18 | + it('should return dashed date for JS Date', function () { |
| 19 | + expect(getCalendarDateString(new Date('30 Mar 2020'))).toEqual(expectedFormattedDate); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should throw "Invalid Date" for invalid JS Date', function () { |
| 23 | + expect(() => {getCalendarDateString(new Date('30/03/2020'));}).toThrow(throwMessage); |
| 24 | + }); |
| 25 | + |
| 26 | + it('should return dashed date for timestamp number', function () { |
| 27 | + expect(getCalendarDateString(timestamp)).toEqual(expectedFormattedDate); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should return epoch date for invalid timestamp number', function () { |
| 31 | + expect(getCalendarDateString(666)).toEqual(epochDate); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should return dashed date for slashed date string', function () { |
| 35 | + expect(getCalendarDateString('2020/03/30')).toEqual(expectedFormattedDate); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should return dashed date for formatted date string', function () { |
| 39 | + expect(getCalendarDateString('30 Mar 2020')).toEqual(expectedFormattedDate); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should return "Invalid Date" for invalid date string', function () { |
| 43 | + expect(getCalendarDateString('30/3/2020')).toEqual(throwMessage); |
| 44 | + }); |
| 45 | + }); |
| 46 | +}); |
0 commit comments