@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.
Files changed (93) hide show
  1. package/dist/formats/date.cjs +49 -0
  2. package/dist/formats/date.d.cts +45 -0
  3. package/dist/formats/date.d.mts +45 -0
  4. package/dist/formats/date.mjs +2 -0
  5. package/dist/formats/object.cjs +49 -0
  6. package/dist/formats/object.d.cts +45 -0
  7. package/dist/formats/object.d.mts +45 -0
  8. package/dist/formats/object.mjs +2 -0
  9. package/dist/formats/plain-date-time.cjs +49 -0
  10. package/dist/formats/plain-date-time.d.cts +45 -0
  11. package/dist/formats/plain-date-time.d.mts +45 -0
  12. package/dist/formats/plain-date-time.mjs +2 -0
  13. package/dist/formats/plain-date.cjs +49 -0
  14. package/dist/formats/plain-date.d.cts +45 -0
  15. package/dist/formats/plain-date.d.mts +45 -0
  16. package/dist/formats/plain-date.mjs +2 -0
  17. package/dist/formats/plain-month-day.cjs +49 -0
  18. package/dist/formats/plain-month-day.d.cts +45 -0
  19. package/dist/formats/plain-month-day.d.mts +45 -0
  20. package/dist/formats/plain-month-day.mjs +2 -0
  21. package/dist/formats/plain-year-month.cjs +49 -0
  22. package/dist/formats/plain-year-month.d.cts +45 -0
  23. package/dist/formats/plain-year-month.d.mts +45 -0
  24. package/dist/formats/plain-year-month.mjs +2 -0
  25. package/dist/formats/zoned-date-time.cjs +49 -0
  26. package/dist/formats/zoned-date-time.d.cts +45 -0
  27. package/dist/formats/zoned-date-time.d.mts +45 -0
  28. package/dist/formats/zoned-date-time.mjs +2 -0
  29. package/dist/index.cjs +49 -0
  30. package/dist/index.d.cts +2 -0
  31. package/dist/index.d.mts +2 -0
  32. package/dist/index.mjs +2 -0
  33. package/dist/temporal-polyfill-DTx0VIX5.mjs +4556 -0
  34. package/dist/temporal-polyfill-DU8VfleL.cjs +4860 -0
  35. package/dist/weeks-view-context-BN6qR-83.d.mts +2022 -0
  36. package/dist/weeks-view-context-aHGgYkpt.d.cts +2022 -0
  37. package/package.json +89 -0
  38. package/src/calendar-context.ts +22 -0
  39. package/src/calendar-provider.test.tsx +123 -0
  40. package/src/calendar-provider.tsx +538 -0
  41. package/src/calendar-types.ts +212 -0
  42. package/src/compute-weeks-in-window.test.ts +83 -0
  43. package/src/compute-weeks-in-window.ts +40 -0
  44. package/src/context.ts +34 -0
  45. package/src/day-cell.tsx +635 -0
  46. package/src/drag-handle.tsx +137 -0
  47. package/src/formats/date.ts +110 -0
  48. package/src/formats/formats.test.ts +18 -0
  49. package/src/formats/object.ts +110 -0
  50. package/src/formats/plain-date-time.ts +110 -0
  51. package/src/formats/plain-date.ts +110 -0
  52. package/src/formats/plain-month-day.ts +110 -0
  53. package/src/formats/plain-year-month.ts +110 -0
  54. package/src/formats/zoned-date-time.ts +110 -0
  55. package/src/grid-header.tsx +141 -0
  56. package/src/grid.event-perf.test.tsx +282 -0
  57. package/src/grid.perf.test.tsx +467 -0
  58. package/src/grid.tsx +608 -0
  59. package/src/index.ts +116 -0
  60. package/src/keyboard.test.ts +498 -0
  61. package/src/keyboard.ts +142 -0
  62. package/src/month-separator.test.tsx +183 -0
  63. package/src/month-separator.tsx +238 -0
  64. package/src/month-view-context.ts +26 -0
  65. package/src/month-view-types.ts +89 -0
  66. package/src/month-view.test.tsx +1433 -0
  67. package/src/month-view.tsx +373 -0
  68. package/src/navigation.tsx +350 -0
  69. package/src/overflow.test.ts +124 -0
  70. package/src/overflow.ts +233 -0
  71. package/src/range-preview.tsx +90 -0
  72. package/src/resolve-first-week.test.ts +132 -0
  73. package/src/resolve-first-week.ts +145 -0
  74. package/src/root-selection.ts +621 -0
  75. package/src/selected-range.tsx +163 -0
  76. package/src/temporal-polyfill.test.ts +317 -0
  77. package/src/temporal-polyfill.ts +566 -0
  78. package/src/test-temporal.ts +17 -0
  79. package/src/types.ts +814 -0
  80. package/src/utils.bench.ts +183 -0
  81. package/src/utils.test.ts +983 -0
  82. package/src/utils.ts +493 -0
  83. package/src/view-context.ts +28 -0
  84. package/src/week-number.tsx +118 -0
  85. package/src/weeks-grid.tsx +265 -0
  86. package/src/weeks-keyboard.test.ts +222 -0
  87. package/src/weeks-keyboard.ts +156 -0
  88. package/src/weeks-navigation.tsx +209 -0
  89. package/src/weeks-view-context.ts +26 -0
  90. package/src/weeks-view-state.ts +421 -0
  91. package/src/weeks-view-types.ts +102 -0
  92. package/src/weeks-view.test.tsx +479 -0
  93. package/src/weeks-view.tsx +127 -0
