|
| 1 | +import { |
| 2 | + getArrayInArray, |
| 3 | + getCalendarDays, |
| 4 | + getDayNames, |
| 5 | + getMonths, |
| 6 | + getYears, |
| 7 | +} from '../../src/Vue3DatePicker/utils/util'; |
| 8 | +import { |
| 9 | + getDefaultPattern, |
| 10 | + parseFreeInput, |
| 11 | + resetDateTime, |
| 12 | + setDateTime, |
| 13 | +} from '../../src/Vue3DatePicker/utils/date-utils'; |
| 14 | + |
| 15 | +describe('Utils and date utils formatting', () => { |
| 16 | + it('Should get calendar days', () => { |
| 17 | + const days = getCalendarDays(0, 2021, 1, false); |
| 18 | + |
| 19 | + expect(days).toHaveLength(5); |
| 20 | + expect(days[0].days).toHaveLength(7); |
| 21 | + expect(days[0].days[0].text).toEqual(28); |
| 22 | + }); |
| 23 | + |
| 24 | + it('Should get calendar days starting from sunday', () => { |
| 25 | + const days = getCalendarDays(0, 2021, 0, false); |
| 26 | + expect(days).toHaveLength(6); |
| 27 | + expect(days[0].days[0].text).toEqual(27); |
| 28 | + }); |
| 29 | + |
| 30 | + it('Should get calendar days with hidden offset dats', () => { |
| 31 | + const days = getCalendarDays(0, 2021, 1, true); |
| 32 | + |
| 33 | + expect(days).toHaveLength(5); |
| 34 | + expect(days[0].days[0].text).toEqual(''); |
| 35 | + }); |
| 36 | + |
| 37 | + it('Should group array by 3', () => { |
| 38 | + const items = getArrayInArray(Array.from(Array(10).keys())); |
| 39 | + |
| 40 | + expect(items).toHaveLength(4); |
| 41 | + expect(items[0]).toHaveLength(3); |
| 42 | + }); |
| 43 | + |
| 44 | + it('Should get day names', () => { |
| 45 | + const days = getDayNames('de', 1); |
| 46 | + |
| 47 | + expect(days).toHaveLength(7); |
| 48 | + expect(days[1]).toEqual('Di'); |
| 49 | + }); |
| 50 | + |
| 51 | + it('Should generate years', () => { |
| 52 | + const years = getYears([2021, 2025]); |
| 53 | + |
| 54 | + expect(years).toHaveLength(5); |
| 55 | + expect(years[1].value).toEqual(2022); |
| 56 | + }); |
| 57 | + |
| 58 | + it('Should get month values', () => { |
| 59 | + const months = getMonths('en', 'long'); |
| 60 | + |
| 61 | + expect(months).toHaveLength(12); |
| 62 | + expect(months[0].text).toEqual('January'); |
| 63 | + }); |
| 64 | + |
| 65 | + it('Should get default pattern', () => { |
| 66 | + const patternDef = getDefaultPattern(null, true, false, false, true); |
| 67 | + const patternMonthPicker = getDefaultPattern(null, true, true, false, false); |
| 68 | + |
| 69 | + expect(patternDef).toEqual('MM/dd/yyyy, HH:mm'); |
| 70 | + expect(patternMonthPicker).toEqual('MM/yyyy'); |
| 71 | + }); |
| 72 | + |
| 73 | + it('Should parse free input', () => { |
| 74 | + const date = parseFreeInput('01/01/2021', 'MM/dd/yyyy, HH:mm'); |
| 75 | + |
| 76 | + expect(date).toBeDefined(); |
| 77 | + expect(date?.getMonth()).toEqual(0); |
| 78 | + }); |
| 79 | + |
| 80 | + it('Should reset date time', () => { |
| 81 | + const date = new Date(); |
| 82 | + const resetDate = resetDateTime(date); |
| 83 | + |
| 84 | + expect(resetDate.getHours()).toEqual(0); |
| 85 | + expect(resetDate.getMinutes()).toEqual(0); |
| 86 | + expect(resetDate.getSeconds()).toEqual(0); |
| 87 | + expect(resetDate.getMilliseconds()).toEqual(0); |
| 88 | + }); |
| 89 | + |
| 90 | + it('Should set date time', () => { |
| 91 | + const date = setDateTime(new Date(), 12, 12); |
| 92 | + |
| 93 | + expect(date.getHours()).toEqual(12); |
| 94 | + expect(date.getMinutes()).toEqual(12); |
| 95 | + }); |
| 96 | +}); |
0 commit comments