@assistant-ui/react-generative-ui 0.0.23 → 0.1.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 (338) hide show
  1. package/README.md +2 -0
  2. package/dist/a2ui.d.ts +1 -4
  3. package/dist/a2ui.d.ts.map +1 -1
  4. package/dist/a2ui.js +1 -4
  5. package/dist/index.d.ts +1 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -10
  8. package/dist/index.server.d.ts +1 -2
  9. package/dist/index.server.d.ts.map +1 -1
  10. package/dist/index.server.js +1 -10
  11. package/dist/ir.d.ts +1 -111
  12. package/dist/ir.d.ts.map +1 -1
  13. package/dist/ir.js +1 -175
  14. package/dist/slack.d.ts +1 -4
  15. package/dist/slack.d.ts.map +1 -1
  16. package/dist/slack.js +1 -4
  17. package/dist/teams.d.ts +1 -4
  18. package/dist/teams.d.ts.map +1 -1
  19. package/dist/teams.js +1 -4
  20. package/package.json +5 -5
  21. package/src/a2ui.ts +1 -22
  22. package/src/index.server.ts +1 -2
  23. package/src/index.test.ts +75 -0
  24. package/src/index.ts +1 -2
  25. package/src/ir.ts +1 -279
  26. package/src/slack.ts +1 -39
  27. package/src/teams.ts +1 -35
  28. package/dist/JSONGenerativeUI.client.d.ts +0 -28
  29. package/dist/JSONGenerativeUI.client.d.ts.map +0 -1
  30. package/dist/JSONGenerativeUI.client.js +0 -101
  31. package/dist/JSONGenerativeUI.client.js.map +0 -1
  32. package/dist/JSONGenerativeUI.server.d.ts +0 -21
  33. package/dist/JSONGenerativeUI.server.d.ts.map +0 -1
  34. package/dist/JSONGenerativeUI.server.js +0 -32
  35. package/dist/JSONGenerativeUI.server.js.map +0 -1
  36. package/dist/JSONGenerativeUI.shared.d.ts +0 -63
  37. package/dist/JSONGenerativeUI.shared.d.ts.map +0 -1
  38. package/dist/JSONGenerativeUI.shared.js +0 -31
  39. package/dist/JSONGenerativeUI.shared.js.map +0 -1
  40. package/dist/RadioGroupScope.d.ts +0 -6
  41. package/dist/RadioGroupScope.d.ts.map +0 -1
  42. package/dist/RadioGroupScope.js +0 -25
  43. package/dist/RadioGroupScope.js.map +0 -1
  44. package/dist/a2ui/BindingContext.d.ts +0 -11
  45. package/dist/a2ui/BindingContext.d.ts.map +0 -1
  46. package/dist/a2ui/BindingContext.js +0 -12
  47. package/dist/a2ui/BindingContext.js.map +0 -1
  48. package/dist/a2ui/PresentRenderer.d.ts +0 -11
  49. package/dist/a2ui/PresentRenderer.d.ts.map +0 -1
  50. package/dist/a2ui/PresentRenderer.js +0 -39
  51. package/dist/a2ui/PresentRenderer.js.map +0 -1
  52. package/dist/a2ui/convert.d.ts +0 -15
  53. package/dist/a2ui/convert.d.ts.map +0 -1
  54. package/dist/a2ui/convert.js +0 -728
  55. package/dist/a2ui/convert.js.map +0 -1
  56. package/dist/a2ui/dataModel.d.ts +0 -9
  57. package/dist/a2ui/dataModel.d.ts.map +0 -1
  58. package/dist/a2ui/dataModel.js +0 -44
  59. package/dist/a2ui/dataModel.js.map +0 -1
  60. package/dist/a2ui/reducer.d.ts +0 -8
  61. package/dist/a2ui/reducer.d.ts.map +0 -1
  62. package/dist/a2ui/reducer.js +0 -242
  63. package/dist/a2ui/reducer.js.map +0 -1
  64. package/dist/a2ui/snapshot.d.ts +0 -3
  65. package/dist/a2ui/snapshot.d.ts.map +0 -1
  66. package/dist/a2ui/snapshot.js +0 -33
  67. package/dist/a2ui/snapshot.js.map +0 -1
  68. package/dist/a2ui/types.d.ts +0 -88
  69. package/dist/a2ui/types.d.ts.map +0 -1
  70. package/dist/a2ui/types.js +0 -6
  71. package/dist/a2ui/types.js.map +0 -1
  72. package/dist/a2ui/valueFunctions.d.ts +0 -16
  73. package/dist/a2ui/valueFunctions.d.ts.map +0 -1
  74. package/dist/a2ui/valueFunctions.js +0 -332
  75. package/dist/a2ui/valueFunctions.js.map +0 -1
  76. package/dist/actionRegistry.d.ts +0 -29
  77. package/dist/actionRegistry.d.ts.map +0 -1
  78. package/dist/actionRegistry.js +0 -41
  79. package/dist/actionRegistry.js.map +0 -1
  80. package/dist/answeredValues.d.ts +0 -16
  81. package/dist/answeredValues.d.ts.map +0 -1
  82. package/dist/answeredValues.js +0 -37
  83. package/dist/answeredValues.js.map +0 -1
  84. package/dist/buildPresentParameters.d.ts +0 -21
  85. package/dist/buildPresentParameters.d.ts.map +0 -1
  86. package/dist/buildPresentParameters.js +0 -95
  87. package/dist/buildPresentParameters.js.map +0 -1
  88. package/dist/constants.d.ts +0 -15
  89. package/dist/constants.d.ts.map +0 -1
  90. package/dist/constants.js +0 -19
  91. package/dist/constants.js.map +0 -1
  92. package/dist/convert/boundSpec.d.ts +0 -48
  93. package/dist/convert/boundSpec.d.ts.map +0 -1
  94. package/dist/convert/boundSpec.js +0 -108
  95. package/dist/convert/boundSpec.js.map +0 -1
  96. package/dist/convert/copyBounded.d.ts +0 -25
  97. package/dist/convert/copyBounded.d.ts.map +0 -1
  98. package/dist/convert/copyBounded.js +0 -38
  99. package/dist/convert/copyBounded.js.map +0 -1
  100. package/dist/convert/isElement.d.ts +0 -3
  101. package/dist/convert/isElement.d.ts.map +0 -1
  102. package/dist/convert/isElement.js +0 -6
  103. package/dist/convert/isElement.js.map +0 -1
  104. package/dist/convert/takeRun.d.ts +0 -6
  105. package/dist/convert/takeRun.d.ts.map +0 -1
  106. package/dist/convert/takeRun.js +0 -20
  107. package/dist/convert/takeRun.js.map +0 -1
  108. package/dist/defineGenerativeComponents.d.ts +0 -29
  109. package/dist/defineGenerativeComponents.d.ts.map +0 -1
  110. package/dist/defineGenerativeComponents.js +0 -34
  111. package/dist/defineGenerativeComponents.js.map +0 -1
  112. package/dist/fieldReferences.d.ts +0 -9
  113. package/dist/fieldReferences.d.ts.map +0 -1
  114. package/dist/fieldReferences.js +0 -53
  115. package/dist/fieldReferences.js.map +0 -1
  116. package/dist/generativeUIToJSX.d.ts +0 -18
  117. package/dist/generativeUIToJSX.d.ts.map +0 -1
  118. package/dist/generativeUIToJSX.js +0 -76
  119. package/dist/generativeUIToJSX.js.map +0 -1
  120. package/dist/index.shared.d.ts +0 -15
  121. package/dist/index.shared.d.ts.map +0 -1
  122. package/dist/index.shared.js +0 -9
  123. package/dist/ir.js.map +0 -1
  124. package/dist/renderGenerativeUI.d.ts +0 -14
  125. package/dist/renderGenerativeUI.d.ts.map +0 -1
  126. package/dist/renderGenerativeUI.js +0 -83
  127. package/dist/renderGenerativeUI.js.map +0 -1
  128. package/dist/scopeSchema.d.ts +0 -6
  129. package/dist/scopeSchema.d.ts.map +0 -1
  130. package/dist/scopeSchema.js +0 -56
  131. package/dist/scopeSchema.js.map +0 -1
  132. package/dist/slack/constants.d.ts +0 -93
  133. package/dist/slack/constants.d.ts.map +0 -1
  134. package/dist/slack/constants.js +0 -146
  135. package/dist/slack/constants.js.map +0 -1
  136. package/dist/slack/decodeBlockAction.d.ts +0 -10
  137. package/dist/slack/decodeBlockAction.d.ts.map +0 -1
  138. package/dist/slack/decodeBlockAction.js +0 -129
  139. package/dist/slack/decodeBlockAction.js.map +0 -1
  140. package/dist/slack/fromSlackBlocks.d.ts +0 -27
  141. package/dist/slack/fromSlackBlocks.d.ts.map +0 -1
  142. package/dist/slack/fromSlackBlocks.js +0 -483
  143. package/dist/slack/fromSlackBlocks.js.map +0 -1
  144. package/dist/slack/toSlackBlocks.d.ts +0 -4
  145. package/dist/slack/toSlackBlocks.d.ts.map +0 -1
  146. package/dist/slack/toSlackBlocks.js +0 -901
  147. package/dist/slack/toSlackBlocks.js.map +0 -1
  148. package/dist/slack/types.d.ts +0 -204
  149. package/dist/slack/types.d.ts.map +0 -1
  150. package/dist/slack/types.js +0 -0
  151. package/dist/teams/constants.d.ts +0 -34
  152. package/dist/teams/constants.d.ts.map +0 -1
  153. package/dist/teams/constants.js +0 -68
  154. package/dist/teams/constants.js.map +0 -1
  155. package/dist/teams/decodeSubmitData.d.ts +0 -26
  156. package/dist/teams/decodeSubmitData.d.ts.map +0 -1
  157. package/dist/teams/decodeSubmitData.js +0 -70
  158. package/dist/teams/decodeSubmitData.js.map +0 -1
  159. package/dist/teams/temporalId.d.ts +0 -5
  160. package/dist/teams/temporalId.d.ts.map +0 -1
  161. package/dist/teams/temporalId.js +0 -28
  162. package/dist/teams/temporalId.js.map +0 -1
  163. package/dist/teams/toAdaptiveCard.d.ts +0 -45
  164. package/dist/teams/toAdaptiveCard.d.ts.map +0 -1
  165. package/dist/teams/toAdaptiveCard.js +0 -642
  166. package/dist/teams/toAdaptiveCard.js.map +0 -1
  167. package/dist/teams/toTeamsAttachments.d.ts +0 -10
  168. package/dist/teams/toTeamsAttachments.d.ts.map +0 -1
  169. package/dist/teams/toTeamsAttachments.js +0 -99
  170. package/dist/teams/toTeamsAttachments.js.map +0 -1
  171. package/dist/teams/types.d.ts +0 -224
  172. package/dist/teams/types.d.ts.map +0 -1
  173. package/dist/teams/types.js +0 -0
  174. package/dist/temporal.d.ts +0 -33
  175. package/dist/temporal.d.ts.map +0 -1
  176. package/dist/temporal.js +0 -152
  177. package/dist/temporal.js.map +0 -1
  178. package/dist/types.d.ts +0 -99
  179. package/dist/types.d.ts.map +0 -1
  180. package/dist/types.js +0 -0
  181. package/dist/vocabulary/alert.d.ts +0 -32
  182. package/dist/vocabulary/alert.d.ts.map +0 -1
  183. package/dist/vocabulary/alert.js +0 -160
  184. package/dist/vocabulary/alert.js.map +0 -1
  185. package/dist/vocabulary/collectFormValues.d.ts +0 -23
  186. package/dist/vocabulary/collectFormValues.d.ts.map +0 -1
  187. package/dist/vocabulary/collectFormValues.js +0 -44
  188. package/dist/vocabulary/collectFormValues.js.map +0 -1
  189. package/dist/vocabulary/data.d.ts +0 -66
  190. package/dist/vocabulary/data.d.ts.map +0 -1
  191. package/dist/vocabulary/data.js +0 -503
  192. package/dist/vocabulary/data.js.map +0 -1
  193. package/dist/vocabulary/dispatch.d.ts +0 -9
  194. package/dist/vocabulary/dispatch.d.ts.map +0 -1
  195. package/dist/vocabulary/dispatch.js +0 -50
  196. package/dist/vocabulary/dispatch.js.map +0 -1
  197. package/dist/vocabulary/fact.d.ts +0 -19
  198. package/dist/vocabulary/fact.d.ts.map +0 -1
  199. package/dist/vocabulary/fact.js +0 -51
  200. package/dist/vocabulary/fact.js.map +0 -1
  201. package/dist/vocabulary/form.d.ts +0 -11
  202. package/dist/vocabulary/form.d.ts.map +0 -1
  203. package/dist/vocabulary/form.js +0 -23
  204. package/dist/vocabulary/form.js.map +0 -1
  205. package/dist/vocabulary/formatValue.d.ts +0 -7
  206. package/dist/vocabulary/formatValue.d.ts.map +0 -1
  207. package/dist/vocabulary/formatValue.js +0 -76
  208. package/dist/vocabulary/formatValue.js.map +0 -1
  209. package/dist/vocabulary/icon.d.ts +0 -41
  210. package/dist/vocabulary/icon.d.ts.map +0 -1
  211. package/dist/vocabulary/icon.js +0 -272
  212. package/dist/vocabulary/icon.js.map +0 -1
  213. package/dist/vocabulary/index.d.ts +0 -12
  214. package/dist/vocabulary/index.d.ts.map +0 -1
  215. package/dist/vocabulary/index.js +0 -36
  216. package/dist/vocabulary/index.js.map +0 -1
  217. package/dist/vocabulary/interactive.d.ts +0 -230
  218. package/dist/vocabulary/interactive.d.ts.map +0 -1
  219. package/dist/vocabulary/interactive.js +0 -530
  220. package/dist/vocabulary/interactive.js.map +0 -1
  221. package/dist/vocabulary/layout.d.ts +0 -79
  222. package/dist/vocabulary/layout.d.ts.map +0 -1
  223. package/dist/vocabulary/layout.js +0 -139
  224. package/dist/vocabulary/layout.js.map +0 -1
  225. package/dist/vocabulary/list.d.ts +0 -14
  226. package/dist/vocabulary/list.d.ts.map +0 -1
  227. package/dist/vocabulary/list.js +0 -50
  228. package/dist/vocabulary/list.js.map +0 -1
  229. package/dist/vocabulary/media.d.ts +0 -25
  230. package/dist/vocabulary/media.d.ts.map +0 -1
  231. package/dist/vocabulary/media.js +0 -42
  232. package/dist/vocabulary/media.js.map +0 -1
  233. package/dist/vocabulary/text.d.ts +0 -57
  234. package/dist/vocabulary/text.d.ts.map +0 -1
  235. package/dist/vocabulary/text.js +0 -49
  236. package/dist/vocabulary/text.js.map +0 -1
  237. package/dist/vocabulary/toTextContent.d.ts +0 -2
  238. package/dist/vocabulary/toTextContent.d.ts.map +0 -1
  239. package/dist/vocabulary/toTextContent.js +0 -6
  240. package/dist/vocabulary/toTextContent.js.map +0 -1
  241. package/src/JSONGenerativeUI.client.tsx +0 -168
  242. package/src/JSONGenerativeUI.server.tsx +0 -39
  243. package/src/JSONGenerativeUI.shared.ts +0 -90
  244. package/src/JSONGenerativeUI.test.tsx +0 -1298
  245. package/src/RadioGroupScope.server.test.tsx +0 -24
  246. package/src/RadioGroupScope.tsx +0 -34
  247. package/src/a2ui/BindingContext.ts +0 -26
  248. package/src/a2ui/PresentRenderer.tsx +0 -83
  249. package/src/a2ui/convert.test.ts +0 -2923
  250. package/src/a2ui/convert.ts +0 -1207
  251. package/src/a2ui/dataModel.ts +0 -69
  252. package/src/a2ui/reducer.test.ts +0 -422
  253. package/src/a2ui/reducer.ts +0 -363
  254. package/src/a2ui/snapshot.test.ts +0 -52
  255. package/src/a2ui/snapshot.ts +0 -52
  256. package/src/a2ui/types.ts +0 -114
  257. package/src/a2ui/valueFunctions.test.ts +0 -271
  258. package/src/a2ui/valueFunctions.ts +0 -523
  259. package/src/actionRegistry.test.ts +0 -90
  260. package/src/actionRegistry.ts +0 -88
  261. package/src/answeredValues.test.ts +0 -33
  262. package/src/answeredValues.tsx +0 -70
  263. package/src/buildPresentParameters.test.ts +0 -246
  264. package/src/buildPresentParameters.ts +0 -130
  265. package/src/constants.ts +0 -17
  266. package/src/convert/boundSpec.test.ts +0 -192
  267. package/src/convert/boundSpec.ts +0 -134
  268. package/src/convert/copyBounded.test.ts +0 -131
  269. package/src/convert/copyBounded.ts +0 -38
  270. package/src/convert/isElement.ts +0 -6
  271. package/src/convert/takeRun.test.ts +0 -64
  272. package/src/convert/takeRun.ts +0 -19
  273. package/src/defineGenerativeComponents.ts +0 -38
  274. package/src/fieldReferences.test.ts +0 -66
  275. package/src/fieldReferences.ts +0 -83
  276. package/src/generativeUIToJSX.test.ts +0 -268
  277. package/src/generativeUIToJSX.ts +0 -152
  278. package/src/index.server.test.ts +0 -106
  279. package/src/index.shared.ts +0 -61
  280. package/src/ir.test.ts +0 -203
  281. package/src/renderGenerativeUI.test.tsx +0 -373
  282. package/src/renderGenerativeUI.tsx +0 -165
  283. package/src/scopeSchema.test.ts +0 -72
  284. package/src/scopeSchema.ts +0 -71
  285. package/src/slack/a2uiSlack.test.ts +0 -198
  286. package/src/slack/constants.ts +0 -194
  287. package/src/slack/datePicker.test.ts +0 -612
  288. package/src/slack/decodeBlockAction.test.ts +0 -233
  289. package/src/slack/decodeBlockAction.ts +0 -232
  290. package/src/slack/fromSlackBlocks.test.ts +0 -1465
  291. package/src/slack/fromSlackBlocks.ts +0 -789
  292. package/src/slack/toSlackBlocks.test.ts +0 -3065
  293. package/src/slack/toSlackBlocks.ts +0 -1818
  294. package/src/slack/types.ts +0 -264
  295. package/src/teams/constants.ts +0 -93
  296. package/src/teams/decodeSubmitData.test.ts +0 -397
  297. package/src/teams/decodeSubmitData.ts +0 -110
  298. package/src/teams/temporal.test.ts +0 -766
  299. package/src/teams/temporalId.ts +0 -56
  300. package/src/teams/toAdaptiveCard.test.ts +0 -1897
  301. package/src/teams/toAdaptiveCard.ts +0 -1057
  302. package/src/teams/toTeamsAttachments.test.ts +0 -74
  303. package/src/teams/toTeamsAttachments.ts +0 -133
  304. package/src/teams/types.ts +0 -266
  305. package/src/temporal.test.ts +0 -319
  306. package/src/temporal.ts +0 -259
  307. package/src/types.ts +0 -119
  308. package/src/vocabulary/alert.test.tsx +0 -427
  309. package/src/vocabulary/alert.tsx +0 -217
  310. package/src/vocabulary/collectFormValues.test.ts +0 -389
  311. package/src/vocabulary/collectFormValues.ts +0 -116
  312. package/src/vocabulary/data.test.tsx +0 -858
  313. package/src/vocabulary/data.tsx +0 -819
  314. package/src/vocabulary/datepicker.dom.test.tsx +0 -1148
  315. package/src/vocabulary/dispatch.ts +0 -83
  316. package/src/vocabulary/fact.test.tsx +0 -94
  317. package/src/vocabulary/fact.tsx +0 -54
  318. package/src/vocabulary/form.test.tsx +0 -113
  319. package/src/vocabulary/form.tsx +0 -39
  320. package/src/vocabulary/formatValue.test.ts +0 -72
  321. package/src/vocabulary/formatValue.ts +0 -127
  322. package/src/vocabulary/icon.test.tsx +0 -64
  323. package/src/vocabulary/icon.tsx +0 -174
  324. package/src/vocabulary/index.test.ts +0 -65
  325. package/src/vocabulary/index.ts +0 -33
  326. package/src/vocabulary/interactive.dispatch.test.tsx +0 -454
  327. package/src/vocabulary/interactive.dom.test.tsx +0 -1747
  328. package/src/vocabulary/interactive.test.tsx +0 -377
  329. package/src/vocabulary/interactive.tsx +0 -1048
  330. package/src/vocabulary/layout.test.tsx +0 -323
  331. package/src/vocabulary/layout.tsx +0 -247
  332. package/src/vocabulary/list.test.tsx +0 -222
  333. package/src/vocabulary/list.tsx +0 -50
  334. package/src/vocabulary/media.test.tsx +0 -85
  335. package/src/vocabulary/media.tsx +0 -56
  336. package/src/vocabulary/text.test.tsx +0 -102
  337. package/src/vocabulary/text.tsx +0 -60
  338. package/src/vocabulary/toTextContent.ts +0 -2
