@klinking/colander 3.1.0-alpha.1 → 3.1.0-alpha.10

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 (98) hide show
  1. package/dist/formats/date.cjs +2 -3
  2. package/dist/formats/date.d.cts +10 -14
  3. package/dist/formats/date.d.mts +10 -14
  4. package/dist/formats/date.mjs +2 -3
  5. package/dist/formats/object.cjs +2 -3
  6. package/dist/formats/object.d.cts +10 -14
  7. package/dist/formats/object.d.mts +10 -14
  8. package/dist/formats/object.mjs +2 -3
  9. package/dist/formats/plain-date-time.cjs +2 -3
  10. package/dist/formats/plain-date-time.d.cts +10 -14
  11. package/dist/formats/plain-date-time.d.mts +10 -14
  12. package/dist/formats/plain-date-time.mjs +2 -3
  13. package/dist/formats/plain-date.cjs +2 -3
  14. package/dist/formats/plain-date.d.cts +10 -14
  15. package/dist/formats/plain-date.d.mts +10 -14
  16. package/dist/formats/plain-date.mjs +2 -3
  17. package/dist/formats/plain-month-day.cjs +2 -3
  18. package/dist/formats/plain-month-day.d.cts +10 -14
  19. package/dist/formats/plain-month-day.d.mts +10 -14
  20. package/dist/formats/plain-month-day.mjs +2 -3
  21. package/dist/formats/plain-year-month.cjs +2 -3
  22. package/dist/formats/plain-year-month.d.cts +10 -14
  23. package/dist/formats/plain-year-month.d.mts +10 -14
  24. package/dist/formats/plain-year-month.mjs +2 -3
  25. package/dist/formats/zoned-date-time.cjs +2 -3
  26. package/dist/formats/zoned-date-time.d.cts +10 -14
  27. package/dist/formats/zoned-date-time.d.mts +10 -14
  28. package/dist/formats/zoned-date-time.mjs +2 -3
  29. package/dist/{weeks-view-context-CNAq2Hiu.d.cts → index-K1_zOIpa.d.mts} +198 -114
  30. package/dist/{weeks-view-context-CsP3PBiu.d.mts → index-bRoYX03d.d.cts} +198 -114
  31. package/dist/index.cjs +1 -1
  32. package/dist/index.d.cts +2 -11
  33. package/dist/index.d.mts +2 -11
  34. package/dist/index.mjs +1 -2
  35. package/dist/{weeks-navigation-CJzhxbgj.cjs → weeks-navigation-3UTRiTUP.cjs} +1102 -952
  36. package/dist/{weeks-navigation-Bg0nZLgh.mjs → weeks-navigation-BoHqK5fq.mjs} +1102 -951
  37. package/package.json +21 -18
  38. package/src/calendar-provider.test.tsx +88 -1
  39. package/src/calendar-provider.tsx +89 -73
  40. package/src/calendar-types.ts +2 -0
  41. package/src/compute-weeks-in-window.test.ts +1 -1
  42. package/src/day-cell-state.test.ts +214 -0
  43. package/src/day-cell-state.ts +244 -0
  44. package/src/day-cell-store.test.tsx +273 -0
  45. package/src/day-cell-store.tsx +204 -0
  46. package/src/day-cell.test.tsx +73 -90
  47. package/src/day-cell.tsx +106 -444
  48. package/src/drag-handle.tsx +2 -2
  49. package/src/formats/date.ts +2 -0
  50. package/src/formats/formats.test.ts +1 -1
  51. package/src/formats/object.ts +2 -0
  52. package/src/formats/plain-date-time.ts +2 -0
  53. package/src/formats/plain-date.ts +2 -0
  54. package/src/formats/plain-month-day.ts +2 -0
  55. package/src/formats/plain-year-month.ts +2 -0
  56. package/src/formats/zoned-date-time.ts +2 -0
  57. package/src/grid-header.tsx +3 -3
  58. package/src/grid.event-perf.test.tsx +7 -1
  59. package/src/grid.perf.test.tsx +7 -1
  60. package/src/grid.tsx +38 -77
  61. package/src/index.ts +2 -0
  62. package/src/keyboard.test.ts +1 -1
  63. package/src/month-separator.test.tsx +1 -1
  64. package/src/month-view-navigation.ts +180 -0
  65. package/src/month-view-types.ts +3 -0
  66. package/src/month-view.bounds.test.tsx +136 -0
  67. package/src/month-view.test.tsx +89 -1
  68. package/src/month-view.tsx +74 -217
  69. package/src/month-window.test.ts +207 -0
  70. package/src/month-window.ts +93 -0
  71. package/src/navigation.tsx +18 -76
  72. package/src/out-of-range.test.ts +34 -54
  73. package/src/out-of-range.ts +47 -123
  74. package/src/range-preview.test.ts +120 -0
  75. package/src/range-preview.tsx +3 -5
  76. package/src/resolve-first-week.test.ts +1 -1
  77. package/src/root-selection.ts +99 -97
  78. package/src/selected-range.tsx +3 -5
  79. package/src/store.ts +72 -0
  80. package/src/today.test.tsx +105 -0
  81. package/src/types.ts +24 -1
  82. package/src/utils.bench.ts +158 -106
  83. package/src/utils.test.ts +26 -1
  84. package/src/utils.ts +40 -9
  85. package/src/view-context.test.tsx +126 -0
  86. package/src/view-context.ts +45 -0
  87. package/src/week-number.test.tsx +76 -0
  88. package/src/week-number.tsx +48 -19
  89. package/src/weeks-grid.tsx +20 -10
  90. package/src/weeks-keyboard.test.ts +1 -1
  91. package/src/weeks-navigation.tsx +15 -31
  92. package/src/weeks-view-state.ts +67 -101
  93. package/src/weeks-view-types.ts +4 -1
  94. package/src/weeks-view.bounds.test.tsx +246 -0
  95. package/src/weeks-view.test.tsx +116 -14
  96. package/src/weeks-view.tsx +24 -52
  97. package/src/weeks-window.test.ts +131 -0
  98. package/src/weeks-window.ts +102 -0
