@moltenship/calendar 1.0.0-rc.2 → 2.0.0-beta.1

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