@klinking/colander 3.1.0-alpha.6 → 3.1.0-alpha.8
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 +2 -3
- package/dist/formats/date.d.cts +10 -14
- package/dist/formats/date.d.mts +10 -14
- package/dist/formats/date.mjs +2 -3
- package/dist/formats/object.cjs +2 -3
- package/dist/formats/object.d.cts +10 -14
- package/dist/formats/object.d.mts +10 -14
- package/dist/formats/object.mjs +2 -3
- package/dist/formats/plain-date-time.cjs +2 -3
- package/dist/formats/plain-date-time.d.cts +10 -14
- package/dist/formats/plain-date-time.d.mts +10 -14
- package/dist/formats/plain-date-time.mjs +2 -3
- package/dist/formats/plain-date.cjs +2 -3
- package/dist/formats/plain-date.d.cts +10 -14
- package/dist/formats/plain-date.d.mts +10 -14
- package/dist/formats/plain-date.mjs +2 -3
- package/dist/formats/plain-month-day.cjs +2 -3
- package/dist/formats/plain-month-day.d.cts +10 -14
- package/dist/formats/plain-month-day.d.mts +10 -14
- package/dist/formats/plain-month-day.mjs +2 -3
- package/dist/formats/plain-year-month.cjs +2 -3
- package/dist/formats/plain-year-month.d.cts +10 -14
- package/dist/formats/plain-year-month.d.mts +10 -14
- package/dist/formats/plain-year-month.mjs +2 -3
- package/dist/formats/zoned-date-time.cjs +2 -3
- package/dist/formats/zoned-date-time.d.cts +10 -14
- package/dist/formats/zoned-date-time.d.mts +10 -14
- package/dist/formats/zoned-date-time.mjs +2 -3
- package/dist/{index-DnFCKyyw.d.cts → index-BqzrxYgn.d.cts} +106 -116
- package/dist/{index-q3cQKJdA.d.mts → index-CkhYFmf4.d.mts} +106 -116
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -2
- package/dist/{weeks-navigation-Dn3UtG76.mjs → weeks-navigation-BWB5OvqW.mjs} +151 -188
- package/dist/{weeks-navigation-SuKJZJCM.cjs → weeks-navigation-CatYJIKb.cjs} +153 -191
- package/package.json +17 -18
- package/src/calendar-provider.test.tsx +1 -1
- package/src/compute-weeks-in-window.test.ts +1 -1
- package/src/day-cell-state.test.ts +1 -1
- package/src/day-cell.test.tsx +1 -1
- package/src/formats/formats.test.ts +1 -1
- package/src/grid.event-perf.test.tsx +7 -1
- package/src/grid.perf.test.tsx +7 -1
- package/src/grid.tsx +1 -1
- package/src/keyboard.test.ts +1 -1
- package/src/month-separator.test.tsx +1 -1
- package/src/month-view.bounds.test.tsx +1 -1
- package/src/month-view.test.tsx +89 -1
- package/src/month-view.tsx +14 -5
- package/src/month-window.test.ts +1 -1
- package/src/out-of-range.test.ts +34 -54
- package/src/out-of-range.ts +47 -123
- package/src/range-preview.test.ts +1 -1
- package/src/resolve-first-week.test.ts +1 -1
- package/src/today.test.tsx +8 -1
- package/src/utils.bench.ts +158 -106
- package/src/utils.test.ts +1 -1
- package/src/view-context.test.tsx +1 -1
- package/src/weeks-keyboard.test.ts +1 -1
- package/src/weeks-navigation.tsx +15 -6
- package/src/weeks-view-state.ts +21 -12
- package/src/weeks-view.bounds.test.tsx +246 -0
- package/src/weeks-view.test.tsx +1 -1
- package/src/weeks-window.test.ts +110 -22
- package/src/weeks-window.ts +57 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@klinking/colander",
|
|
3
|
-
"version": "3.1.0-alpha.
|
|
3
|
+
"version": "3.1.0-alpha.8",
|
|
4
4
|
"homepage": "https://github.com/klink-ing/colander#readme",
|
|
5
5
|
"bugs": "https://github.com/klink-ing/colander/issues",
|
|
6
6
|
"license": "MIT",
|
|
@@ -127,24 +127,23 @@
|
|
|
127
127
|
}
|
|
128
128
|
},
|
|
129
129
|
"devDependencies": {
|
|
130
|
-
"@base-ui/react": "^1.
|
|
130
|
+
"@base-ui/react": "^1.9.0",
|
|
131
131
|
"@js-temporal/polyfill": "^0.5.1",
|
|
132
|
-
"@playwright/test": "^1.
|
|
133
|
-
"@testing-library/dom": "^10.4.
|
|
134
|
-
"@testing-library/react": "^16.3.
|
|
135
|
-
"@types/react": "^19.
|
|
136
|
-
"@types/react-dom": "^19.
|
|
137
|
-
"@vitejs/plugin-react": "^
|
|
138
|
-
"jsdom": "^
|
|
139
|
-
"
|
|
140
|
-
"react": "^19.
|
|
141
|
-
"
|
|
142
|
-
"
|
|
143
|
-
"tsx": "^4.
|
|
144
|
-
"typescript": "^
|
|
145
|
-
"vite": "npm:@voidzero-dev/vite-plus-core
|
|
146
|
-
"vite-plus": "
|
|
147
|
-
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
|
|
132
|
+
"@playwright/test": "^1.65.2",
|
|
133
|
+
"@testing-library/dom": "^10.4.2",
|
|
134
|
+
"@testing-library/react": "^16.3.3",
|
|
135
|
+
"@types/react": "^19.3.3",
|
|
136
|
+
"@types/react-dom": "^19.3.0",
|
|
137
|
+
"@vitejs/plugin-react": "^6.3.0",
|
|
138
|
+
"jsdom": "^31.0.1",
|
|
139
|
+
"react": "^19.3.1",
|
|
140
|
+
"react-dom": "^19.3.1",
|
|
141
|
+
"rollup-plugin-visualizer": "^7.3.0",
|
|
142
|
+
"ts-morph": "^28.0.0",
|
|
143
|
+
"tsx": "^4.23.15",
|
|
144
|
+
"typescript": "^7.0.2",
|
|
145
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@8.3.8001",
|
|
146
|
+
"vite-plus": "1.8.0"
|
|
148
147
|
},
|
|
149
148
|
"peerDependencies": {
|
|
150
149
|
"@base-ui/react": ">=1.0.0",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { render, act, cleanup } from "@testing-library/react";
|
|
3
3
|
import type { ComponentProps } from "react";
|
|
4
|
-
import { describe, it, expect, vi, afterEach } from "
|
|
4
|
+
import { describe, it, expect, vi, afterEach } from "vite-plus/test";
|
|
5
5
|
import { useCalendarStable, useCalendarState } from "./calendar-context";
|
|
6
6
|
import { CalendarProvider } from "./calendar-provider";
|
|
7
7
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
-
import { describe, expect, it } from "
|
|
2
|
+
import { describe, expect, it } from "vite-plus/test";
|
|
3
3
|
import { computeDayCellState, dayCellStateEqual } from "./day-cell-state";
|
|
4
4
|
import type { DayCellInputs } from "./day-cell-state";
|
|
5
5
|
import type { OutsideDays } from "./types";
|
package/src/day-cell.test.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="vite/client" />
|
|
2
2
|
import * as root from "@klinking/colander";
|
|
3
|
-
import { describe, it, expect } from "
|
|
3
|
+
import { describe, it, expect } from "vite-plus/test";
|
|
4
4
|
|
|
5
5
|
const formatModules = import.meta.glob<Record<string, unknown>>(
|
|
6
6
|
["./*.ts", "!./*.test.ts"],
|
|
@@ -2,7 +2,13 @@ import { Temporal } from "@js-temporal/polyfill";
|
|
|
2
2
|
import { render, act, fireEvent } from "@testing-library/react";
|
|
3
3
|
import { Profiler, type ProfilerOnRenderCallback } from "react";
|
|
4
4
|
// @vitest-environment jsdom
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
describe,
|
|
7
|
+
it,
|
|
8
|
+
expect,
|
|
9
|
+
beforeAll,
|
|
10
|
+
type TestOptions,
|
|
11
|
+
} from "vite-plus/test";
|
|
6
12
|
|
|
7
13
|
const perfOptions: TestOptions = { retry: 3 };
|
|
8
14
|
import { Grid } from "./grid";
|
package/src/grid.perf.test.tsx
CHANGED
|
@@ -2,7 +2,13 @@ import { Temporal } from "@js-temporal/polyfill";
|
|
|
2
2
|
import { render } from "@testing-library/react";
|
|
3
3
|
import { Profiler, type ProfilerOnRenderCallback } from "react";
|
|
4
4
|
// @vitest-environment jsdom
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
describe,
|
|
7
|
+
it,
|
|
8
|
+
expect,
|
|
9
|
+
beforeAll,
|
|
10
|
+
type TestOptions,
|
|
11
|
+
} from "vite-plus/test";
|
|
6
12
|
|
|
7
13
|
const perfOptions: TestOptions = { retry: 3 };
|
|
8
14
|
import { WeekDataContext } from "./context";
|
package/src/grid.tsx
CHANGED
|
@@ -109,7 +109,7 @@ function useWeeksGridKeyboard() {
|
|
|
109
109
|
shiftKey: e.shiftKey,
|
|
110
110
|
focusedDate,
|
|
111
111
|
windowStart: weeksState.windowInfo.windowStart,
|
|
112
|
-
weekCount:
|
|
112
|
+
weekCount: weeksState.windowInfo.weekCount,
|
|
113
113
|
minValue,
|
|
114
114
|
maxValue,
|
|
115
115
|
disabled,
|
package/src/keyboard.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, it, expect } from "
|
|
1
|
+
import { describe, it, expect } from "vite-plus/test";
|
|
2
2
|
import { computeNextFocusDate, computeMonthJumpTarget } from "./keyboard";
|
|
3
3
|
import type { KeyboardNavInput } from "./keyboard";
|
|
4
4
|
import { temporalVariants } from "./test-temporal";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { act, cleanup, render, screen } from "@testing-library/react";
|
|
3
|
-
import { afterEach, describe, expect, it, vi } from "
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from "vite-plus/test";
|
|
4
4
|
import { MonthView } from "./month-view";
|
|
5
5
|
import type { MonthViewProps } from "./month-view";
|
|
6
6
|
import { useMonthViewStable, useMonthViewState } from "./month-view-context";
|
package/src/month-view.test.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import { Temporal } from "@js-temporal/polyfill";
|
|
|
2
2
|
import { render, act } from "@testing-library/react";
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
// @vitest-environment jsdom
|
|
5
|
-
import { describe, it, expect, vi } from "
|
|
5
|
+
import { describe, it, expect, vi } from "vite-plus/test";
|
|
6
6
|
import { useCalendarStable } from "./calendar-context";
|
|
7
7
|
import { Grid } from "./grid";
|
|
8
8
|
import { MonthView } from "./month-view";
|
|
@@ -2092,3 +2092,91 @@ describe("outsideDays", () => {
|
|
|
2092
2092
|
});
|
|
2093
2093
|
});
|
|
2094
2094
|
});
|
|
2095
|
+
|
|
2096
|
+
describe("opening month", () => {
|
|
2097
|
+
// 2020 dates keep the real today out of every window under test.
|
|
2098
|
+
const ym = (s: string) => Temporal.PlainYearMonth.from(s);
|
|
2099
|
+
const day = (s: string) => Temporal.PlainDate.from(s);
|
|
2100
|
+
|
|
2101
|
+
it.each([
|
|
2102
|
+
{
|
|
2103
|
+
description: "defaultMonth opens on that month, not today's",
|
|
2104
|
+
props: { defaultMonth: ym("2020-03") },
|
|
2105
|
+
keys: [],
|
|
2106
|
+
expected: { months: ["2020-03"], focused: "2020-03-01", monthChanges: 0 },
|
|
2107
|
+
},
|
|
2108
|
+
{
|
|
2109
|
+
description: "defaultMonth opens on that month in range mode",
|
|
2110
|
+
props: { selectionMode: "range", defaultMonth: ym("2020-03") },
|
|
2111
|
+
keys: [],
|
|
2112
|
+
expected: { months: ["2020-03"], focused: "2020-03-01", monthChanges: 0 },
|
|
2113
|
+
},
|
|
2114
|
+
{
|
|
2115
|
+
description: "defaultMonth wins over a defaultValue outside it",
|
|
2116
|
+
props: { defaultMonth: ym("2020-03"), defaultValue: day("2020-05-15") },
|
|
2117
|
+
keys: [],
|
|
2118
|
+
expected: { months: ["2020-03"], focused: "2020-03-01", monthChanges: 0 },
|
|
2119
|
+
},
|
|
2120
|
+
{
|
|
2121
|
+
description: "a defaultValue inside a multi-month window keeps focus",
|
|
2122
|
+
props: {
|
|
2123
|
+
defaultMonth: ym("2020-03"),
|
|
2124
|
+
defaultValue: day("2020-04-15"),
|
|
2125
|
+
numberOfMonths: 2,
|
|
2126
|
+
},
|
|
2127
|
+
keys: [],
|
|
2128
|
+
expected: {
|
|
2129
|
+
months: ["2020-03", "2020-04"],
|
|
2130
|
+
focused: "2020-04-15",
|
|
2131
|
+
monthChanges: 0,
|
|
2132
|
+
},
|
|
2133
|
+
},
|
|
2134
|
+
{
|
|
2135
|
+
description: "the first arrow key after defaultMonth moves within it",
|
|
2136
|
+
props: { defaultMonth: ym("2020-03") },
|
|
2137
|
+
keys: ["ArrowRight"],
|
|
2138
|
+
expected: { months: ["2020-03"], focused: "2020-03-02", monthChanges: 0 },
|
|
2139
|
+
},
|
|
2140
|
+
{
|
|
2141
|
+
description: "the first arrow key in a controlled month moves within it",
|
|
2142
|
+
props: { month: ym("2020-03") },
|
|
2143
|
+
keys: ["ArrowRight"],
|
|
2144
|
+
expected: { months: ["2020-03"], focused: "2020-03-02", monthChanges: 0 },
|
|
2145
|
+
},
|
|
2146
|
+
])("$description", ({ props, keys, expected }) => {
|
|
2147
|
+
const onMonthChange = vi.fn();
|
|
2148
|
+
let captured: { months: string[]; focused: string } | undefined;
|
|
2149
|
+
const { container } = render(
|
|
2150
|
+
<MonthView
|
|
2151
|
+
{...defaultProps}
|
|
2152
|
+
{...(props as object)}
|
|
2153
|
+
onMonthChange={onMonthChange}
|
|
2154
|
+
>
|
|
2155
|
+
<Grid />
|
|
2156
|
+
<MonthDataCapture
|
|
2157
|
+
onCapture={(d) => {
|
|
2158
|
+
captured = {
|
|
2159
|
+
months: d.allMonths.map((m) =>
|
|
2160
|
+
Temporal.PlainYearMonth.from(m).toString(),
|
|
2161
|
+
),
|
|
2162
|
+
focused: d.focusedDate,
|
|
2163
|
+
};
|
|
2164
|
+
}}
|
|
2165
|
+
/>
|
|
2166
|
+
</MonthView>,
|
|
2167
|
+
);
|
|
2168
|
+
const grid = container.querySelector('[role="grid"]')!;
|
|
2169
|
+
for (const key of keys) {
|
|
2170
|
+
act(() => {
|
|
2171
|
+
grid.dispatchEvent(
|
|
2172
|
+
new KeyboardEvent("keydown", { key, bubbles: true }),
|
|
2173
|
+
);
|
|
2174
|
+
});
|
|
2175
|
+
}
|
|
2176
|
+
|
|
2177
|
+
expect({
|
|
2178
|
+
...captured,
|
|
2179
|
+
monthChanges: onMonthChange.mock.calls.length,
|
|
2180
|
+
}).toEqual(expected);
|
|
2181
|
+
});
|
|
2182
|
+
});
|
package/src/month-view.tsx
CHANGED
|
@@ -58,11 +58,6 @@ function MonthViewRoot(props: MonthViewRootProps) {
|
|
|
58
58
|
const T = calStable.temporal;
|
|
59
59
|
const { timeZone, today, weekStartDay, isDateDisabled } = calStable;
|
|
60
60
|
|
|
61
|
-
// --- Focus state ---
|
|
62
|
-
const [focusedDate, setFocusedDate] = useState<Temporal.PlainDate>(() =>
|
|
63
|
-
resolveInitialAnchor(calState.selected, today, timeZone, T),
|
|
64
|
-
);
|
|
65
|
-
|
|
66
61
|
const [gridHasFocus, setGridHasFocus] = useState(false);
|
|
67
62
|
const gridFocusedRef = useRef(false);
|
|
68
63
|
|
|
@@ -80,6 +75,20 @@ function MonthViewRoot(props: MonthViewRootProps) {
|
|
|
80
75
|
[numberOfMonths, outOfRangeBehavior, minValue, maxValue, T],
|
|
81
76
|
);
|
|
82
77
|
|
|
78
|
+
// --- Focus state ---
|
|
79
|
+
// Focus starts inside the window the view opens on. Arrow keys move from
|
|
80
|
+
// the focused date, so focus outside the window would pull the view to it.
|
|
81
|
+
const [focusedDate, setFocusedDate] = useState<Temporal.PlainDate>(() => {
|
|
82
|
+
const anchor = resolveInitialAnchor(calState.selected, today, timeZone, T);
|
|
83
|
+
const opening = monthProp ?? defaultMonthProp;
|
|
84
|
+
if (!opening || windowPolicy.isVisible(opening, anchor)) return anchor;
|
|
85
|
+
return T.PlainDate.from({
|
|
86
|
+
year: opening.year,
|
|
87
|
+
month: opening.month,
|
|
88
|
+
day: 1,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
83
92
|
const initialAnchor = useCallback(
|
|
84
93
|
() => resolveInitialAnchor(calState.selected, today, timeZone, T),
|
|
85
94
|
[calState.selected, today, timeZone, T],
|
package/src/month-window.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
-
import { describe, expect, it } from "
|
|
2
|
+
import { describe, expect, it } from "vite-plus/test";
|
|
3
3
|
import { createMonthWindowPolicy } from "./month-window";
|
|
4
4
|
import type { MonthWindowPolicyInput } from "./month-window";
|
|
5
5
|
|
package/src/out-of-range.test.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
-
import { describe, it, expect } from "
|
|
3
|
-
import {
|
|
4
|
-
applyOutOfRange,
|
|
5
|
-
canShift,
|
|
6
|
-
type OutOfRangeBehavior,
|
|
7
|
-
} from "./out-of-range";
|
|
2
|
+
import { describe, it, expect } from "vite-plus/test";
|
|
3
|
+
import { applyOutOfRange, type OutOfRangeBehavior } from "./out-of-range";
|
|
8
4
|
|
|
9
5
|
const T = Temporal;
|
|
10
6
|
const pd = (s: string) => T.PlainDate.from(s);
|
|
@@ -19,7 +15,7 @@ describe("applyOutOfRange", () => {
|
|
|
19
15
|
targetFirstWeek: pd("2026-02-01"),
|
|
20
16
|
weekCount: 8,
|
|
21
17
|
behavior: "unbounded" as OutOfRangeBehavior,
|
|
22
|
-
useMinMax:
|
|
18
|
+
useMinMax: "both" as const,
|
|
23
19
|
expected: { firstWeek: "2026-02-01", weekCount: 8 },
|
|
24
20
|
},
|
|
25
21
|
{
|
|
@@ -27,7 +23,7 @@ describe("applyOutOfRange", () => {
|
|
|
27
23
|
targetFirstWeek: pd("2025-12-07"),
|
|
28
24
|
weekCount: 8,
|
|
29
25
|
behavior: "stop" as OutOfRangeBehavior,
|
|
30
|
-
useMinMax:
|
|
26
|
+
useMinMax: "both" as const,
|
|
31
27
|
expected: { firstWeek: "2025-12-07", weekCount: 8 },
|
|
32
28
|
},
|
|
33
29
|
{
|
|
@@ -35,7 +31,7 @@ describe("applyOutOfRange", () => {
|
|
|
35
31
|
targetFirstWeek: pd("2026-01-11"),
|
|
36
32
|
weekCount: 8,
|
|
37
33
|
behavior: "snap" as OutOfRangeBehavior,
|
|
38
|
-
useMinMax:
|
|
34
|
+
useMinMax: "both" as const,
|
|
39
35
|
expected: {
|
|
40
36
|
firstWeek: "2025-11-16",
|
|
41
37
|
weekCount: 8,
|
|
@@ -46,7 +42,7 @@ describe("applyOutOfRange", () => {
|
|
|
46
42
|
targetFirstWeek: pd("2026-01-11"),
|
|
47
43
|
weekCount: 8,
|
|
48
44
|
behavior: "snap-shrink" as OutOfRangeBehavior,
|
|
49
|
-
useMinMax:
|
|
45
|
+
useMinMax: "both" as const,
|
|
50
46
|
expected: {
|
|
51
47
|
firstWeek: "2025-11-30",
|
|
52
48
|
weekCount: 6,
|
|
@@ -57,18 +53,42 @@ describe("applyOutOfRange", () => {
|
|
|
57
53
|
targetFirstWeek: pd("2025-12-07"),
|
|
58
54
|
weekCount: 8,
|
|
59
55
|
behavior: "stop-shrink" as OutOfRangeBehavior,
|
|
60
|
-
useMinMax:
|
|
56
|
+
useMinMax: "both" as const,
|
|
61
57
|
expected: {
|
|
62
58
|
firstWeek: "2025-12-07",
|
|
63
59
|
weekCount: 5,
|
|
64
60
|
},
|
|
65
61
|
},
|
|
62
|
+
{
|
|
63
|
+
description: "max only, snap — pulls back when target overshoots max",
|
|
64
|
+
targetFirstWeek: pd("2026-01-11"),
|
|
65
|
+
weekCount: 8,
|
|
66
|
+
behavior: "snap" as OutOfRangeBehavior,
|
|
67
|
+
useMinMax: "max" as const,
|
|
68
|
+
expected: { firstWeek: "2025-11-16", weekCount: 8 },
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
description: "min only, snap — pulls forward when target undershoots min",
|
|
72
|
+
targetFirstWeek: pd("2025-10-01"),
|
|
73
|
+
weekCount: 8,
|
|
74
|
+
behavior: "snap" as OutOfRangeBehavior,
|
|
75
|
+
useMinMax: "min" as const,
|
|
76
|
+
expected: { firstWeek: "2025-11-30", weekCount: 8 },
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
description: "min only, stop-shrink — trims leading disabled rows",
|
|
80
|
+
targetFirstWeek: pd("2025-11-16"),
|
|
81
|
+
weekCount: 8,
|
|
82
|
+
behavior: "stop-shrink" as OutOfRangeBehavior,
|
|
83
|
+
useMinMax: "min" as const,
|
|
84
|
+
expected: { firstWeek: "2025-11-30", weekCount: 6 },
|
|
85
|
+
},
|
|
66
86
|
{
|
|
67
87
|
description: "no min/max — all modes behave as unbounded",
|
|
68
88
|
targetFirstWeek: pd("2026-06-01"),
|
|
69
89
|
weekCount: 8,
|
|
70
90
|
behavior: "snap" as OutOfRangeBehavior,
|
|
71
|
-
useMinMax:
|
|
91
|
+
useMinMax: "none" as const,
|
|
72
92
|
expected: { firstWeek: "2026-06-01", weekCount: 8 },
|
|
73
93
|
},
|
|
74
94
|
])(
|
|
@@ -78,7 +98,8 @@ describe("applyOutOfRange", () => {
|
|
|
78
98
|
targetFirstWeek,
|
|
79
99
|
weekCount,
|
|
80
100
|
behavior,
|
|
81
|
-
...(useMinMax && { min
|
|
101
|
+
...((useMinMax === "both" || useMinMax === "min") && { min }),
|
|
102
|
+
...((useMinMax === "both" || useMinMax === "max") && { max }),
|
|
82
103
|
weekStartDay: 0,
|
|
83
104
|
T,
|
|
84
105
|
});
|
|
@@ -87,44 +108,3 @@ describe("applyOutOfRange", () => {
|
|
|
87
108
|
},
|
|
88
109
|
);
|
|
89
110
|
});
|
|
90
|
-
|
|
91
|
-
describe("canShift", () => {
|
|
92
|
-
const min = pd("2025-12-01");
|
|
93
|
-
const max = pd("2026-01-10");
|
|
94
|
-
|
|
95
|
-
it.each([
|
|
96
|
-
{
|
|
97
|
-
description: "unbounded — always true",
|
|
98
|
-
behavior: "unbounded" as OutOfRangeBehavior,
|
|
99
|
-
currentFirstWeek: pd("2026-06-01"),
|
|
100
|
-
direction: 1 as const,
|
|
101
|
-
expected: true,
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
description: "stop — false when target has no valid weeks",
|
|
105
|
-
behavior: "stop" as OutOfRangeBehavior,
|
|
106
|
-
currentFirstWeek: pd("2025-12-28"),
|
|
107
|
-
direction: 1 as const,
|
|
108
|
-
expected: false,
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
description: "snap — false when already at clamp position",
|
|
112
|
-
behavior: "snap" as OutOfRangeBehavior,
|
|
113
|
-
currentFirstWeek: pd("2025-11-16"),
|
|
114
|
-
direction: 1 as const,
|
|
115
|
-
expected: false,
|
|
116
|
-
},
|
|
117
|
-
])("$description", ({ behavior, currentFirstWeek, direction, expected }) => {
|
|
118
|
-
const result = canShift({
|
|
119
|
-
currentFirstWeek,
|
|
120
|
-
weekCount: 8,
|
|
121
|
-
direction,
|
|
122
|
-
behavior,
|
|
123
|
-
min,
|
|
124
|
-
max,
|
|
125
|
-
weekStartDay: 0,
|
|
126
|
-
T,
|
|
127
|
-
});
|
|
128
|
-
expect(result).toBe(expected);
|
|
129
|
-
});
|
|
130
|
-
});
|