@@ -2,21 +2,26 @@ import type { Temporal } from "@js-temporal/polyfill";
2
2
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
3
  import { useCalendarStable, useCalendarState } from "./calendar-context";
4
4
  import { computeWeeksInWindow } from "./compute-weeks-in-window";
5
- import { applyOutOfRange, type OutOfRangeBehavior } from "./out-of-range";
5
+ import type { OutOfRangeBehavior } from "./out-of-range";
6
6
  import {
7
7
  resolveFirstWeekSpec,
8
8
  resolveFirstWeek,
9
9
  type FirstWeekSpec,
10
10
  } from "./resolve-first-week";
11
11
  import type { RootState } from "./types";
12
- import { selectedToZdt, toZonedDateTime } from "./utils";
13
- import type { ViewContextValue } from "./view-context";
12
+ import { resolveInitialAnchor, selectedToZdt } from "./utils";
13
+ import type {
14
+ ViewContextValue,
15
+ ViewStableContextValue,
16
+ ViewStateContextValue,
17
+ } from "./view-context";
14
18
  import type {
15
19
  WeeksViewRootProps,
16
20
  WeeksViewStableContextValue,
17
21
  WeeksViewStateContextValue,
18
22
  WindowInfo,
19
23
  } from "./weeks-view-types";
24
+ import { createWeekWindowPolicy } from "./weeks-window";
20
25
 
