chore: fix tests
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { EntityObject } from '../../../../chrono_manager/src/models/entity'
|
||||
import type { EventOccurrence, EventMutation } from '../../../../chrono_manager/src/types/event'
|
||||
import { daysVisibleRange } from '../../../src/utils/dateRanges'
|
||||
import { expandEntityOccurrences } from '../../../src/utils/recurrence'
|
||||
import { daysVisibleRange } from '../../../src/utils/date'
|
||||
import { expandEntityInstances } from '../../../src/utils/recurrence'
|
||||
|
||||
function localIso(year: number, month: number, day: number, hour = 9): string {
|
||||
return new Date(year, month, day, hour).toISOString()
|
||||
@@ -34,14 +34,14 @@ describe('daily recurrence', () => {
|
||||
precision: 'daily',
|
||||
interval: 2,
|
||||
})
|
||||
const occurrences = expandEntityOccurrences(
|
||||
const instances = expandEntityInstances(
|
||||
entity,
|
||||
daysVisibleRange(new Date(2026, 5, 4), 6),
|
||||
)
|
||||
|
||||
expect(occurrences.map(occurrence => new Date(occurrence.startMs).getDate())).toEqual([5, 7, 9])
|
||||
expect(occurrences.every(occurrence => occurrence.durationMs === 60 * 60 * 1000)).toBe(true)
|
||||
expect(new Set(occurrences.map(occurrence => occurrence.key)).size).toBe(3)
|
||||
expect(instances.map(instance => new Date(instance.startMs).getDate())).toEqual([5, 7, 9])
|
||||
expect(instances.every(instance => instance.durationMs === 60 * 60 * 1000)).toBe(true)
|
||||
expect(new Set(instances.map(instance => instance.key)).size).toBe(3)
|
||||
})
|
||||
|
||||
it('honors iteration limits before the requested range', () => {
|
||||
@@ -51,12 +51,12 @@ describe('daily recurrence', () => {
|
||||
interval: 1,
|
||||
iterations: 3,
|
||||
})
|
||||
const occurrences = expandEntityOccurrences(
|
||||
const instances = expandEntityInstances(
|
||||
entity,
|
||||
daysVisibleRange(new Date(2026, 5, 10), 3),
|
||||
)
|
||||
|
||||
expect(occurrences).toEqual([])
|
||||
expect(instances).toEqual([])
|
||||
})
|
||||
|
||||
it('treats a date-only conclusion as an inclusive local date', () => {
|
||||
@@ -66,12 +66,12 @@ describe('daily recurrence', () => {
|
||||
interval: 1,
|
||||
concludes: '2026-06-03',
|
||||
})
|
||||
const occurrences = expandEntityOccurrences(
|
||||
const instances = expandEntityInstances(
|
||||
entity,
|
||||
daysVisibleRange(new Date(2026, 5, 1), 5),
|
||||
)
|
||||
|
||||
expect(occurrences.map(occurrence => new Date(occurrence.startMs).getDate())).toEqual([1, 2, 3])
|
||||
expect(instances.map(instance => new Date(instance.startMs).getDate())).toEqual([1, 2, 3])
|
||||
})
|
||||
|
||||
it('preserves local wall-clock time across daylight-saving changes', () => {
|
||||
@@ -80,12 +80,12 @@ describe('daily recurrence', () => {
|
||||
precision: 'daily',
|
||||
interval: 1,
|
||||
}, {}, localIso(2026, 2, 7, 9))
|
||||
const occurrences = expandEntityOccurrences(
|
||||
const instances = expandEntityInstances(
|
||||
entity,
|
||||
daysVisibleRange(new Date(2026, 2, 7), 3),
|
||||
)
|
||||
|
||||
expect(occurrences.map(occurrence => new Date(occurrence.startMs).getHours())).toEqual([9, 9, 9])
|
||||
expect(instances.map(instance => new Date(instance.startMs).getHours())).toEqual([9, 9, 9])
|
||||
})
|
||||
|
||||
it('preserves exclusive calendar-day duration for recurring timeless events', () => {
|
||||
@@ -101,15 +101,15 @@ describe('daily recurrence', () => {
|
||||
event.endsOn = '2026-03-08T00:00:00+00:00'
|
||||
event.timeless = true
|
||||
|
||||
const occurrences = expandEntityOccurrences(
|
||||
const instances = expandEntityInstances(
|
||||
entity,
|
||||
daysVisibleRange(new Date(2026, 2, 7), 3),
|
||||
)
|
||||
|
||||
expect(occurrences).toHaveLength(3)
|
||||
expect(occurrences.map(occurrence => new Date(occurrence.startMs).getHours())).toEqual([0, 0, 0])
|
||||
expect(occurrences.map(occurrence => {
|
||||
const end = new Date(occurrence.endMs)
|
||||
expect(instances).toHaveLength(3)
|
||||
expect(instances.map(instance => new Date(instance.startMs).getHours())).toEqual([0, 0, 0])
|
||||
expect(instances.map(instance => {
|
||||
const end = new Date(instance.endMs)
|
||||
return [end.getDate(), end.getHours()]
|
||||
})).toEqual([[8, 0], [9, 0], [10, 0]])
|
||||
})
|
||||
@@ -123,12 +123,12 @@ describe('weekly recurrence', () => {
|
||||
interval: 1,
|
||||
onDayOfWeek: [1, 3],
|
||||
})
|
||||
const occurrences = expandEntityOccurrences(
|
||||
const instances = expandEntityInstances(
|
||||
entity,
|
||||
daysVisibleRange(new Date(2026, 5, 1), 10),
|
||||
)
|
||||
|
||||
expect(occurrences.map(occurrence => new Date(occurrence.startMs).getDate())).toEqual([1, 3, 8, 10])
|
||||
expect(instances.map(instance => new Date(instance.startMs).getDate())).toEqual([1, 3, 8, 10])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -145,12 +145,12 @@ describe('recurrence mutations', () => {
|
||||
mutationExclusion: true,
|
||||
},
|
||||
})
|
||||
const occurrences = expandEntityOccurrences(
|
||||
const instances = expandEntityInstances(
|
||||
entity,
|
||||
daysVisibleRange(new Date(2026, 5, 1), 3),
|
||||
)
|
||||
|
||||
expect(occurrences.map(occurrence => new Date(occurrence.startMs).getDate())).toEqual([1, 3])
|
||||
expect(instances.map(instance => new Date(instance.startMs).getDate())).toEqual([1, 3])
|
||||
})
|
||||
|
||||
it('moves and restyles a modified occurrence without duplicating it', () => {
|
||||
@@ -171,13 +171,13 @@ describe('recurrence mutations', () => {
|
||||
color: '#abcdef',
|
||||
},
|
||||
})
|
||||
const occurrences = expandEntityOccurrences(
|
||||
const instances = expandEntityInstances(
|
||||
entity,
|
||||
daysVisibleRange(new Date(2026, 5, 1), 5),
|
||||
)
|
||||
const moved = occurrences.find(occurrence => occurrence.occurrenceId === sourceId)
|
||||
const moved = instances.find(instance => instance.instanceId === sourceId)
|
||||
|
||||
expect(occurrences).toHaveLength(2)
|
||||
expect(instances).toHaveLength(2)
|
||||
expect(new Date(moved!.startMs).getHours()).toBe(14)
|
||||
expect(moved!.durationMs).toBe(2 * 60 * 60 * 1000)
|
||||
expect(moved!.label).toBe('Moved standup')
|
||||
|
||||
Reference in New Issue
Block a user