@moltenship/calendar 1.0.0-rc.2 → 2.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 (78) hide show
  1. package/README.md +27 -6
  2. package/dist/index.d.mts +3 -3
  3. package/dist/index.mjs +2 -2
  4. package/docs/accessibility.md +305 -0
  5. package/docs/agents/changes.md +449 -0
  6. package/docs/agents/coding-agents.md +116 -0
  7. package/docs/agents/connect.md +444 -0
  8. package/docs/agents/deleting.md +296 -0
  9. package/docs/agents/reference.md +511 -0
  10. package/docs/agents/server.md +317 -0
  11. package/docs/agents/webmcp.md +153 -0
  12. package/docs/agents.md +355 -0
  13. package/docs/annotations.md +198 -0
  14. package/docs/api/changes.md +264 -0
  15. package/docs/api/components.md +245 -0
  16. package/docs/api/dnd-kit.md +265 -0
  17. package/docs/api/events.md +153 -0
  18. package/docs/api/primitives.md +218 -0
  19. package/docs/api/store.md +92 -0
  20. package/docs/api.md +57 -0
  21. package/docs/availability.md +576 -0
  22. package/docs/comparison.md +278 -0
  23. package/docs/concepts/anatomy.md +73 -0
  24. package/docs/concepts/events.md +163 -0
  25. package/docs/concepts/how-it-works.md +112 -0
  26. package/docs/concepts/state.md +244 -0
  27. package/docs/concepts/time.md +168 -0
  28. package/docs/customization.md +271 -0
  29. package/docs/frameworks.md +116 -0
  30. package/docs/guides/dnd-kit.md +333 -0
  31. package/docs/guides/google-calendar-sync.md +1246 -0
  32. package/docs/guides/google-calendar.md +367 -0
  33. package/docs/guides/motion.md +414 -0
  34. package/docs/guides/nextjs-app-router.md +630 -0
  35. package/docs/guides/nextjs.md +149 -0
  36. package/docs/guides/performance.md +103 -0
  37. package/docs/guides/tanstack-query.md +485 -0
  38. package/docs/ics/feed.md +484 -0
  39. package/docs/ics/import.md +183 -0
  40. package/docs/ics/reference.md +482 -0
  41. package/docs/ics.md +142 -0
  42. package/docs/index.md +149 -0
  43. package/docs/installation.md +209 -0
  44. package/docs/interactions.md +441 -0
  45. package/docs/llms.txt +99 -0
  46. package/docs/migrating-to-2.md +497 -0
  47. package/docs/quick-start.md +163 -0
  48. package/docs/recurrence/calendar.md +598 -0
  49. package/docs/recurrence/model.md +128 -0
  50. package/docs/recurrence/reference.md +547 -0
  51. package/docs/recurrence.md +122 -0
  52. package/docs/stylex.md +290 -0
  53. package/docs/temporal/daylight-saving-time.md +172 -0
  54. package/docs/temporal/month-grid.md +119 -0
  55. package/docs/temporal/reference.md +167 -0
  56. package/docs/temporal.md +105 -0
  57. package/docs/testing.md +600 -0
  58. package/docs/theme-builder.md +82 -0
  59. package/docs/theming.md +275 -0
  60. package/docs/undo-redo.md +347 -0
  61. package/docs/views/agenda.md +222 -0
  62. package/docs/views/custom-views.md +195 -0
  63. package/docs/views/month.md +110 -0
  64. package/docs/views/resource-columns.md +265 -0
  65. package/docs/views/resource-timeline.md +226 -0
  66. package/docs/views/scrolling.md +193 -0
  67. package/docs/views/week-and-day.md +258 -0
  68. package/docs/views/year.md +138 -0
  69. package/docs/views.md +69 -0
  70. package/package.json +42 -14
  71. package/skills/moltenship-time/SKILL.md +77 -0
  72. package/skills/moltenship-time/references/agent-ready.md +272 -0
  73. package/skills/moltenship-time/references/changes.md +188 -0
  74. package/skills/moltenship-time/references/compose.md +175 -0
  75. package/skills/moltenship-time/references/mistakes.md +100 -0
  76. package/skills/moltenship-time/references/solid.md +213 -0
  77. package/skills/moltenship-time/references/state.md +129 -0
  78. package/skills/moltenship-time/references/testing.md +176 -0