21
26
  /**
22
27
  * Core state management hook for WeeksView.Root.
@@ -42,7 +47,7 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
42
47
  const calState = useCalendarState();
43
48
 
44
49
  const T = calStable.temporal;
45
- const { weekStartDay, isDateDisabled, minValue, maxValue, timeZone } =
50
+ const { weekStartDay, isDateDisabled, minValue, maxValue, timeZone, today } =
46
51
  calStable;
47
52
 
48
53
  // --- Controlled/uncontrolled firstWeek ---
@@ -59,16 +64,9 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
59
64
  if (firstWeekProp !== undefined) return resolveSpec(firstWeekProp);
60
65
  if (defaultFirstWeekProp !== undefined)
61
66
  return resolveSpec(defaultFirstWeekProp);
62
- // Derive from selection or today
63
- if (calState.selected) {
64
- const plain = toZonedDateTime(
65
- calState.selected,
66
- timeZone,
67
- T,
68
- ).toPlainDate();
69
- return resolveSpec(plain);
70
- }
71
- return resolveSpec(T.Now.plainDateISO());
67
+ return resolveSpec(
68
+ resolveInitialAnchor(calState.selected, today, timeZone, T),
69
+ );
72
70
  });
73
71
 
74
72
  const resolvedFirstWeek = isControlled
@@ -82,26 +80,22 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
82
80
  );
83
81
 
84
82
  // --- Apply out-of-range behavior ---
85
- const outOfRangeResult = useMemo(
83
+ const windowPolicy = useMemo(
86
84
  () =>
87
- applyOutOfRange({
88
- targetFirstWeek: resolvedFirstWeek,
85
+ createWeekWindowPolicy({
89
86
  weekCount,
90
87
  behavior: outOfRangeBehavior,
91
- ...(minValue !== undefined && { min: minValue }),
92
- ...(maxValue !== undefined && { max: maxValue }),
88
+ min: minValue,
89
+ max: maxValue,
93
90
  weekStartDay,
94
91
  T,
95
92
  }),
96
- [
97
- resolvedFirstWeek,
98
- weekCount,
99
- outOfRangeBehavior,
100
- minValue,
101
- maxValue,
102
- weekStartDay,
103
- T,
104
- ],
93
+ [weekCount, outOfRangeBehavior, minValue, maxValue, weekStartDay, T],
94
+ );
95
+
96
+ const outOfRangeResult = useMemo(
97
+ () => windowPolicy.resolve(resolvedFirstWeek),
98
+ [windowPolicy, resolvedFirstWeek],
105
99
  );
106
100
 
107
101
  // Recompute weeks if the out-of-range behavior adjusted the window
@@ -141,10 +135,10 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
141
135
  const firstWeek = weeks[0];
142
136
  const lastWeek = weeks[weeks.length - 1];
143
137
  if (firstWeek === undefined || lastWeek === undefined) {
144
- const today = T.Now.plainDateISO();
138
+ const now = today();
145
139
  return {
146
- windowStart: today,
147
- windowEnd: today,
140
+ windowStart: now,
141
+ windowEnd: now,
148
142
  weekCount: 0,
149
143
  dayCount: 0,
150
144
  enabledWeekCount: 0,
@@ -313,58 +307,30 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
313
307
  [isControlled, onFirstWeekChange],
314
308
  );
315
309
 
310
+ // Moves start from the window as shown (post snap/shrink), not the requested
311
+ // first week, so they agree with what the Prev/Next buttons report.
312
+ const shownWindow = useMemo(
313
+ () => ({
314
+ firstWeek: windowInfo.windowStart,
315
+ weekCount: windowInfo.weekCount,
316
+ }),
317
+ [windowInfo.windowStart, windowInfo.weekCount],
318
+ );
319
+
316
320
  const goNext = useCallback(
317
321
  (shiftBy?: number) => {
318
- const shift = shiftBy ?? weekCount;
319
- const target = resolvedFirstWeek.add({ weeks: shift });
320
- const adjusted = applyOutOfRange({
321
- targetFirstWeek: target,
322
- weekCount,
323
- behavior: outOfRangeBehavior,
324
- ...(minValue !== undefined && { min: minValue }),
325
- ...(maxValue !== undefined && { max: maxValue }),
326
- weekStartDay,
327
- T,
328
- });
329
- updateFirstWeek(adjusted.firstWeek);
322
+ const next = windowPolicy.shift(shownWindow, 1, shiftBy);
323
+ if (next) updateFirstWeek(next.firstWeek);
330
324
  },
331
- [
332
- resolvedFirstWeek,
333
- weekCount,
334
- outOfRangeBehavior,
335
- minValue,
336
- maxValue,
337
- weekStartDay,
338
- T,
339
- updateFirstWeek,
340
- ],
325
+ [shownWindow, windowPolicy, updateFirstWeek],
341
326
  );
342
327
 
343
328
  const goPrev = useCallback(
344
329
  (shiftBy?: number) => {
345
- const shift = shiftBy ?? weekCount;
346
- const target = resolvedFirstWeek.subtract({ weeks: shift });
347
- const adjusted = applyOutOfRange({
348
- targetFirstWeek: target,
349
- weekCount,
350
- behavior: outOfRangeBehavior,
351
- ...(minValue !== undefined && { min: minValue }),
352
- ...(maxValue !== undefined && { max: maxValue }),
353
- weekStartDay,
354
- T,
355
- });
356
- updateFirstWeek(adjusted.firstWeek);
330
+ const next = windowPolicy.shift(shownWindow, -1, shiftBy);
331
+ if (next) updateFirstWeek(next.firstWeek);
357
332
  },
358
- [
359
- resolvedFirstWeek,
360
- weekCount,
361
- outOfRangeBehavior,
362
- minValue,
363
- maxValue,
364
- weekStartDay,
365
- T,
366
- updateFirstWeek,
367
- ],
333
+ [shownWindow, windowPolicy, updateFirstWeek],
368
334
  );
369
335
 
370
336
  // --- scrollToWeek ---
@@ -373,35 +339,16 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
373
339
  target: FirstWeekSpec,
374
340
  options?: { snap?: "start" | "center" | "end" | "nearest" },
375
341
  ) => {
376
- const resolvedTarget = resolveSpec(target);
377
- const newFirstWeek = resolveFirstWeek(
378
- resolvedFirstWeek,
342
+ const requested = resolveFirstWeek(
343
+ shownWindow.firstWeek,
379
344
  weekCount,
380
- resolvedTarget,
345
+ resolveSpec(target),
381
346
  options,
382
347
  );
383
- const adjusted = applyOutOfRange({
384
- targetFirstWeek: newFirstWeek,
385
- weekCount,
386
- behavior: outOfRangeBehavior,
387
- ...(minValue !== undefined && { min: minValue }),
388
- ...(maxValue !== undefined && { max: maxValue }),
389
- weekStartDay,
390
- T,
391
- });
392
- updateFirstWeek(adjusted.firstWeek);
348
+ const next = windowPolicy.moveTo(requested);
349
+ if (next) updateFirstWeek(next.firstWeek);
393
350
  },
394
- [
395
- resolvedFirstWeek,
396
- weekCount,
397
- resolveSpec,
398
- outOfRangeBehavior,
399
- minValue,
400
- maxValue,
401
- weekStartDay,
402
- T,
403
- updateFirstWeek,
404
- ],
351
+ [shownWindow, weekCount, resolveSpec, windowPolicy, updateFirstWeek],
405
352
  );
406
353
 
407
354
  // --- Fire onWindowChange ---
@@ -428,6 +375,7 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
428
375
  weekCount,
429
376
  scrollBy,
430
377
  outOfRangeBehavior,
378
+ windowPolicy,
431
379
  goNext,
432
380
  goPrev,
433
381
  scrollToWeek,
@@ -438,6 +386,7 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
438
386
  weekCount,
439
387
  scrollBy,
440
388
  outOfRangeBehavior,
389
+ windowPolicy,
441
390
  goNext,
442
391
  goPrev,
443
392
  scrollToWeek,
@@ -491,5 +440,22 @@ export function useWeeksViewRootState(props: WeeksViewRootProps) {
491
440
  [focusedDate, tabTargetDate, gridHasFocus],
492
441
  );
493
442
 
494
- return { stableCtx, stateCtx, viewCtx, scrollToWeek };
443
+ const viewStableCtx = useMemo<ViewStableContextValue>(
444
+ () => ({ gridFocusedRef, outsideDays: "enabled", setFocusedDate }),
445
+ [],
446
+ );
447
+
448
+ const viewStateCtx = useMemo<ViewStateContextValue>(
449
+ () => ({ currentDateTime, rootState }),
450
+ [currentDateTime, rootState],
451
+ );
452
+
453
+ return {
454
+ stableCtx,
455
+ stateCtx,
456
+ viewCtx,
457
+ viewStableCtx,
458
+ viewStateCtx,
459
+ scrollToWeek,
460
+ };
495
461
  }
@@ -3,6 +3,7 @@ import type { WeekDescriptor } from "./compute-weeks-in-window";
3
3
  import type { OutOfRangeBehavior } from "./out-of-range";
4
4
  import type { FirstWeekSpec, ScrollToWeekSnap } from "./resolve-first-week";
5
5
  import type { RootState } from "./types";
6
+ import type { WeekWindowPolicy } from "./weeks-window";
6
7
 
7
8
  // ---------------------------------------------------------------------------
8
9
  // WeeksView.Root props
@@ -63,7 +64,7 @@ export interface WindowInfo {
63
64
  windowStart: Temporal.PlainDate;
64
65
  /** The last date of the visible window. */
