@jsb188/calendar 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +45 -0
- package/src/constants/calendar.ts +153 -0
- package/src/css.d.ts +7 -0
- package/src/libs/calendar-geometry.ts +500 -0
- package/src/libs/calendar-gesture.ts +341 -0
- package/src/libs/calendar-now.ts +39 -0
- package/src/libs/calendar-range.ts +401 -0
- package/src/libs/calendar-state.ts +26 -0
- package/src/libs/calendar-url.ts +191 -0
- package/src/libs/roster-layout.ts +388 -0
- package/src/main.ts +32 -0
- package/src/modules/Calendar.tsx +736 -0
- package/src/modules/MiniCalendar.tsx +376 -0
- package/src/types/calendar.d.ts +128 -0
- package/src/types/shift-form.d.ts +19 -0
- package/src/ui/CalendarAgendaUI.tsx +115 -0
- package/src/ui/CalendarMonthUI.tsx +142 -0
- package/src/ui/CalendarToolbarUI.tsx +133 -0
- package/src/ui/CalendarUI.tsx +401 -0
- package/src/ui/CalendarYearUI.tsx +67 -0
- package/src/ui/RosterUI.tsx +273 -0
- package/src/ui/ShiftFormUI.tsx +333 -0
- package/tests/calendar-geometry.test.ts +549 -0
- package/tests/calendar-gesture.test.ts +340 -0
- package/tests/calendar-range.test.ts +358 -0
- package/tests/calendar-url.test.ts +189 -0
- package/tests/roster-layout.test.ts +210 -0
- package/tsconfig.json +13 -0
- package/vitest.config.ts +11 -0
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
getCalendarAllDayLayout,
|
|
4
|
+
getCalendarEventsByDateKey,
|
|
5
|
+
getCalendarMonthCells,
|
|
6
|
+
getCalendarTimedLayout,
|
|
7
|
+
} from '../src/libs/calendar-geometry.ts';
|
|
8
|
+
import {
|
|
9
|
+
getCalendarRange,
|
|
10
|
+
parseCalendarDateParam,
|
|
11
|
+
} from '../src/libs/calendar-range.ts';
|
|
12
|
+
import type { CalendarEventObj } from '../src/types/calendar.d.ts';
|
|
13
|
+
|
|
14
|
+
const LA = 'America/Los_Angeles';
|
|
15
|
+
const NOW = new Date('2026-07-22T19:00:00Z');
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Build the week of 2026-07-19 in Los Angeles.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
function buildWeek() {
|
|
22
|
+
return getCalendarRange({
|
|
23
|
+
view: 'WEEK',
|
|
24
|
+
anchorDate: parseCalendarDateParam('2026-07-22', NOW, LA),
|
|
25
|
+
now: NOW,
|
|
26
|
+
timeZone: LA,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/*
|
|
31
|
+
* Build one timed event. Times are ISO strings so the tests read as instants.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
function buildEvent(
|
|
35
|
+
id: string,
|
|
36
|
+
startAt: string,
|
|
37
|
+
endAt: string,
|
|
38
|
+
overrides: Partial<CalendarEventObj> = {},
|
|
39
|
+
): CalendarEventObj {
|
|
40
|
+
return {
|
|
41
|
+
id,
|
|
42
|
+
calendarId: 'cal1',
|
|
43
|
+
title: id,
|
|
44
|
+
startAt: new Date(startAt),
|
|
45
|
+
endAt: new Date(endAt),
|
|
46
|
+
allDay: false,
|
|
47
|
+
kind: 'SHIFT',
|
|
48
|
+
status: 'PUBLISHED',
|
|
49
|
+
assigneeResourceIds: [],
|
|
50
|
+
...overrides,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
describe('getCalendarTimedLayout', () => {
|
|
55
|
+
it('places one event at the right minutes of its day', () => {
|
|
56
|
+
const week = buildWeek();
|
|
57
|
+
// 09:00–17:00 local on Wednesday the 22nd
|
|
58
|
+
const layout = getCalendarTimedLayout(
|
|
59
|
+
[buildEvent('a', '2026-07-22T16:00:00Z', '2026-07-23T00:00:00Z')],
|
|
60
|
+
week.days,
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
expect(layout).toHaveLength(1);
|
|
64
|
+
expect(layout[0].dayIndex).toBe(3);
|
|
65
|
+
expect(layout[0].startMinute).toBe(9 * 60);
|
|
66
|
+
expect(layout[0].endMinute).toBe(17 * 60);
|
|
67
|
+
expect(layout[0].left).toBe(0);
|
|
68
|
+
expect(layout[0].width).toBe(1);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('splits an overnight shift into one rectangle per day', () => {
|
|
72
|
+
const week = buildWeek();
|
|
73
|
+
// 22:00 Wednesday to 06:00 Thursday, local
|
|
74
|
+
const layout = getCalendarTimedLayout(
|
|
75
|
+
[buildEvent('night', '2026-07-23T05:00:00Z', '2026-07-23T13:00:00Z')],
|
|
76
|
+
week.days,
|
|
77
|
+
).sort((left, right) => left.dayIndex - right.dayIndex);
|
|
78
|
+
|
|
79
|
+
expect(layout).toHaveLength(2);
|
|
80
|
+
|
|
81
|
+
expect(layout[0].dayIndex).toBe(3);
|
|
82
|
+
expect(layout[0].startMinute).toBe(22 * 60);
|
|
83
|
+
expect(layout[0].endMinute).toBe(24 * 60);
|
|
84
|
+
expect(layout[0].continuesToNextDay).toBe(true);
|
|
85
|
+
expect(layout[0].continuesFromPreviousDay).toBe(false);
|
|
86
|
+
|
|
87
|
+
expect(layout[1].dayIndex).toBe(4);
|
|
88
|
+
expect(layout[1].startMinute).toBe(0);
|
|
89
|
+
expect(layout[1].endMinute).toBe(6 * 60);
|
|
90
|
+
expect(layout[1].continuesFromPreviousDay).toBe(true);
|
|
91
|
+
expect(layout[1].continuesToNextDay).toBe(false);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('does not draw an event ending exactly at midnight on the next day', () => {
|
|
95
|
+
const week = buildWeek();
|
|
96
|
+
const layout = getCalendarTimedLayout(
|
|
97
|
+
[buildEvent('closes', '2026-07-22T22:00:00Z', '2026-07-23T07:00:00Z')],
|
|
98
|
+
week.days,
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
// A half-open interval ending at the boundary belongs only to the day it ran
|
|
102
|
+
expect(layout).toHaveLength(1);
|
|
103
|
+
expect(layout[0].dayIndex).toBe(3);
|
|
104
|
+
expect(layout[0].endMinute).toBe(24 * 60);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('draws an event starting exactly at midnight on its own day', () => {
|
|
108
|
+
const week = buildWeek();
|
|
109
|
+
// 00:00–08:00 local on Wednesday the 22nd. The mirror of the case above:
|
|
110
|
+
// the day span is found by binary search, so both boundary directions
|
|
111
|
+
// have to land on the day the event actually belongs to.
|
|
112
|
+
const layout = getCalendarTimedLayout(
|
|
113
|
+
[buildEvent('opens', '2026-07-22T07:00:00Z', '2026-07-22T15:00:00Z')],
|
|
114
|
+
week.days,
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
expect(layout).toHaveLength(1);
|
|
118
|
+
expect(layout[0].dayIndex).toBe(3);
|
|
119
|
+
expect(layout[0].startMinute).toBe(0);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('draws an event covering the first and last day of the range', () => {
|
|
123
|
+
const week = buildWeek();
|
|
124
|
+
// Sunday 00:00 local through the following Sunday: every column, with
|
|
125
|
+
// both ends of the binary search clamped to the range
|
|
126
|
+
const layout = getCalendarTimedLayout(
|
|
127
|
+
[buildEvent('all_week', '2026-07-19T07:00:00Z', '2026-07-26T07:00:00Z')],
|
|
128
|
+
week.days,
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
expect(layout.map((entry) => entry.dayIndex)).toEqual([
|
|
132
|
+
0, 1, 2, 3, 4, 5, 6,
|
|
133
|
+
]);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('splits two overlapping events down the middle', () => {
|
|
137
|
+
const week = buildWeek();
|
|
138
|
+
const layout = getCalendarTimedLayout(
|
|
139
|
+
[
|
|
140
|
+
buildEvent('a', '2026-07-22T16:00:00Z', '2026-07-22T20:00:00Z'),
|
|
141
|
+
buildEvent('b', '2026-07-22T17:00:00Z', '2026-07-22T21:00:00Z'),
|
|
142
|
+
],
|
|
143
|
+
week.days,
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
expect(layout.map((entry) => entry.columnCount)).toEqual([2, 2]);
|
|
147
|
+
expect(layout.map((entry) => entry.left).sort()).toEqual([0, 0.5]);
|
|
148
|
+
expect(layout.every((entry) => entry.width === 0.5)).toBe(true);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('gives a non-overlapping later event the full width', () => {
|
|
152
|
+
const week = buildWeek();
|
|
153
|
+
// Two at 9am, one at 2pm: the 2pm event is its own cluster
|
|
154
|
+
const layout = getCalendarTimedLayout(
|
|
155
|
+
[
|
|
156
|
+
buildEvent('a', '2026-07-22T16:00:00Z', '2026-07-22T18:00:00Z'),
|
|
157
|
+
buildEvent('b', '2026-07-22T16:00:00Z', '2026-07-22T18:00:00Z'),
|
|
158
|
+
buildEvent('c', '2026-07-22T21:00:00Z', '2026-07-22T22:00:00Z'),
|
|
159
|
+
],
|
|
160
|
+
week.days,
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
const afternoon = layout.find((entry) => entry.event.id === 'c');
|
|
164
|
+
|
|
165
|
+
expect(afternoon?.columnCount).toBe(1);
|
|
166
|
+
expect(afternoon?.width).toBe(1);
|
|
167
|
+
expect(
|
|
168
|
+
layout
|
|
169
|
+
.filter((entry) => entry.event.id !== 'c')
|
|
170
|
+
.every((entry) => entry.columnCount === 2),
|
|
171
|
+
).toBe(true);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('treats a transitively-overlapping chain as one cluster', () => {
|
|
175
|
+
const week = buildWeek();
|
|
176
|
+
// A 9-12, B 10-13, C 11-14 — A and C never touch, but every column is
|
|
177
|
+
// still busy when C starts, so all three must share the width or B
|
|
178
|
+
// would be drawn over one of them
|
|
179
|
+
const layout = getCalendarTimedLayout(
|
|
180
|
+
[
|
|
181
|
+
buildEvent('a', '2026-07-22T16:00:00Z', '2026-07-22T19:00:00Z'),
|
|
182
|
+
buildEvent('b', '2026-07-22T17:00:00Z', '2026-07-22T20:00:00Z'),
|
|
183
|
+
buildEvent('c', '2026-07-22T18:00:00Z', '2026-07-22T21:00:00Z'),
|
|
184
|
+
],
|
|
185
|
+
week.days,
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
expect(layout.map((entry) => entry.columnCount)).toEqual([3, 3, 3]);
|
|
189
|
+
expect(layout.map((entry) => entry.column).sort()).toEqual([0, 1, 2]);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('packs a chain into fewer columns when an earlier one has ended', () => {
|
|
193
|
+
const week = buildWeek();
|
|
194
|
+
// A 9-11, B 10-12, C 11:30-13 — the same chain shape, but C can reuse
|
|
195
|
+
// the column A vacated, so two columns is the correct answer and three
|
|
196
|
+
// would waste half the day's width
|
|
197
|
+
const layout = getCalendarTimedLayout(
|
|
198
|
+
[
|
|
199
|
+
buildEvent('a', '2026-07-22T16:00:00Z', '2026-07-22T18:00:00Z'),
|
|
200
|
+
buildEvent('b', '2026-07-22T17:00:00Z', '2026-07-22T19:00:00Z'),
|
|
201
|
+
buildEvent('c', '2026-07-22T18:30:00Z', '2026-07-22T20:00:00Z'),
|
|
202
|
+
],
|
|
203
|
+
week.days,
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
const byId = Object.fromEntries(
|
|
207
|
+
layout.map((entry) => [entry.event.id, entry]),
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
expect(layout.map((entry) => entry.columnCount)).toEqual([2, 2, 2]);
|
|
211
|
+
expect(byId.c.column).toBe(byId.a.column);
|
|
212
|
+
expect(byId.b.column).not.toBe(byId.a.column);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('reuses a freed column for a later non-overlapping event in the same cluster', () => {
|
|
216
|
+
const week = buildWeek();
|
|
217
|
+
// A 9-10, B 9-12, C 10:30-11 — C can take A's column
|
|
218
|
+
const layout = getCalendarTimedLayout(
|
|
219
|
+
[
|
|
220
|
+
buildEvent('a', '2026-07-22T16:00:00Z', '2026-07-22T17:00:00Z'),
|
|
221
|
+
buildEvent('b', '2026-07-22T16:00:00Z', '2026-07-22T19:00:00Z'),
|
|
222
|
+
buildEvent('c', '2026-07-22T17:30:00Z', '2026-07-22T18:00:00Z'),
|
|
223
|
+
],
|
|
224
|
+
week.days,
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
const byId = Object.fromEntries(
|
|
228
|
+
layout.map((entry) => [entry.event.id, entry]),
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
expect(byId.c.column).toBe(byId.a.column);
|
|
232
|
+
expect(byId.b.columnCount).toBe(2);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('stacks rather than slivers past the column cap', () => {
|
|
236
|
+
const week = buildWeek();
|
|
237
|
+
const events = Array.from({ length: 8 }, (_unused, index) =>
|
|
238
|
+
buildEvent(`e${index}`, '2026-07-22T16:00:00Z', '2026-07-22T20:00:00Z'),
|
|
239
|
+
);
|
|
240
|
+
const layout = getCalendarTimedLayout(events, week.days);
|
|
241
|
+
|
|
242
|
+
expect(layout.every((entry) => entry.columnCount === 8)).toBe(true);
|
|
243
|
+
// Nothing is narrower than a readable slice, and each peeks out
|
|
244
|
+
expect(layout.every((entry) => entry.width >= 0.1)).toBe(true);
|
|
245
|
+
expect(new Set(layout.map((entry) => entry.left)).size).toBeGreaterThan(1);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('keeps two near-instant events side by side rather than stacked', () => {
|
|
249
|
+
const week = buildWeek();
|
|
250
|
+
// Five minutes apart and five minutes long: they do not overlap in time,
|
|
251
|
+
// but both are drawn at the minimum height, so they overlap on screen
|
|
252
|
+
const layout = getCalendarTimedLayout(
|
|
253
|
+
[
|
|
254
|
+
buildEvent('a', '2026-07-22T16:00:00Z', '2026-07-22T16:05:00Z'),
|
|
255
|
+
buildEvent('b', '2026-07-22T16:05:00Z', '2026-07-22T16:10:00Z'),
|
|
256
|
+
],
|
|
257
|
+
week.days,
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
expect(layout.map((entry) => entry.columnCount)).toEqual([2, 2]);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it('excludes all-day entries from the time grid', () => {
|
|
264
|
+
const week = buildWeek();
|
|
265
|
+
const layout = getCalendarTimedLayout(
|
|
266
|
+
[
|
|
267
|
+
buildEvent('holiday', '2026-07-22T07:00:00Z', '2026-07-23T07:00:00Z', {
|
|
268
|
+
allDay: true,
|
|
269
|
+
}),
|
|
270
|
+
],
|
|
271
|
+
week.days,
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
expect(layout).toHaveLength(0);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('drops an event entirely outside the range', () => {
|
|
278
|
+
const week = buildWeek();
|
|
279
|
+
const layout = getCalendarTimedLayout(
|
|
280
|
+
[buildEvent('past', '2026-06-01T16:00:00Z', '2026-06-01T18:00:00Z')],
|
|
281
|
+
week.days,
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
expect(layout).toHaveLength(0);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it('places events correctly on a DST fall-back day', () => {
|
|
288
|
+
const range = getCalendarRange({
|
|
289
|
+
view: 'DAY',
|
|
290
|
+
anchorDate: parseCalendarDateParam('2026-11-01', NOW, LA),
|
|
291
|
+
now: NOW,
|
|
292
|
+
timeZone: LA,
|
|
293
|
+
});
|
|
294
|
+
// 9am local on the 25-hour day is 17:00Z (PST, after the transition)
|
|
295
|
+
const layout = getCalendarTimedLayout(
|
|
296
|
+
[buildEvent('a', '2026-11-01T17:00:00Z', '2026-11-01T18:00:00Z')],
|
|
297
|
+
range.days,
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
// Measured from the day's own start, an extra hour has already elapsed
|
|
301
|
+
expect(layout[0].startMinute).toBe(10 * 60);
|
|
302
|
+
expect(layout[0].endMinute).toBe(11 * 60);
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
describe('getCalendarAllDayLayout', () => {
|
|
307
|
+
it('spans an all-day entry across its day columns', () => {
|
|
308
|
+
const week = buildWeek();
|
|
309
|
+
const bars = getCalendarAllDayLayout(
|
|
310
|
+
[
|
|
311
|
+
buildEvent('conf', '2026-07-21T07:00:00Z', '2026-07-24T07:00:00Z', {
|
|
312
|
+
allDay: true,
|
|
313
|
+
}),
|
|
314
|
+
],
|
|
315
|
+
week.days,
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
expect(bars).toHaveLength(1);
|
|
319
|
+
expect(bars[0].startDayIndex).toBe(2);
|
|
320
|
+
expect(bars[0].endDayIndex).toBe(4);
|
|
321
|
+
expect(bars[0].row).toBe(0);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it('packs non-overlapping bars onto the same row', () => {
|
|
325
|
+
const week = buildWeek();
|
|
326
|
+
const bars = getCalendarAllDayLayout(
|
|
327
|
+
[
|
|
328
|
+
buildEvent('a', '2026-07-19T07:00:00Z', '2026-07-21T07:00:00Z', {
|
|
329
|
+
allDay: true,
|
|
330
|
+
}),
|
|
331
|
+
buildEvent('b', '2026-07-23T07:00:00Z', '2026-07-25T07:00:00Z', {
|
|
332
|
+
allDay: true,
|
|
333
|
+
}),
|
|
334
|
+
],
|
|
335
|
+
week.days,
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
expect(bars.map((bar) => bar.row)).toEqual([0, 0]);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it('pushes an overlapping bar to the next row', () => {
|
|
342
|
+
const week = buildWeek();
|
|
343
|
+
const bars = getCalendarAllDayLayout(
|
|
344
|
+
[
|
|
345
|
+
buildEvent('a', '2026-07-19T07:00:00Z', '2026-07-23T07:00:00Z', {
|
|
346
|
+
allDay: true,
|
|
347
|
+
}),
|
|
348
|
+
buildEvent('b', '2026-07-21T07:00:00Z', '2026-07-25T07:00:00Z', {
|
|
349
|
+
allDay: true,
|
|
350
|
+
}),
|
|
351
|
+
],
|
|
352
|
+
week.days,
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
expect(bars.map((bar) => bar.row).sort()).toEqual([0, 1]);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it('keeps a multi-day timed entry out of the all-day band', () => {
|
|
359
|
+
const week = buildWeek();
|
|
360
|
+
// Each timed segment belongs only to the timed grid.
|
|
361
|
+
const bars = getCalendarAllDayLayout(
|
|
362
|
+
[
|
|
363
|
+
buildEvent('closure', '2026-07-20T18:00:00Z', '2026-07-23T02:00:00Z', {
|
|
364
|
+
kind: 'BLOCK',
|
|
365
|
+
}),
|
|
366
|
+
],
|
|
367
|
+
week.days,
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
expect(bars).toHaveLength(0);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
it('leaves a single-day timed entry in the grid', () => {
|
|
374
|
+
const week = buildWeek();
|
|
375
|
+
const bars = getCalendarAllDayLayout(
|
|
376
|
+
[buildEvent('shift', '2026-07-22T16:00:00Z', '2026-07-22T20:00:00Z')],
|
|
377
|
+
week.days,
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
expect(bars).toHaveLength(0);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it('clips a bar that starts before or ends after the range', () => {
|
|
384
|
+
const week = buildWeek();
|
|
385
|
+
const bars = getCalendarAllDayLayout(
|
|
386
|
+
[
|
|
387
|
+
buildEvent('long', '2026-07-01T07:00:00Z', '2026-08-01T07:00:00Z', {
|
|
388
|
+
allDay: true,
|
|
389
|
+
}),
|
|
390
|
+
],
|
|
391
|
+
week.days,
|
|
392
|
+
);
|
|
393
|
+
|
|
394
|
+
expect(bars[0].startDayIndex).toBe(0);
|
|
395
|
+
expect(bars[0].endDayIndex).toBe(6);
|
|
396
|
+
expect(bars[0].continuesFromPreviousDay).toBe(true);
|
|
397
|
+
expect(bars[0].continuesToNextDay).toBe(true);
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
describe('getCalendarEventsByDateKey', () => {
|
|
402
|
+
it('lists a multi-day entry under every day it covers', () => {
|
|
403
|
+
const week = buildWeek();
|
|
404
|
+
const byDateKey = getCalendarEventsByDateKey(
|
|
405
|
+
[
|
|
406
|
+
buildEvent('conf', '2026-07-21T07:00:00Z', '2026-07-24T07:00:00Z', {
|
|
407
|
+
allDay: true,
|
|
408
|
+
}),
|
|
409
|
+
],
|
|
410
|
+
week.days,
|
|
411
|
+
);
|
|
412
|
+
|
|
413
|
+
expect(byDateKey.get('2026-07-20')?.map((event) => event.id)).toEqual([]);
|
|
414
|
+
expect(byDateKey.get('2026-07-21')?.map((event) => event.id)).toEqual([
|
|
415
|
+
'conf',
|
|
416
|
+
]);
|
|
417
|
+
expect(byDateKey.get('2026-07-22')?.map((event) => event.id)).toEqual([
|
|
418
|
+
'conf',
|
|
419
|
+
]);
|
|
420
|
+
expect(byDateKey.get('2026-07-23')?.map((event) => event.id)).toEqual([
|
|
421
|
+
'conf',
|
|
422
|
+
]);
|
|
423
|
+
expect(byDateKey.get('2026-07-24')?.map((event) => event.id)).toEqual([]);
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
it('sorts all-day entries above timed ones, then chronologically', () => {
|
|
427
|
+
const week = buildWeek();
|
|
428
|
+
const byDateKey = getCalendarEventsByDateKey(
|
|
429
|
+
[
|
|
430
|
+
buildEvent('late', '2026-07-22T21:00:00Z', '2026-07-22T22:00:00Z'),
|
|
431
|
+
buildEvent('early', '2026-07-22T16:00:00Z', '2026-07-22T17:00:00Z'),
|
|
432
|
+
buildEvent('holiday', '2026-07-22T07:00:00Z', '2026-07-23T07:00:00Z', {
|
|
433
|
+
allDay: true,
|
|
434
|
+
}),
|
|
435
|
+
],
|
|
436
|
+
week.days,
|
|
437
|
+
);
|
|
438
|
+
|
|
439
|
+
expect(byDateKey.get('2026-07-22')?.map((event) => event.id)).toEqual([
|
|
440
|
+
'holiday',
|
|
441
|
+
'early',
|
|
442
|
+
'late',
|
|
443
|
+
]);
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
it('gives every day in the range a bucket, empty or not', () => {
|
|
447
|
+
const week = buildWeek();
|
|
448
|
+
const byDateKey = getCalendarEventsByDateKey([], week.days);
|
|
449
|
+
|
|
450
|
+
expect(byDateKey.size).toBe(7);
|
|
451
|
+
expect([...byDateKey.values()].every((events) => events.length === 0)).toBe(
|
|
452
|
+
true,
|
|
453
|
+
);
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
describe('getCalendarMonthCells', () => {
|
|
458
|
+
it('gives every day in the grid a cell', () => {
|
|
459
|
+
const month = getCalendarRange({
|
|
460
|
+
view: 'MONTH',
|
|
461
|
+
anchorDate: parseCalendarDateParam('2026-07-22', NOW, LA),
|
|
462
|
+
now: NOW,
|
|
463
|
+
timeZone: LA,
|
|
464
|
+
});
|
|
465
|
+
const cells = getCalendarMonthCells([], month.days, 3);
|
|
466
|
+
|
|
467
|
+
expect(cells).toHaveLength(42);
|
|
468
|
+
expect(
|
|
469
|
+
cells.every(
|
|
470
|
+
(cell) => cell.events.length === 0 && cell.overflowCount === 0,
|
|
471
|
+
),
|
|
472
|
+
).toBe(true);
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
it('truncates a busy cell and reports the remainder', () => {
|
|
476
|
+
const month = getCalendarRange({
|
|
477
|
+
view: 'MONTH',
|
|
478
|
+
anchorDate: parseCalendarDateParam('2026-07-22', NOW, LA),
|
|
479
|
+
now: NOW,
|
|
480
|
+
timeZone: LA,
|
|
481
|
+
});
|
|
482
|
+
const events = Array.from({ length: 7 }, (_unused, index) =>
|
|
483
|
+
buildEvent(
|
|
484
|
+
`e${index}`,
|
|
485
|
+
`2026-07-22T${String(16 + index).padStart(2, '0')}:00:00Z`,
|
|
486
|
+
`2026-07-22T${String(17 + index).padStart(2, '0')}:00:00Z`,
|
|
487
|
+
),
|
|
488
|
+
);
|
|
489
|
+
|
|
490
|
+
const cell = getCalendarMonthCells(events, month.days, 3).find(
|
|
491
|
+
(entry) => entry.day.dateKey === '2026-07-22',
|
|
492
|
+
);
|
|
493
|
+
|
|
494
|
+
// The count is computed, never left to a CSS overflow to hide
|
|
495
|
+
expect(cell?.events).toHaveLength(3);
|
|
496
|
+
expect(cell?.overflowCount).toBe(4);
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
it('counts a multi-day entry in every cell it covers', () => {
|
|
500
|
+
const month = getCalendarRange({
|
|
501
|
+
view: 'MONTH',
|
|
502
|
+
anchorDate: parseCalendarDateParam('2026-07-22', NOW, LA),
|
|
503
|
+
now: NOW,
|
|
504
|
+
timeZone: LA,
|
|
505
|
+
});
|
|
506
|
+
const cells = getCalendarMonthCells(
|
|
507
|
+
[
|
|
508
|
+
buildEvent('conf', '2026-07-21T07:00:00Z', '2026-07-24T07:00:00Z', {
|
|
509
|
+
allDay: true,
|
|
510
|
+
}),
|
|
511
|
+
],
|
|
512
|
+
month.days,
|
|
513
|
+
3,
|
|
514
|
+
);
|
|
515
|
+
|
|
516
|
+
const covered = cells
|
|
517
|
+
.filter((cell) => cell.events.length > 0)
|
|
518
|
+
.map((cell) => cell.day.dateKey);
|
|
519
|
+
|
|
520
|
+
expect(covered).toEqual(['2026-07-21', '2026-07-22', '2026-07-23']);
|
|
521
|
+
});
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
describe('year range', () => {
|
|
525
|
+
it('builds every day of the year', () => {
|
|
526
|
+
const year = getCalendarRange({
|
|
527
|
+
view: 'YEAR',
|
|
528
|
+
anchorDate: parseCalendarDateParam('2026-07-22', NOW, LA),
|
|
529
|
+
now: NOW,
|
|
530
|
+
timeZone: LA,
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
expect(year.days).toHaveLength(365);
|
|
534
|
+
expect(year.days[0].dateKey).toBe('2026-01-01');
|
|
535
|
+
expect(year.days[364].dateKey).toBe('2026-12-31');
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
it('handles a leap year', () => {
|
|
539
|
+
const year = getCalendarRange({
|
|
540
|
+
view: 'YEAR',
|
|
541
|
+
anchorDate: parseCalendarDateParam('2028-03-01', NOW, LA),
|
|
542
|
+
now: NOW,
|
|
543
|
+
timeZone: LA,
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
expect(year.days).toHaveLength(366);
|
|
547
|
+
expect(year.days[365].dateKey).toBe('2028-12-31');
|
|
548
|
+
});
|
|
549
|
+
});
|