@@ -0,0 +1,102 @@
1
+ import type { Temporal } from "@js-temporal/polyfill";
2
+ import type { WeekDescriptor } from "./compute-weeks-in-window";
3
+ import type { OverflowBehavior } from "./overflow";
4
+ import type { FirstWeekSpec, ScrollToWeekSnap } from "./resolve-first-week";
5
+
6
+ // ---------------------------------------------------------------------------
7
+ // WeeksView.Root props
8
+ // ---------------------------------------------------------------------------
9
+
10
+ /** Props accepted by `WeeksView.Root`. */
11
+ export interface WeeksViewRootProps {
12
+ /** Number of week rows to display simultaneously. */
13
+ weekCount: number;
14
+ /** The controlled first visible week. When provided, the component is controlled. */
15
+ firstWeek?: FirstWeekSpec;
16
+ /** The initial first visible week (uncontrolled). */
17
+ defaultFirstWeek?: FirstWeekSpec;
18
+ /** Called when the first visible week changes via navigation or focus movement. */
19
+ onFirstWeekChange?: (date: Temporal.PlainDate) => void;
20
+ /**
21
+ * How much to scroll per navigation step.
22
+ * - `"row"` — scroll one week row at a time.
23
+ * - `"page"` — scroll a full page (all visible rows) at a time.
24
+ * @default "row"
25
+ */
26
+ scrollBy?: "row" | "page";
27
+ /**
28
+ * How navigation behaves at `min`/`max` bounds.
29
+ * @default "unbounded"
30
+ */
31
+ overflowBehavior?: OverflowBehavior;
32
+ /** Called when the visible window changes. */
33
+ onWindowChange?: (info: WindowInfo) => void;
34
+ /** React children. */
35
+ children?: React.ReactNode;
36
+ }
37
+
38
+ // ---------------------------------------------------------------------------
39
+ // WindowInfo
40
+ // ---------------------------------------------------------------------------
41
+
42
+ /** A month/year pair visible in the weeks window. */
43
+ export interface VisibleMonth {
44
+ month: number;
45
+ year: number;
46
+ }
47
+
48
+ /** Describes the currently visible window of weeks. */
49
+ export interface WindowInfo {
50
+ /** The first date of the visible window. */
51
+ windowStart: Temporal.PlainDate;
52
+ /** The last date of the visible window. */
53
+ windowEnd: Temporal.PlainDate;
54
+ /** Number of week rows in the window (the prop value, not actual when shrunk). */
55
+ weekCount: number;
56
+ /** Total number of calendar days in the window. */
57
+ dayCount: number;
58
+ /** Number of weeks that contain at least one enabled date. */
59
+ enabledWeekCount: number;
60
+ /** Number of enabled (selectable) dates in the window. */
61
+ enabledDayCount: number;
62
+ /** Distinct months visible in the window, in chronological order. */
63
+ visibleMonths: VisibleMonth[];
64
+ }
65
+
66
+ // ---------------------------------------------------------------------------
67
+ // WeeksView context values
68
+ // ---------------------------------------------------------------------------
69
+
70
+ /** Stable values (config + callbacks) provided by `WeeksView.Root`. */
71
+ export interface WeeksViewStableContextValue {
72
+ /** Number of week rows to display (the prop value). */
73
+ weekCount: number;
74
+ /** How much to scroll per navigation step. */
75
+ scrollBy: "row" | "page";
76
+ /** How navigation behaves at bounds. */
77
+ overflowBehavior: OverflowBehavior;
78
+ /** Navigate to the next week(s). Optionally override the shift amount (in weeks). */
79
+ goNext: (shiftBy?: number) => void;
80
+ /** Navigate to the previous week(s). Optionally override the shift amount (in weeks). */
81
+ goPrev: (shiftBy?: number) => void;
82
+ /** Imperatively scroll so that the target week is visible at the given snap position. */
83
+ scrollToWeek: (target: FirstWeekSpec, options?: { snap?: ScrollToWeekSnap }) => void;
84
+ /** Ref tracking whether the grid currently holds DOM focus (avoids state re-renders). */
85
+ gridFocusedRef: React.MutableRefObject<boolean>;
86
+ /** Register (or clear) the id of a label element for `aria-labelledby`. */
87
+ setGridLabelId: (id: string | undefined) => void;
88
+ }
89
+
90
+ /** Volatile state provided by `WeeksView.Root`. */
91
+ export interface WeeksViewStateContextValue {
92
+ /** The logically focused date in the grid. */
93
+ focusedDate: Temporal.PlainDate;
94
+ /** Information about the currently visible window. */
95
+ windowInfo: WindowInfo;
96
+ /** Label element id for `aria-labelledby` on the grid. */
97
+ gridLabelIds: Record<number, string>;
98
+ /** Computed week descriptors for all visible rows. */
99
+ weeks: WeekDescriptor[];
100
+ /** Date-time representing the current moment (for "today" highlighting). */
101
+ currentDateTime: Temporal.PlainDateTime;
102
+ }
@@ -0,0 +1,479 @@
1
+ import { Temporal } from "@js-temporal/polyfill";
2
+ import { render, screen, act, cleanup, within } from "@testing-library/react";
3
+ import { describe, it, expect, vi, afterEach } from "vitest";
4
+ import { Grid, GridBody, WeekTemplate, DayCellTemplate, DayButton } from "./grid";
5
+ import { GridHeader, GridHeaderCell } from "./grid-header";
6
+ import {
7
+ MonthSeparator,
8
+ MonthSeparatorMonth,
9
+ MonthSeparatorYear,
10
+ MonthSeparatorWeekCount,
11
+ } from "./month-separator";
12
+ import { useViewContext } from "./view-context";
13
+ import { NextWeeksButton, PrevWeeksButton } from "./weeks-navigation";
14
+ import { WeeksView } from "./weeks-view";
15
+ import { useWeeksViewState, useWeeksViewStable } from "./weeks-view-context";
16
+
17
+ const T = Temporal;
18
+
19
+ // ---------------------------------------------------------------------------
20
+ // Test helper components
21
+ // ---------------------------------------------------------------------------
22
+
23
+ function WindowDisplay() {
24
+ const state = useWeeksViewState();
25
+ return (
26
+ <div>
27
+ <span data-testid="start">{state.windowInfo.windowStart.toString()}</span>
28
+ <span data-testid="end">{state.windowInfo.windowEnd.toString()}</span>
29
+ <span data-testid="count">{state.windowInfo.weekCount}</span>
30
+ <span data-testid="day-count">{state.windowInfo.dayCount}</span>
31
+ <span data-testid="enabled-week-count">{state.windowInfo.enabledWeekCount}</span>
32
+ <span data-testid="enabled-day-count">{state.windowInfo.enabledDayCount}</span>
33
+ </div>
34
+ );
35
+ }
36
+
37
+ function ViewTypeDisplay() {
38
+ const view = useViewContext();
39
+ return <span data-testid="view-type">{view.viewType}</span>;
40
+ }
41
+
42
+ function FocusDisplay() {
43
+ const view = useViewContext();
44
+ return <span data-testid="focus">{view.focusedDate.toString()}</span>;
45
+ }
46
+
47
+ function NavButtons() {
48
+ const { goNext, goPrev } = useWeeksViewStable();
49
+ return (
50
+ <div>
51
+ <button type="button" onClick={() => goPrev()} data-testid="prev">
52
+ Prev
53
+ </button>
54
+ <button type="button" onClick={() => goNext()} data-testid="next">
55
+ Next
56
+ </button>
57
+ </div>
58
+ );
59
+ }
60
+
61
+ // ---------------------------------------------------------------------------
62
+ // Tests
63
+ // ---------------------------------------------------------------------------
64
+
65
+ afterEach(() => {
66
+ cleanup();
67
+ });
68
+
69
+ describe("WeeksView", () => {
70
+ it("renders 8 weeks starting from firstWeek", () => {
71
+ render(
72
+ <WeeksView temporal={T} weekCount={8} defaultFirstWeek={T.PlainDate.from("2026-03-01")}>
73
+ <WindowDisplay />
74
+ </WeeksView>,
75
+ );
76
+ expect(screen.getByTestId("start").textContent).toBe("2026-03-01");
77
+ expect(screen.getByTestId("end").textContent).toBe("2026-04-25");
78
+ expect(screen.getByTestId("count").textContent).toBe("8");
79
+ expect(screen.getByTestId("day-count").textContent).toBe("56");
80
+ });
81
+
82
+ it("provides viewType=weeks", () => {
83
+ render(
84
+ <WeeksView temporal={T} weekCount={4} defaultFirstWeek={T.PlainDate.from("2026-03-01")}>
85
+ <ViewTypeDisplay />
86
+ </WeeksView>,
87
+ );
88
+ expect(screen.getByTestId("view-type").textContent).toBe("weeks");
89
+ });
90
+
91
+ it("accepts { month, year } as firstWeek", () => {
92
+ render(
93
+ <WeeksView temporal={T} weekCount={4} defaultFirstWeek={{ month: 3, year: 2026 }}>
94
+ <WindowDisplay />
95
+ </WeeksView>,
96
+ );
97
+ expect(screen.getByTestId("start").textContent).toBe("2026-03-01");
98
+ });
99
+
100
+ it("fires onWindowChange on mount", () => {
101
+ const onWindowChange = vi.fn();
102
+ render(
103
+ <WeeksView
104
+ temporal={T}
105
+ weekCount={4}
106
+ defaultFirstWeek={T.PlainDate.from("2026-03-01")}
107
+ onWindowChange={onWindowChange}
108
+ >
109
+ <div />
110
+ </WeeksView>,
111
+ );
112
+ expect(onWindowChange).toHaveBeenCalledTimes(1);
113
+ expect(onWindowChange.mock.calls[0][0].weekCount).toBe(4);
114
+ });
115
+
116
+ it("navigates forward via goNext (buttons always shift by weekCount)", () => {
117
+ render(
118
+ <WeeksView
119
+ temporal={T}
120
+ weekCount={4}
121
+ defaultFirstWeek={T.PlainDate.from("2026-03-01")}
122
+ scrollBy="row"
123
+ >
124
+ <WindowDisplay />
125
+ <NavButtons />
126
+ </WeeksView>,
127
+ );
128
+ expect(screen.getByTestId("start").textContent).toBe("2026-03-01");
129
+
130
+ act(() => {
131
+ screen.getByTestId("next").click();
132
+ });
133
+ // Buttons always shift by weekCount (4), regardless of scrollBy
134
+ expect(screen.getByTestId("start").textContent).toBe("2026-03-29");
135
+ });
136
+
137
+ it("navigates backward via goPrev (buttons always shift by weekCount)", () => {
138
+ render(
139
+ <WeeksView
140
+ temporal={T}
141
+ weekCount={4}
142
+ defaultFirstWeek={T.PlainDate.from("2026-03-29")}
143
+ scrollBy="row"
144
+ >
145
+ <WindowDisplay />
146
+ <NavButtons />
147
+ </WeeksView>,
148
+ );
149
+ act(() => {
150
+ screen.getByTestId("prev").click();
151
+ });
152
+ expect(screen.getByTestId("start").textContent).toBe("2026-03-01");
153
+ });
154
+
155
+ it("navigates by page when scrollBy=page", () => {
156
+ render(
157
+ <WeeksView
158
+ temporal={T}
159
+ weekCount={4}
160
+ defaultFirstWeek={T.PlainDate.from("2026-03-01")}
161
+ scrollBy="page"
162
+ >
163
+ <WindowDisplay />
164
+ <NavButtons />
165
+ </WeeksView>,
166
+ );
167
+ act(() => {
168
+ screen.getByTestId("next").click();
169
+ });
170
+ // scrollBy=page shifts by weekCount (4) weeks = 28 days
171
+ expect(screen.getByTestId("start").textContent).toBe("2026-03-29");
172
+ });
173
+
174
+ it("focuses selected date if visible", () => {
175
+ render(
176
+ <WeeksView
177
+ temporal={T}
178
+ weekCount={8}
179
+ defaultFirstWeek={T.PlainDate.from("2026-03-01")}
180
+ defaultValue={T.PlainDate.from("2026-03-15")}
181
+ >
182
+ <FocusDisplay />
183
+ </WeeksView>,
184
+ );
185
+ expect(screen.getByTestId("focus").textContent).toBe("2026-03-15");
186
+ });
187
+
188
+ it("focuses first day of window when no selection", () => {
189
+ render(
190
+ <WeeksView temporal={T} weekCount={8} defaultFirstWeek={T.PlainDate.from("2026-03-01")}>
191
+ <FocusDisplay />
192
+ </WeeksView>,
193
+ );
194
+ expect(screen.getByTestId("focus").textContent).toBe("2026-03-01");
195
+ });
196
+
197
+ it("snaps firstWeek to the start of the week (Sunday)", () => {
198
+ // 2026-03-04 is a Wednesday; should snap back to 2026-03-01 (Sunday)
199
+ render(
200
+ <WeeksView temporal={T} weekCount={4} defaultFirstWeek={T.PlainDate.from("2026-03-04")}>
201
+ <WindowDisplay />
202
+ </WeeksView>,
203
+ );
204
+ expect(screen.getByTestId("start").textContent).toBe("2026-03-01");
205
+ });
206
+
207
+ it("computes enabledDayCount/enabledWeekCount with isDateDisabled", () => {
208
+ // Disable all Mondays
209
+ const isDateDisabled = (date: Temporal.PlainDate) => date.dayOfWeek === 1; // Monday
210
+
211
+ render(
212
+ <WeeksView
213
+ temporal={T}
214
+ weekCount={1}
215
+ defaultFirstWeek={T.PlainDate.from("2026-03-01")}
216
+ isDateDisabled={isDateDisabled}
217
+ >
218
+ <WindowDisplay />
219
+ </WeeksView>,
220
+ );
221
+ // 1 week = 7 days, 1 Monday disabled => 6 enabled days
222
+ expect(screen.getByTestId("enabled-day-count").textContent).toBe("6");
223
+ expect(screen.getByTestId("enabled-week-count").textContent).toBe("1");
224
+ });
225
+
226
+ it("fires onFirstWeekChange on navigation", () => {
227
+ const onFirstWeekChange = vi.fn();
228
+ render(
229
+ <WeeksView
230
+ temporal={T}
231
+ weekCount={4}
232
+ defaultFirstWeek={T.PlainDate.from("2026-03-01")}
233
+ onFirstWeekChange={onFirstWeekChange}
234
+ >
235
+ <NavButtons />
236
+ </WeeksView>,
237
+ );
238
+ act(() => {
239
+ screen.getByTestId("next").click();
240
+ });
241
+ expect(onFirstWeekChange).toHaveBeenCalledTimes(1);
242
+ // weekCount=4, so shifts by 4 weeks
243
+ expect(onFirstWeekChange.mock.calls[0][0].toString()).toBe("2026-03-29");
244
+ });
245
+
246
+ it("accepts { isoWeek, isoYear } as firstWeek", () => {
247
+ render(
248
+ <WeeksView temporal={T} weekCount={1} defaultFirstWeek={{ isoWeek: 10, isoYear: 2026 }}>
249
+ <WindowDisplay />
250
+ </WeeksView>,
251
+ );
252
+ // ISO week 10 of 2026: Mon 2026-03-02, snapped to Sun 2026-03-01
253
+ expect(screen.getByTestId("start").textContent).toBe("2026-03-01");
254
+ });
255
+
256
+ it("provides weeks data via context", () => {
257
+ function WeeksDataDisplay() {
258
+ const state = useWeeksViewState();
259
+ return <span data-testid="weeks-length">{state.weeks.length}</span>;
260
+ }
261
+
262
+ render(
263
+ <WeeksView temporal={T} weekCount={6} defaultFirstWeek={T.PlainDate.from("2026-03-01")}>
264
+ <WeeksDataDisplay />
265
+ </WeeksView>,
266
+ );
267
+ expect(screen.getByTestId("weeks-length").textContent).toBe("6");
268
+ });
269
+
270
+ it("ensures focusedDate stays in window after navigation", () => {
271
+ render(
272
+ <WeeksView
273
+ temporal={T}
274
+ weekCount={2}
275
+ defaultFirstWeek={T.PlainDate.from("2026-03-01")}
276
+ scrollBy="page"
277
+ >
278
+ <FocusDisplay />
279
+ <NavButtons />
280
+ </WeeksView>,
281
+ );
282
+ expect(screen.getByTestId("focus").textContent).toBe("2026-03-01");
283
+
284
+ act(() => {
285
+ screen.getByTestId("next").click();
286
+ });
287
+ // After navigating 2 weeks forward (page), focused date should be in new window
288
+ expect(screen.getByTestId("focus").textContent).toBe("2026-03-15");
289
+ });
290
+ });
291
+
292
+ // ---------------------------------------------------------------------------
293
+ // Regression tests for fixed bugs
294
+ // ---------------------------------------------------------------------------
295
+
296
+ describe("WeeksView regression: no spurious data-outside-month (Bug #1)", () => {
297
+ it("days within weeks view do not have data-outside-month", () => {
298
+ // Bug: computeDayCellState received { year: 0, month: 0 } as currentDateTime
299
+ // in weeks view, so isCurrentMonth was always false and every day got
300
+ // data-outside-month. Fix passes per-day { year, month }.
301
+ const { container } = render(
302
+ <WeeksView temporal={T} weekCount={4} defaultFirstWeek={T.PlainDate.from("2026-03-01")}>
303
+ <Grid>
304
+ <GridHeader>
305
+ <GridHeaderCell />
306
+ </GridHeader>
307
+ <GridBody>
308
+ <WeekTemplate>
309
+ <DayCellTemplate>
310
+ <DayButton />
311
+ </DayCellTemplate>
312
+ </WeekTemplate>
313
+ </GridBody>
314
+ </Grid>
315
+ </WeeksView>,
316
+ );
317
+
318
+ const cells = container.querySelectorAll("td[role='gridcell']");
319
+ expect(cells.length).toBeGreaterThan(0);
320
+
321
+ const outsideMonthCells = container.querySelectorAll("td[data-outside-month]");
322
+ expect(outsideMonthCells.length).toBe(0);
323
+ });
324
+
325
+ it("days spanning a month boundary still have no data-outside-month", () => {
326
+ // Window: 2026-03-22 through 2026-04-18 (4 weeks crossing March/April)
327
+ const { container } = render(
328
+ <WeeksView temporal={T} weekCount={4} defaultFirstWeek={T.PlainDate.from("2026-03-22")}>
329
+ <Grid>
330
+ <GridBody>
331
+ <WeekTemplate>
332
+ <DayCellTemplate />
333
+ </WeekTemplate>
334
+ </GridBody>
335
+ </Grid>
336
+ </WeeksView>,
337
+ );
338
+
339
+ const outsideMonthCells = container.querySelectorAll("td[data-outside-month]");
340
+ expect(outsideMonthCells.length).toBe(0);
341
+ });
342
+ });
343
+
344
+ describe("WeeksView regression: MonthSeparator renders in context (Bug #2)", () => {
345
+ it("MonthSeparator renders month and year at month boundaries", () => {
346
+ // Window: 2026-03-22 through 2026-04-18 (4 weeks crossing March/April)
347
+ // Should render separators for March and April.
348
+ const { container } = render(
349
+ <WeeksView temporal={T} weekCount={4} defaultFirstWeek={T.PlainDate.from("2026-03-22")}>
350
+ <Grid>
351
+ <GridBody>
352
+ <MonthSeparator>
353
+ <MonthSeparatorMonth /> <MonthSeparatorYear />
354
+ </MonthSeparator>
355
+ <WeekTemplate>
356
+ <DayCellTemplate />
357
+ </WeekTemplate>
358
+ </GridBody>
359
+ </Grid>
360
+ </WeeksView>,
361
+ );
362
+
363
+ const view = within(container);
364
+ // March separator (first visible)
365
+ expect(view.getByText("March")).toBeTruthy();
366
+ // April separator (month boundary)
367
+ expect(view.getByText("April")).toBeTruthy();
368
+ // Year should appear for both
369
+ expect(view.getAllByText("2026").length).toBeGreaterThanOrEqual(2);
370
+ });
371
+
372
+ it("MonthSeparatorWeekCount shows correct counts", () => {
373
+ // Window: 2026-03-22 through 2026-04-18
374
+ // March 22 is a Sunday, so weeks starting: Mar 22, Mar 29, Apr 5, Apr 12
375
+ // March: weeks at index 0 (month=3) and 1 (month=3) -> weeksVisibleAfter=2
376
+ // April: weeks at index 2 (month=4) and 3 (month=4) -> weeksVisibleAfter=2
377
+ const { container } = render(
378
+ <WeeksView temporal={T} weekCount={4} defaultFirstWeek={T.PlainDate.from("2026-03-22")}>
379
+ <Grid>
380
+ <GridBody>
381
+ <MonthSeparator>
382
+ <MonthSeparatorMonth /> <MonthSeparatorWeekCount data-testid="wc" />
383
+ </MonthSeparator>
384
+ <WeekTemplate>
385
+ <DayCellTemplate />
386
+ </WeekTemplate>
387
+ </GridBody>
388
+ </Grid>
389
+ </WeeksView>,
390
+ );
391
+
392
+ // Both separators should show weeksVisibleAfter
393
+ const weekCountSpans = container.querySelectorAll("[data-testid='wc']");
394
+ expect(weekCountSpans.length).toBe(2);
395
+ });
396
+
397
+ it("MonthSeparator does not throw outside WeeksView context", () => {
398
+ // MonthSeparator used outside any context should throw a helpful error
399
+ // (from useMonthSeparatorData)
400
+ expect(() =>
401
+ render(
402
+ <table>
403
+ <tbody>
404
+ <MonthSeparator />
405
+ </tbody>
406
+ </table>,
407
+ ),
408
+ ).toThrow();
409
+ });
410
+ });
411
+
412
+ describe("WeeksView regression: goNext/goPrev shift by weekCount (Bug #3)", () => {
413
+ it("NextWeeksButton shifts by weekCount, not scrollBy", () => {
414
+ // Bug: goNext used shiftAmount (from scrollBy) as default. With
415
+ // scrollBy="row", buttons shifted by 1 week instead of weekCount.
416
+ // Fix: goNext/goPrev default to weekCount.
417
+ render(
418
+ <WeeksView
419
+ temporal={T}
420
+ weekCount={4}
421
+ defaultFirstWeek={T.PlainDate.from("2026-03-01")}
422
+ scrollBy="row"
423
+ >
424
+ <WindowDisplay />
425
+ <NextWeeksButton data-testid="next-btn">Next</NextWeeksButton>
426
+ </WeeksView>,
427
+ );
428
+ expect(screen.getByTestId("start").textContent).toBe("2026-03-01");
429
+
430
+ act(() => {
431
+ screen.getByTestId("next-btn").click();
432
+ });
433
+ // Should shift by weekCount=4, landing on 2026-03-29
434
+ expect(screen.getByTestId("start").textContent).toBe("2026-03-29");
435
+ });
436
+
437
+ it("PrevWeeksButton shifts by weekCount, not scrollBy", () => {
438
+ render(
439
+ <WeeksView
440
+ temporal={T}
441
+ weekCount={4}
442
+ defaultFirstWeek={T.PlainDate.from("2026-03-29")}
443
+ scrollBy="row"
444
+ >
445
+ <WindowDisplay />
446
+ <PrevWeeksButton data-testid="prev-btn">Prev</PrevWeeksButton>
447
+ </WeeksView>,
448
+ );
449
+ expect(screen.getByTestId("start").textContent).toBe("2026-03-29");
450
+
451
+ act(() => {
452
+ screen.getByTestId("prev-btn").click();
453
+ });
454
+ // Should shift by weekCount=4, landing on 2026-03-01
455
+ expect(screen.getByTestId("start").textContent).toBe("2026-03-01");
456
+ });
457
+
458
+ it("NextWeeksButton with explicit shiftBy overrides weekCount", () => {
459
+ render(
460
+ <WeeksView
461
+ temporal={T}
462
+ weekCount={4}
463
+ defaultFirstWeek={T.PlainDate.from("2026-03-01")}
464
+ scrollBy="row"
465
+ >
466
+ <WindowDisplay />
467
+ <NextWeeksButton shiftBy={2} data-testid="next-btn">
468
+ Next
469
+ </NextWeeksButton>
470
+ </WeeksView>,
471
+ );
472
+
473
+ act(() => {
474
+ screen.getByTestId("next-btn").click();
475
+ });
476
+ // Explicit shiftBy=2 should shift by 2 weeks, landing on 2026-03-15
477
+ expect(screen.getByTestId("start").textContent).toBe("2026-03-15");
478
+ });
479
+ });