65
66
  windowEnd: Temporal.PlainDate;
66
- /** Number of week rows in the window (the prop value, not actual when shrunk). */
67
+ /** Number of week rows actually shown (fewer than the `weekCount` prop when shrunk). */
67
68
  weekCount: number;
68
69
  /** Total number of calendar days in the window. */
69
70
  dayCount: number;
@@ -87,6 +88,8 @@ export interface WeeksViewStableContextValue {
87
88
  scrollBy: "row" | "page";
88
89
  /** How navigation behaves at bounds. */
89
90
  outOfRangeBehavior: OutOfRangeBehavior;
91
+ /** Where the window may sit given `min`/`max` and `outOfRangeBehavior`. */
92
+ windowPolicy: WeekWindowPolicy;
90
93
  /** Navigate to the next week(s). Optionally override the shift amount (in weeks). */
91
94
  goNext: (shiftBy?: number) => void;
92
95
  /** Navigate to the previous week(s). Optionally override the shift amount (in weeks). */
@@ -0,0 +1,246 @@
1
+ import { Temporal } from "@js-temporal/polyfill";
2
+ import {
3
+ render,
4
+ screen,
5
+ act,
6
+ cleanup,
7
+ fireEvent,
8
+ } from "@testing-library/react";
9
+ import { createRef } from "react";
10
+ import { describe, it, expect, afterEach } from "vite-plus/test";
11
+ import {
12
+ Grid,
13
+ GridBody,
14
+ WeekTemplate,
15
+ DayCellTemplate,
16
+ DayButton,
17
+ } from "./grid";
18
+ import type { OutOfRangeBehavior } from "./out-of-range";
19
+ import { useViewContext } from "./view-context";
20
+ import { NextWeeksButton, PrevWeeksButton } from "./weeks-navigation";
21
+ import { WeeksView, type WeeksViewRootHandle } from "./weeks-view";
22
+ import { useWeeksViewState } from "./weeks-view-context";
23
+
24
+ const T = Temporal;
25
+ const pd = (s: string) => T.PlainDate.from(s);
26
+
27
+ function WindowDisplay() {
28
+ const { windowInfo } = useWeeksViewState();
29
+ return (
30
+ <div>
31
+ <span data-testid="start">{windowInfo.windowStart.toString()}</span>
32
+ <span data-testid="count">{windowInfo.weekCount}</span>
33
+ </div>
34
+ );
35
+ }
36
+
37
+ function FocusDisplay() {
38
+ return (
39
+ <span data-testid="focus">{useViewContext().focusedDate.toString()}</span>
40
+ );
41
+ }
42
+
43
+ interface Setup {
44
+ behavior: OutOfRangeBehavior;
45
+ weekCount: number;
46
+ firstWeek: string;
47
+ min?: string;
48
+ max?: string;
49
+ value?: string;
50
+ handle?: React.RefObject<WeeksViewRootHandle | null>;
51
+ }
52
+
53
+ function renderWindow({
54
+ behavior,
55
+ weekCount,
56
+ firstWeek,
57
+ min,
58
+ max,
59
+ value,
60
+ handle,
61
+ }: Setup) {
62
+ return render(
63
+ <WeeksView
64
+ ref={handle}
65
+ temporal={T}
66
+ weekCount={weekCount}
67
+ defaultFirstWeek={pd(firstWeek)}
68
+ outOfRangeBehavior={behavior}
69
+ {...(min && { min: pd(min) })}
70
+ {...(max && { max: pd(max) })}
71
+ {...(value && { defaultValue: pd(value) })}
72
+ >
73
+ <FocusDisplay />
74
+ <WindowDisplay />
75
+ <PrevWeeksButton data-testid="prev" />
76
+ <NextWeeksButton data-testid="next" />
77
+ <Grid>
78
+ <GridBody>
79
+ <WeekTemplate>
80
+ <DayCellTemplate>
81
+ <DayButton />
82
+ </DayCellTemplate>
83
+ </WeekTemplate>
84
+ </GridBody>
85
+ </Grid>
86
+ </WeeksView>,
87
+ );
88
+ }
89
+
90
+ const start = () => screen.getByTestId("start").textContent;
91
+ const click = (id: string) =>
92
+ act(() => {
93
+ screen.getByTestId(id).click();
94
+ });
95
+
96
+ afterEach(cleanup);
97
+
98
+ describe("WeeksView window bounds: stop holds for every way of moving", () => {
99
+ it.each([
100
+ {
101
+ description: "scrollToWeek refuses to leave the bound under stop",
102
+ behavior: "stop" as const,
103
+ expected: { start: "2026-03-01" },
104
+ },
105
+ {
106
+ description: "scrollToWeek refuses to leave the bound under stop-shrink",
107
+ behavior: "stop-shrink" as const,
108
+ expected: { start: "2026-03-01" },
109
+ },
110
+ ])("$description", ({ behavior, expected }) => {
111
+ const handle = createRef<WeeksViewRootHandle>();
112
+ renderWindow({
113
+ behavior,
114
+ weekCount: 2,
115
+ firstWeek: "2026-03-01",
116
+ min: "2026-03-01",
117
+ max: "2026-03-14",
118
+ handle,
119
+ });
120
+
121
+ act(() => handle.current?.scrollToWeek(pd("2026-06-07")));
122
+
123
+ expect(start()).toBe(expected.start);
124
+ });
125
+
126
+ it("scrollToWeek still moves when the target window keeps an in-range day", () => {
127
+ const handle = createRef<WeeksViewRootHandle>();
128
+ renderWindow({
129
+ behavior: "stop",
130
+ weekCount: 2,
131
+ firstWeek: "2026-03-01",
132
+ min: "2026-03-01",
133
+ max: "2026-03-21",
134
+ handle,
135
+ });
136
+
137
+ act(() => handle.current?.scrollToWeek(pd("2026-03-08")));
138
+
139
+ expect(start()).toBe("2026-03-08");
140
+ });
141
+ });
142
+
143
+ describe("WeeksView window bounds: a single bound is honored", () => {
144
+ it.each([
145
+ {
146
+ description: "min only, stop: Prev cannot page before min",
147
+ behavior: "stop" as const,
148
+ bounds: { min: "2026-03-01" },
149
+ button: "prev",
150
+ expected: { start: "2026-03-01", disabled: true },
151
+ },
152
+ {
153
+ description: "max only, stop: Next cannot page past max",
154
+ behavior: "stop" as const,
155
+ bounds: { max: "2026-03-14" },
156
+ button: "next",
157
+ expected: { start: "2026-03-01", disabled: true },
158
+ },
159
+ {
160
+ description: "max only, snap: Next snaps back instead of overshooting",
161
+ behavior: "snap" as const,
162
+ bounds: { max: "2026-03-14" },
163
+ button: "next",
164
+ expected: { start: "2026-03-01", disabled: true },
165
+ },
166
+ ])("$description", ({ behavior, bounds, button, expected }) => {
167
+ renderWindow({
168
+ behavior,
169
+ weekCount: 2,
170
+ firstWeek: "2026-03-01",
171
+ ...bounds,
172
+ });
173
+
174
+ expect((screen.getByTestId(button) as HTMLButtonElement).disabled).toBe(
175
+ expected.disabled,
176
+ );
177
+ click(button);
178
+ expect(start()).toBe(expected.start);
179
+ });
180
+ });
181
+
182
+ describe("WeeksView window bounds: a shrunk window pages by the rows it shows", () => {
183
+ // 4-row prop, but max 03-14 trims the window to the 2 rows 03-01..03-14.
184
+ const shrunk = {
185
+ behavior: "stop-shrink" as const,
186
+ weekCount: 4,
187
+ firstWeek: "2026-03-01",
188
+ min: "2026-01-01",
189
+ max: "2026-03-14",
190
+ };
191
+
192
+ it("Prev shifts by the shown row count", () => {
193
+ renderWindow(shrunk);
194
+ expect(screen.getByTestId("count").textContent).toBe("2");
195
+
196
+ click("prev");
197
+
198
+ expect(start()).toBe("2026-02-15");
199
+ });
200
+
201
+ it("PageUp moves focus by the shown row count", () => {
202
+ renderWindow({ ...shrunk, value: "2026-03-08" });
203
+
204
+ fireEvent.keyDown(screen.getByRole("grid"), { key: "PageUp" });
205
+
206
+ expect(screen.getByTestId("focus").textContent).toBe("2026-02-22");
207
+ });
208
+ });
209
+
210
+ describe("WeeksView window bounds: End stays inside a trimmed window", () => {
211
+ it("End focuses the last shown day after leading rows are trimmed", () => {
212
+ // min trims 02-15 and 02-22, leaving the 2 rows 03-01..03-14.
213
+ renderWindow({
214
+ behavior: "stop-shrink",
215
+ weekCount: 4,
216
+ firstWeek: "2026-02-15",
217
+ min: "2026-03-01",
218
+ value: "2026-03-01",
219
+ });
220
+ expect(screen.getByTestId("count").textContent).toBe("2");
221
+
222
+ fireEvent.keyDown(screen.getByRole("grid"), { key: "End" });
223
+
224
+ expect(screen.getByTestId("focus").textContent).toBe("2026-03-14");
225
+ });
226
+ });
227
+
228
+ describe("WeeksView window bounds: buttons act on the window that is shown", () => {
229
+ it("Prev from an over-shoot initial window moves from the snapped window", () => {
230
+ // 03-22 overshoots max, so the shown window is the snapped 03-01 one.
231
+ renderWindow({
232
+ behavior: "snap",
233
+ weekCount: 2,
234
+ firstWeek: "2026-03-22",
235
+ max: "2026-03-14",
236
+ });
237
+ expect(start()).toBe("2026-03-01");
238
+ expect((screen.getByTestId("prev") as HTMLButtonElement).disabled).toBe(
239
+ false,
240
+ );
241
+
242
+ click("prev");
243
+
244
+ expect(start()).toBe("2026-02-15");
245
+ });
246
+ });