@jsb188/calendar 1.1.10 → 1.1.11
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 +8 -6
- package/src/constants/calendar.ts +8 -1
- package/src/libs/calendar-geometry.ts +167 -91
- package/src/libs/calendar-gesture.ts +58 -15
- package/src/libs/calendar-now.ts +39 -0
- package/src/libs/calendar-range.ts +86 -27
- package/src/libs/calendar-state.ts +10 -3
- package/src/libs/calendar-url.ts +31 -8
- package/src/main.ts +3 -0
- package/src/modules/Calendar.tsx +369 -275
- package/src/modules/MiniCalendar.tsx +370 -0
- package/src/ui/CalendarAgendaUI.tsx +31 -11
- package/src/ui/CalendarCoverageUI.tsx +66 -23
- package/src/ui/CalendarEventDetailUI.tsx +122 -117
- package/src/ui/CalendarEventFormUI.tsx +86 -59
- package/src/ui/CalendarMonthUI.tsx +25 -21
- package/src/ui/CalendarRailUI.tsx +199 -139
- package/src/ui/CalendarRequestUI.tsx +216 -177
- package/src/ui/CalendarToolbarUI.tsx +27 -18
- package/src/ui/CalendarUI.tsx +255 -229
- package/src/ui/CalendarViolationUI.tsx +53 -30
- package/src/ui/CalendarYearUI.tsx +36 -50
- package/tests/calendar-geometry.test.ts +226 -78
- package/tests/calendar-gesture.test.ts +43 -12
- package/tests/calendar-range.test.ts +159 -33
- package/tests/calendar-url.test.ts +55 -12
|
@@ -5,7 +5,10 @@ import {
|
|
|
5
5
|
getCalendarMonthCells,
|
|
6
6
|
getCalendarTimedLayout,
|
|
7
7
|
} from '../src/libs/calendar-geometry.ts';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
getCalendarRange,
|
|
10
|
+
parseCalendarDateParam,
|
|
11
|
+
} from '../src/libs/calendar-range.ts';
|
|
9
12
|
import type { CalendarEventObj } from '../src/types/calendar.d.ts';
|
|
10
13
|
|
|
11
14
|
const LA = 'America/Los_Angeles';
|
|
@@ -28,7 +31,12 @@ function buildWeek() {
|
|
|
28
31
|
* Build one timed event. Times are ISO strings so the tests read as instants.
|
|
29
32
|
*/
|
|
30
33
|
|
|
31
|
-
function buildEvent(
|
|
34
|
+
function buildEvent(
|
|
35
|
+
id: string,
|
|
36
|
+
startAt: string,
|
|
37
|
+
endAt: string,
|
|
38
|
+
overrides: Partial<CalendarEventObj> = {},
|
|
39
|
+
): CalendarEventObj {
|
|
32
40
|
return {
|
|
33
41
|
id,
|
|
34
42
|
calendarId: 'cal1',
|
|
@@ -47,7 +55,10 @@ describe('getCalendarTimedLayout', () => {
|
|
|
47
55
|
it('places one event at the right minutes of its day', () => {
|
|
48
56
|
const week = buildWeek();
|
|
49
57
|
// 09:00–17:00 local on Wednesday the 22nd
|
|
50
|
-
const layout = getCalendarTimedLayout(
|
|
58
|
+
const layout = getCalendarTimedLayout(
|
|
59
|
+
[buildEvent('a', '2026-07-22T16:00:00Z', '2026-07-23T00:00:00Z')],
|
|
60
|
+
week.days,
|
|
61
|
+
);
|
|
51
62
|
|
|
52
63
|
expect(layout).toHaveLength(1);
|
|
53
64
|
expect(layout[0].dayIndex).toBe(3);
|
|
@@ -93,12 +104,44 @@ describe('getCalendarTimedLayout', () => {
|
|
|
93
104
|
expect(layout[0].endMinute).toBe(24 * 60);
|
|
94
105
|
});
|
|
95
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
|
+
|
|
96
136
|
it('splits two overlapping events down the middle', () => {
|
|
97
137
|
const week = buildWeek();
|
|
98
|
-
const layout = getCalendarTimedLayout(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
+
);
|
|
102
145
|
|
|
103
146
|
expect(layout.map((entry) => entry.columnCount)).toEqual([2, 2]);
|
|
104
147
|
expect(layout.map((entry) => entry.left).sort()).toEqual([0, 0.5]);
|
|
@@ -108,17 +151,24 @@ describe('getCalendarTimedLayout', () => {
|
|
|
108
151
|
it('gives a non-overlapping later event the full width', () => {
|
|
109
152
|
const week = buildWeek();
|
|
110
153
|
// Two at 9am, one at 2pm: the 2pm event is its own cluster
|
|
111
|
-
const layout = getCalendarTimedLayout(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
+
);
|
|
116
162
|
|
|
117
163
|
const afternoon = layout.find((entry) => entry.event.id === 'c');
|
|
118
164
|
|
|
119
165
|
expect(afternoon?.columnCount).toBe(1);
|
|
120
166
|
expect(afternoon?.width).toBe(1);
|
|
121
|
-
expect(
|
|
167
|
+
expect(
|
|
168
|
+
layout
|
|
169
|
+
.filter((entry) => entry.event.id !== 'c')
|
|
170
|
+
.every((entry) => entry.columnCount === 2),
|
|
171
|
+
).toBe(true);
|
|
122
172
|
});
|
|
123
173
|
|
|
124
174
|
it('treats a transitively-overlapping chain as one cluster', () => {
|
|
@@ -126,11 +176,14 @@ describe('getCalendarTimedLayout', () => {
|
|
|
126
176
|
// A 9-12, B 10-13, C 11-14 — A and C never touch, but every column is
|
|
127
177
|
// still busy when C starts, so all three must share the width or B
|
|
128
178
|
// would be drawn over one of them
|
|
129
|
-
const layout = getCalendarTimedLayout(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
+
);
|
|
134
187
|
|
|
135
188
|
expect(layout.map((entry) => entry.columnCount)).toEqual([3, 3, 3]);
|
|
136
189
|
expect(layout.map((entry) => entry.column).sort()).toEqual([0, 1, 2]);
|
|
@@ -141,13 +194,18 @@ describe('getCalendarTimedLayout', () => {
|
|
|
141
194
|
// A 9-11, B 10-12, C 11:30-13 — the same chain shape, but C can reuse
|
|
142
195
|
// the column A vacated, so two columns is the correct answer and three
|
|
143
196
|
// would waste half the day's width
|
|
144
|
-
const layout = getCalendarTimedLayout(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
+
);
|
|
149
205
|
|
|
150
|
-
const byId = Object.fromEntries(
|
|
206
|
+
const byId = Object.fromEntries(
|
|
207
|
+
layout.map((entry) => [entry.event.id, entry]),
|
|
208
|
+
);
|
|
151
209
|
|
|
152
210
|
expect(layout.map((entry) => entry.columnCount)).toEqual([2, 2, 2]);
|
|
153
211
|
expect(byId.c.column).toBe(byId.a.column);
|
|
@@ -157,13 +215,18 @@ describe('getCalendarTimedLayout', () => {
|
|
|
157
215
|
it('reuses a freed column for a later non-overlapping event in the same cluster', () => {
|
|
158
216
|
const week = buildWeek();
|
|
159
217
|
// A 9-10, B 9-12, C 10:30-11 — C can take A's column
|
|
160
|
-
const layout = getCalendarTimedLayout(
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
+
);
|
|
165
226
|
|
|
166
|
-
const byId = Object.fromEntries(
|
|
227
|
+
const byId = Object.fromEntries(
|
|
228
|
+
layout.map((entry) => [entry.event.id, entry]),
|
|
229
|
+
);
|
|
167
230
|
|
|
168
231
|
expect(byId.c.column).toBe(byId.a.column);
|
|
169
232
|
expect(byId.b.columnCount).toBe(2);
|
|
@@ -171,9 +234,9 @@ describe('getCalendarTimedLayout', () => {
|
|
|
171
234
|
|
|
172
235
|
it('stacks rather than slivers past the column cap', () => {
|
|
173
236
|
const week = buildWeek();
|
|
174
|
-
const events = Array.from({ length: 8 }, (_unused, index) =>
|
|
175
|
-
buildEvent(`e${index}`, '2026-07-22T16:00:00Z', '2026-07-22T20:00:00Z')
|
|
176
|
-
)
|
|
237
|
+
const events = Array.from({ length: 8 }, (_unused, index) =>
|
|
238
|
+
buildEvent(`e${index}`, '2026-07-22T16:00:00Z', '2026-07-22T20:00:00Z'),
|
|
239
|
+
);
|
|
177
240
|
const layout = getCalendarTimedLayout(events, week.days);
|
|
178
241
|
|
|
179
242
|
expect(layout.every((entry) => entry.columnCount === 8)).toBe(true);
|
|
@@ -186,26 +249,37 @@ describe('getCalendarTimedLayout', () => {
|
|
|
186
249
|
const week = buildWeek();
|
|
187
250
|
// Five minutes apart and five minutes long: they do not overlap in time,
|
|
188
251
|
// but both are drawn at the minimum height, so they overlap on screen
|
|
189
|
-
const layout = getCalendarTimedLayout(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
+
);
|
|
193
259
|
|
|
194
260
|
expect(layout.map((entry) => entry.columnCount)).toEqual([2, 2]);
|
|
195
261
|
});
|
|
196
262
|
|
|
197
263
|
it('excludes all-day entries from the time grid', () => {
|
|
198
264
|
const week = buildWeek();
|
|
199
|
-
const layout = getCalendarTimedLayout(
|
|
200
|
-
|
|
201
|
-
|
|
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
|
+
);
|
|
202
273
|
|
|
203
274
|
expect(layout).toHaveLength(0);
|
|
204
275
|
});
|
|
205
276
|
|
|
206
277
|
it('drops an event entirely outside the range', () => {
|
|
207
278
|
const week = buildWeek();
|
|
208
|
-
const layout = getCalendarTimedLayout(
|
|
279
|
+
const layout = getCalendarTimedLayout(
|
|
280
|
+
[buildEvent('past', '2026-06-01T16:00:00Z', '2026-06-01T18:00:00Z')],
|
|
281
|
+
week.days,
|
|
282
|
+
);
|
|
209
283
|
|
|
210
284
|
expect(layout).toHaveLength(0);
|
|
211
285
|
});
|
|
@@ -218,7 +292,10 @@ describe('getCalendarTimedLayout', () => {
|
|
|
218
292
|
timeZone: LA,
|
|
219
293
|
});
|
|
220
294
|
// 9am local on the 25-hour day is 17:00Z (PST, after the transition)
|
|
221
|
-
const layout = getCalendarTimedLayout(
|
|
295
|
+
const layout = getCalendarTimedLayout(
|
|
296
|
+
[buildEvent('a', '2026-11-01T17:00:00Z', '2026-11-01T18:00:00Z')],
|
|
297
|
+
range.days,
|
|
298
|
+
);
|
|
222
299
|
|
|
223
300
|
// Measured from the day's own start, an extra hour has already elapsed
|
|
224
301
|
expect(layout[0].startMinute).toBe(10 * 60);
|
|
@@ -229,9 +306,14 @@ describe('getCalendarTimedLayout', () => {
|
|
|
229
306
|
describe('getCalendarAllDayLayout', () => {
|
|
230
307
|
it('spans an all-day entry across its day columns', () => {
|
|
231
308
|
const week = buildWeek();
|
|
232
|
-
const bars = getCalendarAllDayLayout(
|
|
233
|
-
|
|
234
|
-
|
|
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
|
+
);
|
|
235
317
|
|
|
236
318
|
expect(bars).toHaveLength(1);
|
|
237
319
|
expect(bars[0].startDayIndex).toBe(2);
|
|
@@ -241,20 +323,34 @@ describe('getCalendarAllDayLayout', () => {
|
|
|
241
323
|
|
|
242
324
|
it('packs non-overlapping bars onto the same row', () => {
|
|
243
325
|
const week = buildWeek();
|
|
244
|
-
const bars = getCalendarAllDayLayout(
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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
|
+
);
|
|
248
337
|
|
|
249
338
|
expect(bars.map((bar) => bar.row)).toEqual([0, 0]);
|
|
250
339
|
});
|
|
251
340
|
|
|
252
341
|
it('pushes an overlapping bar to the next row', () => {
|
|
253
342
|
const week = buildWeek();
|
|
254
|
-
const bars = getCalendarAllDayLayout(
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|
+
);
|
|
258
354
|
|
|
259
355
|
expect(bars.map((bar) => bar.row).sort()).toEqual([0, 1]);
|
|
260
356
|
});
|
|
@@ -262,9 +358,14 @@ describe('getCalendarAllDayLayout', () => {
|
|
|
262
358
|
it('promotes a multi-day timed entry into the band', () => {
|
|
263
359
|
const week = buildWeek();
|
|
264
360
|
// A three-day closure is not usefully drawn as three tall columns
|
|
265
|
-
const bars = getCalendarAllDayLayout(
|
|
266
|
-
|
|
267
|
-
|
|
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
|
+
);
|
|
268
369
|
|
|
269
370
|
expect(bars).toHaveLength(1);
|
|
270
371
|
expect(bars[0].startDayIndex).toBe(1);
|
|
@@ -273,16 +374,24 @@ describe('getCalendarAllDayLayout', () => {
|
|
|
273
374
|
|
|
274
375
|
it('leaves a single-day timed entry in the grid', () => {
|
|
275
376
|
const week = buildWeek();
|
|
276
|
-
const bars = getCalendarAllDayLayout(
|
|
377
|
+
const bars = getCalendarAllDayLayout(
|
|
378
|
+
[buildEvent('shift', '2026-07-22T16:00:00Z', '2026-07-22T20:00:00Z')],
|
|
379
|
+
week.days,
|
|
380
|
+
);
|
|
277
381
|
|
|
278
382
|
expect(bars).toHaveLength(0);
|
|
279
383
|
});
|
|
280
384
|
|
|
281
385
|
it('clips a bar that starts before or ends after the range', () => {
|
|
282
386
|
const week = buildWeek();
|
|
283
|
-
const bars = getCalendarAllDayLayout(
|
|
284
|
-
|
|
285
|
-
|
|
387
|
+
const bars = getCalendarAllDayLayout(
|
|
388
|
+
[
|
|
389
|
+
buildEvent('long', '2026-07-01T07:00:00Z', '2026-08-01T07:00:00Z', {
|
|
390
|
+
allDay: true,
|
|
391
|
+
}),
|
|
392
|
+
],
|
|
393
|
+
week.days,
|
|
394
|
+
);
|
|
286
395
|
|
|
287
396
|
expect(bars[0].startDayIndex).toBe(0);
|
|
288
397
|
expect(bars[0].endDayIndex).toBe(6);
|
|
@@ -294,26 +403,46 @@ describe('getCalendarAllDayLayout', () => {
|
|
|
294
403
|
describe('getCalendarEventsByDateKey', () => {
|
|
295
404
|
it('lists a multi-day entry under every day it covers', () => {
|
|
296
405
|
const week = buildWeek();
|
|
297
|
-
const byDateKey = getCalendarEventsByDateKey(
|
|
298
|
-
|
|
299
|
-
|
|
406
|
+
const byDateKey = getCalendarEventsByDateKey(
|
|
407
|
+
[
|
|
408
|
+
buildEvent('conf', '2026-07-21T07:00:00Z', '2026-07-24T07:00:00Z', {
|
|
409
|
+
allDay: true,
|
|
410
|
+
}),
|
|
411
|
+
],
|
|
412
|
+
week.days,
|
|
413
|
+
);
|
|
300
414
|
|
|
301
415
|
expect(byDateKey.get('2026-07-20')?.map((event) => event.id)).toEqual([]);
|
|
302
|
-
expect(byDateKey.get('2026-07-21')?.map((event) => event.id)).toEqual([
|
|
303
|
-
|
|
304
|
-
|
|
416
|
+
expect(byDateKey.get('2026-07-21')?.map((event) => event.id)).toEqual([
|
|
417
|
+
'conf',
|
|
418
|
+
]);
|
|
419
|
+
expect(byDateKey.get('2026-07-22')?.map((event) => event.id)).toEqual([
|
|
420
|
+
'conf',
|
|
421
|
+
]);
|
|
422
|
+
expect(byDateKey.get('2026-07-23')?.map((event) => event.id)).toEqual([
|
|
423
|
+
'conf',
|
|
424
|
+
]);
|
|
305
425
|
expect(byDateKey.get('2026-07-24')?.map((event) => event.id)).toEqual([]);
|
|
306
426
|
});
|
|
307
427
|
|
|
308
428
|
it('sorts all-day entries above timed ones, then chronologically', () => {
|
|
309
429
|
const week = buildWeek();
|
|
310
|
-
const byDateKey = getCalendarEventsByDateKey(
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
430
|
+
const byDateKey = getCalendarEventsByDateKey(
|
|
431
|
+
[
|
|
432
|
+
buildEvent('late', '2026-07-22T21:00:00Z', '2026-07-22T22:00:00Z'),
|
|
433
|
+
buildEvent('early', '2026-07-22T16:00:00Z', '2026-07-22T17:00:00Z'),
|
|
434
|
+
buildEvent('holiday', '2026-07-22T07:00:00Z', '2026-07-23T07:00:00Z', {
|
|
435
|
+
allDay: true,
|
|
436
|
+
}),
|
|
437
|
+
],
|
|
438
|
+
week.days,
|
|
439
|
+
);
|
|
315
440
|
|
|
316
|
-
expect(byDateKey.get('2026-07-22')?.map((event) => event.id)).toEqual([
|
|
441
|
+
expect(byDateKey.get('2026-07-22')?.map((event) => event.id)).toEqual([
|
|
442
|
+
'holiday',
|
|
443
|
+
'early',
|
|
444
|
+
'late',
|
|
445
|
+
]);
|
|
317
446
|
});
|
|
318
447
|
|
|
319
448
|
it('gives every day in the range a bucket, empty or not', () => {
|
|
@@ -321,7 +450,9 @@ describe('getCalendarEventsByDateKey', () => {
|
|
|
321
450
|
const byDateKey = getCalendarEventsByDateKey([], week.days);
|
|
322
451
|
|
|
323
452
|
expect(byDateKey.size).toBe(7);
|
|
324
|
-
expect([...byDateKey.values()].every((events) => events.length === 0)).toBe(
|
|
453
|
+
expect([...byDateKey.values()].every((events) => events.length === 0)).toBe(
|
|
454
|
+
true,
|
|
455
|
+
);
|
|
325
456
|
});
|
|
326
457
|
});
|
|
327
458
|
|
|
@@ -336,7 +467,11 @@ describe('getCalendarMonthCells', () => {
|
|
|
336
467
|
const cells = getCalendarMonthCells([], month.days, 3);
|
|
337
468
|
|
|
338
469
|
expect(cells).toHaveLength(42);
|
|
339
|
-
expect(
|
|
470
|
+
expect(
|
|
471
|
+
cells.every(
|
|
472
|
+
(cell) => cell.events.length === 0 && cell.overflowCount === 0,
|
|
473
|
+
),
|
|
474
|
+
).toBe(true);
|
|
340
475
|
});
|
|
341
476
|
|
|
342
477
|
it('truncates a busy cell and reports the remainder', () => {
|
|
@@ -347,9 +482,16 @@ describe('getCalendarMonthCells', () => {
|
|
|
347
482
|
timeZone: LA,
|
|
348
483
|
});
|
|
349
484
|
const events = Array.from({ length: 7 }, (_unused, index) =>
|
|
350
|
-
buildEvent(
|
|
485
|
+
buildEvent(
|
|
486
|
+
`e${index}`,
|
|
487
|
+
`2026-07-22T${String(16 + index).padStart(2, '0')}:00:00Z`,
|
|
488
|
+
`2026-07-22T${String(17 + index).padStart(2, '0')}:00:00Z`,
|
|
489
|
+
),
|
|
490
|
+
);
|
|
351
491
|
|
|
352
|
-
const cell = getCalendarMonthCells(events, month.days, 3).find(
|
|
492
|
+
const cell = getCalendarMonthCells(events, month.days, 3).find(
|
|
493
|
+
(entry) => entry.day.dateKey === '2026-07-22',
|
|
494
|
+
);
|
|
353
495
|
|
|
354
496
|
// The count is computed, never left to a CSS overflow to hide
|
|
355
497
|
expect(cell?.events).toHaveLength(3);
|
|
@@ -364,12 +506,18 @@ describe('getCalendarMonthCells', () => {
|
|
|
364
506
|
timeZone: LA,
|
|
365
507
|
});
|
|
366
508
|
const cells = getCalendarMonthCells(
|
|
367
|
-
[
|
|
509
|
+
[
|
|
510
|
+
buildEvent('conf', '2026-07-21T07:00:00Z', '2026-07-24T07:00:00Z', {
|
|
511
|
+
allDay: true,
|
|
512
|
+
}),
|
|
513
|
+
],
|
|
368
514
|
month.days,
|
|
369
515
|
3,
|
|
370
516
|
);
|
|
371
517
|
|
|
372
|
-
const covered = cells
|
|
518
|
+
const covered = cells
|
|
519
|
+
.filter((cell) => cell.events.length > 0)
|
|
520
|
+
.map((cell) => cell.day.dateKey);
|
|
373
521
|
|
|
374
522
|
expect(covered).toEqual(['2026-07-21', '2026-07-22', '2026-07-23']);
|
|
375
523
|
});
|
|
@@ -5,7 +5,10 @@ import {
|
|
|
5
5
|
getCalendarPointerSlot,
|
|
6
6
|
getCalendarResizeRange,
|
|
7
7
|
} from '../src/libs/calendar-gesture.ts';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
getCalendarRange,
|
|
10
|
+
parseCalendarDateParam,
|
|
11
|
+
} from '../src/libs/calendar-range.ts';
|
|
9
12
|
|
|
10
13
|
const LA = 'America/Los_Angeles';
|
|
11
14
|
const NOW = new Date('2026-07-22T19:00:00Z');
|
|
@@ -65,10 +68,24 @@ describe('getCalendarPointerSlot', () => {
|
|
|
65
68
|
it('clamps a pointer dragged outside the grid', () => {
|
|
66
69
|
const week = buildWeek();
|
|
67
70
|
|
|
68
|
-
expect(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
expect(
|
|
72
|
+
getCalendarPointerSlot({
|
|
73
|
+
offsetX: -50,
|
|
74
|
+
offsetY: -100,
|
|
75
|
+
contentWidth: 700,
|
|
76
|
+
hourHeight: 48,
|
|
77
|
+
days: week.days,
|
|
78
|
+
}),
|
|
79
|
+
).toEqual({ dayIndex: 0, minute: 0 });
|
|
80
|
+
expect(
|
|
81
|
+
getCalendarPointerSlot({
|
|
82
|
+
offsetX: 9999,
|
|
83
|
+
offsetY: 99999,
|
|
84
|
+
contentWidth: 700,
|
|
85
|
+
hourHeight: 48,
|
|
86
|
+
days: week.days,
|
|
87
|
+
}),
|
|
88
|
+
).toEqual({ dayIndex: 6, minute: 24 * 60 });
|
|
72
89
|
});
|
|
73
90
|
});
|
|
74
91
|
|
|
@@ -100,7 +117,9 @@ describe('getCalendarCreateRange', () => {
|
|
|
100
117
|
moved: true,
|
|
101
118
|
});
|
|
102
119
|
|
|
103
|
-
expect(range.endAt.getTime() - range.startAt.getTime()).toBe(
|
|
120
|
+
expect(range.endAt.getTime() - range.startAt.getTime()).toBe(
|
|
121
|
+
3 * 60 * 60_000,
|
|
122
|
+
);
|
|
104
123
|
});
|
|
105
124
|
|
|
106
125
|
it('accepts a drag drawn upward', () => {
|
|
@@ -115,7 +134,9 @@ describe('getCalendarCreateRange', () => {
|
|
|
115
134
|
});
|
|
116
135
|
|
|
117
136
|
expect(range.startAt.toISOString()).toBe('2026-07-22T16:00:00.000Z');
|
|
118
|
-
expect(range.endAt.getTime() - range.startAt.getTime()).toBe(
|
|
137
|
+
expect(range.endAt.getTime() - range.startAt.getTime()).toBe(
|
|
138
|
+
3 * 60 * 60_000,
|
|
139
|
+
);
|
|
119
140
|
});
|
|
120
141
|
|
|
121
142
|
it('gives a barely-moved drag the minimum length', () => {
|
|
@@ -159,7 +180,9 @@ describe('getCalendarCreateRange', () => {
|
|
|
159
180
|
moved: false,
|
|
160
181
|
});
|
|
161
182
|
|
|
162
|
-
expect(range.endAt.getTime()).toBeLessThanOrEqual(
|
|
183
|
+
expect(range.endAt.getTime()).toBeLessThanOrEqual(
|
|
184
|
+
week.days[3].endAt.getTime(),
|
|
185
|
+
);
|
|
163
186
|
});
|
|
164
187
|
});
|
|
165
188
|
|
|
@@ -181,7 +204,9 @@ describe('getCalendarMoveRange', () => {
|
|
|
181
204
|
|
|
182
205
|
// The block starts an hour before the pointer, not at it
|
|
183
206
|
expect(range.startAt.toISOString()).toBe('2026-07-22T20:00:00.000Z');
|
|
184
|
-
expect(range.endAt.getTime() - range.startAt.getTime()).toBe(
|
|
207
|
+
expect(range.endAt.getTime() - range.startAt.getTime()).toBe(
|
|
208
|
+
4 * 60 * 60_000,
|
|
209
|
+
);
|
|
185
210
|
});
|
|
186
211
|
|
|
187
212
|
it('moves an event to another day', () => {
|
|
@@ -211,8 +236,12 @@ describe('getCalendarMoveRange', () => {
|
|
|
211
236
|
currentMinute: 23 * 60,
|
|
212
237
|
});
|
|
213
238
|
|
|
214
|
-
expect(range.endAt.getTime()).toBeLessThanOrEqual(
|
|
215
|
-
|
|
239
|
+
expect(range.endAt.getTime()).toBeLessThanOrEqual(
|
|
240
|
+
week.days[3].endAt.getTime(),
|
|
241
|
+
);
|
|
242
|
+
expect(range.endAt.getTime() - range.startAt.getTime()).toBe(
|
|
243
|
+
4 * 60 * 60_000,
|
|
244
|
+
);
|
|
216
245
|
});
|
|
217
246
|
|
|
218
247
|
it('keeps a shift the same number of hours across a DST day', () => {
|
|
@@ -230,7 +259,9 @@ describe('getCalendarMoveRange', () => {
|
|
|
230
259
|
});
|
|
231
260
|
|
|
232
261
|
// Four hours of actual work stays four hours, even on a 25-hour day
|
|
233
|
-
expect(range.endAt.getTime() - range.startAt.getTime()).toBe(
|
|
262
|
+
expect(range.endAt.getTime() - range.startAt.getTime()).toBe(
|
|
263
|
+
4 * 60 * 60_000,
|
|
264
|
+
);
|
|
234
265
|
});
|
|
235
266
|
});
|
|
236
267
|
|