test: fix calendar tests
This commit is contained in:
@@ -1,12 +1,30 @@
|
||||
import { addMonths, areDatesInSameMonth } from '@/Utils/DateUtils'
|
||||
import { addCalendarMonths, areDatesInSameMonth } from '@/Utils/DateUtils'
|
||||
import { CalendarMonth } from './CalendarMonth'
|
||||
import { insertMonthsWithTarget } from './CalendarUtilts'
|
||||
|
||||
describe('calendar utils', () => {
|
||||
it('handles flakey date', () => {
|
||||
const date = new Date('Mon Oct 31 2022 08:10:18 GMT-0500')
|
||||
const result = addCalendarMonths(date, -1)
|
||||
|
||||
expect(areDatesInSameMonth(date, result)).toEqual(false)
|
||||
})
|
||||
|
||||
it('addMonths', () => {
|
||||
const today = new Date()
|
||||
const result = addCalendarMonths(today, -1)
|
||||
|
||||
expect(areDatesInSameMonth(today, result)).toEqual(false)
|
||||
})
|
||||
|
||||
it('insertMonthsWithTarget in past', () => {
|
||||
const today = new Date()
|
||||
const months: CalendarMonth[] = [{ date: addMonths(today, -1) }, { date: today }, { date: addMonths(today, 1) }]
|
||||
const targetMonth = addMonths(today, -12)
|
||||
const months: CalendarMonth[] = [
|
||||
{ date: addCalendarMonths(today, -1) },
|
||||
{ date: today },
|
||||
{ date: addCalendarMonths(today, 1) },
|
||||
]
|
||||
const targetMonth = addCalendarMonths(today, -12)
|
||||
|
||||
const result = insertMonthsWithTarget(months, targetMonth)
|
||||
|
||||
@@ -16,8 +34,12 @@ describe('calendar utils', () => {
|
||||
|
||||
it('insertMonthsWithTarget in future', () => {
|
||||
const today = new Date()
|
||||
const months: CalendarMonth[] = [{ date: addMonths(today, -1) }, { date: today }, { date: addMonths(today, 1) }]
|
||||
const targetMonth = addMonths(today, 12)
|
||||
const months: CalendarMonth[] = [
|
||||
{ date: addCalendarMonths(today, -1) },
|
||||
{ date: today },
|
||||
{ date: addCalendarMonths(today, 1) },
|
||||
]
|
||||
const targetMonth = addCalendarMonths(today, 12)
|
||||
|
||||
const result = insertMonthsWithTarget(months, targetMonth)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { addMonths, numberOfMonthsBetweenDates } from '@/Utils/DateUtils'
|
||||
import { addCalendarMonths, numberOfMonthsBetweenDates } from '@/Utils/DateUtils'
|
||||
import { CalendarActivity } from './CalendarActivity'
|
||||
import { CalendarMonth } from './CalendarMonth'
|
||||
|
||||
@@ -40,12 +40,12 @@ export function insertMonths(months: CalendarMonth[], location: 'front' | 'end',
|
||||
|
||||
for (let i = 1; i <= number; i++) {
|
||||
if (location === 'front') {
|
||||
const minusNFromFirstMonth = addMonths(earlierMonth, -i)
|
||||
const minusNFromFirstMonth = addCalendarMonths(earlierMonth, -i)
|
||||
months.unshift({
|
||||
date: minusNFromFirstMonth,
|
||||
})
|
||||
} else {
|
||||
const plusNFromLastMonth = addMonths(laterMonth, i)
|
||||
const plusNFromLastMonth = addCalendarMonths(laterMonth, i)
|
||||
months.push({
|
||||
date: plusNFromLastMonth,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user