@klinking/colander 0.0.0
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/dist/formats/date.cjs +49 -0
- package/dist/formats/date.d.cts +45 -0
- package/dist/formats/date.d.mts +45 -0
- package/dist/formats/date.mjs +2 -0
- package/dist/formats/object.cjs +49 -0
- package/dist/formats/object.d.cts +45 -0
- package/dist/formats/object.d.mts +45 -0
- package/dist/formats/object.mjs +2 -0
- package/dist/formats/plain-date-time.cjs +49 -0
- package/dist/formats/plain-date-time.d.cts +45 -0
- package/dist/formats/plain-date-time.d.mts +45 -0
- package/dist/formats/plain-date-time.mjs +2 -0
- package/dist/formats/plain-date.cjs +49 -0
- package/dist/formats/plain-date.d.cts +45 -0
- package/dist/formats/plain-date.d.mts +45 -0
- package/dist/formats/plain-date.mjs +2 -0
- package/dist/formats/plain-month-day.cjs +49 -0
- package/dist/formats/plain-month-day.d.cts +45 -0
- package/dist/formats/plain-month-day.d.mts +45 -0
- package/dist/formats/plain-month-day.mjs +2 -0
- package/dist/formats/plain-year-month.cjs +49 -0
- package/dist/formats/plain-year-month.d.cts +45 -0
- package/dist/formats/plain-year-month.d.mts +45 -0
- package/dist/formats/plain-year-month.mjs +2 -0
- package/dist/formats/zoned-date-time.cjs +49 -0
- package/dist/formats/zoned-date-time.d.cts +45 -0
- package/dist/formats/zoned-date-time.d.mts +45 -0
- package/dist/formats/zoned-date-time.mjs +2 -0
- package/dist/index.cjs +49 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +2 -0
- package/dist/temporal-polyfill-DTx0VIX5.mjs +4556 -0
- package/dist/temporal-polyfill-DU8VfleL.cjs +4860 -0
- package/dist/weeks-view-context-BN6qR-83.d.mts +2022 -0
- package/dist/weeks-view-context-aHGgYkpt.d.cts +2022 -0
- package/package.json +89 -0
- package/src/calendar-context.ts +22 -0
- package/src/calendar-provider.test.tsx +123 -0
- package/src/calendar-provider.tsx +538 -0
- package/src/calendar-types.ts +212 -0
- package/src/compute-weeks-in-window.test.ts +83 -0
- package/src/compute-weeks-in-window.ts +40 -0
- package/src/context.ts +34 -0
- package/src/day-cell.tsx +635 -0
- package/src/drag-handle.tsx +137 -0
- package/src/formats/date.ts +110 -0
- package/src/formats/formats.test.ts +18 -0
- package/src/formats/object.ts +110 -0
- package/src/formats/plain-date-time.ts +110 -0
- package/src/formats/plain-date.ts +110 -0
- package/src/formats/plain-month-day.ts +110 -0
- package/src/formats/plain-year-month.ts +110 -0
- package/src/formats/zoned-date-time.ts +110 -0
- package/src/grid-header.tsx +141 -0
- package/src/grid.event-perf.test.tsx +282 -0
- package/src/grid.perf.test.tsx +467 -0
- package/src/grid.tsx +608 -0
- package/src/index.ts +116 -0
- package/src/keyboard.test.ts +498 -0
- package/src/keyboard.ts +142 -0
- package/src/month-separator.test.tsx +183 -0
- package/src/month-separator.tsx +238 -0
- package/src/month-view-context.ts +26 -0
- package/src/month-view-types.ts +89 -0
- package/src/month-view.test.tsx +1433 -0
- package/src/month-view.tsx +373 -0
- package/src/navigation.tsx +350 -0
- package/src/overflow.test.ts +124 -0
- package/src/overflow.ts +233 -0
- package/src/range-preview.tsx +90 -0
- package/src/resolve-first-week.test.ts +132 -0
- package/src/resolve-first-week.ts +145 -0
- package/src/root-selection.ts +621 -0
- package/src/selected-range.tsx +163 -0
- package/src/temporal-polyfill.test.ts +317 -0
- package/src/temporal-polyfill.ts +566 -0
- package/src/test-temporal.ts +17 -0
- package/src/types.ts +814 -0
- package/src/utils.bench.ts +183 -0
- package/src/utils.test.ts +983 -0
- package/src/utils.ts +493 -0
- package/src/view-context.ts +28 -0
- package/src/week-number.tsx +118 -0
- package/src/weeks-grid.tsx +265 -0
- package/src/weeks-keyboard.test.ts +222 -0
- package/src/weeks-keyboard.ts +156 -0
- package/src/weeks-navigation.tsx +209 -0
- package/src/weeks-view-context.ts +26 -0
- package/src/weeks-view-state.ts +421 -0
- package/src/weeks-view-types.ts +102 -0
- package/src/weeks-view.test.tsx +479 -0
- package/src/weeks-view.tsx +127 -0
|
@@ -0,0 +1,1433 @@
|
|
|
1
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
+
import { render, act } from "@testing-library/react";
|
|
3
|
+
// @vitest-environment jsdom
|
|
4
|
+
import { describe, it, expect, vi } from "vitest";
|
|
5
|
+
import { useCalendarStable } from "./calendar-context";
|
|
6
|
+
import { Grid } from "./grid";
|
|
7
|
+
import { MonthView } from "./month-view";
|
|
8
|
+
import { useMonthViewState } from "./month-view-context";
|
|
9
|
+
import { MonthYearString, PrevMonthButton, NextMonthButton } from "./navigation";
|
|
10
|
+
import type { DateRange, ValueChangeMeta, MonthData } from "./types";
|
|
11
|
+
import { useViewContext } from "./view-context";
|
|
12
|
+
|
|
13
|
+
const temporal = {
|
|
14
|
+
Now: Temporal.Now,
|
|
15
|
+
PlainDate: Temporal.PlainDate,
|
|
16
|
+
PlainDateTime: Temporal.PlainDateTime,
|
|
17
|
+
PlainMonthDay: Temporal.PlainMonthDay,
|
|
18
|
+
PlainYearMonth: Temporal.PlainYearMonth,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const defaultProps = {
|
|
22
|
+
temporal,
|
|
23
|
+
locale: "en-US",
|
|
24
|
+
timeZone: "America/New_York",
|
|
25
|
+
format: "PlainDate" as const,
|
|
26
|
+
} as const;
|
|
27
|
+
|
|
28
|
+
const march10 = Temporal.PlainDate.from("2026-03-10");
|
|
29
|
+
const march20 = Temporal.PlainDate.from("2026-03-20");
|
|
30
|
+
|
|
31
|
+
/** Helper that captures `setRange` from context. */
|
|
32
|
+
function SetRangeTrigger({
|
|
33
|
+
onCapture,
|
|
34
|
+
}: {
|
|
35
|
+
onCapture: (setRange: (start: Temporal.PlainDate, end: Temporal.PlainDate) => void) => void;
|
|
36
|
+
}) {
|
|
37
|
+
const { setRange } = useCalendarStable();
|
|
38
|
+
onCapture(setRange);
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Helper that captures a select function (onSelect + setFocusedDate) from context. */
|
|
43
|
+
function SelectTrigger({
|
|
44
|
+
onCapture,
|
|
45
|
+
}: {
|
|
46
|
+
onCapture: (onSelect: (date: Temporal.PlainDate) => void) => void;
|
|
47
|
+
}) {
|
|
48
|
+
const { onSelect } = useCalendarStable();
|
|
49
|
+
const { setFocusedDate } = useViewContext();
|
|
50
|
+
onCapture((date: Temporal.PlainDate) => {
|
|
51
|
+
setFocusedDate(date);
|
|
52
|
+
onSelect(date);
|
|
53
|
+
});
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
describe("rangeMode", () => {
|
|
58
|
+
const march5 = Temporal.PlainDate.from("2026-03-05");
|
|
59
|
+
const march15 = Temporal.PlainDate.from("2026-03-15");
|
|
60
|
+
const march25 = Temporal.PlainDate.from("2026-03-25");
|
|
61
|
+
|
|
62
|
+
type RangeChangeFn = (
|
|
63
|
+
value: DateRange<"PlainDate"> | null,
|
|
64
|
+
meta: ValueChangeMeta<DateRange<"PlainDate"> | null>,
|
|
65
|
+
) => void;
|
|
66
|
+
|
|
67
|
+
function renderRangeRoot(
|
|
68
|
+
rangeMode: "adjust-start" | "adjust-end" | "nearest-start" | "nearest-end" | "reset",
|
|
69
|
+
onValueChange: RangeChangeFn,
|
|
70
|
+
) {
|
|
71
|
+
let selectFn: (date: Temporal.PlainDate) => void = () => {};
|
|
72
|
+
const result = render(
|
|
73
|
+
<MonthView
|
|
74
|
+
{...defaultProps}
|
|
75
|
+
selectionMode="range"
|
|
76
|
+
defaultValue={{ start: march10, end: march20 }}
|
|
77
|
+
onValueChange={onValueChange}
|
|
78
|
+
rangeMode={rangeMode}
|
|
79
|
+
>
|
|
80
|
+
<SelectTrigger
|
|
81
|
+
onCapture={(fn) => {
|
|
82
|
+
selectFn = fn;
|
|
83
|
+
}}
|
|
84
|
+
/>
|
|
85
|
+
</MonthView>,
|
|
86
|
+
);
|
|
87
|
+
return { ...result, select: selectFn };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
it.each<{
|
|
91
|
+
description: string;
|
|
92
|
+
action: "adjust-start" | "adjust-end" | "nearest-start" | "nearest-end" | "reset";
|
|
93
|
+
clickDate: Temporal.PlainDate;
|
|
94
|
+
expected: { start: string; end: string };
|
|
95
|
+
}>([
|
|
96
|
+
{
|
|
97
|
+
description: '"adjust-start" moves range start to clicked date',
|
|
98
|
+
action: "adjust-start",
|
|
99
|
+
clickDate: march15,
|
|
100
|
+
expected: { start: "2026-03-15", end: "2026-03-20" },
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
description: '"adjust-end" moves range end to clicked date',
|
|
104
|
+
action: "adjust-end",
|
|
105
|
+
clickDate: march15,
|
|
106
|
+
expected: { start: "2026-03-10", end: "2026-03-15" },
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
description: '"reset" collapses range to single-day at clicked date',
|
|
110
|
+
action: "reset",
|
|
111
|
+
clickDate: march15,
|
|
112
|
+
expected: { start: "2026-03-15", end: "2026-03-15" },
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
description: '"nearest-end" moves end when date is closer to end',
|
|
116
|
+
action: "nearest-end",
|
|
117
|
+
clickDate: Temporal.PlainDate.from("2026-03-18"),
|
|
118
|
+
expected: { start: "2026-03-10", end: "2026-03-18" },
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
description: '"nearest-start" moves start when date is closer to start',
|
|
122
|
+
action: "nearest-start",
|
|
123
|
+
clickDate: Temporal.PlainDate.from("2026-03-12"),
|
|
124
|
+
expected: { start: "2026-03-12", end: "2026-03-20" },
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
description: '"nearest-end" tie goes to end',
|
|
128
|
+
action: "nearest-end",
|
|
129
|
+
clickDate: march15,
|
|
130
|
+
expected: { start: "2026-03-10", end: "2026-03-15" },
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
description: '"nearest-start" tie goes to start',
|
|
134
|
+
action: "nearest-start",
|
|
135
|
+
clickDate: march15,
|
|
136
|
+
expected: { start: "2026-03-15", end: "2026-03-20" },
|
|
137
|
+
},
|
|
138
|
+
])("$description", ({ action, clickDate, expected }) => {
|
|
139
|
+
const onValueChange = vi.fn<RangeChangeFn>();
|
|
140
|
+
const { unmount, select } = renderRangeRoot(action, onValueChange);
|
|
141
|
+
|
|
142
|
+
act(() => {
|
|
143
|
+
select(clickDate);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const [value] = onValueChange.mock.calls[0];
|
|
147
|
+
expect(value!.start!.toString()).toBe(expected.start);
|
|
148
|
+
expect(value!.end!.toString()).toBe(expected.end);
|
|
149
|
+
|
|
150
|
+
unmount();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("clicking before range always extends start regardless of mode", () => {
|
|
154
|
+
const onValueChange = vi.fn<RangeChangeFn>();
|
|
155
|
+
const { unmount, select } = renderRangeRoot("adjust-end", onValueChange);
|
|
156
|
+
|
|
157
|
+
act(() => {
|
|
158
|
+
select(march5);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const [value] = onValueChange.mock.calls[0];
|
|
162
|
+
expect(value?.start?.toString()).toBe("2026-03-05");
|
|
163
|
+
expect(value?.end?.toString()).toBe("2026-03-20");
|
|
164
|
+
|
|
165
|
+
unmount();
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("clicking after range always extends end regardless of mode", () => {
|
|
169
|
+
const onValueChange = vi.fn<RangeChangeFn>();
|
|
170
|
+
const { unmount, select } = renderRangeRoot("adjust-start", onValueChange);
|
|
171
|
+
|
|
172
|
+
act(() => {
|
|
173
|
+
select(march25);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const [value] = onValueChange.mock.calls[0];
|
|
177
|
+
expect(value?.start?.toString()).toBe("2026-03-10");
|
|
178
|
+
expect(value?.end?.toString()).toBe("2026-03-25");
|
|
179
|
+
|
|
180
|
+
unmount();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("clicking on start boundary of multi-day range collapses to single-day", () => {
|
|
184
|
+
const onValueChange = vi.fn<RangeChangeFn>();
|
|
185
|
+
const { unmount, select } = renderRangeRoot("nearest-end", onValueChange);
|
|
186
|
+
|
|
187
|
+
act(() => {
|
|
188
|
+
select(march10);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const [value] = onValueChange.mock.calls[0];
|
|
192
|
+
expect(value!.start!.toString()).toBe("2026-03-10");
|
|
193
|
+
expect(value!.end!.toString()).toBe("2026-03-10");
|
|
194
|
+
|
|
195
|
+
unmount();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("clicking on end boundary of multi-day range collapses to single-day", () => {
|
|
199
|
+
const onValueChange = vi.fn<RangeChangeFn>();
|
|
200
|
+
const { unmount, select } = renderRangeRoot("nearest-end", onValueChange);
|
|
201
|
+
|
|
202
|
+
act(() => {
|
|
203
|
+
select(march20);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
const [value] = onValueChange.mock.calls[0];
|
|
207
|
+
expect(value!.start!.toString()).toBe("2026-03-20");
|
|
208
|
+
expect(value!.end!.toString()).toBe("2026-03-20");
|
|
209
|
+
|
|
210
|
+
unmount();
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
describe("setRange normalization", () => {
|
|
215
|
+
it("sorts start and end when called in order", () => {
|
|
216
|
+
const onValueChange = vi.fn();
|
|
217
|
+
let captured: (s: Temporal.PlainDate, e: Temporal.PlainDate) => void = () => {};
|
|
218
|
+
|
|
219
|
+
const { unmount } = render(
|
|
220
|
+
<MonthView {...defaultProps} selectionMode="range" onValueChange={onValueChange}>
|
|
221
|
+
<SetRangeTrigger
|
|
222
|
+
onCapture={(fn) => {
|
|
223
|
+
captured = fn;
|
|
224
|
+
}}
|
|
225
|
+
/>
|
|
226
|
+
</MonthView>,
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
act(() => {
|
|
230
|
+
captured(march10, march20);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
expect(onValueChange).toHaveBeenCalledWith(
|
|
234
|
+
{ start: march10, end: march20 },
|
|
235
|
+
expect.objectContaining({ date: undefined }),
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
unmount();
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("normalizes reversed arguments so start <= end", () => {
|
|
242
|
+
const onValueChange = vi.fn();
|
|
243
|
+
let captured: (s: Temporal.PlainDate, e: Temporal.PlainDate) => void = () => {};
|
|
244
|
+
|
|
245
|
+
const { unmount } = render(
|
|
246
|
+
<MonthView {...defaultProps} selectionMode="range" onValueChange={onValueChange}>
|
|
247
|
+
<SetRangeTrigger
|
|
248
|
+
onCapture={(fn) => {
|
|
249
|
+
captured = fn;
|
|
250
|
+
}}
|
|
251
|
+
/>
|
|
252
|
+
</MonthView>,
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
// Call with end before start
|
|
256
|
+
act(() => {
|
|
257
|
+
captured(march20, march10);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
const [value] = onValueChange.mock.calls[0] as [
|
|
261
|
+
DateRange<"PlainDate">,
|
|
262
|
+
ValueChangeMeta<DateRange<"PlainDate"> | null>,
|
|
263
|
+
];
|
|
264
|
+
expect(Temporal.PlainDate.compare(value.start!, value.end!)).toBeLessThanOrEqual(0);
|
|
265
|
+
expect(value).toEqual({ start: march10, end: march20 });
|
|
266
|
+
|
|
267
|
+
unmount();
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it("handles same date for both start and end", () => {
|
|
271
|
+
const onValueChange = vi.fn();
|
|
272
|
+
let captured: (s: Temporal.PlainDate, e: Temporal.PlainDate) => void = () => {};
|
|
273
|
+
|
|
274
|
+
const { unmount } = render(
|
|
275
|
+
<MonthView {...defaultProps} selectionMode="range" onValueChange={onValueChange}>
|
|
276
|
+
<SetRangeTrigger
|
|
277
|
+
onCapture={(fn) => {
|
|
278
|
+
captured = fn;
|
|
279
|
+
}}
|
|
280
|
+
/>
|
|
281
|
+
</MonthView>,
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
act(() => {
|
|
285
|
+
captured(march10, march10);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
expect(onValueChange).toHaveBeenCalledWith(
|
|
289
|
+
{ start: march10, end: march10 },
|
|
290
|
+
expect.objectContaining({ date: undefined }),
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
unmount();
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
/** Helper that captures allMonths, currentMonth, and focusedDate from context. */
|
|
298
|
+
function MonthDataCapture({
|
|
299
|
+
onCapture,
|
|
300
|
+
}: {
|
|
301
|
+
onCapture: (data: {
|
|
302
|
+
allMonths: MonthData[];
|
|
303
|
+
currentMonth: { year: number; month: number };
|
|
304
|
+
focusedDate: string;
|
|
305
|
+
}) => void;
|
|
306
|
+
}) {
|
|
307
|
+
const { allMonths, currentMonth } = useMonthViewState();
|
|
308
|
+
const { focusedDate } = useViewContext();
|
|
309
|
+
onCapture({
|
|
310
|
+
allMonths,
|
|
311
|
+
currentMonth: { year: currentMonth.year, month: currentMonth.month },
|
|
312
|
+
focusedDate: focusedDate.toString(),
|
|
313
|
+
});
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
describe("numberOfMonths", () => {
|
|
318
|
+
const march15 = Temporal.PlainDate.from("2026-03-15");
|
|
319
|
+
const april15 = Temporal.PlainDate.from("2026-04-15");
|
|
320
|
+
|
|
321
|
+
it("computes correct number of months in allMonths", () => {
|
|
322
|
+
let captured: { allMonths: MonthData[] } | undefined;
|
|
323
|
+
|
|
324
|
+
const { unmount } = render(
|
|
325
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={3}>
|
|
326
|
+
<MonthDataCapture
|
|
327
|
+
onCapture={(d) => {
|
|
328
|
+
captured = d;
|
|
329
|
+
}}
|
|
330
|
+
/>
|
|
331
|
+
</MonthView>,
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
expect(captured!.allMonths).toHaveLength(3);
|
|
335
|
+
expect(captured!.allMonths.map((m) => `${m.year}-${m.month}`)).toEqual([
|
|
336
|
+
"2026-3",
|
|
337
|
+
"2026-4",
|
|
338
|
+
"2026-5",
|
|
339
|
+
]);
|
|
340
|
+
|
|
341
|
+
unmount();
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it("defaults to 1 month when numberOfMonths is omitted", () => {
|
|
345
|
+
let captured: { allMonths: MonthData[] } | undefined;
|
|
346
|
+
|
|
347
|
+
const { unmount } = render(
|
|
348
|
+
<MonthView {...defaultProps} defaultValue={march15}>
|
|
349
|
+
<MonthDataCapture
|
|
350
|
+
onCapture={(d) => {
|
|
351
|
+
captured = d;
|
|
352
|
+
}}
|
|
353
|
+
/>
|
|
354
|
+
</MonthView>,
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
expect(captured!.allMonths).toHaveLength(1);
|
|
358
|
+
expect(captured!.allMonths[0].year).toBe(2026);
|
|
359
|
+
expect(captured!.allMonths[0].month).toBe(3);
|
|
360
|
+
|
|
361
|
+
unmount();
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it("does not shift currentMonth when selecting a date already in a visible month", () => {
|
|
365
|
+
let selectFn: (date: Temporal.PlainDate) => void = () => {};
|
|
366
|
+
let captured: { currentMonth: { year: number; month: number } } | undefined;
|
|
367
|
+
|
|
368
|
+
const { unmount } = render(
|
|
369
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={2}>
|
|
370
|
+
<SelectTrigger
|
|
371
|
+
onCapture={(fn) => {
|
|
372
|
+
selectFn = fn;
|
|
373
|
+
}}
|
|
374
|
+
/>
|
|
375
|
+
<MonthDataCapture
|
|
376
|
+
onCapture={(d) => {
|
|
377
|
+
captured = d;
|
|
378
|
+
}}
|
|
379
|
+
/>
|
|
380
|
+
</MonthView>,
|
|
381
|
+
);
|
|
382
|
+
|
|
383
|
+
expect(captured!.currentMonth).toEqual({ year: 2026, month: 3 });
|
|
384
|
+
|
|
385
|
+
// Select a date in April (second visible month) — should NOT shift
|
|
386
|
+
act(() => {
|
|
387
|
+
selectFn(april15);
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
expect(captured!.currentMonth).toEqual({ year: 2026, month: 3 });
|
|
391
|
+
|
|
392
|
+
unmount();
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it("shifts currentMonth when selecting outside all visible months", () => {
|
|
396
|
+
let selectFn: (date: Temporal.PlainDate) => void = () => {};
|
|
397
|
+
let captured: { currentMonth: { year: number; month: number } } | undefined;
|
|
398
|
+
|
|
399
|
+
const { unmount } = render(
|
|
400
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={2}>
|
|
401
|
+
<SelectTrigger
|
|
402
|
+
onCapture={(fn) => {
|
|
403
|
+
selectFn = fn;
|
|
404
|
+
}}
|
|
405
|
+
/>
|
|
406
|
+
<MonthDataCapture
|
|
407
|
+
onCapture={(d) => {
|
|
408
|
+
captured = d;
|
|
409
|
+
}}
|
|
410
|
+
/>
|
|
411
|
+
</MonthView>,
|
|
412
|
+
);
|
|
413
|
+
|
|
414
|
+
// Select June — outside visible March+April window
|
|
415
|
+
const june15 = Temporal.PlainDate.from("2026-06-15");
|
|
416
|
+
act(() => {
|
|
417
|
+
selectFn(june15);
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
expect(captured!.currentMonth).toEqual({ year: 2026, month: 6 });
|
|
421
|
+
|
|
422
|
+
unmount();
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
it("each month in allMonths has valid week data", () => {
|
|
426
|
+
let captured: { allMonths: MonthData[] } | undefined;
|
|
427
|
+
|
|
428
|
+
const { unmount } = render(
|
|
429
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={2}>
|
|
430
|
+
<MonthDataCapture
|
|
431
|
+
onCapture={(d) => {
|
|
432
|
+
captured = d;
|
|
433
|
+
}}
|
|
434
|
+
/>
|
|
435
|
+
</MonthView>,
|
|
436
|
+
);
|
|
437
|
+
|
|
438
|
+
for (const monthData of captured!.allMonths) {
|
|
439
|
+
expect(monthData.weeks.length).toBeGreaterThanOrEqual(4);
|
|
440
|
+
expect(monthData.weeks.length).toBeLessThanOrEqual(6);
|
|
441
|
+
for (const week of monthData.weeks) {
|
|
442
|
+
expect(week).toHaveLength(7);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
unmount();
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
it("handles year boundary (December → January)", () => {
|
|
450
|
+
const dec15 = Temporal.PlainDate.from("2026-12-15");
|
|
451
|
+
let captured: { allMonths: MonthData[] } | undefined;
|
|
452
|
+
|
|
453
|
+
const { unmount } = render(
|
|
454
|
+
<MonthView {...defaultProps} defaultValue={dec15} numberOfMonths={2}>
|
|
455
|
+
<MonthDataCapture
|
|
456
|
+
onCapture={(d) => {
|
|
457
|
+
captured = d;
|
|
458
|
+
}}
|
|
459
|
+
/>
|
|
460
|
+
</MonthView>,
|
|
461
|
+
);
|
|
462
|
+
|
|
463
|
+
expect(captured!.allMonths.map((m) => `${m.year}-${m.month}`)).toEqual(["2026-12", "2027-1"]);
|
|
464
|
+
|
|
465
|
+
unmount();
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
it("renders separate grid labels for each month", () => {
|
|
469
|
+
const { container, unmount } = render(
|
|
470
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={2}>
|
|
471
|
+
<MonthYearString monthIndex={0} />
|
|
472
|
+
<MonthYearString monthIndex={1} />
|
|
473
|
+
<Grid monthIndex={0} />
|
|
474
|
+
<Grid monthIndex={1} />
|
|
475
|
+
</MonthView>,
|
|
476
|
+
);
|
|
477
|
+
|
|
478
|
+
const grids = container.querySelectorAll('[role="grid"]');
|
|
479
|
+
expect(grids).toHaveLength(2);
|
|
480
|
+
|
|
481
|
+
const labelledBy0 = grids[0].getAttribute("aria-labelledby");
|
|
482
|
+
const labelledBy1 = grids[1].getAttribute("aria-labelledby");
|
|
483
|
+
expect(labelledBy0).toBeTruthy();
|
|
484
|
+
expect(labelledBy1).toBeTruthy();
|
|
485
|
+
expect(labelledBy0).not.toBe(labelledBy1);
|
|
486
|
+
|
|
487
|
+
const label0El = document.getElementById(labelledBy0!);
|
|
488
|
+
const label1El = document.getElementById(labelledBy1!);
|
|
489
|
+
expect(label0El?.textContent).toContain("March");
|
|
490
|
+
expect(label1El?.textContent).toContain("April");
|
|
491
|
+
|
|
492
|
+
unmount();
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
it("Grid monthIndex selects correct month data", () => {
|
|
496
|
+
const { container, unmount } = render(
|
|
497
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={2}>
|
|
498
|
+
<Grid monthIndex={0} />
|
|
499
|
+
<Grid monthIndex={1} />
|
|
500
|
+
</MonthView>,
|
|
501
|
+
);
|
|
502
|
+
|
|
503
|
+
const grids = container.querySelectorAll('[role="grid"]');
|
|
504
|
+
const grid0Dates = grids[0].querySelectorAll("[data-date]");
|
|
505
|
+
const grid1Dates = grids[1].querySelectorAll("[data-date]");
|
|
506
|
+
|
|
507
|
+
expect(grid0Dates.length).toBeGreaterThan(0);
|
|
508
|
+
expect(grid1Dates.length).toBeGreaterThan(0);
|
|
509
|
+
|
|
510
|
+
const grid0HasMarch = Array.from(grid0Dates).some((el) =>
|
|
511
|
+
el.getAttribute("data-date")?.startsWith("2026-03"),
|
|
512
|
+
);
|
|
513
|
+
const grid1HasApril = Array.from(grid1Dates).some((el) =>
|
|
514
|
+
el.getAttribute("data-date")?.startsWith("2026-04"),
|
|
515
|
+
);
|
|
516
|
+
expect(grid0HasMarch).toBe(true);
|
|
517
|
+
expect(grid1HasApril).toBe(true);
|
|
518
|
+
|
|
519
|
+
unmount();
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
it("updates allMonths when numberOfMonths prop changes", () => {
|
|
523
|
+
let captured: { allMonths: MonthData[] } | undefined;
|
|
524
|
+
|
|
525
|
+
const { rerender, unmount } = render(
|
|
526
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={1}>
|
|
527
|
+
<MonthDataCapture
|
|
528
|
+
onCapture={(d) => {
|
|
529
|
+
captured = d;
|
|
530
|
+
}}
|
|
531
|
+
/>
|
|
532
|
+
</MonthView>,
|
|
533
|
+
);
|
|
534
|
+
|
|
535
|
+
expect(captured!.allMonths).toHaveLength(1);
|
|
536
|
+
|
|
537
|
+
rerender(
|
|
538
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={3}>
|
|
539
|
+
<MonthDataCapture
|
|
540
|
+
onCapture={(d) => {
|
|
541
|
+
captured = d;
|
|
542
|
+
}}
|
|
543
|
+
/>
|
|
544
|
+
</MonthView>,
|
|
545
|
+
);
|
|
546
|
+
|
|
547
|
+
expect(captured!.allMonths).toHaveLength(3);
|
|
548
|
+
expect(captured!.allMonths.map((m) => `${m.year}-${m.month}`)).toEqual([
|
|
549
|
+
"2026-3",
|
|
550
|
+
"2026-4",
|
|
551
|
+
"2026-5",
|
|
552
|
+
]);
|
|
553
|
+
|
|
554
|
+
unmount();
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
it("clamps numberOfMonths to 1–12 range", () => {
|
|
558
|
+
let captured: { allMonths: MonthData[] } | undefined;
|
|
559
|
+
|
|
560
|
+
const { unmount } = render(
|
|
561
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={0}>
|
|
562
|
+
<MonthDataCapture
|
|
563
|
+
onCapture={(d) => {
|
|
564
|
+
captured = d;
|
|
565
|
+
}}
|
|
566
|
+
/>
|
|
567
|
+
</MonthView>,
|
|
568
|
+
);
|
|
569
|
+
|
|
570
|
+
// 0 should be clamped to 1
|
|
571
|
+
expect(captured!.allMonths).toHaveLength(1);
|
|
572
|
+
|
|
573
|
+
unmount();
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
it("keyboard PageDown from last visible month shifts view", () => {
|
|
577
|
+
let captured:
|
|
578
|
+
| { currentMonth: { year: number; month: number }; focusedDate: string }
|
|
579
|
+
| undefined;
|
|
580
|
+
|
|
581
|
+
const { container, unmount } = render(
|
|
582
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={2}>
|
|
583
|
+
<MonthDataCapture
|
|
584
|
+
onCapture={(d) => {
|
|
585
|
+
captured = d;
|
|
586
|
+
}}
|
|
587
|
+
/>
|
|
588
|
+
<Grid monthIndex={0} />
|
|
589
|
+
<Grid monthIndex={1} />
|
|
590
|
+
</MonthView>,
|
|
591
|
+
);
|
|
592
|
+
|
|
593
|
+
// Initially March+April, focused on March 15
|
|
594
|
+
expect(captured!.currentMonth).toEqual({ year: 2026, month: 3 });
|
|
595
|
+
expect(captured!.focusedDate).toBe("2026-03-15");
|
|
596
|
+
|
|
597
|
+
// Press PageDown to move focus to April 15 — still within visible range
|
|
598
|
+
const grid = container.querySelector('[role="grid"]')!;
|
|
599
|
+
act(() => {
|
|
600
|
+
grid.dispatchEvent(new KeyboardEvent("keydown", { key: "PageDown", bubbles: true }));
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
expect(captured!.focusedDate).toBe("2026-04-15");
|
|
604
|
+
// April is the second visible month, so currentMonth stays at March
|
|
605
|
+
expect(captured!.currentMonth).toEqual({ year: 2026, month: 3 });
|
|
606
|
+
|
|
607
|
+
// Press PageDown again — May is outside the visible range, should shift
|
|
608
|
+
act(() => {
|
|
609
|
+
grid.dispatchEvent(new KeyboardEvent("keydown", { key: "PageDown", bubbles: true }));
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
expect(captured!.focusedDate).toBe("2026-05-15");
|
|
613
|
+
expect(captured!.currentMonth).toEqual({ year: 2026, month: 5 });
|
|
614
|
+
|
|
615
|
+
unmount();
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
it("keyboard PageUp from first visible month shifts view", () => {
|
|
619
|
+
let captured:
|
|
620
|
+
| { currentMonth: { year: number; month: number }; focusedDate: string }
|
|
621
|
+
| undefined;
|
|
622
|
+
|
|
623
|
+
const { container, unmount } = render(
|
|
624
|
+
<MonthView {...defaultProps} defaultValue={april15} numberOfMonths={2}>
|
|
625
|
+
<MonthDataCapture
|
|
626
|
+
onCapture={(d) => {
|
|
627
|
+
captured = d;
|
|
628
|
+
}}
|
|
629
|
+
/>
|
|
630
|
+
<Grid monthIndex={0} />
|
|
631
|
+
</MonthView>,
|
|
632
|
+
);
|
|
633
|
+
|
|
634
|
+
// Initially April+May, focused on April 15
|
|
635
|
+
expect(captured!.currentMonth).toEqual({ year: 2026, month: 4 });
|
|
636
|
+
|
|
637
|
+
// Press PageUp to move focus to March 15 — outside visible range
|
|
638
|
+
const grid = container.querySelector('[role="grid"]')!;
|
|
639
|
+
act(() => {
|
|
640
|
+
grid.dispatchEvent(new KeyboardEvent("keydown", { key: "PageUp", bubbles: true }));
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
expect(captured!.focusedDate).toBe("2026-03-15");
|
|
644
|
+
expect(captured!.currentMonth).toEqual({ year: 2026, month: 3 });
|
|
645
|
+
|
|
646
|
+
unmount();
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
it("outsideMonth is relative to each grid's month", () => {
|
|
650
|
+
const { container, unmount } = render(
|
|
651
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={2}>
|
|
652
|
+
<Grid monthIndex={0} />
|
|
653
|
+
<Grid monthIndex={1} />
|
|
654
|
+
</MonthView>,
|
|
655
|
+
);
|
|
656
|
+
|
|
657
|
+
const grids = container.querySelectorAll('[role="grid"]');
|
|
658
|
+
|
|
659
|
+
// In grid 0 (March), outside-month dates should not be March dates
|
|
660
|
+
const grid0OutsideMonth = Array.from(grids[0].querySelectorAll("[data-outside-month]"));
|
|
661
|
+
for (const el of grid0OutsideMonth) {
|
|
662
|
+
const dateStr = el.getAttribute("data-date")!;
|
|
663
|
+
expect(dateStr.startsWith("2026-03")).toBe(false);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
// In grid 1 (April), outside-month dates should not be April dates
|
|
667
|
+
const grid1OutsideMonth = Array.from(grids[1].querySelectorAll("[data-outside-month]"));
|
|
668
|
+
for (const el of grid1OutsideMonth) {
|
|
669
|
+
const dateStr = el.getAttribute("data-date")!;
|
|
670
|
+
expect(dateStr.startsWith("2026-04")).toBe(false);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
unmount();
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
describe("navigation buttons with multi-month", () => {
|
|
677
|
+
it("next button computes destination from last visible month", () => {
|
|
678
|
+
const { container, unmount } = render(
|
|
679
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={3}>
|
|
680
|
+
<NextMonthButton data-testid="next" />
|
|
681
|
+
</MonthView>,
|
|
682
|
+
);
|
|
683
|
+
|
|
684
|
+
// With numberOfMonths=3 viewing March, the last visible month is May.
|
|
685
|
+
// "Next" should point to June 2026.
|
|
686
|
+
const btn = container.querySelector('[data-testid="next"]')!;
|
|
687
|
+
expect(btn.getAttribute("disabled")).toBeNull();
|
|
688
|
+
|
|
689
|
+
unmount();
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
it("prev button computes destination from first visible month", () => {
|
|
693
|
+
const { container, unmount } = render(
|
|
694
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={3}>
|
|
695
|
+
<PrevMonthButton data-testid="prev" />
|
|
696
|
+
</MonthView>,
|
|
697
|
+
);
|
|
698
|
+
|
|
699
|
+
// "Prev" should point to February 2026 (one before first visible).
|
|
700
|
+
const btn = container.querySelector('[data-testid="prev"]')!;
|
|
701
|
+
expect(btn.getAttribute("disabled")).toBeNull();
|
|
702
|
+
|
|
703
|
+
unmount();
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
it("next button disabled when last visible month reaches max", () => {
|
|
707
|
+
const maxDate = Temporal.PlainDate.from("2026-05-31");
|
|
708
|
+
const { container, unmount } = render(
|
|
709
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={3} max={maxDate}>
|
|
710
|
+
<NextMonthButton data-testid="next" />
|
|
711
|
+
</MonthView>,
|
|
712
|
+
);
|
|
713
|
+
|
|
714
|
+
// Last visible month is May, max is May 31 → next (June) is beyond max
|
|
715
|
+
const btn = container.querySelector('[data-testid="next"]')!;
|
|
716
|
+
expect(btn.getAttribute("disabled")).toBe("");
|
|
717
|
+
|
|
718
|
+
unmount();
|
|
719
|
+
});
|
|
720
|
+
|
|
721
|
+
it("prev button disabled when first visible month reaches min", () => {
|
|
722
|
+
const minDate = Temporal.PlainDate.from("2026-03-01");
|
|
723
|
+
const { container, unmount } = render(
|
|
724
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={2} min={minDate}>
|
|
725
|
+
<PrevMonthButton data-testid="prev" />
|
|
726
|
+
</MonthView>,
|
|
727
|
+
);
|
|
728
|
+
|
|
729
|
+
// First visible month is March, min is March 1 → prev (Feb) is before min
|
|
730
|
+
const btn = container.querySelector('[data-testid="prev"]')!;
|
|
731
|
+
expect(btn.getAttribute("disabled")).toBe("");
|
|
732
|
+
|
|
733
|
+
unmount();
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
it("clicking next shifts view by one month", () => {
|
|
737
|
+
let captured: { currentMonth: { year: number; month: number } } | undefined;
|
|
738
|
+
|
|
739
|
+
const { container, unmount } = render(
|
|
740
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={2}>
|
|
741
|
+
<MonthDataCapture
|
|
742
|
+
onCapture={(d) => {
|
|
743
|
+
captured = d;
|
|
744
|
+
}}
|
|
745
|
+
/>
|
|
746
|
+
<NextMonthButton data-testid="next" />
|
|
747
|
+
</MonthView>,
|
|
748
|
+
);
|
|
749
|
+
|
|
750
|
+
expect(captured!.currentMonth).toEqual({ year: 2026, month: 3 });
|
|
751
|
+
|
|
752
|
+
act(() => {
|
|
753
|
+
container
|
|
754
|
+
.querySelector('[data-testid="next"]')!
|
|
755
|
+
.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
// Shifts by 1 month, not by numberOfMonths
|
|
759
|
+
expect(captured!.currentMonth).toEqual({ year: 2026, month: 4 });
|
|
760
|
+
|
|
761
|
+
unmount();
|
|
762
|
+
});
|
|
763
|
+
|
|
764
|
+
it("clicking prev shifts view by one month", () => {
|
|
765
|
+
let captured: { currentMonth: { year: number; month: number } } | undefined;
|
|
766
|
+
|
|
767
|
+
const { container, unmount } = render(
|
|
768
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={2}>
|
|
769
|
+
<MonthDataCapture
|
|
770
|
+
onCapture={(d) => {
|
|
771
|
+
captured = d;
|
|
772
|
+
}}
|
|
773
|
+
/>
|
|
774
|
+
<PrevMonthButton data-testid="prev" />
|
|
775
|
+
</MonthView>,
|
|
776
|
+
);
|
|
777
|
+
|
|
778
|
+
act(() => {
|
|
779
|
+
container
|
|
780
|
+
.querySelector('[data-testid="prev"]')!
|
|
781
|
+
.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
782
|
+
});
|
|
783
|
+
|
|
784
|
+
expect(captured!.currentMonth).toEqual({ year: 2026, month: 2 });
|
|
785
|
+
|
|
786
|
+
unmount();
|
|
787
|
+
});
|
|
788
|
+
});
|
|
789
|
+
|
|
790
|
+
describe("range selection across months", () => {
|
|
791
|
+
it("range spanning two visible months shows inRange on intermediate dates", () => {
|
|
792
|
+
const rangeStart = Temporal.PlainDate.from("2026-03-25");
|
|
793
|
+
const rangeEnd = Temporal.PlainDate.from("2026-04-05");
|
|
794
|
+
|
|
795
|
+
const { container, unmount } = render(
|
|
796
|
+
<MonthView
|
|
797
|
+
{...defaultProps}
|
|
798
|
+
selectionMode="range"
|
|
799
|
+
value={{ start: rangeStart, end: rangeEnd }}
|
|
800
|
+
numberOfMonths={2}
|
|
801
|
+
>
|
|
802
|
+
<Grid monthIndex={0} />
|
|
803
|
+
<Grid monthIndex={1} />
|
|
804
|
+
</MonthView>,
|
|
805
|
+
);
|
|
806
|
+
|
|
807
|
+
const grids = container.querySelectorAll('[role="grid"]');
|
|
808
|
+
|
|
809
|
+
// Grid 0 (March): March 25-31 should be in range
|
|
810
|
+
const grid0InRange = Array.from(grids[0].querySelectorAll("[data-in-range]"));
|
|
811
|
+
const grid0InRangeDates = grid0InRange.map((el) => el.getAttribute("data-date"));
|
|
812
|
+
expect(grid0InRangeDates).toContain("2026-03-25");
|
|
813
|
+
expect(grid0InRangeDates).toContain("2026-03-31");
|
|
814
|
+
|
|
815
|
+
// Grid 1 (April): April 1-5 should be in range
|
|
816
|
+
const grid1InRange = Array.from(grids[1].querySelectorAll("[data-in-range]"));
|
|
817
|
+
const grid1InRangeDates = grid1InRange.map((el) => el.getAttribute("data-date"));
|
|
818
|
+
expect(grid1InRangeDates).toContain("2026-04-01");
|
|
819
|
+
expect(grid1InRangeDates).toContain("2026-04-05");
|
|
820
|
+
|
|
821
|
+
unmount();
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
it("range-start and range-end markers appear in correct grids", () => {
|
|
825
|
+
const rangeStart = Temporal.PlainDate.from("2026-03-20");
|
|
826
|
+
const rangeEnd = Temporal.PlainDate.from("2026-04-10");
|
|
827
|
+
|
|
828
|
+
const { container, unmount } = render(
|
|
829
|
+
<MonthView
|
|
830
|
+
{...defaultProps}
|
|
831
|
+
selectionMode="range"
|
|
832
|
+
value={{ start: rangeStart, end: rangeEnd }}
|
|
833
|
+
numberOfMonths={2}
|
|
834
|
+
>
|
|
835
|
+
<Grid monthIndex={0} />
|
|
836
|
+
<Grid monthIndex={1} />
|
|
837
|
+
</MonthView>,
|
|
838
|
+
);
|
|
839
|
+
|
|
840
|
+
const grids = container.querySelectorAll('[role="grid"]');
|
|
841
|
+
|
|
842
|
+
// range-start should be in grid 0 (March 20)
|
|
843
|
+
const grid0RangeStart = grids[0].querySelector('[data-range-start][data-date="2026-03-20"]');
|
|
844
|
+
expect(grid0RangeStart).toBeTruthy();
|
|
845
|
+
|
|
846
|
+
// range-end should be in grid 1 (April 10)
|
|
847
|
+
const grid1RangeEnd = grids[1].querySelector('[data-range-end][data-date="2026-04-10"]');
|
|
848
|
+
expect(grid1RangeEnd).toBeTruthy();
|
|
849
|
+
|
|
850
|
+
unmount();
|
|
851
|
+
});
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
describe("grid state attributes", () => {
|
|
855
|
+
it("each grid exposes correct month and year in state", () => {
|
|
856
|
+
const { container, unmount } = render(
|
|
857
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={2}>
|
|
858
|
+
<Grid monthIndex={0} />
|
|
859
|
+
<Grid monthIndex={1} />
|
|
860
|
+
</MonthView>,
|
|
861
|
+
);
|
|
862
|
+
|
|
863
|
+
const grids = container.querySelectorAll('[role="grid"]');
|
|
864
|
+
|
|
865
|
+
// Grid state attributes reflect each grid's month
|
|
866
|
+
expect(grids[0].getAttribute("data-weeks-in-month")).toBeTruthy();
|
|
867
|
+
expect(grids[0].getAttribute("data-days-per-week")).toBe("7");
|
|
868
|
+
expect(grids[1].getAttribute("data-weeks-in-month")).toBeTruthy();
|
|
869
|
+
expect(grids[1].getAttribute("data-days-per-week")).toBe("7");
|
|
870
|
+
|
|
871
|
+
unmount();
|
|
872
|
+
});
|
|
873
|
+
|
|
874
|
+
it("CSS custom properties set per grid", () => {
|
|
875
|
+
const { container, unmount } = render(
|
|
876
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={2}>
|
|
877
|
+
<Grid monthIndex={0} />
|
|
878
|
+
<Grid monthIndex={1} />
|
|
879
|
+
</MonthView>,
|
|
880
|
+
);
|
|
881
|
+
|
|
882
|
+
const grids = container.querySelectorAll('[role="grid"]');
|
|
883
|
+
|
|
884
|
+
// Each grid should have its own CSS custom properties
|
|
885
|
+
const style0 = (grids[0] as HTMLElement).style;
|
|
886
|
+
const style1 = (grids[1] as HTMLElement).style;
|
|
887
|
+
expect(style0.getPropertyValue("--calendar-days-per-week")).toBe("7");
|
|
888
|
+
expect(style1.getPropertyValue("--calendar-days-per-week")).toBe("7");
|
|
889
|
+
expect(style0.getPropertyValue("--calendar-weeks-in-month")).toBeTruthy();
|
|
890
|
+
expect(style1.getPropertyValue("--calendar-weeks-in-month")).toBeTruthy();
|
|
891
|
+
|
|
892
|
+
unmount();
|
|
893
|
+
});
|
|
894
|
+
});
|
|
895
|
+
|
|
896
|
+
describe("backward compatibility", () => {
|
|
897
|
+
it("single-month without monthIndex works unchanged", () => {
|
|
898
|
+
const { container, unmount } = render(
|
|
899
|
+
<MonthView {...defaultProps} defaultValue={march15}>
|
|
900
|
+
<MonthYearString />
|
|
901
|
+
<Grid />
|
|
902
|
+
</MonthView>,
|
|
903
|
+
);
|
|
904
|
+
|
|
905
|
+
const grids = container.querySelectorAll('[role="grid"]');
|
|
906
|
+
expect(grids).toHaveLength(1);
|
|
907
|
+
|
|
908
|
+
// Grid should have aria-labelledby pointing to the MonthYearString
|
|
909
|
+
const labelledBy = grids[0].getAttribute("aria-labelledby");
|
|
910
|
+
expect(labelledBy).toBeTruthy();
|
|
911
|
+
const label = document.getElementById(labelledBy!);
|
|
912
|
+
expect(label?.textContent).toContain("March");
|
|
913
|
+
|
|
914
|
+
unmount();
|
|
915
|
+
});
|
|
916
|
+
|
|
917
|
+
it("explicit monthIndex={0} on single-month setup works", () => {
|
|
918
|
+
const { container, unmount } = render(
|
|
919
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={1}>
|
|
920
|
+
<MonthYearString monthIndex={0} />
|
|
921
|
+
<Grid monthIndex={0} />
|
|
922
|
+
</MonthView>,
|
|
923
|
+
);
|
|
924
|
+
|
|
925
|
+
const grids = container.querySelectorAll('[role="grid"]');
|
|
926
|
+
expect(grids).toHaveLength(1);
|
|
927
|
+
|
|
928
|
+
const dates = Array.from(grids[0].querySelectorAll("[data-date]"));
|
|
929
|
+
const hasMarch = dates.some((el) => el.getAttribute("data-date")?.startsWith("2026-03"));
|
|
930
|
+
expect(hasMarch).toBe(true);
|
|
931
|
+
|
|
932
|
+
unmount();
|
|
933
|
+
});
|
|
934
|
+
});
|
|
935
|
+
|
|
936
|
+
describe("onMonthChange with multi-month", () => {
|
|
937
|
+
it("fires when navigation shifts visible months", () => {
|
|
938
|
+
const onMonthChange = vi.fn();
|
|
939
|
+
|
|
940
|
+
const { container, unmount } = render(
|
|
941
|
+
<MonthView
|
|
942
|
+
{...defaultProps}
|
|
943
|
+
defaultValue={march15}
|
|
944
|
+
numberOfMonths={2}
|
|
945
|
+
onMonthChange={onMonthChange}
|
|
946
|
+
>
|
|
947
|
+
<NextMonthButton data-testid="next" />
|
|
948
|
+
</MonthView>,
|
|
949
|
+
);
|
|
950
|
+
|
|
951
|
+
// Should not fire on mount
|
|
952
|
+
expect(onMonthChange).not.toHaveBeenCalled();
|
|
953
|
+
|
|
954
|
+
act(() => {
|
|
955
|
+
container
|
|
956
|
+
.querySelector('[data-testid="next"]')!
|
|
957
|
+
.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
958
|
+
});
|
|
959
|
+
|
|
960
|
+
expect(onMonthChange).toHaveBeenCalledTimes(1);
|
|
961
|
+
const arg = onMonthChange.mock.calls[0][0];
|
|
962
|
+
// Should report the new first visible month (April)
|
|
963
|
+
expect(arg.month).toBe(4);
|
|
964
|
+
expect(arg.year).toBe(2026);
|
|
965
|
+
|
|
966
|
+
unmount();
|
|
967
|
+
});
|
|
968
|
+
|
|
969
|
+
it("does not fire when selection stays within visible months", () => {
|
|
970
|
+
const onMonthChange = vi.fn();
|
|
971
|
+
let selectFn: (date: Temporal.PlainDate) => void = () => {};
|
|
972
|
+
|
|
973
|
+
const { unmount } = render(
|
|
974
|
+
<MonthView
|
|
975
|
+
{...defaultProps}
|
|
976
|
+
defaultValue={march15}
|
|
977
|
+
numberOfMonths={2}
|
|
978
|
+
onMonthChange={onMonthChange}
|
|
979
|
+
>
|
|
980
|
+
<SelectTrigger
|
|
981
|
+
onCapture={(fn) => {
|
|
982
|
+
selectFn = fn;
|
|
983
|
+
}}
|
|
984
|
+
/>
|
|
985
|
+
</MonthView>,
|
|
986
|
+
);
|
|
987
|
+
|
|
988
|
+
// Select within April (second visible month) — shouldn't trigger month change
|
|
989
|
+
act(() => {
|
|
990
|
+
selectFn(april15);
|
|
991
|
+
});
|
|
992
|
+
|
|
993
|
+
expect(onMonthChange).not.toHaveBeenCalled();
|
|
994
|
+
|
|
995
|
+
unmount();
|
|
996
|
+
});
|
|
997
|
+
});
|
|
998
|
+
|
|
999
|
+
describe("focusedDate across months", () => {
|
|
1000
|
+
it("preserves focusedDate when numberOfMonths increases", () => {
|
|
1001
|
+
let captured: { focusedDate: string } | undefined;
|
|
1002
|
+
|
|
1003
|
+
const { rerender, unmount } = render(
|
|
1004
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={1}>
|
|
1005
|
+
<MonthDataCapture
|
|
1006
|
+
onCapture={(d) => {
|
|
1007
|
+
captured = d;
|
|
1008
|
+
}}
|
|
1009
|
+
/>
|
|
1010
|
+
</MonthView>,
|
|
1011
|
+
);
|
|
1012
|
+
|
|
1013
|
+
expect(captured!.focusedDate).toBe("2026-03-15");
|
|
1014
|
+
|
|
1015
|
+
rerender(
|
|
1016
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={3}>
|
|
1017
|
+
<MonthDataCapture
|
|
1018
|
+
onCapture={(d) => {
|
|
1019
|
+
captured = d;
|
|
1020
|
+
}}
|
|
1021
|
+
/>
|
|
1022
|
+
</MonthView>,
|
|
1023
|
+
);
|
|
1024
|
+
|
|
1025
|
+
// focusedDate should not change when numberOfMonths grows
|
|
1026
|
+
expect(captured!.focusedDate).toBe("2026-03-15");
|
|
1027
|
+
|
|
1028
|
+
unmount();
|
|
1029
|
+
});
|
|
1030
|
+
|
|
1031
|
+
it("preserves focusedDate when numberOfMonths decreases", () => {
|
|
1032
|
+
let captured: { focusedDate: string } | undefined;
|
|
1033
|
+
|
|
1034
|
+
const { rerender, unmount } = render(
|
|
1035
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={3}>
|
|
1036
|
+
<MonthDataCapture
|
|
1037
|
+
onCapture={(d) => {
|
|
1038
|
+
captured = d;
|
|
1039
|
+
}}
|
|
1040
|
+
/>
|
|
1041
|
+
</MonthView>,
|
|
1042
|
+
);
|
|
1043
|
+
|
|
1044
|
+
expect(captured!.focusedDate).toBe("2026-03-15");
|
|
1045
|
+
|
|
1046
|
+
rerender(
|
|
1047
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={1}>
|
|
1048
|
+
<MonthDataCapture
|
|
1049
|
+
onCapture={(d) => {
|
|
1050
|
+
captured = d;
|
|
1051
|
+
}}
|
|
1052
|
+
/>
|
|
1053
|
+
</MonthView>,
|
|
1054
|
+
);
|
|
1055
|
+
|
|
1056
|
+
expect(captured!.focusedDate).toBe("2026-03-15");
|
|
1057
|
+
|
|
1058
|
+
unmount();
|
|
1059
|
+
});
|
|
1060
|
+
|
|
1061
|
+
it("arrow key within visible months does not shift view", () => {
|
|
1062
|
+
let captured:
|
|
1063
|
+
| { currentMonth: { year: number; month: number }; focusedDate: string }
|
|
1064
|
+
| undefined;
|
|
1065
|
+
|
|
1066
|
+
// Focus on March 31, with April also visible
|
|
1067
|
+
const march31 = Temporal.PlainDate.from("2026-03-31");
|
|
1068
|
+
const { container, unmount } = render(
|
|
1069
|
+
<MonthView {...defaultProps} defaultValue={march31} numberOfMonths={2}>
|
|
1070
|
+
<MonthDataCapture
|
|
1071
|
+
onCapture={(d) => {
|
|
1072
|
+
captured = d;
|
|
1073
|
+
}}
|
|
1074
|
+
/>
|
|
1075
|
+
<Grid monthIndex={0} />
|
|
1076
|
+
</MonthView>,
|
|
1077
|
+
);
|
|
1078
|
+
|
|
1079
|
+
expect(captured!.focusedDate).toBe("2026-03-31");
|
|
1080
|
+
expect(captured!.currentMonth).toEqual({ year: 2026, month: 3 });
|
|
1081
|
+
|
|
1082
|
+
// ArrowRight → April 1, still within visible range
|
|
1083
|
+
const grid = container.querySelector('[role="grid"]')!;
|
|
1084
|
+
act(() => {
|
|
1085
|
+
grid.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowRight", bubbles: true }));
|
|
1086
|
+
});
|
|
1087
|
+
|
|
1088
|
+
expect(captured!.focusedDate).toBe("2026-04-01");
|
|
1089
|
+
expect(captured!.currentMonth).toEqual({ year: 2026, month: 3 });
|
|
1090
|
+
|
|
1091
|
+
unmount();
|
|
1092
|
+
});
|
|
1093
|
+
});
|
|
1094
|
+
});
|
|
1095
|
+
|
|
1096
|
+
describe("outsideDays", () => {
|
|
1097
|
+
const march15 = Temporal.PlainDate.from("2026-03-15");
|
|
1098
|
+
|
|
1099
|
+
describe('outsideDays="enabled" (default)', () => {
|
|
1100
|
+
it("outside-month cells are visible and interactive", () => {
|
|
1101
|
+
const { container, unmount } = render(
|
|
1102
|
+
<MonthView {...defaultProps} defaultValue={march15}>
|
|
1103
|
+
<Grid />
|
|
1104
|
+
</MonthView>,
|
|
1105
|
+
);
|
|
1106
|
+
|
|
1107
|
+
const outsideCells = Array.from(container.querySelectorAll("td[data-outside-month]"));
|
|
1108
|
+
expect(outsideCells.length).toBeGreaterThan(0);
|
|
1109
|
+
|
|
1110
|
+
// None should have data-hidden
|
|
1111
|
+
for (const cell of outsideCells) {
|
|
1112
|
+
expect(cell.getAttribute("data-hidden")).toBeNull();
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
// All outside-month td cells should contain a button
|
|
1116
|
+
for (const cell of outsideCells) {
|
|
1117
|
+
expect(cell.querySelector("button")).not.toBeNull();
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
// Buttons should not be disabled
|
|
1121
|
+
for (const cell of outsideCells) {
|
|
1122
|
+
const btn = cell.querySelector("button");
|
|
1123
|
+
expect(btn?.disabled).toBe(false);
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
unmount();
|
|
1127
|
+
});
|
|
1128
|
+
});
|
|
1129
|
+
|
|
1130
|
+
describe('outsideDays="readOnly"', () => {
|
|
1131
|
+
it("outside-month buttons render but are disabled", () => {
|
|
1132
|
+
const { container, unmount } = render(
|
|
1133
|
+
<MonthView {...defaultProps} defaultValue={march15} outsideDays="readOnly">
|
|
1134
|
+
<Grid />
|
|
1135
|
+
</MonthView>,
|
|
1136
|
+
);
|
|
1137
|
+
|
|
1138
|
+
const outsideCells = Array.from(container.querySelectorAll("td[data-outside-month]"));
|
|
1139
|
+
expect(outsideCells.length).toBeGreaterThan(0);
|
|
1140
|
+
|
|
1141
|
+
for (const cell of outsideCells) {
|
|
1142
|
+
expect(cell.getAttribute("data-hidden")).toBeNull();
|
|
1143
|
+
expect(cell.getAttribute("data-disabled")).not.toBeNull();
|
|
1144
|
+
const btn = cell.querySelector("button");
|
|
1145
|
+
expect(btn).not.toBeNull();
|
|
1146
|
+
expect(btn?.disabled).toBe(true);
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
unmount();
|
|
1150
|
+
});
|
|
1151
|
+
|
|
1152
|
+
it("range attributes still paint through outside-month cells", () => {
|
|
1153
|
+
// March 2026 starts on Sunday — so the grid has no leading padding.
|
|
1154
|
+
// But it ends on Tuesday Mar 31, so April 1–4 are outside-month padding.
|
|
1155
|
+
// Use a range that extends into April to verify range attrs paint through.
|
|
1156
|
+
const march25 = Temporal.PlainDate.from("2026-03-25");
|
|
1157
|
+
const april3 = Temporal.PlainDate.from("2026-04-03");
|
|
1158
|
+
|
|
1159
|
+
const { container, unmount } = render(
|
|
1160
|
+
<MonthView
|
|
1161
|
+
{...defaultProps}
|
|
1162
|
+
selectionMode="range"
|
|
1163
|
+
value={{ start: march25, end: april3 }}
|
|
1164
|
+
outsideDays="readOnly"
|
|
1165
|
+
>
|
|
1166
|
+
<Grid />
|
|
1167
|
+
</MonthView>,
|
|
1168
|
+
);
|
|
1169
|
+
|
|
1170
|
+
// April 1 in the March grid is outside-month
|
|
1171
|
+
const april1Cell = container.querySelector('[data-date="2026-04-01"]');
|
|
1172
|
+
expect(april1Cell).not.toBeNull();
|
|
1173
|
+
expect(april1Cell!.getAttribute("data-outside-month")).not.toBeNull();
|
|
1174
|
+
expect(april1Cell!.getAttribute("data-in-range")).not.toBeNull();
|
|
1175
|
+
|
|
1176
|
+
unmount();
|
|
1177
|
+
});
|
|
1178
|
+
});
|
|
1179
|
+
|
|
1180
|
+
describe('outsideDays="disabled"', () => {
|
|
1181
|
+
it("outside-month buttons render but are disabled, no range attrs", () => {
|
|
1182
|
+
// March 2026 ends on Tue Mar 31, so April 1–4 appear as outside-month padding.
|
|
1183
|
+
const march25 = Temporal.PlainDate.from("2026-03-25");
|
|
1184
|
+
const april3 = Temporal.PlainDate.from("2026-04-03");
|
|
1185
|
+
|
|
1186
|
+
const { container, unmount } = render(
|
|
1187
|
+
<MonthView
|
|
1188
|
+
{...defaultProps}
|
|
1189
|
+
selectionMode="range"
|
|
1190
|
+
value={{ start: march25, end: april3 }}
|
|
1191
|
+
outsideDays="disabled"
|
|
1192
|
+
>
|
|
1193
|
+
<Grid />
|
|
1194
|
+
</MonthView>,
|
|
1195
|
+
);
|
|
1196
|
+
|
|
1197
|
+
const outsideCells = Array.from(container.querySelectorAll("td[data-outside-month]"));
|
|
1198
|
+
expect(outsideCells.length).toBeGreaterThan(0);
|
|
1199
|
+
|
|
1200
|
+
for (const cell of outsideCells) {
|
|
1201
|
+
expect(cell.getAttribute("data-hidden")).toBeNull();
|
|
1202
|
+
expect(cell.getAttribute("data-disabled")).not.toBeNull();
|
|
1203
|
+
expect(cell.querySelector("button")).not.toBeNull();
|
|
1204
|
+
// No range attributes
|
|
1205
|
+
expect(cell.getAttribute("data-in-range")).toBeNull();
|
|
1206
|
+
expect(cell.getAttribute("data-range-start")).toBeNull();
|
|
1207
|
+
expect(cell.getAttribute("data-range-end")).toBeNull();
|
|
1208
|
+
expect(cell.getAttribute("data-range-boundary")).toBeNull();
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
unmount();
|
|
1212
|
+
});
|
|
1213
|
+
});
|
|
1214
|
+
|
|
1215
|
+
describe('outsideDays="hidden"', () => {
|
|
1216
|
+
it("outside-month cells are empty with data-hidden and aria-hidden", () => {
|
|
1217
|
+
const { container, unmount } = render(
|
|
1218
|
+
<MonthView {...defaultProps} defaultValue={march15} outsideDays="hidden">
|
|
1219
|
+
<Grid />
|
|
1220
|
+
</MonthView>,
|
|
1221
|
+
);
|
|
1222
|
+
|
|
1223
|
+
const hiddenCells = Array.from(container.querySelectorAll("[data-hidden]"));
|
|
1224
|
+
expect(hiddenCells.length).toBeGreaterThan(0);
|
|
1225
|
+
|
|
1226
|
+
for (const cell of hiddenCells) {
|
|
1227
|
+
expect(cell.getAttribute("data-outside-month")).not.toBeNull();
|
|
1228
|
+
expect(cell.querySelector("button")).toBeNull();
|
|
1229
|
+
expect(cell.getAttribute("aria-hidden")).toBe("true");
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
unmount();
|
|
1233
|
+
});
|
|
1234
|
+
|
|
1235
|
+
it("hidden cells have no range attributes", () => {
|
|
1236
|
+
const march5 = Temporal.PlainDate.from("2026-03-05");
|
|
1237
|
+
const march25 = Temporal.PlainDate.from("2026-03-25");
|
|
1238
|
+
|
|
1239
|
+
const { container, unmount } = render(
|
|
1240
|
+
<MonthView
|
|
1241
|
+
{...defaultProps}
|
|
1242
|
+
selectionMode="range"
|
|
1243
|
+
value={{ start: march5, end: march25 }}
|
|
1244
|
+
outsideDays="hidden"
|
|
1245
|
+
>
|
|
1246
|
+
<Grid />
|
|
1247
|
+
</MonthView>,
|
|
1248
|
+
);
|
|
1249
|
+
|
|
1250
|
+
const hiddenCells = Array.from(container.querySelectorAll("[data-hidden]"));
|
|
1251
|
+
expect(hiddenCells.length).toBeGreaterThan(0);
|
|
1252
|
+
|
|
1253
|
+
for (const cell of hiddenCells) {
|
|
1254
|
+
expect(cell.getAttribute("data-in-range")).toBeNull();
|
|
1255
|
+
expect(cell.getAttribute("data-range-start")).toBeNull();
|
|
1256
|
+
expect(cell.getAttribute("data-range-end")).toBeNull();
|
|
1257
|
+
expect(cell.getAttribute("data-range-boundary")).toBeNull();
|
|
1258
|
+
expect(cell.getAttribute("data-selected")).toBeNull();
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
unmount();
|
|
1262
|
+
});
|
|
1263
|
+
|
|
1264
|
+
it("in-month cells still show range attributes", () => {
|
|
1265
|
+
const march5 = Temporal.PlainDate.from("2026-03-05");
|
|
1266
|
+
const march25 = Temporal.PlainDate.from("2026-03-25");
|
|
1267
|
+
|
|
1268
|
+
const { container, unmount } = render(
|
|
1269
|
+
<MonthView
|
|
1270
|
+
{...defaultProps}
|
|
1271
|
+
selectionMode="range"
|
|
1272
|
+
value={{ start: march5, end: march25 }}
|
|
1273
|
+
outsideDays="hidden"
|
|
1274
|
+
>
|
|
1275
|
+
<Grid />
|
|
1276
|
+
</MonthView>,
|
|
1277
|
+
);
|
|
1278
|
+
|
|
1279
|
+
const rangeStart = container.querySelector("[data-range-start]");
|
|
1280
|
+
expect(rangeStart).not.toBeNull();
|
|
1281
|
+
expect(rangeStart!.getAttribute("data-date")).toBe("2026-03-05");
|
|
1282
|
+
|
|
1283
|
+
const rangeEnd = container.querySelector("[data-range-end]");
|
|
1284
|
+
expect(rangeEnd).not.toBeNull();
|
|
1285
|
+
expect(rangeEnd!.getAttribute("data-date")).toBe("2026-03-25");
|
|
1286
|
+
|
|
1287
|
+
const inRangeCells = Array.from(container.querySelectorAll("[data-in-range]"));
|
|
1288
|
+
expect(inRangeCells.length).toBeGreaterThan(0);
|
|
1289
|
+
|
|
1290
|
+
for (const cell of inRangeCells) {
|
|
1291
|
+
expect(cell.getAttribute("data-hidden")).toBeNull();
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
unmount();
|
|
1295
|
+
});
|
|
1296
|
+
|
|
1297
|
+
it("works with multi-month: each grid hides its own outside-month cells", () => {
|
|
1298
|
+
const { container, unmount } = render(
|
|
1299
|
+
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={2} outsideDays="hidden">
|
|
1300
|
+
<Grid monthIndex={0} />
|
|
1301
|
+
<Grid monthIndex={1} />
|
|
1302
|
+
</MonthView>,
|
|
1303
|
+
);
|
|
1304
|
+
|
|
1305
|
+
const grids = Array.from(container.querySelectorAll("[role='grid']"));
|
|
1306
|
+
expect(grids.length).toBe(2);
|
|
1307
|
+
|
|
1308
|
+
for (const grid of grids) {
|
|
1309
|
+
const hiddenInGrid = grid.querySelectorAll("[data-hidden]");
|
|
1310
|
+
Array.from(hiddenInGrid).forEach((cell) => {
|
|
1311
|
+
expect(cell.querySelector("button")).toBeNull();
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
unmount();
|
|
1316
|
+
});
|
|
1317
|
+
|
|
1318
|
+
it("range spanning months clips per grid", () => {
|
|
1319
|
+
const march25 = Temporal.PlainDate.from("2026-03-25");
|
|
1320
|
+
const april5 = Temporal.PlainDate.from("2026-04-05");
|
|
1321
|
+
|
|
1322
|
+
const { container, unmount } = render(
|
|
1323
|
+
<MonthView
|
|
1324
|
+
{...defaultProps}
|
|
1325
|
+
selectionMode="range"
|
|
1326
|
+
value={{ start: march25, end: april5 }}
|
|
1327
|
+
numberOfMonths={2}
|
|
1328
|
+
outsideDays="hidden"
|
|
1329
|
+
>
|
|
1330
|
+
<Grid monthIndex={0} />
|
|
1331
|
+
<Grid monthIndex={1} />
|
|
1332
|
+
</MonthView>,
|
|
1333
|
+
);
|
|
1334
|
+
|
|
1335
|
+
const grids = Array.from(container.querySelectorAll("[role='grid']"));
|
|
1336
|
+
|
|
1337
|
+
const grid0Hidden = Array.from(grids[0].querySelectorAll("[data-hidden]"));
|
|
1338
|
+
for (const cell of grid0Hidden) {
|
|
1339
|
+
expect(cell.getAttribute("data-in-range")).toBeNull();
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
const grid1Hidden = Array.from(grids[1].querySelectorAll("[data-hidden]"));
|
|
1343
|
+
for (const cell of grid1Hidden) {
|
|
1344
|
+
expect(cell.getAttribute("data-in-range")).toBeNull();
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
const rangeStartInGrid0 = grids[0].querySelector("[data-range-start]");
|
|
1348
|
+
expect(rangeStartInGrid0).not.toBeNull();
|
|
1349
|
+
expect(rangeStartInGrid0!.getAttribute("data-date")).toBe("2026-03-25");
|
|
1350
|
+
|
|
1351
|
+
const rangeEndInGrid1 = grids[1].querySelector("[data-range-end]");
|
|
1352
|
+
expect(rangeEndInGrid1).not.toBeNull();
|
|
1353
|
+
expect(rangeEndInGrid1!.getAttribute("data-date")).toBe("2026-04-05");
|
|
1354
|
+
|
|
1355
|
+
unmount();
|
|
1356
|
+
});
|
|
1357
|
+
|
|
1358
|
+
it("fixedWeeks + hidden renders empty rows for padding weeks", () => {
|
|
1359
|
+
const feb15 = Temporal.PlainDate.from("2026-02-15");
|
|
1360
|
+
|
|
1361
|
+
const { container, unmount } = render(
|
|
1362
|
+
<MonthView {...defaultProps} defaultValue={feb15} fixedWeeks outsideDays="hidden">
|
|
1363
|
+
<Grid />
|
|
1364
|
+
</MonthView>,
|
|
1365
|
+
);
|
|
1366
|
+
|
|
1367
|
+
const rows = container.querySelectorAll("tbody tr");
|
|
1368
|
+
expect(rows.length).toBe(6);
|
|
1369
|
+
|
|
1370
|
+
const lastRow = rows[rows.length - 1];
|
|
1371
|
+
const cells = lastRow.querySelectorAll("td");
|
|
1372
|
+
const allHidden = Array.from(cells).every(
|
|
1373
|
+
(cell) => cell.getAttribute("data-hidden") !== null,
|
|
1374
|
+
);
|
|
1375
|
+
expect(allHidden).toBe(true);
|
|
1376
|
+
|
|
1377
|
+
unmount();
|
|
1378
|
+
});
|
|
1379
|
+
});
|
|
1380
|
+
|
|
1381
|
+
describe("range clipping per grid", () => {
|
|
1382
|
+
it("disabled clips range in SelectedRange but readonly does not", () => {
|
|
1383
|
+
const march25 = Temporal.PlainDate.from("2026-03-25");
|
|
1384
|
+
const april5 = Temporal.PlainDate.from("2026-04-05");
|
|
1385
|
+
|
|
1386
|
+
// "disabled" — outside-month cells should NOT have range attrs
|
|
1387
|
+
const { container: c1, unmount: u1 } = render(
|
|
1388
|
+
<MonthView
|
|
1389
|
+
{...defaultProps}
|
|
1390
|
+
selectionMode="range"
|
|
1391
|
+
value={{ start: march25, end: april5 }}
|
|
1392
|
+
numberOfMonths={2}
|
|
1393
|
+
outsideDays="disabled"
|
|
1394
|
+
>
|
|
1395
|
+
<Grid monthIndex={0} />
|
|
1396
|
+
<Grid monthIndex={1} />
|
|
1397
|
+
</MonthView>,
|
|
1398
|
+
);
|
|
1399
|
+
|
|
1400
|
+
const grids1 = Array.from(c1.querySelectorAll("[role='grid']"));
|
|
1401
|
+
// Grid 0 (March): April dates should have no range attrs
|
|
1402
|
+
const outsideInGrid0 = Array.from(grids1[0].querySelectorAll("[data-outside-month]"));
|
|
1403
|
+
for (const cell of outsideInGrid0) {
|
|
1404
|
+
expect(cell.getAttribute("data-in-range")).toBeNull();
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
u1();
|
|
1408
|
+
|
|
1409
|
+
// "readonly" — outside-month cells SHOULD have range attrs
|
|
1410
|
+
const { container: c2, unmount: u2 } = render(
|
|
1411
|
+
<MonthView
|
|
1412
|
+
{...defaultProps}
|
|
1413
|
+
selectionMode="range"
|
|
1414
|
+
value={{ start: march25, end: april5 }}
|
|
1415
|
+
numberOfMonths={2}
|
|
1416
|
+
outsideDays="readOnly"
|
|
1417
|
+
>
|
|
1418
|
+
<Grid monthIndex={0} />
|
|
1419
|
+
<Grid monthIndex={1} />
|
|
1420
|
+
</MonthView>,
|
|
1421
|
+
);
|
|
1422
|
+
|
|
1423
|
+
const grids2 = Array.from(c2.querySelectorAll("[role='grid']"));
|
|
1424
|
+
// Grid 0 (March): April dates should still have range attrs with readonly
|
|
1425
|
+
const outsideInGrid0Readonly = Array.from(
|
|
1426
|
+
grids2[0].querySelectorAll("[data-outside-month][data-in-range]"),
|
|
1427
|
+
);
|
|
1428
|
+
expect(outsideInGrid0Readonly.length).toBeGreaterThan(0);
|
|
1429
|
+
|
|
1430
|
+
u2();
|
|
1431
|
+
});
|
|
1432
|
+
});
|
|
1433
|
+
});
|