@@ -0,0 +1,600 @@
1
+ # Testing
2
+
3
+ Test the calendar you built with a fixed clock, typed builders, a render harness, and keyboard and pointer drivers.
4
+
5
+ Source: https://time.molten.sh/docs/react/testing
6
+
7
+ `@moltenship/calendar-testing` tests the calendar your app builds: your copies of the registry
8
+ views, your policies and the code that saves changes. It renders your `Root` with a fixed clock,
9
+ time zone and locale, owns the events the way your app's state would, records what the calendar
10
+ tells your app, and drives it with the keyboard and the pointer as a person would.
11
+
12
+ It uses only the public API of `@moltenship/calendar` and `@moltenship/calendar-recurrence`, and
13
+ depends on no test runner. The examples here use [Vitest](https://vitest.dev) with jsdom; happy-dom
14
+ works too, and pointer tests run in [Vitest's browser mode](#pointer-and-touch).
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ pnpm add -D @moltenship/calendar-testing vitest jsdom
20
+ ```
21
+
22
+ Its peer dependencies are the four packages a 2.0 app already has: `react` and `react-dom` 19, which
23
+ the harness renders and hydrates with, and `@ui-sdk/core` and `@ui-sdk/react`, which the calendar's
24
+ parts are built on. See [Installation](./installation.md) if the app doesn't have them yet.
25
+
26
+ ## Set up Vitest
27
+
28
+ Run the tests in a DOM environment:
29
+
30
+ ```ts title="vitest.config.ts"
31
+ import { defineConfig } from "vitest/config";
32
+
33
+ export default defineConfig({
34
+ test: { environment: "jsdom", setupFiles: ["./tests/setup.ts"] },
35
+ });
36
+ ```
37
+
38
+ Node.js 26 and later have `Temporal`. On an older runtime, or a browser without it, install the
39
+ polyfill in the setup file, as the app does. The package never installs one itself, and its helpers
40
+ throw an error that says so when `Temporal` is missing.
41
+
42
+ ```ts title="tests/setup.ts"
43
+ if (!("Temporal" in globalThis)) await import("temporal-polyfill/global");
44
+ ```
45
+
46
+ The registry's controls are ui-sdk's, which read paint timing, measure toasts and wait for
47
+ transitions, none of which jsdom has. jsdom's stylesheet also hides every popup that isn't
48
+ `:popover-open`, which nothing matches without the Popover API. A test that renders them adds
49
+ these to the setup file:
50
+
51
+ ```ts title="tests/setup.ts"
52
+ performance.getEntriesByType ??= () => [];
53
+ globalThis.ResizeObserver ??= class {
54
+ disconnect() {}
55
+ observe() {}
56
+ unobserve() {}
57
+ };
58
+ Element.prototype.getAnimations ??= () => [];
59
+ // ui-sdk marks an open popup `data-open`; jsdom weighs its rules by specificity alone.
60
+ const popups = document.createElement("style");
61
+ popups.textContent = "[popover][data-open] { display: block !important; }";
62
+ document.head.append(popups);
63
+ ```
64
+
65
+ The harness turns on React's `IS_REACT_ACT_ENVIRONMENT` flag when it first renders, unless your
66
+ setup set it already.
67
+
68
+ ## A fixed clock and zone
69
+
70
+ The calendar reads the current time only from `Root`'s `now` or `clock`, and the time zone from
71
+ `timeZone` or `defaultTimeZone`; `locale` and `weekRules` are required props. So a test makes it
72
+ deterministic through props, without faking timers or patching `Temporal.Now`.
73
+
74
+ `createTestEnvironment(options?)` fixes all of them. Its defaults are Thursday, 8 October 2026 at
75
+ noon UTC, US English, weeks from Monday, and left to right.
76
+
77
+ ```ts
78
+ const environment = createTestEnvironment({ timeZone: "Europe/Berlin" });
79
+
80
+ environment.now; // 2026-10-08T12:00:00Z, a Temporal.Instant
81
+ environment.today; // 2026-10-08, now's date in the zone
82
+ environment.at("09:00"); // 09:00 today in Berlin: 2026-10-08T07:00:00Z
83
+ environment.at("2026-10-26T09:00"); // a wall time in Berlin, after the clocks go back
84
+ environment.rootProps; // { now, defaultTimeZone, locale, weekRules, direction, defaultAnchorDate }
85
+ ```
86
+
87
+ `at` reads a time alone on the environment's own date, `today`, however far the calendar has moved.
88
+
89
+ | Option | Default |
90
+ | ------------ | -------------------------------------------------------------------------- |
91
+ | `now` | `"2026-10-08T12:00:00Z"`; text without a zone is a wall time on `timeZone` |
92
+ | `timeZone` | `"UTC"` |
93
+ | `locale` | `"en-US"` |
94
+ | `weekRules` | `{ firstDay: 1, minimalDays: 4, weekend: [6, 7] }` |
95
+ | `direction` | `"ltr"` |
96
+ | `anchorDate` | `today` |
97
+
98
+ To show a later time, call the harness's `setNow`: the calendar re-renders with it at once. To let
99
+ time pass as an app's clock does, pass `createTestClock(start)` as the harness's `clock` option, or
100
+ `Root`'s `clock` in your own render, and move it with `set` or `advance`. The calendar samples a
101
+ clock once a minute, so move fake timers with it. A clock reads text without a zone as UTC.
102
+
103
+ ## Builders
104
+
105
+ Builders make records in the canonical shape `createCanonicalEventAdapter` reads. Every field has
106
+ a default, so a test names only what it's about. Text times without a zone are wall times on the
107
+ event's `timeZone`, UTC by default, and `timeZone` becomes the event's `sourceTimeZone`.
108
+
109
+ | Builder | Makes |
110
+ | ------------------------------ | -------------------------------------------------------------------------------------------- |
111
+ | `buildEvent(input?)` | A timed event: an hour at 09:00 on the default date. `start` with `end` or `duration` |
112
+ | `buildAllDayEvent(input?)` | An all-day event: `start` with `end` (exclusive) or `days` |
113
+ | `buildResource(input?)` | A `CalendarResource`, with `timeZone`, `parentId` and `availability` |
114
+ | `buildRecurringEvent(input)` | A timed series for `@moltenship/calendar-recurrence`: `rule` as RRULE text, `exceptionDates` |
115
+ | `withRecurrence(event, input)` | Makes any event, all-day ones too, the master of a series |
116
+ | `buildAvailability(input?)` | Working hours: `days`, `hours` such as `"09:00-17:00"`, `exceptions`; 9 to 5 on weekdays |
117
+
118
+ An event's `id` defaults to its title and its title to its ID, so `buildEvent({ title: "Standup" })`
119
+ is the event `"Standup"`.
120
+
121
+ ## Render a calendar
122
+
123
+ Create your calendar as the app does, then render it with `renderCalendar`. Clean up after each
124
+ test.
125
+
126
+ ```tsx title="calendar.test.tsx"
127
+ import {
128
+ createCalendar,
129
+ createCanonicalEventAdapter,
130
+ type CalendarEvent,
131
+ } from "@moltenship/calendar";
132
+ import {
133
+ buildEvent,
134
+ cleanup,
135
+ createTestEnvironment,
136
+ hydrateCalendar,
137
+ renderCalendar,
138
+ } from "@moltenship/calendar-testing";
139
+
140
+ import { createAgent } from "@ui-sdk/react/agent";
141
+
142
+ import { calendarAnnouncements } from "@/components/calendar/announcements";
143
+ import { createWeekView } from "@/components/calendar/time-grid-view/time-grid-view";
144
+
145
+ type Meeting = CalendarEvent<null>;
146
+
147
+ const Calendar = createCalendar<Meeting>()({
148
+ eventAdapter: createCanonicalEventAdapter<null>(),
149
+ views: [createWeekView<Meeting>()],
150
+ });
151
+
152
+ // Unmounts every calendar a test rendered.
153
+ afterEach(cleanup);
154
+ ```
155
+
156
+ `afterEach`, `expect` and `test` come from `vitest`.
157
+
158
+ `renderCalendar(Calendar, options)` renders `Root` with the environment's props inside `act`, and
159
+ `<Calendar.ActiveView />` inside it. It owns the events: a change your calendar saves is applied to
160
+ them, so the next render shows it, as your app's state would.
161
+
162
+ ```tsx title="calendar.test.tsx"
163
+ const environment = createTestEnvironment({ timeZone: "Europe/Berlin" });
164
+ const standup = buildEvent({ title: "Standup", start: environment.at("09:00") });
165
+
166
+ test("a saved move reaches onEventChange and the events", async () => {
167
+ const calendar = await renderCalendar(Calendar, {
168
+ environment,
169
+ events: [standup],
170
+ messages: calendarAnnouncements,
171
+ });
172
+
173
+ await calendar.propose({
174
+ cause: "move",
175
+ eventId: "Standup",
176
+ proposed: {
177
+ kind: "timed",
178
+ start: environment.at("10:00"),
179
+ end: environment.at("10:30"),
180
+ },
181
+ });
182
+
183
+ expect(calendar.changes.map((change) => change.cause)).toEqual(["move"]);
184
+ expect(calendar.results[0]?.result.status).toBe("committed");
185
+ expect(String(calendar.events()[0]?.start)).toBe("2026-10-08T08:00:00Z");
186
+ });
187
+ ```
188
+
189
+ | Option | Effect |
190
+ | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
191
+ | `events` | The events the calendar starts with |
192
+ | `view` | The view it opens on; the first registered one by default |
193
+ | `environment` | `createTestEnvironment()` by default |
194
+ | `clock` | A clock to read the time from instead of the environment's fixed `now` |
195
+ | `resources` | `Root`'s `resources` |
196
+ | `onEventChange` | Called with each change before the harness applies it. Return a promise to keep the change pending; throw or reject to roll it back |
197
+ | `onEventChangeResult` | Called with each result after the harness records it |
198
+ | `applyChange` | Applies a saved change to your events. The default, `applyCanonicalChange`, needs canonical events; pass your own for your app's records |
199
+ | `createEvent` | The record a created event gets, from the change and a free `new-<n>` ID; the proposed placement goes over it. `{ id, title: "New event", data: null }` by default |
200
+ | `readOnly` | Renders `Root` without `onEventChange` |
201
+ | `messages` | Renders `<Calendar.Announcer messages={messages} />` |
202
+ | `rootProps` | Any other `Root` prop, such as `policies` or `availability` |
203
+ | `children` | What `Root` renders instead of `<Calendar.ActiveView />` |
204
+ | `wrapper` | A component around the calendar, such as a provider |
205
+ | `strictMode` | Renders in `StrictMode` |
206
+ | `container` | Where to render; a new element in `document.body` by default, which unmounting removes |
207
+ | `identifierPrefix` | `useId`'s prefix |
208
+
209
+ The harness it returns:
210
+
211
+ | Member | Contents |
212
+ | --------------------------------- | ------------------------------------------------------------------------------------ |
213
+ | `container` | The element the calendar rendered into |
214
+ | `changes` | Every change `onEventChange` received, in order |
215
+ | `results` | Every `onEventChangeResult` call: `{ result, detail }` |
216
+ | `diagnostics` | What `onDiagnosticsChange` last reported |
217
+ | `events()` | The events now, with every saved change applied |
218
+ | `state()`, `meta()` | `useCalendarState()` and `useCalendarMeta()`, read from inside `Root` |
219
+ | `pendingChanges()` | `useCalendarPendingChanges()`: changes still validating, saving or awaiting events |
220
+ | `actions`, `act(callback)` | The calendar's actions, and a way to call them inside `act` |
221
+ | `propose(proposal)` | `proposeEventChange` inside `act`; resolves with its result once it settles |
222
+ | `setEvents`, `setNow`, `rerender` | Change the events, the fixed `now`, or the options that apply after the first render |
223
+ | `unmount()` | Unmounts it; `cleanup()` unmounts every one |
224
+
225
+ `setNow` takes exact text, a wall time on the environment's zone, or a time such as `"10:00"` on
226
+ the calendar's current date. `rerender` changes the events, the handlers, `children`, `messages`,
227
+ `resources`, `readOnly` and `rootProps`; the view, the environment, the wrapper and the container
228
+ set up the first render. Change the view or date through `act`, as a person would:
229
+ `await calendar.act((actions) => actions.setView("day"))`. Change the locale, week rules or
230
+ direction through `rootProps`: `await calendar.rerender({ rootProps: { locale: "de-DE" } })`.
231
+
232
+ Name the harness type with `CalendarHarnessFor<typeof Calendar>`.
233
+
234
+ ## Saves that take time
235
+
236
+ When `onEventChange` returns a promise, the calendar shows the change as pending until it settles.
237
+ Hold the promise in the test to check what the calendar shows meanwhile.
238
+
239
+ ```tsx title="calendar.test.tsx"
240
+ test("a slow save stays pending, then settles", async () => {
241
+ let finish = () => {};
242
+ const calendar = await renderCalendar(Calendar, {
243
+ environment,
244
+ events: [standup],
245
+ onEventChange: () => new Promise<void>((resolve) => (finish = resolve)),
246
+ });
247
+
248
+ // Propose through act without waiting for the save, which the test holds.
249
+ let saving: ReturnType<typeof calendar.actions.proposeEventChange> | undefined;
250
+ await calendar.act((actions) => {
251
+ saving = actions.proposeEventChange({
252
+ cause: "move",
253
+ eventId: "Standup",
254
+ proposed: { kind: "timed", start: environment.at("11:00"), end: environment.at("12:00") },
255
+ });
256
+ });
257
+ expect([...calendar.pendingChanges().values()].map(({ phase }) => phase)).toEqual(["saving"]);
258
+
259
+ await calendar.act(() => finish());
260
+ expect((await saving)?.status).toBe("committed");
261
+ expect(calendar.pendingChanges().size).toBe(0);
262
+ });
263
+ ```
264
+
265
+ ## Changes an agent makes
266
+
267
+ An [agent](./agents.md) acts on the calendar through a bridge, and its changes take the same path
268
+ as a person's. Test them with the real bridge: no model is involved, since a step is a plain object.
269
+
270
+ ```tsx title="calendar.test.tsx"
271
+ test("an agent's move is saved like a person's, and says who asked", async () => {
272
+ const agent = createAgent();
273
+ const calendar = await renderCalendar(Calendar, {
274
+ environment,
275
+ events: [standup],
276
+ // An agent finds a calendar by its name, on the frame.
277
+ rootProps: { label: "Team calendar" },
278
+ children: (
279
+ <Calendar.Frame>
280
+ <Calendar.ActiveView />
281
+ </Calendar.Frame>
282
+ ),
283
+ });
284
+
285
+ const outcome = await calendar.act(() =>
286
+ agent.act({
287
+ steps: [
288
+ {
289
+ ref: "Team calendar",
290
+ action: "moveEvent",
291
+ // One object per action. The event's ID is what `listEvents` gives the agent.
292
+ args: [{ eventId: standup.id, start: "2026-10-08T11:00" }],
293
+ },
294
+ ],
295
+ }),
296
+ );
297
+ await calendar.settled();
298
+
299
+ // The step returns the change, and the harness saved it at once.
300
+ expect(outcome.steps[0]?.result).toMatchObject({ cause: "move", status: "saved" });
301
+ expect(calendar.changes.map((change) => change.cause)).toEqual(["move"]);
302
+ expect(calendar.results[0]?.detail.input).toBe("agent");
303
+ expect(calendar.placementOf("Standup").wallRange).toBe("2026-10-08T11:00/2026-10-08T12:00");
304
+ });
305
+ ```
306
+
307
+ Three things make it work:
308
+
309
+ - **A name and a frame.** The bridge lists a calendar that renders `Calendar.Frame`, and finds it
310
+ by the `label` on `Root`. The harness renders `<Calendar.ActiveView />` alone by default, so pass
311
+ the frame as `children`.
312
+ - **`calendar.act`.** The agent's steps change React state, so they run inside `act` like any
313
+ other change.
314
+ - **`calendar.settled()`.** A step returns the change with its `status`: `"saved"` when the handler
315
+ saved at once, as the harness does by default, and `"saving"` when the handler returned a
316
+ promise. `settled()` waits for every save before the test reads `results`.
317
+
318
+ `results[n].detail.input` is `"agent"` for these changes, which is how an app's handler, a policy
319
+ and the history tell them from a person's.
320
+
321
+ ## Find what the calendar shows
322
+
323
+ Queries find events through the calendar's own events, by ID, title or start, so they don't
324
+ depend on the text a view renders or its language. Cells are found by the attributes every
325
+ registry view carries for the pointer layer: `data-event-id` on events, `data-date` on day cells
326
+ and time columns, `data-all-day` on a time grid's all-day cells, `data-axis="inline"` on a
327
+ timeline's time strips, and `data-resource-id` on a resource's column or row. A view of your own
328
+ that follows the [same contract](./interactions.md#in-your-own-views) works the same way: a
329
+ `data-date` element without `data-all-day` counts as a time column, and in a time grid, events sit
330
+ inside their column.
331
+
332
+ ```tsx title="calendar.test.tsx"
333
+ test("queries find events by title, and cells by date", async () => {
334
+ const calendar = await renderCalendar(Calendar, { environment, events: [standup] });
335
+
336
+ const event = calendar.getEvent("Standup");
337
+ expect(calendar.getTimeColumn("2026-10-08").contains(event)).toBe(true);
338
+ expect(calendar.queryEvent("Lunch")).toBeNull();
339
+
340
+ // A slot exists only while it has focus, so the keyboard driver focuses it.
341
+ await calendar.keyboard.focusCell({ date: "2026-10-08", time: "14:00" });
342
+ expect(document.activeElement?.getAttribute("aria-label")).toBe("Thursday, October 8 at 2:00 PM");
343
+ });
344
+ ```
345
+
346
+ | Query | Returns |
347
+ | -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
348
+ | `getEvent(event)` | The first element showing an event |
349
+ | `getAllEvents(event)` | Every element showing it: one per part the view draws, such as a time grid's day, a month's week row, a resource's column |
350
+ | `queryEvent(event)` | The first element, or `null` when the view doesn't show it |
351
+ | `getDayCell(date, { resourceId? })` | A time grid's all-day cell, or else a month's day |
352
+ | `getTimeColumn(date, { resourceId? })` | The column of a date's hours, or its strip along a timeline row |
353
+ | `getResource(resource)` | The element a resource's column or row carries its ID on; `resource` is an ID, `null` for the unassigned row, or `{ title }` |
354
+ | `placementOf(event)` | Where it shows now, pending changes included, as text: `range`, `wallRange`, `isPending` |
355
+
356
+ `event` is an ID or a title as text (an ID wins), or `{ id }`, `{ title }` or `{ start }`. A
357
+ `start` is a date for an all-day event, a date and time for a floating one, or a time for a timed
358
+ one, exact or on the calendar's wall clock. The `get` queries throw a `CalendarQueryError` that
359
+ lists the calendar's events when they find nothing, and every query throws when it finds several
360
+ events. `placementOf` gives text, such as `"2026-10-09T08:30:00Z/2026-10-09T09:30:00Z"`, which
361
+ reads plainly in a failing assertion; `wallRange` gives the same ends on the display zone's clock,
362
+ to the minute.
363
+
364
+ ## Keyboard
365
+
366
+ `calendar.keyboard` presses keys on the focused element inside `act`, as a person would, so it
367
+ works in jsdom, happy-dom and a browser alike, and through every check your views make. Focus
368
+ goes through the calendar's own focus, as arrow keys move it, so a slot, which renders only while
369
+ it has focus, can take it too.
370
+
371
+ ```tsx title="calendar.test.tsx"
372
+ test("Space, arrow keys and Enter move the standup a day on and half an hour later", async () => {
373
+ const calendar = await renderCalendar(Calendar, {
374
+ environment,
375
+ events: [standup],
376
+ messages: calendarAnnouncements,
377
+ });
378
+
379
+ // Focus the event, Space, two slots down and a day across, then Enter.
380
+ await calendar.keyboard.moveEvent("Standup", { across: 1, down: 2 });
381
+ await calendar.settled();
382
+
383
+ expect(calendar.placementOf("Standup").wallRange).toBe("2026-10-09T09:30/2026-10-09T10:30");
384
+ expect(calendar.lastAnnouncement()).toBe("Moved Standup to Friday, October 9, 9:30 – 10:30 AM.");
385
+ expect(calendar.results[0]?.detail.input).toBe("keyboard");
386
+ });
387
+ ```
388
+
389
+ | Method | Keys |
390
+ | ------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
391
+ | `focusEvent(event, { date?, resourceId? })` | Focuses the event's part on `date`, by default the day it starts or the first day shown, in `resourceId` |
392
+ | `focusCell({ date, time?, resourceId? })` | Focuses a day, or a slot with `time` |
393
+ | `press(key, modifiers?)`, `arrows({ up, down, left, right })` | Any key on whatever has focus, or arrow keys by count |
394
+ | `step({ across, down })` | Arrow keys by direction |
395
+ | `grab()`, `grabEdge()` | Space picks up the focused event or starts a create; Shift+Space picks up its end, and again its start |
396
+ | `drop()`, `cancel()` | Enter and Escape |
397
+ | `moveEvent(event, { across?, down?, date?, resourceId? })` | Focus, Space, the steps, Enter |
398
+ | `resizeEvent(event, { edge?, across?, down?, date?, resourceId? })` | Focus, Shift+Space (twice for the start), the steps, Enter |
399
+ | `createEvent(cell, steps?)` | Focus the cell, Space, the steps, Enter |
400
+
401
+ The focus methods throw when the view doesn't show what they name, and leave the calendar's focus
402
+ as it was. A step `across` goes toward the end of the line: Arrow Right in a left-to-right
403
+ calendar, Arrow Left in a right-to-left one, from `Root`'s `direction`. A step `down` is Arrow
404
+ Down; negative steps go back and up. What a step is depends on the view:
405
+
406
+ | View | `across` | `down` |
407
+ | ----------------- | ---------------------------------------------- | ----------------------------- |
408
+ | Week, day | A day | A slot, 15 minutes by default |
409
+ | Month | A day | A week |
410
+ | Resource columns | A column: the next resource, then the next day | A slot |
411
+ | Resource timeline | A slot, or a day over days | The next resource |
412
+
413
+ ## Wait for saves
414
+
415
+ Drivers return once their keys or moves are handled, not when the change is saved. `settled()`
416
+ waits until no change is pending: every proposal validated, saved, and in the events. It gives up
417
+ after five seconds of real time, and says which changes are still pending. It doesn't advance fake
418
+ timers, so a save that waits on one needs them advanced first.
419
+
420
+ `announcements()` lists what the `Announcer` said, oldest first, a message said twice included,
421
+ and `lastAnnouncement()` what it says now, with `Intl`'s thin and no-break spaces made plain.
422
+ Render one with the `messages` option, or your own in `children`: only the one mounted last
423
+ speaks, and the harness follows whichever does. `normalizeText(text)` makes your own text plain
424
+ the same way.
425
+
426
+ ## Pointer and touch
427
+
428
+ `calendar.pointer` drags with Pointer Events at measured points, as a mouse, a pen or a finger
429
+ would. It needs a page that's laid out and real timers, so it runs in a browser:
430
+
431
+ ```ts title="vitest.config.ts"
432
+ import { defineConfig } from "vitest/config";
433
+ import { playwright } from "@vitest/browser-playwright";
434
+
435
+ export default defineConfig({
436
+ test: {
437
+ browser: {
438
+ enabled: true,
439
+ provider: playwright(),
440
+ instances: [{ browser: "chromium" }],
441
+ },
442
+ },
443
+ });
444
+ ```
445
+
446
+ ```tsx title="calendar.browser.test.tsx"
447
+ test("a mouse moves the standup to Friday at 11:00", async () => {
448
+ const calendar = await renderCalendar(Calendar, {
449
+ // Give the calendar a height, as the app's layout does.
450
+ children: (
451
+ <Calendar.Frame className="flex h-dvh flex-col">
452
+ <Calendar.Viewport className="min-h-0 flex-1">
453
+ <Calendar.ActiveView />
454
+ </Calendar.Viewport>
455
+ </Calendar.Frame>
456
+ ),
457
+ events: [standup],
458
+ });
459
+
460
+ await calendar.pointer.moveEvent("Standup", { date: "2026-10-09", time: "11:00" });
461
+ await calendar.settled();
462
+
463
+ expect(calendar.placementOf("Standup").range).toBe("2026-10-09T11:00:00Z/2026-10-09T12:00:00Z");
464
+ });
465
+ ```
466
+
467
+ | Method | Drag |
468
+ | ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
469
+ | `moveEvent(event, { date, time?, resourceId? })` | By the event's middle, so it starts at `time` on `date`; without `time`, by whole days, keeping its time. It stays in its resource unless `resourceId` names another |
470
+ | `resizeEvent(event, { date, time?, edge? })` | Its end (or start) handle to `time`, or to `date` in a view that resizes by days, as a timeline over days does |
471
+ | `createEvent(from, to)` | Across empty slots or days, both included |
472
+ | `drag(from, to)` | From one element or point to another |
473
+
474
+ Each takes `{ pointerType }`: `"mouse"` by default, `"pen"`, or `"touch"`, which holds still
475
+ until the long press starts a drag. The press and the drop must be on screen: the drivers scroll
476
+ the event into view, and throw when its middle is covered or when the drop point isn't on its cell,
477
+ so make the calendar tall enough. Where they let go is measured again after each frame, so a view
478
+ that auto-scrolls under the pointer still gets the drop where it was meant. The repository runs
479
+ these drivers on its views in Chromium on every pull request, and in Firefox and WebKit, WebKit on
480
+ `temporal-polyfill`, in the full gate.
481
+
482
+ ### What jsdom can't do
483
+
484
+ jsdom and happy-dom don't lay pages out: every element is an empty box at the top left, and
485
+ nothing scrolls. So in them:
486
+
487
+ - the pointer drivers throw a `PointerLayoutError` that says to use a browser;
488
+ - views measure nothing, so anything that depends on sizes, such as virtualized resource columns
489
+ past the first screen, auto-scroll at an edge, or which part of a scrolling view is visible,
490
+ isn't there to test;
491
+ - CSS doesn't apply: hidden, clipped and focus-visible states are classes, not what's shown.
492
+
493
+ Keyboard drivers, queries, the harness, saves and announcements work in all three.
494
+
495
+ ## Fixtures
496
+
497
+ Fixtures are ready datasets for contract tests: tests that every view, or your custom one, should
498
+ pass on the same data. Each is a function that builds new records, with the environment,
499
+ resources and `Root` props it's meant for, so spreading it into the harness's options renders it.
500
+ Merge `rootProps` when you pass your own. Their events are canonical, with `data: { group }`, so
501
+ type your calendar with `FixtureEvent` and `FixtureResource`.
502
+
503
+ ```tsx title="calendar.test.tsx"
504
+ import { dstWeekFixture, type FixtureEvent } from "@moltenship/calendar-testing";
505
+
506
+ const FixtureCalendar = createCalendar<FixtureEvent>()({
507
+ eventAdapter: createCanonicalEventAdapter<{ readonly group: string }>(),
508
+ views: [createWeekView<FixtureEvent>()],
509
+ });
510
+
511
+ test("a move a day on keeps an event's wall time across the clocks going back", async () => {
512
+ // New York's week of Sunday 1 November 2026, with a 09:00 standup every day.
513
+ const calendar = await renderCalendar(FixtureCalendar, { ...dstWeekFixture(), view: "week" });
514
+
515
+ // `d6` is Saturday's standup; a day on is Sunday, after the change.
516
+ await calendar.keyboard.moveEvent("d6", { across: 1 });
517
+ await calendar.settled();
518
+
519
+ expect(calendar.placementOf("d6").wallRange).toBe("2026-11-01T09:00/2026-11-01T09:30");
520
+ });
521
+ ```
522
+
523
+ | Fixture | Data |
524
+ | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
525
+ | `denseDayFixture()` | Thursday 8 October 2026 in UTC: 30 timed events, from back-to-back half hours that overlap nothing to five at once at 13:00 and a staircase, two across midnight, and 3 all-day events |
526
+ | `dstWeekFixture({ change? })` | New York's week to Sunday 1 November 2026, when the clocks go back, or with `change: "spring"` to 8 March, when they go forward: a 09:00 standup a day, an event in the changing hour, one across the change |
527
+ | `resourceDayFixture()` | A team in three zones, one with hours of its own, and rooms under a parent that opens expanded; events on one resource, on several, and on none; working hours from 9 to 6 |
528
+ | `multiZoneSeriesFixture()` | Series in Berlin, Los Angeles and Tokyo from 19 October 2026, across Berlin's and Los Angeles' DST changes a week apart |
529
+
530
+ Each fixture's JSDoc lists its events and resources by ID, title and time. Those, and the counts,
531
+ are part of the API: they change only in a major version, so tests can name them.
532
+
533
+ `multiZoneSeriesFixture` gives series masters, `series`, not events: a calendar shows a series
534
+ once it's expanded into occurrences, as your app does with `@moltenship/calendar-recurrence`.
535
+
536
+ ```tsx title="calendar.test.tsx"
537
+ import {
538
+ createCanonicalRecurrenceAdapter,
539
+ createOccurrenceAdapter,
540
+ createOccurrenceExpander,
541
+ type RecurrenceOccurrence,
542
+ } from "@moltenship/calendar-recurrence";
543
+ import { multiZoneSeriesFixture, type FixtureSeriesEvent } from "@moltenship/calendar-testing";
544
+
545
+ type Occurrence = RecurrenceOccurrence<FixtureSeriesEvent, string>;
546
+
547
+ const SeriesCalendar = createCalendar<Occurrence>()({
548
+ eventAdapter: createOccurrenceAdapter(createCanonicalEventAdapter<{ readonly group: string }>()),
549
+ views: [createWeekView<Occurrence>()],
550
+ });
551
+
552
+ test("Berlin's standup is an hour later in UTC once its clocks go back; Los Angeles' isn't yet", async () => {
553
+ const { environment, series } = multiZoneSeriesFixture();
554
+ const week = {
555
+ end: Temporal.PlainDate.from("2026-11-02"),
556
+ start: Temporal.PlainDate.from("2026-10-26"),
557
+ };
558
+ const { occurrences } = createOccurrenceExpander(
559
+ createCanonicalRecurrenceAdapter<{ readonly group: string }>(),
560
+ ).expand(series, { range: week, timeZone: environment.timeZone });
561
+
562
+ const calendar = await renderCalendar(SeriesCalendar, {
563
+ environment,
564
+ events: occurrences,
565
+ // Occurrences are views of their series: save changes through the recurrence edits instead.
566
+ readOnly: true,
567
+ rootProps: { defaultAnchorDate: week.start },
568
+ view: "week",
569
+ });
570
+
571
+ expect(calendar.placementOf({ start: "2026-10-26T08:00:00Z" }).title).toBe("Standup (Berlin)");
572
+ expect(calendar.placementOf({ start: "2026-10-27T17:00:00Z" }).title).toBe(
573
+ "Review (Los Angeles)",
574
+ );
575
+ });
576
+ ```
577
+
578
+ ## Server rendering and hydration
579
+
580
+ `hydrateCalendar` takes the same options. It renders the calendar with `renderToString`, puts the
581
+ markup in a container and hydrates it, then returns the same harness, with the markup as
582
+ `serverMarkup`. When the client renders something else, it throws a `HydrationMismatchError` with
583
+ React's reasons: a recoverable error, or a warning such as an attribute that differs, which React
584
+ only logs. It watches the console for those while hydration runs, so test with React's development
585
+ build, which logs them. A component that throws on the client fails the test with its error, and
586
+ nothing stays mounted. A fixed `now` renders today's date on the server too, so a calendar with
587
+ one hydrates with nothing to patch.
588
+
589
+ ```tsx title="calendar.test.tsx"
590
+ test("the week renders on the server and hydrates without a mismatch", async () => {
591
+ // Throws a HydrationMismatchError when the client renders something else.
592
+ const calendar = await hydrateCalendar(Calendar, { environment, events: [standup] });
593
+
594
+ expect(calendar.serverMarkup).toContain("Standup");
595
+ });
596
+ ```
597
+
598
+ The server render runs in the test's DOM environment, so code that checks for `window` takes its
599
+ browser branch there too. To test a real server boundary, render with `react-dom/server` in a
600
+ Node environment and hydrate in another, as the repository's SSR fixture does.