@@ -1,1148 +0,0 @@
1
- // @vitest-environment jsdom
2
-
3
- import * as React from "react";
4
- import { createRoot, hydrateRoot, type Root } from "react-dom/client";
5
- import { renderToString } from "react-dom/server";
6
- import { afterEach, describe, expect, it, vi } from "vitest";
7
- import { A2uiBindingContext } from "../a2ui/BindingContext";
8
- import { AnsweredValuesProvider } from "../answeredValues";
9
- import { FIELD_VALUE_ATTR } from "../constants";
10
- import { renderGenerativeUI } from "../renderGenerativeUI";
11
- import { normalizeTemporalInputValue } from "../temporal";
12
- import type { GenerativeUIDispatch } from "../types";
13
- import { defaultGenerativeUILibrary } from "./index";
14
- import { interactiveVocabulary } from "./interactive";
15
- import { collectFormValues } from "./collectFormValues";
16
-
17
- (
18
- globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
19
- ).IS_REACT_ACT_ENVIRONMENT = true;
20
-
21
- let root: Root | undefined;
22
-
23
- afterEach(async () => {
24
- await React.act(async () => root?.unmount());
25
- root = undefined;
26
- document.body.innerHTML = "";
27
- vi.restoreAllMocks();
28
- });
29
-
30
- const view = (
31
- props: Record<string, unknown>,
32
- dispatch?: GenerativeUIDispatch,
33
- ) =>
34
- renderGenerativeUI(
35
- { $type: "DatePicker", label: "When", name: "when", ...props },
36
- interactiveVocabulary,
37
- { status: "done", ...(dispatch ? { dispatch } : {}) },
38
- );
39
-
40
- const mount = async (element: React.ReactNode) => {
41
- const container = document.createElement("div");
42
- document.body.append(container);
43
- root = createRoot(container);
44
- await React.act(async () => root!.render(element));
45
- return container;
46
- };
47
-
48
- const change = async (input: HTMLInputElement, value: string) => {
49
- await React.act(async () => {
50
- Object.getOwnPropertyDescriptor(
51
- HTMLInputElement.prototype,
52
- "value",
53
- )!.set!.call(input, value);
54
- input.dispatchEvent(new Event("input", { bubbles: true }));
55
- });
56
- };
57
-
58
- const nativeValue = (type: string, value: string) => {
59
- const input = document.createElement("input");
60
- input.type = type;
61
- input.value = value;
62
- return input.value;
63
- };
64
-
65
- const normalizedNativeValue = (type: string, value: string) =>
66
- normalizeTemporalInputValue(nativeValue(type, value));
67
-
68
- describe("DatePicker temporal contract", () => {
69
- it.each([
70
- ["2026-07-15T12:34Z", "2026-07-16T13:45Z", ""],
71
- ["2026-07-15T12:34:56+08:00", "2026-07-16T21:45:00+08:00", "1"],
72
- [
73
- "2026-07-15T12:34:56.123456-00:00",
74
- "2026-07-16T13:45:00.000000-00:00",
75
- "any",
76
- ],
77
- ])(
78
- "preserves the anchor through an empty segment edit of %s",
79
- async (value, emitted, step) => {
80
- const dispatch = vi.fn();
81
- const container = await mount(
82
- view(
83
- { inputType: "datetime", value, $action: { type: "save" } },
84
- dispatch,
85
- ),
86
- );
87
- const input = container.querySelector("input")!;
88
- await change(input, "2026-07-16T08:30");
89
- expect(input.step).toBe(step);
90
- await change(input, "");
91
- expect(dispatch).toHaveBeenLastCalledWith({ type: "save", $input: "" });
92
- expect(collectFormValues([input])).toEqual({ when: "" });
93
- expect(input.step).toBe(step);
94
- await change(input, "2026-07-16T09:45");
95
- expect(dispatch).toHaveBeenLastCalledWith({
96
- type: "save",
97
- $input: emitted,
98
- });
99
- expect(collectFormValues([input])).toEqual({ when: emitted });
100
- expect(input.step).toBe(step);
101
- },
102
- );
103
-
104
- it("submits an edited instant fraction", async () => {
105
- const dispatch = vi.fn();
106
- const container = await mount(
107
- view(
108
- {
109
- inputType: "datetime",
110
- value: "2025-12-15T17:00:00.250Z",
111
- $action: { type: "save" },
112
- },
113
- dispatch,
114
- ),
115
- );
116
- const input = container.querySelector("input")!;
117
- await change(input, "2025-12-15T12:00:00.750");
118
- expect(dispatch).toHaveBeenLastCalledWith({
119
- type: "save",
120
- $input: "2025-12-15T17:00:00.750Z",
121
- });
122
- expect(collectFormValues([input])).toEqual({
123
- when: "2025-12-15T17:00:00.750Z",
124
- });
125
- });
126
-
127
- it.each(["2025-11-02T01:30:00.25", "2025-11-02T01:30:00.250"])(
128
- "submits an untouched repeated hour instant when the browser reports %s",
129
- async (reported) => {
130
- const anchor = "2025-11-02T06:30:00.250Z";
131
- const container = await mount(
132
- view({ inputType: "datetime", value: anchor }),
133
- );
134
- const input = container.querySelector("input")!;
135
- vi.spyOn(input, "value", "get").mockReturnValue(reported);
136
- expect(collectFormValues([input])).toEqual({ when: anchor });
137
- },
138
- );
139
-
140
- it.each([
141
- [
142
- "2026-07-15T12:34:56.123456Z",
143
- "2026-07-15T08:34:56.123",
144
- "2026-07-16T08:34:56.123",
145
- "2026-07-16T12:34:56.123456Z",
146
- ],
147
- [
148
- "2026-07-15T12:34:56.5Z",
149
- "2026-07-15T08:34:56.500",
150
- "2026-07-16T08:34:56.500",
151
- "2026-07-16T12:34:56.5Z",
152
- ],
153
- ])(
154
- "keeps the fraction's precision when only the day changes from %s",
155
- async (value, displayed, edited, emitted) => {
156
- const dispatch = vi.fn();
157
- const container = await mount(
158
- view(
159
- { inputType: "datetime", value, $action: { type: "save" } },
160
- dispatch,
161
- ),
162
- );
163
- const input = container.querySelector("input")!;
164
- expect(input.value).toBe(nativeValue(input.type, displayed));
165
- if (value === "2026-07-15T12:34:56.5Z") {
166
- expect(input.getAttribute("value")).toBe("2026-07-15T08:34:56.500");
167
- expect(input.value).toBe("2026-07-15T08:34:56.5");
168
- expect(collectFormValues([input])).toEqual({ when: value });
169
- }
170
- await change(input, edited);
171
- expect(dispatch).toHaveBeenLastCalledWith({
172
- type: "save",
173
- $input: emitted,
174
- });
175
- expect(collectFormValues([input])).toEqual({ when: emitted });
176
- },
177
- );
178
-
179
- it("pads edited milliseconds to the anchor precision", async () => {
180
- const dispatch = vi.fn();
181
- const container = await mount(
182
- view(
183
- {
184
- inputType: "datetime",
185
- value: "2026-07-15T12:34:56.123456Z",
186
- $action: { type: "save" },
187
- },
188
- dispatch,
189
- ),
190
- );
191
- const input = container.querySelector("input")!;
192
- await change(input, "2026-07-16T08:34:56.789");
193
- expect(dispatch).toHaveBeenLastCalledWith({
194
- type: "save",
195
- $input: "2026-07-16T12:34:56.789000Z",
196
- });
197
- });
198
-
199
- it("submits a cleared instant fraction in its original offset", async () => {
200
- const dispatch = vi.fn();
201
- const container = await mount(
202
- renderGenerativeUI(
203
- {
204
- $type: "Form",
205
- $action: { type: "submit" },
206
- children: [
207
- {
208
- $type: "DatePicker",
209
- name: "when",
210
- inputType: "datetime",
211
- value: "2025-12-15T17:00:00.250-00:00",
212
- },
213
- { $type: "Button", label: "Submit", submit: true },
214
- ],
215
- },
216
- defaultGenerativeUILibrary,
217
- { status: "done", dispatch },
218
- ),
219
- );
220
- const input = container.querySelector("input")!;
221
- expect(input.step).toBe("any");
222
- expect(input.value).toBe(
223
- nativeValue(input.type, "2025-12-15T12:00:00.250"),
224
- );
225
- await change(input, "2025-12-15T12:00:00");
226
- expect(input.value).toBe(nativeValue(input.type, "2025-12-15T12:00:00"));
227
- await React.act(async () => container.querySelector("button")!.click());
228
- expect(dispatch).toHaveBeenLastCalledWith({
229
- type: "submit",
230
- $input: { when: "2025-12-15T17:00:00.000-00:00" },
231
- });
232
- });
233
-
234
- it.each([
235
- [
236
- "datetime",
237
- "2026-07-15T12:34:56",
238
- "2026-07-15T12:34:56",
239
- "2026-07-16T09:45:30.500",
240
- "2026-07-16T09:45:30.5",
241
- ],
242
- [
243
- "datetime",
244
- "2026-07-15T12:34:56.500",
245
- "2026-07-15T12:34:56.5",
246
- "2026-07-16T09:45:30.000",
247
- "2026-07-16T09:45:30",
248
- ],
249
- ["time", "12:34:56", "12:34:56", "13:45:30.500", "13:45:30.5"],
250
- ["time", "12:34:56.500", "12:34:56.5", "13:45:30.000", "13:45:30"],
251
- ])(
252
- "dispatches and binds the shortest edited %s value",
253
- async (inputType, value, shown, edited, emitted) => {
254
- const update = vi.fn();
255
- const dispatch = vi.fn();
256
- const BindingContext = A2uiBindingContext!;
257
- const Surface = () => {
258
- const [current, setCurrent] = React.useState(value);
259
- return (
260
- <BindingContext.Provider
261
- value={{
262
- fields: new Map([
263
- ["when", { value: current, arrayValue: false }],
264
- ]),
265
- update: (path, next) => {
266
- update(path, next);
267
- setCurrent(String(next));
268
- },
269
- }}
270
- >
271
- {view(
272
- { inputType, value: current, $action: { type: "save" } },
273
- dispatch,
274
- )}
275
- <output>{current}</output>
276
- </BindingContext.Provider>
277
- );
278
- };
279
- const container = await mount(<Surface />);
280
- const input = container.querySelector("input")!;
281
- expect(input.getAttribute("value")).toBe(shown);
282
- await change(input, edited);
283
- expect(update).toHaveBeenLastCalledWith("when", emitted);
284
- expect(dispatch).toHaveBeenLastCalledWith({
285
- type: "save",
286
- $input: emitted,
287
- });
288
- expect(container.querySelector("output")!.textContent).toBe(emitted);
289
- expect(collectFormValues([input])).toEqual({ when: emitted });
290
- expect(input.getAttribute("value")).toBe(emitted);
291
- },
292
- );
293
-
294
- it("uses shortest edited floating values in $field reads and Form submits", async () => {
295
- const dispatch = vi.fn();
296
- const container = await mount(
297
- <div data-aui="root">
298
- {renderGenerativeUI(
299
- {
300
- $type: "Form",
301
- $action: { type: "submit" },
302
- children: [
303
- {
304
- $type: "DatePicker",
305
- name: "when",
306
- inputType: "datetime",
307
- value: "2025-12-15T17:00:05.500",
308
- },
309
- { $type: "Button", label: "Submit", submit: true },
310
- {
311
- $type: "Button",
312
- label: "Reference",
313
- $action: { type: "reference", when: { $field: "when" } },
314
- },
315
- ],
316
- },
317
- defaultGenerativeUILibrary,
318
- { status: "done", dispatch },
319
- )}
320
- </div>,
321
- );
322
- const input = container.querySelector("input")!;
323
- const [submit, reference] = container.querySelectorAll("button");
324
- await change(input, "2025-12-16T08:30:45.500");
325
- expect(input.getAttribute("value")).toBe("2025-12-16T08:30:45.5");
326
- expect(input.value).toBe("2025-12-16T08:30:45.5");
327
- await React.act(async () => reference!.click());
328
- expect(dispatch).toHaveBeenLastCalledWith({
329
- type: "reference",
330
- when: "2025-12-16T08:30:45.5",
331
- });
332
- await React.act(async () => submit!.click());
333
- expect(dispatch).toHaveBeenLastCalledWith({
334
- type: "submit",
335
- $input: { when: "2025-12-16T08:30:45.5" },
336
- });
337
- await change(input, "2025-12-16T08:30:45.000");
338
- await React.act(async () => reference!.click());
339
- expect(dispatch).toHaveBeenLastCalledWith({
340
- type: "reference",
341
- when: "2025-12-16T08:30:45",
342
- });
343
- await React.act(async () => submit!.click());
344
- expect(dispatch).toHaveBeenLastCalledWith({
345
- type: "submit",
346
- $input: { when: "2025-12-16T08:30:45" },
347
- });
348
- });
349
-
350
- it("preserves the anchor through binding echoes and replaces it on an external update", async () => {
351
- const dispatch = vi.fn();
352
- const BindingContext = A2uiBindingContext!;
353
- let replace: React.Dispatch<React.SetStateAction<string>> | undefined;
354
- const Surface = () => {
355
- const [value, setValue] = React.useState("2026-07-15T12:34-00:00");
356
- replace = setValue;
357
- return (
358
- <BindingContext.Provider
359
- value={{
360
- fields: new Map([["when", { value, arrayValue: false }]]),
361
- update: (_, next) => setValue(String(next)),
362
- }}
363
- >
364
- {view(
365
- { inputType: "datetime", value, $action: { type: "save" } },
366
- dispatch,
367
- )}
368
- </BindingContext.Provider>
369
- );
370
- };
371
- const container = await mount(<Surface />);
372
- const input = container.querySelector("input")!;
373
- await change(input, "2026-07-16T08:30");
374
- await change(input, "");
375
- expect(input.step).toBe("");
376
- await change(input, "2026-07-16T09:45");
377
- expect(dispatch).toHaveBeenLastCalledWith({
378
- type: "save",
379
- $input: "2026-07-16T13:45-00:00",
380
- });
381
- expect(input.step).toBe("");
382
- await React.act(async () => replace!("2026-07-17T12:34:56+08:00"));
383
- await change(input, "");
384
- expect(input.step).toBe("1");
385
- await change(input, "2026-07-18T09:45:30");
386
- expect(dispatch).toHaveBeenLastCalledWith({
387
- type: "save",
388
- $input: "2026-07-18T21:45:30+08:00",
389
- });
390
- });
391
-
392
- it("submits the sanitized live value of an invalid date", async () => {
393
- const container = await mount(view({ value: "12/15/2025" }));
394
- const input = container.querySelector("input")!;
395
- expect(input.value).toBe("");
396
- expect(input.hasAttribute(FIELD_VALUE_ATTR)).toBe(false);
397
- expect(collectFormValues([input])).toEqual({ when: "" });
398
- });
399
-
400
- it.each([
401
- ["2025-12-15T17:00Z", "2025-12-16T14:30Z"],
402
- ["2025-12-15T17:00:00.120000-00:00", "2025-12-16T14:30:00.000000-00:00"],
403
- ])(
404
- "collects the live instant without an input event using %s",
405
- async (value, emitted) => {
406
- const container = await mount(view({ inputType: "datetime", value }));
407
- const input = container.querySelector("input")!;
408
- expect(collectFormValues([input])).toEqual({ when: value });
409
- input.value = "2025-12-16T09:30";
410
- expect(collectFormValues([input])).toEqual({ when: emitted });
411
- input.value = "";
412
- expect(collectFormValues([input])).toEqual({ when: "" });
413
- },
414
- );
415
-
416
- it.each([
417
- {
418
- value: "2026-07-15T12:34:56.123",
419
- min: "2026-07-15T12:00:00",
420
- max: "2026-07-15T13:00:00",
421
- },
422
- {
423
- value: "2026-07-15T12:34:56",
424
- min: "2026-07-15T12:00:00.123",
425
- max: "2026-07-15T13:00:00",
426
- },
427
- {
428
- value: "2026-07-15T12:34:56",
429
- min: "2026-07-15T12:00:00",
430
- max: "2026-07-15T13:00:00.123",
431
- },
432
- ])(
433
- "allows fractional local values and bounds without step mismatch: $value, $min, $max",
434
- async (props) => {
435
- const container = await mount(view({ inputType: "datetime", ...props }));
436
- const input = container.querySelector("input")!;
437
- expect(input.step).toBe("any");
438
- expect(input.validity.stepMismatch).toBe(false);
439
- expect(input.checkValidity()).toBe(true);
440
- },
441
- );
442
-
443
- it("preserves fractional instant bounds in the viewer time zone", async () => {
444
- const container = await mount(
445
- view({
446
- inputType: "datetime",
447
- value: "2026-07-15T12:34Z",
448
- min: "2026-07-15T12:00:00.123+08:00",
449
- max: "2026-07-15T13:00:00.456789-05:30",
450
- }),
451
- );
452
- const input = container.querySelector("input")!;
453
- expect(input.min).toBe("2026-07-15T00:00:00.123");
454
- expect(input.max).toBe("2026-07-15T14:30:00.456");
455
- expect(input.step).toBe("any");
456
- expect(input.validity.stepMismatch).toBe(false);
457
- });
458
-
459
- it.each([
460
- [
461
- "2025-12-15T17:00:00Z",
462
- "2025-12-15T12:00",
463
- "2025-12-16T14:30:00Z",
464
- "2025-12-17T14:30:00Z",
465
- ],
466
- [
467
- "2025-12-15T17:00:00+02:00",
468
- "2025-12-15T10:00",
469
- "2025-12-16T16:30:00+02:00",
470
- "2025-12-17T16:30:00+02:00",
471
- ],
472
- ])(
473
- "submits and resolves canonical instant %s before and after editing",
474
- async (initial, displayed, edited, autofilled) => {
475
- const dispatch = vi.fn();
476
- const tree = (
477
- <div data-aui="root">
478
- {renderGenerativeUI(
479
- {
480
- $type: "Form",
481
- $action: { type: "submit" },
482
- children: [
483
- {
484
- $type: "DatePicker",
485
- name: "when",
486
- inputType: "datetime",
487
- value: initial,
488
- $action: { type: "picker", when: { $field: "when" } },
489
- },
490
- { $type: "Button", label: "Submit", submit: true },
491
- {
492
- $type: "Button",
493
- label: "Reference",
494
- $action: { type: "reference", when: { $field: "when" } },
495
- },
496
- ],
497
- },
498
- defaultGenerativeUILibrary,
499
- { status: "done", dispatch },
500
- )}
501
- </div>
502
- );
503
- const container = await mount(tree);
504
- const input = container.querySelector("input")!;
505
- const [submit, reference] = container.querySelectorAll("button");
506
- expect(input.value).toBe(displayed);
507
- expect(input.getAttribute(FIELD_VALUE_ATTR)).toBe(initial);
508
- await React.act(async () => reference!.click());
509
- expect(dispatch).toHaveBeenLastCalledWith({
510
- type: "reference",
511
- when: initial,
512
- });
513
- await React.act(async () => submit!.click());
514
- expect(dispatch).toHaveBeenLastCalledWith({
515
- type: "submit",
516
- $input: { when: initial },
517
- });
518
- await change(input, "2025-12-16T09:30");
519
- expect(dispatch).toHaveBeenLastCalledWith({
520
- type: "picker",
521
- when: edited,
522
- $input: edited,
523
- });
524
- expect(input.getAttribute(FIELD_VALUE_ATTR)).toBe(edited);
525
- await React.act(async () => reference!.click());
526
- expect(dispatch).toHaveBeenLastCalledWith({
527
- type: "reference",
528
- when: edited,
529
- });
530
- await React.act(async () => submit!.click());
531
- expect(dispatch).toHaveBeenLastCalledWith({
532
- type: "submit",
533
- $input: { when: edited },
534
- });
535
- input.value = "2025-12-17T09:30";
536
- expect(input.getAttribute(FIELD_VALUE_ATTR)).toBe(edited);
537
- await React.act(async () => reference!.click());
538
- expect(dispatch).toHaveBeenLastCalledWith({
539
- type: "reference",
540
- when: autofilled,
541
- });
542
- await React.act(async () => submit!.click());
543
- expect(dispatch).toHaveBeenLastCalledWith({
544
- type: "submit",
545
- $input: { when: autofilled },
546
- });
547
- input.value = "";
548
- await React.act(async () => reference!.click());
549
- expect(dispatch).toHaveBeenLastCalledWith({
550
- type: "reference",
551
- when: "",
552
- });
553
- await React.act(async () => submit!.click());
554
- expect(dispatch).toHaveBeenLastCalledWith({
555
- type: "submit",
556
- $input: { when: "" },
557
- });
558
- },
559
- );
560
-
561
- it.each([
562
- ["time", "17:00:00", "17:00", "08:30:45"],
563
- ["time", "12:00:05.1200", "12:00:05.12", "08:30"],
564
- ["datetime", "2025-12-15T17:00:00", "2025-12-15T17:00", "2025-12-16T08:30"],
565
- ])(
566
- "preserves a canonical %s value through Form and $field",
567
- async (inputType, initial, displayed, edited) => {
568
- const dispatch = vi.fn();
569
- const container = await mount(
570
- <div data-aui="root">
571
- {renderGenerativeUI(
572
- {
573
- $type: "Form",
574
- $action: { type: "submit" },
575
- children: [
576
- {
577
- $type: "DatePicker",
578
- name: "when",
579
- inputType,
580
- value: initial,
581
- },
582
- { $type: "Button", label: "Submit", submit: true },
583
- {
584
- $type: "Button",
585
- label: "Reference",
586
- $action: { type: "reference", when: { $field: "when" } },
587
- },
588
- ],
589
- },
590
- defaultGenerativeUILibrary,
591
- { status: "done", dispatch },
592
- )}
593
- </div>,
594
- );
595
- const input = container.querySelector("input")!;
596
- const [submit, reference] = container.querySelectorAll("button");
597
- expect(input.value).toBe(displayed);
598
- expect(input.getAttribute(FIELD_VALUE_ATTR)).toBe(initial);
599
- await React.act(async () => reference!.click());
600
- expect(dispatch).toHaveBeenLastCalledWith({
601
- type: "reference",
602
- when: initial,
603
- });
604
- await React.act(async () => submit!.click());
605
- expect(dispatch).toHaveBeenLastCalledWith({
606
- type: "submit",
607
- $input: { when: initial },
608
- });
609
-
610
- await change(input, edited);
611
- expect(input.value).toBe(edited);
612
- expect(input.hasAttribute(FIELD_VALUE_ATTR)).toBe(false);
613
- await React.act(async () => reference!.click());
614
- expect(dispatch).toHaveBeenLastCalledWith({
615
- type: "reference",
616
- when: edited,
617
- });
618
- await React.act(async () => submit!.click());
619
- expect(dispatch).toHaveBeenLastCalledWith({
620
- type: "submit",
621
- $input: { when: edited },
622
- });
623
-
624
- input.value = "";
625
- await React.act(async () => reference!.click());
626
- expect(dispatch).toHaveBeenLastCalledWith({
627
- type: "reference",
628
- when: "",
629
- });
630
- await React.act(async () => submit!.click());
631
- expect(dispatch).toHaveBeenLastCalledWith({
632
- type: "submit",
633
- $input: { when: "" },
634
- });
635
- },
636
- );
637
-
638
- it("submits a filled initially empty datetime as an instant in the viewer offset", async () => {
639
- const dispatch = vi.fn();
640
- const container = await mount(
641
- <div data-aui="root">
642
- {renderGenerativeUI(
643
- {
644
- $type: "Form",
645
- $action: { type: "submit" },
646
- children: [
647
- { $type: "DatePicker", name: "when", inputType: "datetime" },
648
- { $type: "Button", label: "Submit", submit: true },
649
- {
650
- $type: "Button",
651
- label: "Reference",
652
- $action: { type: "reference", when: { $field: "when" } },
653
- },
654
- ],
655
- },
656
- defaultGenerativeUILibrary,
657
- { status: "done", dispatch },
658
- )}
659
- </div>,
660
- );
661
- const input = container.querySelector("input")!;
662
- const [submit, reference] = container.querySelectorAll("button");
663
- expect(input.hasAttribute(FIELD_VALUE_ATTR)).toBe(false);
664
-
665
- await change(input, "2025-12-15T09:00");
666
- await React.act(async () => submit!.click());
667
- expect(dispatch).toHaveBeenLastCalledWith({
668
- type: "submit",
669
- $input: { when: "2025-12-15T09:00:00-05:00" },
670
- });
671
- await React.act(async () => reference!.click());
672
- expect(dispatch).toHaveBeenLastCalledWith({
673
- type: "reference",
674
- when: "2025-12-15T09:00:00-05:00",
675
- });
676
- });
677
-
678
- it.each([
679
- ["time", "12:00:00", "12:00", "12:00:00", "1"],
680
- ["time", "12:00:05.1200", "12:00:05.12", "12:00:05.1200", "any"],
681
- ["time", "12:00:05.123456", "12:00:05.123", "12:00:05.123456", "any"],
682
- [
683
- "datetime",
684
- "2025-12-15T12:00:05.123456",
685
- "2025-12-15T12:00:05.123",
686
- "2025-12-15T12:00:05.123456",
687
- "any",
688
- ],
689
- [
690
- "datetime",
691
- "2025-12-15T17:00:00Z",
692
- "2025-12-15T12:00",
693
- "2025-12-15T17:00:00Z",
694
- "1",
695
- ],
696
- ])(
697
- "normalizes %s without rewriting the input on rerender",
698
- async (inputType, canonical, normalized, fieldValue, step) => {
699
- const setter = vi.spyOn(HTMLInputElement.prototype, "value", "set");
700
- const container = await mount(view({ inputType, value: canonical }));
701
- const input = container.querySelector("input")!;
702
- expect(input.value).toBe(normalized);
703
- expect(input.getAttribute("value")).toBe(normalized);
704
- expect(input.getAttribute(FIELD_VALUE_ATTR)).toBe(fieldValue);
705
- expect(collectFormValues([input])).toEqual({
706
- when: fieldValue ?? normalized,
707
- });
708
- expect(input.step).toBe(step);
709
- const calls = setter.mock.calls.length;
710
- await React.act(async () =>
711
- root!.render(view({ inputType, value: canonical })),
712
- );
713
- expect(setter.mock.calls.length).toBe(calls);
714
- },
715
- );
716
-
717
- it("uses a fixed viewer time zone", () => {
718
- expect(Intl.DateTimeFormat().resolvedOptions().timeZone).toBe(
719
- "America/New_York",
720
- );
721
- expect(new Date("2026-07-15T12:00Z").getTimezoneOffset()).toBe(240);
722
- });
723
-
724
- it("declares the three temporal input types and defaults to date", async () => {
725
- const schema = interactiveVocabulary.DatePicker.properties;
726
- for (const inputType of ["date", "datetime", "time"]) {
727
- expect(schema.safeParse({ inputType }).success).toBe(true);
728
- }
729
- expect(schema.safeParse({}).success).toBe(true);
730
- expect(schema.safeParse({ inputType: "datetime-local" }).success).toBe(
731
- false,
732
- );
733
- const container = await mount(view({ value: "2026-07-15" }));
734
- expect(container.querySelector("input")!.type).toBe("date");
735
- });
736
-
737
- it.each([
738
- {
739
- value: "2026-07-15T12:34Z",
740
- displayed: "2026-07-15T08:34",
741
- edited: "2026-07-16T09:45",
742
- emitted: "2026-07-16T13:45Z",
743
- step: "",
744
- },
745
- {
746
- value: "2026-07-15T12:34:56+08:00",
747
- displayed: "2026-07-15T00:34:56",
748
- edited: "2026-07-16T09:45:30",
749
- emitted: "2026-07-16T21:45:30+08:00",
750
- step: "1",
751
- },
752
- {
753
- value: "2026-07-15T12:34:56.123456-05:30",
754
- displayed: "2026-07-15T14:04:56.123",
755
- edited: "2026-07-16T09:45:30",
756
- emitted: "2026-07-16T08:15:30.000000-05:30",
757
- step: "any",
758
- },
759
- ])(
760
- "shows $value locally on the first client render and submits its offset and precision",
761
- async ({ value, displayed, edited, emitted, step }) => {
762
- const dispatch = vi.fn();
763
- let firstType: string | undefined;
764
- const Capture = () => (
765
- <div
766
- ref={(element) => {
767
- if (element && firstType === undefined) {
768
- firstType = element.querySelector("input")!.type;
769
- }
770
- }}
771
- >
772
- {view(
773
- { inputType: "datetime", value, $action: { type: "save" } },
774
- dispatch,
775
- )}
776
- </div>
777
- );
778
- const container = await mount(<Capture />);
779
- const input = container.querySelector("input")!;
780
- expect(firstType).toBe("datetime-local");
781
- expect(input.getAttribute("value")).toBe(displayed);
782
- expect(input.value).toBe(nativeValue("datetime-local", displayed));
783
- expect(input.step).toBe(step);
784
- expect(input.getAttribute("aria-label")).toBe("When");
785
- expect(input.name).toBe("when");
786
- expect(input.readOnly).toBe(false);
787
- await change(input, edited);
788
- expect(dispatch).toHaveBeenLastCalledWith({
789
- type: "save",
790
- $input: emitted,
791
- });
792
- expect(input.value).toBe(nativeValue("datetime-local", edited));
793
- },
794
- );
795
-
796
- it("converts instant bounds and preserves floating bounds", async () => {
797
- const container = await mount(
798
- view({
799
- inputType: "datetime",
800
- value: "2026-07-15T12:34Z",
801
- min: "2026-07-15T00:00:30+08:00",
802
- max: "2026-07-16T23:59:45-05:30",
803
- }),
804
- );
805
- const input = container.querySelector("input")!;
806
- expect(input.min).toBe("2026-07-14T12:00:30");
807
- expect(input.max).toBe("2026-07-17T01:29:45");
808
- await React.act(async () =>
809
- root!.render(
810
- view({
811
- inputType: "datetime",
812
- value: "2026-07-15T12:34Z",
813
- min: "2026-07-15T01:00",
814
- max: "2026-07-15T22:00",
815
- }),
816
- ),
817
- );
818
- expect(input.min).toBe("2026-07-15T01:00");
819
- expect(input.max).toBe("2026-07-15T22:00");
820
- });
821
-
822
- it("normalizes local and converted instant bounds", async () => {
823
- const container = await mount(
824
- view({
825
- inputType: "datetime",
826
- value: "2025-12-15T17:00:00Z",
827
- min: "2025-12-15T17:00:00Z",
828
- max: "2025-12-15T20:00:05.1200",
829
- }),
830
- );
831
- const input = container.querySelector("input")!;
832
- expect(input.min).toBe("2025-12-15T12:00");
833
- expect(input.max).toBe("2025-12-15T20:00:05.12");
834
- });
835
-
836
- it.each([
837
- ["2026-01-15T12:34", "2026-01-15T12:34:00-05:00"],
838
- ["2026-07-15T12:34", "2026-07-15T12:34:00-04:00"],
839
- ])(
840
- "submits an empty datetime with the viewer offset at %s",
841
- async (edited, emitted) => {
842
- const dispatch = vi.fn();
843
- const container = await mount(
844
- view({ inputType: "datetime", $action: { type: "save" } }, dispatch),
845
- );
846
- const input = container.querySelector("input")!;
847
- expect(input.type).toBe("datetime-local");
848
- expect(input.value).toBe("");
849
- await change(input, edited!);
850
- expect(dispatch).toHaveBeenLastCalledWith({
851
- type: "save",
852
- $input: emitted,
853
- });
854
- expect(input.step).toBe("1");
855
- },
856
- );
857
-
858
- it("uses the viewer offset for each unbound edit of an initially empty picker", async () => {
859
- const dispatch = vi.fn();
860
- const container = await mount(
861
- view({ inputType: "datetime", $action: { type: "save" } }, dispatch),
862
- );
863
- const input = container.querySelector("input")!;
864
- await change(input, "2026-01-15T12:34");
865
- await change(input, "2026-07-15T12:34");
866
- expect(dispatch).toHaveBeenLastCalledWith({
867
- type: "save",
868
- $input: "2026-07-15T12:34:00-04:00",
869
- });
870
- await change(input, "");
871
- expect(dispatch).toHaveBeenLastCalledWith({ type: "save", $input: "" });
872
- await change(input, "2026-07-16T12:34");
873
- expect(dispatch).toHaveBeenLastCalledWith({
874
- type: "save",
875
- $input: "2026-07-16T12:34:00-04:00",
876
- });
877
- });
878
-
879
- it.each([
880
- {
881
- inputType: "date",
882
- value: "2026-07-15",
883
- min: "2026-01-01",
884
- max: "2026-12-31",
885
- edited: "2026-07-16",
886
- step: "",
887
- },
888
- {
889
- inputType: "time",
890
- value: "12:34",
891
- min: "09:00",
892
- max: "17:00",
893
- edited: "13:45",
894
- step: "",
895
- },
896
- {
897
- inputType: "time",
898
- value: "12:34:56",
899
- min: "09:00:01",
900
- max: "17:00:59",
901
- edited: "13:45:30",
902
- step: "1",
903
- },
904
- {
905
- inputType: "time",
906
- value: "12:34:56",
907
- min: "09:00:01",
908
- max: "17:00:59",
909
- edited: "13:45:30.500",
910
- step: "1",
911
- },
912
- {
913
- inputType: "datetime",
914
- value: "2026-07-15T12:34",
915
- min: "2026-07-15T09:00",
916
- max: "2026-07-15T17:00",
917
- edited: "2026-07-15T13:45",
918
- step: "",
919
- },
920
- {
921
- inputType: "datetime",
922
- value: "2026-07-15T12:34:56",
923
- min: "2026-07-15T09:00:01",
924
- max: "2026-07-15T17:00:59",
925
- edited: "2026-07-15T13:45:30",
926
- step: "1",
927
- },
928
- ])(
929
- "passes $inputType value $value and bounds through, then normalizes edits",
930
- async ({ inputType, value, min, max, edited, step }) => {
931
- const dispatch = vi.fn();
932
- const container = await mount(
933
- view(
934
- { inputType, value, min, max, $action: { type: "save" } },
935
- dispatch,
936
- ),
937
- );
938
- const input = container.querySelector("input")!;
939
- expect(input.type).toBe(
940
- inputType === "datetime" ? "datetime-local" : inputType,
941
- );
942
- expect(input.getAttribute("value")).toBe(value);
943
- expect(input.hasAttribute(FIELD_VALUE_ATTR)).toBe(false);
944
- expect(collectFormValues([input])).toEqual({
945
- when: normalizedNativeValue(input.type, value),
946
- });
947
- expect(input.value).toBe(nativeValue(input.type, value));
948
- expect(input.min).toBe(min);
949
- expect(input.max).toBe(max);
950
- expect(input.step).toBe(step);
951
- await change(input, edited);
952
- expect(dispatch).toHaveBeenLastCalledWith({
953
- type: "save",
954
- $input: normalizedNativeValue(input.type, edited),
955
- });
956
- expect(input.value).toBe(nativeValue(input.type, edited));
957
- expect(input.getAttribute(FIELD_VALUE_ATTR)).toBe(null);
958
- expect(collectFormValues([input])).toEqual({
959
- when: normalizedNativeValue(input.type, edited),
960
- });
961
- },
962
- );
963
-
964
- it.each([
965
- {
966
- inputType: "datetime",
967
- value: "2026-07-15T12:34:56+08:00",
968
- edited: "2026-07-16T09:45:30",
969
- emitted: "2026-07-16T21:45:30+08:00",
970
- hasInstantAnchor: true,
971
- },
972
- {
973
- inputType: "datetime",
974
- value: "",
975
- edited: "2026-07-16T09:45",
976
- emitted: "2026-07-16T09:45:00-04:00",
977
- hasInstantAnchor: false,
978
- },
979
- {
980
- inputType: "datetime",
981
- value: "2026-07-15T12:34",
982
- edited: "2026-07-16T09:45",
983
- emitted: "2026-07-16T09:45",
984
- hasInstantAnchor: false,
985
- },
986
- {
987
- inputType: "time",
988
- value: "12:34",
989
- edited: "09:45",
990
- emitted: "09:45",
991
- hasInstantAnchor: false,
992
- },
993
- ])(
994
- "sends the same $inputType value to the binding and action for $value",
995
- async ({ inputType, value, edited, emitted, hasInstantAnchor }) => {
996
- const update = vi.fn();
997
- const dispatch = vi.fn();
998
- const BindingContext = A2uiBindingContext!;
999
- const Surface = () => {
1000
- const [current, setCurrent] = React.useState(value);
1001
- return (
1002
- <BindingContext.Provider
1003
- value={{
1004
- fields: new Map([
1005
- ["when", { value: current, arrayValue: false }],
1006
- ]),
1007
- update: (path, next) => {
1008
- update(path, next);
1009
- setCurrent(String(next));
1010
- },
1011
- }}
1012
- >
1013
- {view(
1014
- { inputType, value: current, $action: { type: "save" } },
1015
- dispatch,
1016
- )}
1017
- <output>{current}</output>
1018
- </BindingContext.Provider>
1019
- );
1020
- };
1021
- const container = await mount(<Surface />);
1022
- const input = container.querySelector("input")!;
1023
- expect(input.getAttribute(FIELD_VALUE_ATTR)).toBe(
1024
- hasInstantAnchor ? value : null,
1025
- );
1026
- await change(input, edited);
1027
- expect(update).toHaveBeenLastCalledWith("when", emitted);
1028
- expect(dispatch).toHaveBeenLastCalledWith({
1029
- type: "save",
1030
- $input: emitted,
1031
- });
1032
- expect(container.querySelector("output")!.textContent).toBe(emitted);
1033
- expect(input.getAttribute(FIELD_VALUE_ATTR)).toBe(
1034
- hasInstantAnchor || /(?:Z|[+-]\d{2}:\d{2})$/.test(emitted)
1035
- ? emitted
1036
- : null,
1037
- );
1038
- expect(input.value).toBe(nativeValue(input.type, edited));
1039
- await change(input, "");
1040
- expect(update).toHaveBeenLastCalledWith("when", "");
1041
- expect(dispatch).toHaveBeenLastCalledWith({ type: "save", $input: "" });
1042
- },
1043
- );
1044
-
1045
- it("uses answered values and accepts later value replacements", async () => {
1046
- const dispatch = vi.fn();
1047
- const container = await mount(
1048
- <AnsweredValuesProvider values={{ when: "2026-07-15T12:34:56-05:30" }}>
1049
- {view(
1050
- {
1051
- inputType: "datetime",
1052
- value: "2026-07-15T12:34Z",
1053
- $action: { type: "save" },
1054
- },
1055
- dispatch,
1056
- )}
1057
- </AnsweredValuesProvider>,
1058
- );
1059
- let input = container.querySelector("input")!;
1060
- expect(input.value).toBe(
1061
- nativeValue("datetime-local", "2026-07-15T14:04:56"),
1062
- );
1063
- await change(input, "2026-07-16T09:45:30");
1064
- expect(dispatch).toHaveBeenLastCalledWith({
1065
- type: "save",
1066
- $input: "2026-07-16T08:15:30-05:30",
1067
- });
1068
- await React.act(async () =>
1069
- root!.render(
1070
- <AnsweredValuesProvider values={undefined}>
1071
- {view(
1072
- {
1073
- inputType: "datetime",
1074
- value: "2026-07-17T12:34:56+08:00",
1075
- $action: { type: "save" },
1076
- },
1077
- dispatch,
1078
- )}
1079
- </AnsweredValuesProvider>,
1080
- ),
1081
- );
1082
- input = container.querySelector("input")!;
1083
- expect(input.value).toBe(
1084
- nativeValue("datetime-local", "2026-07-17T00:34:56"),
1085
- );
1086
- await change(input, "2026-07-18T09:45:30");
1087
- expect(dispatch).toHaveBeenLastCalledWith({
1088
- type: "save",
1089
- $input: "2026-07-18T21:45:30+08:00",
1090
- });
1091
- });
1092
-
1093
- it("renders the raw instant on the server and hydrates without a mismatch", async () => {
1094
- const error = vi.spyOn(console, "error").mockImplementation(() => {});
1095
- const onRecoverableError = vi.fn();
1096
- const dispatch = vi.fn();
1097
- const tree = view(
1098
- {
1099
- inputType: "datetime",
1100
- value: "2026-07-15T12:34:56.123+08:00",
1101
- $action: { type: "save" },
1102
- },
1103
- dispatch,
1104
- );
1105
- const html = renderToString(tree);
1106
- expect(html).toContain('type="text"');
1107
- expect(html).toMatch(/readonly=""/i);
1108
- expect(html).toContain('value="2026-07-15T12:34:56.123+08:00"');
1109
- const container = document.createElement("div");
1110
- container.innerHTML = html;
1111
- document.body.append(container);
1112
- await React.act(async () => {
1113
- root = hydrateRoot(container, tree, { onRecoverableError });
1114
- });
1115
- const input = container.querySelector("input")!;
1116
- expect(input.type).toBe("datetime-local");
1117
- expect(input.readOnly).toBe(false);
1118
- expect(input.value).toBe(
1119
- nativeValue("datetime-local", "2026-07-15T00:34:56.123"),
1120
- );
1121
- await change(input, "2026-07-16T09:45:30");
1122
- expect(dispatch).toHaveBeenLastCalledWith({
1123
- type: "save",
1124
- $input: "2026-07-16T21:45:30.000+08:00",
1125
- });
1126
- expect(onRecoverableError).not.toHaveBeenCalled();
1127
- expect(error).not.toHaveBeenCalled();
1128
- });
1129
-
1130
- it.each([
1131
- { inputType: "date", value: "2026-07-15", type: "date" },
1132
- { inputType: "time", value: "12:34:56", type: "time" },
1133
- {
1134
- inputType: "datetime",
1135
- value: "2026-07-15T12:34:56.123",
1136
- type: "datetime-local",
1137
- },
1138
- { inputType: "datetime", value: "", type: "datetime-local" },
1139
- ])(
1140
- "server renders $inputType $value as an editable picker immediately",
1141
- ({ inputType, value, type }) => {
1142
- const html = renderToString(view({ inputType, value }));
1143
- expect(html).toContain(`type="${type}"`);
1144
- expect(html).toContain(`value="${value}"`);
1145
- expect(html.toLowerCase()).not.toContain("readonly");
1146
- },
1147
- );
1148
- });