@malloy-publisher/sdk 0.0.382-dev → 0.2.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 (277) hide show
  1. package/README.md +115 -95
  2. package/TREE_SHAKING.md +16 -11
  3. package/bunfig.toml +7 -0
  4. package/dist/ServerProvider-CTopDUWW.cjs.js +1 -0
  5. package/dist/ServerProvider-DUFPY6Rv.es.js +4072 -0
  6. package/dist/client/api.d.ts +3718 -1507
  7. package/dist/client/configuration.d.ts +1 -1
  8. package/dist/client/index.cjs.js +1 -1
  9. package/dist/client/index.d.ts +1 -1
  10. package/dist/client/index.es.js +85 -59
  11. package/dist/components/Connections/EditConnectionDialog.d.ts +2 -1
  12. package/dist/components/Connections/common.d.ts +8 -2
  13. package/dist/components/Dashboard/Dashboard.d.ts +49 -0
  14. package/dist/components/Dashboard/DashboardTile.d.ts +48 -0
  15. package/dist/components/Dashboard/index.d.ts +2 -0
  16. package/dist/components/DataAppViewer/DataAppViewer.d.ts +23 -0
  17. package/dist/components/DataAppViewer/index.d.ts +1 -0
  18. package/dist/components/Environment/Environment.d.ts +6 -0
  19. package/dist/components/Environment/index.d.ts +2 -0
  20. package/dist/components/Home/AddEnvironmentDialog.d.ts +1 -0
  21. package/dist/components/Home/DeleteEnvironmentDialog.d.ts +5 -0
  22. package/dist/components/Home/EditEnvironmentDialog.d.ts +7 -0
  23. package/dist/components/Home/Home.d.ts +2 -2
  24. package/dist/components/Materializations/CreateEnvMaterializationDialog.d.ts +14 -0
  25. package/dist/components/Materializations/CreateMaterializationDialog.d.ts +10 -0
  26. package/dist/components/Materializations/DeleteMaterializationDialog.d.ts +7 -0
  27. package/dist/components/Materializations/EnvironmentMaterializations.d.ts +7 -0
  28. package/dist/components/Materializations/ManifestView.d.ts +13 -0
  29. package/dist/components/Materializations/MaterializationDetailDialog.d.ts +9 -0
  30. package/dist/components/Materializations/MaterializationRunsList.d.ts +15 -0
  31. package/dist/components/Materializations/Materializations.d.ts +7 -0
  32. package/dist/components/Materializations/ScheduleCard.d.ts +20 -0
  33. package/dist/components/Materializations/SectionLabel.d.ts +10 -0
  34. package/dist/components/Materializations/SetScheduleDialog.d.ts +11 -0
  35. package/dist/components/Materializations/TriggerChip.d.ts +10 -0
  36. package/dist/components/Materializations/cron.d.ts +23 -0
  37. package/dist/components/Materializations/index.d.ts +2 -0
  38. package/dist/components/Materializations/utils.d.ts +46 -0
  39. package/dist/components/Notebook/Notebook.d.ts +47 -4
  40. package/dist/components/Notebook/NotebookCell.d.ts +37 -1
  41. package/dist/components/Notebook/runPlan.d.ts +29 -0
  42. package/dist/components/Notebook/types.d.ts +10 -0
  43. package/dist/components/Package/ContentTypeIcon.d.ts +31 -0
  44. package/dist/components/Package/Package.d.ts +1 -4
  45. package/dist/components/RenderedResult/RenderedResult.d.ts +7 -1
  46. package/dist/components/RenderedResult/ResultContainer.d.ts +5 -1
  47. package/dist/components/RenderedResult/renderLogs.d.ts +6 -0
  48. package/dist/components/ResultsDialog.d.ts +6 -1
  49. package/dist/components/ServerProvider.d.ts +28 -4
  50. package/dist/components/click_helper.d.ts +10 -1
  51. package/dist/components/drill/index.d.ts +3 -0
  52. package/dist/components/drill/markDrillableCells.d.ts +55 -0
  53. package/dist/components/drill/resolveDrill.d.ts +139 -0
  54. package/dist/components/drill/useDrill.d.ts +63 -0
  55. package/dist/components/given/GivenInput.d.ts +52 -0
  56. package/dist/components/given/GivensPanel.d.ts +47 -0
  57. package/dist/components/given/filterValue.d.ts +97 -0
  58. package/dist/components/given/index.d.ts +2 -0
  59. package/dist/components/given/paramCodec.d.ts +60 -0
  60. package/dist/components/given/utils.d.ts +17 -0
  61. package/dist/components/highlighter.d.ts +6 -1
  62. package/dist/components/index.d.ts +7 -2
  63. package/dist/components/styles.d.ts +47 -0
  64. package/dist/constants/docLinks.d.ts +12 -0
  65. package/dist/{core-YNpOLuB1.cjs.js → core-hLahnv0W.cjs.js} +1 -1
  66. package/dist/{core-CjeTkq8O.es.js → core-lb28vQkR.es.js} +1 -1
  67. package/dist/github-dark-BKL9xNgN.cjs.js +1 -0
  68. package/dist/github-dark-DenFmJkN.es.js +4 -0
  69. package/dist/hooks/givenValue.d.ts +10 -0
  70. package/dist/hooks/index.d.ts +4 -0
  71. package/dist/hooks/useDimensionFiltersFromSpec.d.ts +3 -3
  72. package/dist/hooks/useDimensionFiltersQuery.d.ts +3 -3
  73. package/dist/hooks/useDimensionalFilterRangeData.d.ts +4 -4
  74. package/dist/hooks/useGivensState.d.ts +64 -0
  75. package/dist/hooks/useModelGivens.d.ts +10 -0
  76. package/dist/hooks/useSuggestOptions.d.ts +78 -0
  77. package/dist/index-DvEanVgc.cjs.js +339 -0
  78. package/dist/{index-DRDu9kIV.es.js → index-txw04ZbN.es.js} +40531 -27964
  79. package/dist/index.cjs.js +1 -1
  80. package/dist/index.d.ts +4 -1
  81. package/dist/index.es.js +79 -48
  82. package/dist/malloy-explorer.css +12 -1
  83. package/dist/sdk.css +1 -1
  84. package/dist/theme/ThemeContext.d.ts +45 -0
  85. package/dist/theme/buildMalloyExplicitTheme.d.ts +34 -0
  86. package/dist/theme/buildTableCssVars.d.ts +25 -0
  87. package/dist/theme/buildVegaThemeOverride.d.ts +16 -0
  88. package/dist/theme/defaults.d.ts +7 -0
  89. package/dist/theme/index.d.ts +8 -0
  90. package/dist/theme/keys.d.ts +20 -0
  91. package/dist/theme/readChartAnnotations.d.ts +23 -0
  92. package/dist/theme/resolveTheme.d.ts +22 -0
  93. package/dist/theme/types.d.ts +70 -0
  94. package/dist/utils/dataAppEmbed.d.ts +44 -0
  95. package/dist/utils/formatting.d.ts +1 -1
  96. package/dist/utils/malloyString.d.ts +7 -0
  97. package/dist/utils/parsing.d.ts +2 -2
  98. package/dist/utils/queryClient.d.ts +5 -0
  99. package/package.json +19 -8
  100. package/src/client-entry.ts +3 -0
  101. package/src/components/AnalyzePackageButton.tsx +9 -3
  102. package/src/components/ApiErrorDisplay.tsx +3 -0
  103. package/src/components/Connections/AddConnectionDialog.tsx +30 -2
  104. package/src/components/Connections/DeleteConnectionDialog.tsx +14 -3
  105. package/src/components/Connections/EditConnectionDialog.tsx +33 -4
  106. package/src/components/Connections/common.ts +64 -1
  107. package/src/components/DOMElement/DOMElement.tsx +3 -0
  108. package/src/components/DOMElement/index.ts +3 -0
  109. package/src/components/Dashboard/Dashboard.tsx +398 -0
  110. package/src/components/Dashboard/DashboardTile.tsx +153 -0
  111. package/src/components/Dashboard/index.ts +5 -0
  112. package/src/components/DataAppViewer/DataAppViewer.tsx +214 -0
  113. package/src/components/DataAppViewer/index.ts +4 -0
  114. package/src/components/{Project → Environment}/About.tsx +11 -4
  115. package/src/components/Environment/AddPackageDialog.tsx +202 -0
  116. package/src/components/{Project → Environment}/ConnectionExplorer.tsx +17 -14
  117. package/src/components/Environment/Connections.tsx +391 -0
  118. package/src/components/{Project → Environment}/DeletePackageDialog.tsx +8 -4
  119. package/src/components/{Project → Environment}/EditPackageDialog.tsx +21 -13
  120. package/src/components/Environment/Environment.tsx +89 -0
  121. package/src/components/Environment/Packages.tsx +206 -0
  122. package/src/components/Environment/index.ts +5 -0
  123. package/src/components/Home/{AddProjectDialog.tsx → AddEnvironmentDialog.tsx} +25 -19
  124. package/src/components/Home/{DeleteProjectDialog.tsx → DeleteEnvironmentDialog.tsx} +20 -15
  125. package/src/components/Home/{EditProjectDialog.tsx → EditEnvironmentDialog.tsx} +35 -28
  126. package/src/components/Home/Home.tsx +386 -408
  127. package/src/components/Home/index.ts +3 -0
  128. package/src/components/Loading.tsx +3 -0
  129. package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +179 -0
  130. package/src/components/Materializations/CreateMaterializationDialog.tsx +112 -0
  131. package/src/components/Materializations/DeleteMaterializationDialog.tsx +109 -0
  132. package/src/components/Materializations/EnvironmentMaterializations.tsx +267 -0
  133. package/src/components/Materializations/ManifestView.tsx +87 -0
  134. package/src/components/Materializations/MaterializationDetailDialog.tsx +259 -0
  135. package/src/components/Materializations/MaterializationRunsList.tsx +256 -0
  136. package/src/components/Materializations/Materializations.tsx +355 -0
  137. package/src/components/Materializations/ScheduleCard.tsx +231 -0
  138. package/src/components/Materializations/SectionLabel.tsx +30 -0
  139. package/src/components/Materializations/SetScheduleDialog.tsx +162 -0
  140. package/src/components/Materializations/TriggerChip.tsx +44 -0
  141. package/src/components/Materializations/cron.ts +124 -0
  142. package/src/components/Materializations/index.ts +5 -0
  143. package/src/components/Materializations/utils.ts +145 -0
  144. package/src/components/Model/Model.tsx +44 -2
  145. package/src/components/Model/ModelCell.tsx +14 -5
  146. package/src/components/Model/ModelExplorer.tsx +3 -0
  147. package/src/components/Model/ModelExplorerDialog.tsx +4 -1
  148. package/src/components/Model/SourcesExplorer.tsx +9 -6
  149. package/src/components/Model/index.ts +3 -0
  150. package/src/components/Model/useModelData.ts +6 -3
  151. package/src/components/Notebook/Notebook.tsx +475 -339
  152. package/src/components/Notebook/NotebookCell.tsx +264 -25
  153. package/src/components/Notebook/index.ts +3 -0
  154. package/src/components/Notebook/runPlan.spec.ts +155 -0
  155. package/src/components/Notebook/runPlan.ts +67 -0
  156. package/src/components/Notebook/types.ts +14 -0
  157. package/src/components/Package/ContentTypeIcon.spec.ts +91 -0
  158. package/src/components/Package/ContentTypeIcon.tsx +177 -0
  159. package/src/components/Package/FileTreeView.tsx +3 -0
  160. package/src/components/Package/Models.tsx +7 -4
  161. package/src/components/Package/Package.tsx +666 -59
  162. package/src/components/Package/index.ts +3 -0
  163. package/src/components/QueryResult/QueryResult.tsx +17 -8
  164. package/src/components/QueryResult/index.ts +3 -0
  165. package/src/components/RenderedResult/RenderedResult.tsx +685 -67
  166. package/src/components/RenderedResult/ResultContainer.tsx +71 -2
  167. package/src/components/RenderedResult/index.ts +3 -0
  168. package/src/components/RenderedResult/renderLogs.spec.ts +58 -0
  169. package/src/components/RenderedResult/renderLogs.ts +43 -0
  170. package/src/components/ResultsDialog.tsx +13 -1
  171. package/src/components/ServerProvider.tsx +175 -51
  172. package/src/components/Workbook/BrowserWorkbookStorage.ts +3 -0
  173. package/src/components/Workbook/EditableMalloyCell.tsx +3 -0
  174. package/src/components/Workbook/ModelPicker.tsx +7 -4
  175. package/src/components/Workbook/MutableCell.tsx +10 -5
  176. package/src/components/Workbook/Workbook.tsx +8 -5
  177. package/src/components/Workbook/WorkbookList.tsx +3 -0
  178. package/src/components/Workbook/WorkbookManager.ts +3 -0
  179. package/src/components/Workbook/WorkbookStorage.ts +3 -0
  180. package/src/components/Workbook/WorkbookStorageProvider.tsx +3 -0
  181. package/src/components/Workbook/index.ts +3 -0
  182. package/src/components/click_helper.ts +17 -1
  183. package/src/components/drill/index.ts +28 -0
  184. package/src/components/drill/markDrillableCells.dom.spec.ts +313 -0
  185. package/src/components/drill/markDrillableCells.spec.ts +109 -0
  186. package/src/components/drill/markDrillableCells.ts +314 -0
  187. package/src/components/drill/resolveDrill.spec.ts +449 -0
  188. package/src/components/drill/resolveDrill.ts +375 -0
  189. package/src/components/drill/useDrill.tsx +203 -0
  190. package/src/components/filter/DimensionFilter.tsx +3 -0
  191. package/src/components/filter/index.ts +3 -0
  192. package/src/components/filter/utils.ts +16 -5
  193. package/src/components/given/GivenInput.spec.tsx +689 -0
  194. package/src/components/given/GivenInput.tsx +801 -0
  195. package/src/components/given/GivensPanel.spec.tsx +175 -0
  196. package/src/components/given/GivensPanel.tsx +195 -0
  197. package/src/components/given/filterValue.spec.ts +364 -0
  198. package/src/components/given/filterValue.ts +207 -0
  199. package/src/components/given/index.ts +9 -0
  200. package/src/components/given/paramCodec.spec.ts +857 -0
  201. package/src/components/given/paramCodec.ts +483 -0
  202. package/src/components/given/utils.spec.ts +60 -0
  203. package/src/components/given/utils.ts +79 -0
  204. package/src/components/highlighter.ts +22 -5
  205. package/src/components/index.ts +10 -2
  206. package/src/components/styles.ts +82 -33
  207. package/src/constants/docLinks.spec.ts +54 -0
  208. package/src/constants/docLinks.ts +46 -0
  209. package/src/hooks/givenValue.ts +13 -0
  210. package/src/hooks/index.ts +13 -0
  211. package/src/hooks/useDimensionFilters.ts +4 -7
  212. package/src/hooks/useDimensionFiltersFromSpec.ts +8 -5
  213. package/src/hooks/useDimensionFiltersQuery.ts +10 -13
  214. package/src/hooks/useDimensionalFilterRangeData.ts +11 -14
  215. package/src/hooks/useGivensState.spec.ts +449 -0
  216. package/src/hooks/useGivensState.ts +340 -0
  217. package/src/hooks/useModelGivens.ts +29 -0
  218. package/src/hooks/useQueryWithApiError.ts +3 -0
  219. package/src/hooks/useRawQueryData.ts +6 -3
  220. package/src/hooks/useSuggestOptions.spec.ts +112 -0
  221. package/src/hooks/useSuggestOptions.ts +263 -0
  222. package/src/index.ts +10 -1
  223. package/src/react-app-env.d.ts +3 -0
  224. package/src/theme/ThemeContext.tsx +86 -0
  225. package/src/theme/buildMalloyExplicitTheme.ts +61 -0
  226. package/src/theme/buildTableCssVars.spec.ts +67 -0
  227. package/src/theme/buildTableCssVars.ts +67 -0
  228. package/src/theme/buildVegaThemeOverride.spec.ts +56 -0
  229. package/src/theme/buildVegaThemeOverride.ts +47 -0
  230. package/src/theme/defaults.ts +78 -0
  231. package/src/theme/index.ts +11 -0
  232. package/src/theme/keys.ts +32 -0
  233. package/src/theme/readChartAnnotations.spec.ts +58 -0
  234. package/src/theme/readChartAnnotations.ts +69 -0
  235. package/src/theme/resolveTheme.spec.ts +160 -0
  236. package/src/theme/resolveTheme.ts +121 -0
  237. package/src/theme/types.ts +79 -0
  238. package/src/utils/dataAppEmbed.spec.ts +63 -0
  239. package/src/utils/dataAppEmbed.ts +84 -0
  240. package/src/utils/formatting.spec.ts +25 -21
  241. package/src/utils/formatting.ts +11 -7
  242. package/src/utils/malloyString.spec.ts +24 -0
  243. package/src/utils/malloyString.ts +12 -0
  244. package/src/utils/parsing.spec.ts +26 -19
  245. package/src/utils/parsing.ts +11 -6
  246. package/src/utils/queryClient.ts +17 -0
  247. package/test/README.md +141 -0
  248. package/test/setup.ts +29 -0
  249. package/tsconfig.json +12 -1
  250. package/tsconfig.spec.json +22 -0
  251. package/vite.config.ts +3 -0
  252. package/dist/ServerProvider-lOQXDlqB.cjs.js +0 -1
  253. package/dist/ServerProvider-on-8FH5Z.es.js +0 -3060
  254. package/dist/components/Home/AddProjectDialog.d.ts +0 -1
  255. package/dist/components/Home/DeleteProjectDialog.d.ts +0 -5
  256. package/dist/components/Home/EditProjectDialog.d.ts +0 -7
  257. package/dist/components/Package/Config.d.ts +0 -5
  258. package/dist/components/Package/Databases.d.ts +0 -5
  259. package/dist/components/Package/Notebooks.d.ts +0 -6
  260. package/dist/components/Project/Project.d.ts +0 -6
  261. package/dist/components/Project/index.d.ts +0 -2
  262. package/dist/index-BOLBP6_i.cjs.js +0 -233
  263. package/src/components/Package/Config.tsx +0 -97
  264. package/src/components/Package/Connections.tsx +0 -373
  265. package/src/components/Package/Databases.tsx +0 -228
  266. package/src/components/Package/Notebooks.tsx +0 -77
  267. package/src/components/Project/AddPackageDialog.tsx +0 -159
  268. package/src/components/Project/Packages.tsx +0 -191
  269. package/src/components/Project/Project.tsx +0 -52
  270. package/src/components/Project/index.ts +0 -2
  271. /package/dist/components/{Project → Environment}/About.d.ts +0 -0
  272. /package/dist/components/{Project → Environment}/AddPackageDialog.d.ts +0 -0
  273. /package/dist/components/{Project → Environment}/ConnectionExplorer.d.ts +0 -0
  274. /package/dist/components/{Package → Environment}/Connections.d.ts +0 -0
  275. /package/dist/components/{Project → Environment}/DeletePackageDialog.d.ts +0 -0
  276. /package/dist/components/{Project → Environment}/EditPackageDialog.d.ts +0 -0
  277. /package/dist/components/{Project → Environment}/Packages.d.ts +0 -0
@@ -0,0 +1,689 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it, mock } from "bun:test";
5
+ import { cleanup, fireEvent, render, screen } from "@testing-library/react";
6
+ import type { Given } from "../../client";
7
+ import type { GivenValue } from "../../hooks/givenValue";
8
+ import { GivenInput } from "./GivenInput";
9
+
10
+ /**
11
+ * Covers the three-state contract GivenInput's own doc comment specifies:
12
+ * unset vs. an explicit override (including `""` and `false`) vs. a revert.
13
+ * None of it had any verification before this suite.
14
+ *
15
+ * The distinction is not cosmetic: unset omits the given from the request so
16
+ * the server applies the model default, while an explicit `""` is sent
17
+ * verbatim. The only thing telling a user which state they are in is whether
18
+ * the clear (x) affordance is showing, so each test below asserts on it.
19
+ */
20
+
21
+ const clearButtons = () => screen.queryAllByLabelText("clear value");
22
+
23
+ describe("GivenInput: unset vs. explicit override", () => {
24
+ it("unset shows the model default as a placeholder and offers no revert", () => {
25
+ render(
26
+ <GivenInput
27
+ given={{ name: "region", type: "string", default: "'WN'" }}
28
+ value={undefined}
29
+ onChange={() => {}}
30
+ />,
31
+ );
32
+
33
+ const input = screen.getByLabelText("region") as HTMLInputElement;
34
+ expect(input.value).toBe("");
35
+ expect(input.placeholder).toBe("WN");
36
+ // Nothing to revert to: the widget is already showing the default.
37
+ expect(clearButtons()).toHaveLength(0);
38
+ });
39
+
40
+ it("an explicit empty string is an override, not an unset", () => {
41
+ render(
42
+ <GivenInput
43
+ given={{ name: "region", type: "string", default: "'WN'" }}
44
+ value=""
45
+ onChange={() => {}}
46
+ />,
47
+ );
48
+
49
+ const input = screen.getByLabelText("region") as HTMLInputElement;
50
+ expect(input.value).toBe("");
51
+ // The ghost default is suppressed and the revert appears, which is the
52
+ // only thing distinguishing this from the unset case above: both render
53
+ // an empty box.
54
+ expect(input.placeholder).toBe("");
55
+ expect(clearButtons()).toHaveLength(1);
56
+ });
57
+
58
+ it("the revert affordance reverts rather than blanking the field", () => {
59
+ // Typed, not `mock(() => {})`: an untyped zero-arg mock makes
60
+ // `mock.calls` an array of empty tuples, so reading `[0][0]` below does
61
+ // not compile and nothing constrains what the component passes.
62
+ const onChange = mock((_next: GivenValue) => {});
63
+ render(
64
+ <GivenInput
65
+ given={{ name: "region", type: "string" }}
66
+ value="CA"
67
+ onChange={onChange}
68
+ />,
69
+ );
70
+
71
+ fireEvent.click(clearButtons()[0]);
72
+
73
+ // null, not "". `useGivensState` deletes the key on null, which is what
74
+ // returns the given to "use the model default".
75
+ expect(onChange).toHaveBeenCalledTimes(1);
76
+ expect(onChange.mock.calls[0][0]).toBeNull();
77
+ });
78
+ });
79
+
80
+ describe("GivenInput: boolean is three-state, not truthy/falsy", () => {
81
+ it("unset reflects the model default so the box matches what will run", () => {
82
+ render(
83
+ <GivenInput
84
+ given={{ name: "active", type: "boolean", default: "true" }}
85
+ value={undefined}
86
+ onChange={() => {}}
87
+ />,
88
+ );
89
+
90
+ const box = screen.getByLabelText("active") as HTMLInputElement;
91
+ expect(box.checked).toBe(true);
92
+ expect(clearButtons()).toHaveLength(0);
93
+ });
94
+
95
+ it("an explicit false is an override, distinguishable from unset", () => {
96
+ render(
97
+ <GivenInput
98
+ given={{ name: "active", type: "boolean", default: "true" }}
99
+ value={false}
100
+ onChange={() => {}}
101
+ />,
102
+ );
103
+
104
+ const box = screen.getByLabelText("active") as HTMLInputElement;
105
+ expect(box.checked).toBe(false);
106
+ // Guards the `typeof value === "boolean"` test in the component. A
107
+ // truthiness check would read `false` as unset and hide this revert,
108
+ // stranding the user on a value the server is being sent.
109
+ expect(clearButtons()).toHaveLength(1);
110
+ });
111
+ });
112
+
113
+ describe("GivenInput: helper text", () => {
114
+ it("surfaces a description annotation verbatim", () => {
115
+ render(
116
+ <GivenInput
117
+ given={{
118
+ name: "since",
119
+ type: "string",
120
+ annotations: ['#(description="Earliest report date")'],
121
+ }}
122
+ value={undefined}
123
+ onChange={() => {}}
124
+ />,
125
+ );
126
+
127
+ expect(screen.getByText("Earliest report date")).toBeDefined();
128
+ });
129
+
130
+ it("shows an explicit empty-string default as (empty), not as no default", () => {
131
+ render(
132
+ <GivenInput
133
+ given={{ name: "region", type: "string", default: "''" }}
134
+ value={undefined}
135
+ onChange={() => {}}
136
+ />,
137
+ );
138
+
139
+ // Guards the `!== undefined` test in the component: `is ''` renders as
140
+ // "", and a truthiness check would drop the caption entirely, making a
141
+ // real empty-string default look like no default at all.
142
+ expect(screen.getByText("Default: (empty)")).toBeDefined();
143
+ });
144
+ });
145
+
146
+ describe("GivenInput: number", () => {
147
+ it("treats 0 as a value, not as absent", () => {
148
+ render(
149
+ <GivenInput
150
+ given={{ name: "limit", type: "number" }}
151
+ value={0}
152
+ onChange={() => {}}
153
+ />,
154
+ );
155
+
156
+ const input = screen.getByLabelText("limit") as HTMLInputElement;
157
+ expect(input.value).toBe("0");
158
+ expect(clearButtons()).toHaveLength(1);
159
+ });
160
+
161
+ it("still offers a revert when the value is not a number", () => {
162
+ // Reachable through the public component API: GivenInput and GivenValue
163
+ // are both published SDK exports, and GivenValue is a union permitting a
164
+ // string while `type` says number.
165
+ render(
166
+ <GivenInput
167
+ given={{ name: "limit", type: "number" }}
168
+ value={"12abc"}
169
+ onChange={() => {}}
170
+ />,
171
+ );
172
+
173
+ // The box reads empty because the component substitutes "" for a
174
+ // non-number, and passing the raw string instead would not help: a
175
+ // browser discards it anyway on input[type=number] (checked in
176
+ // Chromium). So the revert is the user's only route out, and it used to
177
+ // be hidden too, because it keyed off the rendered string being
178
+ // non-empty rather than off a value being overridden.
179
+ expect(clearButtons()).toHaveLength(1);
180
+ });
181
+ });
182
+
183
+ describe("GivenInput, which types are actually reachable", () => {
184
+ // There used to be an `array<...>` branch here rendering a multi-value
185
+ // widget, and it was unreachable twice over. Malloy's grammar emits only
186
+ // scalar parameter types, so no array given exists to send; and if one did,
187
+ // `given.ts` renders the wire type as the bare discriminator "array", which
188
+ // never matched that branch's `startsWith("array<")` test. It is gone, and
189
+ // both spellings now land on the text box every unknown type gets.
190
+ for (const type of ["array<string>", "array", "record", "geography"]) {
191
+ it(`falls back to a text box for ${type}`, () => {
192
+ render(
193
+ <GivenInput
194
+ given={{ name: "tags", type }}
195
+ value={undefined}
196
+ onChange={() => {}}
197
+ />,
198
+ );
199
+ expect(screen.queryAllByRole("combobox")).toHaveLength(0);
200
+ expect(screen.getByLabelText("tags")).toBeDefined();
201
+ });
202
+ }
203
+ });
204
+
205
+ describe("GivenInput: a control= the widget cannot honour falls through", () => {
206
+ // The picker speaks two languages: plain strings and the STRING filter
207
+ // grammar. Honouring `control=select` on anything else corrupts the value,
208
+ // a `filter<date>` would get string-grammar escaping the temporal parser
209
+ // rejects, and a `number` given would get a string `givensToRequest` forwards
210
+ // verbatim for Malloy to refuse. Nothing populates `control` yet, so these
211
+ // pin the refusal before the slice that starts populating it.
212
+ const pickerCount = () => screen.queryAllByRole("combobox").length;
213
+
214
+ for (const type of ["string", "filter<string>"]) {
215
+ it(`renders a picker for ${type}`, () => {
216
+ render(
217
+ <GivenInput
218
+ given={{ name: "g", type, control: "select" }}
219
+ value={undefined}
220
+ onChange={() => {}}
221
+ />,
222
+ );
223
+ expect(pickerCount()).toBe(1);
224
+ });
225
+ }
226
+
227
+ for (const type of [
228
+ "number",
229
+ "boolean",
230
+ "date",
231
+ "timestamp",
232
+ "filter<number>",
233
+ "filter<date>",
234
+ ]) {
235
+ it(`refuses a picker for ${type} and uses the type's own widget`, () => {
236
+ render(
237
+ <GivenInput
238
+ given={{ name: "g", type, control: "multiselect" }}
239
+ value={undefined}
240
+ onChange={() => {}}
241
+ />,
242
+ );
243
+ expect(pickerCount()).toBe(0);
244
+ });
245
+ }
246
+ });
247
+
248
+ describe("GivenInput: a slider only claims a filter it can represent", () => {
249
+ it("renders a slider for a lower-bound filter", () => {
250
+ render(
251
+ <GivenInput
252
+ given={{
253
+ name: "n",
254
+ type: "filter<number>",
255
+ rangeMin: 0,
256
+ rangeMax: 10,
257
+ }}
258
+ value=">= 5"
259
+ onChange={() => {}}
260
+ />,
261
+ );
262
+ expect(screen.queryAllByRole("slider")).toHaveLength(1);
263
+ });
264
+
265
+ it("falls through for a filter it cannot represent", () => {
266
+ // Otherwise `decodeAtLeast` returns undefined, the control reads "Any"
267
+ // while a range is in force, and the first drag replaces it silently.
268
+ render(
269
+ <GivenInput
270
+ given={{
271
+ name: "n",
272
+ type: "filter<number>",
273
+ rangeMin: 0,
274
+ rangeMax: 10,
275
+ }}
276
+ value="1 to 5"
277
+ onChange={() => {}}
278
+ />,
279
+ );
280
+ expect(screen.queryAllByRole("slider")).toHaveLength(0);
281
+ expect((screen.getByLabelText("n") as HTMLInputElement).value).toBe(
282
+ "1 to 5",
283
+ );
284
+ });
285
+ });
286
+
287
+ describe("GivenInput: multi-pick needs a type that can carry several values", () => {
288
+ it("is single-pick for a plain string given, even when asked for multi", () => {
289
+ // A real array cannot survive the URL: `givenToParam` joins on `,` and
290
+ // reading it back yields the joined string, not the list. So a plain
291
+ // `string` given renders single-pick rather than emitting something the
292
+ // address bar would corrupt.
293
+ const onChange = mock((_next: GivenValue) => {});
294
+ render(
295
+ <GivenInput
296
+ given={{ name: "g", type: "string", control: "multiselect" }}
297
+ value={undefined}
298
+ onChange={onChange}
299
+ />,
300
+ );
301
+ const input = screen.getByRole("combobox");
302
+ fireEvent.keyDown(input, { key: "ArrowDown" });
303
+ // No chips container: a single-pick Autocomplete has no multiple slot.
304
+ expect(screen.queryAllByRole("button", { name: /^g/ })).toHaveLength(0);
305
+ });
306
+
307
+ it("is multi-pick for a filter<string> given", () => {
308
+ render(
309
+ <GivenInput
310
+ given={{
311
+ name: "g",
312
+ type: "filter<string>",
313
+ control: "multiselect",
314
+ }}
315
+ value={undefined}
316
+ onChange={() => {}}
317
+ options={["a", "b"]}
318
+ />,
319
+ );
320
+ expect(screen.queryAllByRole("combobox")).toHaveLength(1);
321
+ });
322
+ });
323
+
324
+ describe("GivenInput: the whole type x control matrix", () => {
325
+ // Six guards decide which widget a given gets (`pickableType`,
326
+ // `multiplePickable`, `filterIsPickable`, `bareDate`, `dateIsPickable`,
327
+ // `sliderIsRepresentable`), each added for its own reason. Read one at a
328
+ // time they are each defensible. What nothing checked is what they do as a
329
+ // SET, so this enumerates every combination rather than sampling, and
330
+ // the property that matters most is the last assertion: no combination falls
331
+ // through every branch and renders nothing at all.
332
+ const widget = () => {
333
+ if (screen.queryAllByRole("combobox").length) return "picker";
334
+ if (screen.queryAllByRole("slider").length) return "slider";
335
+ if (screen.queryAllByRole("checkbox").length) return "checkbox";
336
+ if (screen.queryAllByRole("spinbutton").length) return "number";
337
+ if (screen.queryAllByRole("textbox").length) return "text";
338
+ return "NONE";
339
+ };
340
+
341
+ const show = (
342
+ type: string | undefined,
343
+ control?: string,
344
+ range?: boolean,
345
+ value?: GivenValue,
346
+ ) => {
347
+ // Explicitly, because Testing Library's automatic cleanup runs BETWEEN
348
+ // tests: several renders inside one test otherwise stack up and every
349
+ // query sees the previous widget too.
350
+ cleanup();
351
+ render(
352
+ <GivenInput
353
+ given={
354
+ {
355
+ name: "g",
356
+ type,
357
+ control,
358
+ ...(range ? { rangeMin: 0, rangeMax: 10 } : {}),
359
+ } as Given
360
+ }
361
+ value={value}
362
+ onChange={() => {}}
363
+ />,
364
+ );
365
+ return widget();
366
+ };
367
+
368
+ it("gives a picker only to the string family", () => {
369
+ expect(show("string", "select")).toBe("picker");
370
+ expect(show("filter<string>", "multiselect")).toBe("picker");
371
+ // An undeclared type defaults to string, so it may pick too.
372
+ expect(show(undefined, "select")).toBe("picker");
373
+ // Everything else refuses, because the picker only speaks strings.
374
+ for (const type of [
375
+ "number",
376
+ "boolean",
377
+ "date",
378
+ "timestamp",
379
+ "timestamptz",
380
+ "filter<number>",
381
+ "filter<date>",
382
+ ]) {
383
+ expect(show(type, "select")).not.toBe("picker");
384
+ }
385
+ });
386
+
387
+ it("gives a slider to a bounded number, control= or not", () => {
388
+ expect(show("number", undefined, true)).toBe("slider");
389
+ expect(show("filter<number>", undefined, true)).toBe("slider");
390
+ // A `control=select` on a bounded number still gets the slider: the
391
+ // picker refuses the type, and the slider is what the type implies.
392
+ expect(show("number", "select", true)).toBe("slider");
393
+ // Without bounds there is no slider to give.
394
+ expect(show("number", undefined, false)).toBe("number");
395
+ });
396
+
397
+ it("leaves every other combination on its type's own widget", () => {
398
+ expect(show("boolean", "multiselect")).toBe("checkbox");
399
+ expect(show("date", "select")).toBe("text");
400
+ expect(show("record", "select")).toBe("text");
401
+ });
402
+
403
+ it("routes on the VALUE too, not just the type and control", () => {
404
+ // Three of the six guards read the value rather than the declaration, so
405
+ // a matrix that only ever passes `undefined` cannot see them.
406
+ expect(show("filter<string>", "select", false, "Nike")).toBe("picker");
407
+ // A filter the picker cannot represent falls through to the text box, so
408
+ // the author's filter stays visible rather than being re-encoded.
409
+ expect(show("filter<string>", "select", false, "-Nike")).toBe("text");
410
+ // A lower-bound filter keeps the slider; a range cannot be a threshold.
411
+ expect(show("filter<number>", undefined, true, ">= 5")).toBe("slider");
412
+ expect(show("filter<number>", undefined, true, "1 to 5")).toBe("text");
413
+ });
414
+
415
+ // One test per type rather than one test for the whole matrix. The matrix is
416
+ // 13 types x 3 controls x 2 range states x 9 values, so a single `it` runs
417
+ // 702 renders against bun's 5s default and tipped over it on a CI runner
418
+ // already executing three timezone passes (5872ms, measured). Splitting also
419
+ // means a failure names the type, which the combined assertion could not.
420
+ const MATRIX_TYPES = [
421
+ "string",
422
+ "number",
423
+ "boolean",
424
+ "date",
425
+ "timestamp",
426
+ "timestamptz",
427
+ "filter<string>",
428
+ "filter<number>",
429
+ "filter<date>",
430
+ "filter<timestamp>",
431
+ "array<string>",
432
+ "record",
433
+ undefined,
434
+ ];
435
+
436
+ it.each(MATRIX_TYPES)("never renders nothing, for %s", (type) => {
437
+ const values = [
438
+ undefined,
439
+ "",
440
+ "Nike",
441
+ "-Nike",
442
+ ">= 5",
443
+ "1 to 5",
444
+ "2024-01-15",
445
+ 5,
446
+ true,
447
+ ] as GivenValue[];
448
+ for (const control of [undefined, "select", "multiselect"]) {
449
+ for (const range of [false, true]) {
450
+ for (const value of values) {
451
+ expect(show(type, control, range, value)).not.toBe("NONE");
452
+ }
453
+ }
454
+ }
455
+ });
456
+ });
457
+
458
+ describe("GivenInput: a date value the codec cannot read", () => {
459
+ // Four states (readable, unreadable, empty, unset) and only two of them,
460
+ // empty and unset, look alike: both render a blank picker. The state worth
461
+ // pinning is UNREADABLE, because a DatePicker can only display a date, so
462
+ // the obvious rendering of `?D=last month` is a blank picker whose own
463
+ // `clearable` never appears, which would filter every cell while being
464
+ // invisible and impossible to revert. What this branch must do instead is
465
+ // show the offending value and offer a revert, which is what follows.
466
+ const DATE: Given = { name: "D", type: "date" };
467
+
468
+ it("shows the offending value instead of rendering blank", () => {
469
+ render(
470
+ <GivenInput given={DATE} value="last month" onChange={() => {}} />,
471
+ );
472
+ expect(screen.getByDisplayValue("last month")).toBeDefined();
473
+ expect(screen.getByText(/Not a date/)).toBeDefined();
474
+ });
475
+
476
+ it("does not let the user edit the unreadable value in place", () => {
477
+ // An editable version of this field swapped itself for the picker the
478
+ // moment the typed text first parsed, taking the cursor with it.
479
+ render(
480
+ <GivenInput given={DATE} value="last month" onChange={() => {}} />,
481
+ );
482
+ expect(screen.getByDisplayValue("last month")).toHaveProperty(
483
+ "readOnly",
484
+ true,
485
+ );
486
+ });
487
+
488
+ it("keeps the calendar button on a readable value", () => {
489
+ // Putting the revert in the picker's own `InputProps` REPLACED this
490
+ // button, leaving a date control with no way to open a calendar.
491
+ render(
492
+ <GivenInput given={DATE} value="2024-01-05" onChange={() => {}} />,
493
+ );
494
+ expect(
495
+ screen.getByRole("button", { name: /choose date/i }),
496
+ ).toBeDefined();
497
+ });
498
+
499
+ it("offers a revert, which the picker's own clearable does not", () => {
500
+ const onChange = mock((_next: GivenValue) => {});
501
+ render(
502
+ <GivenInput given={DATE} value="last month" onChange={onChange} />,
503
+ );
504
+
505
+ fireEvent.click(screen.getByRole("button", { name: "clear value" }));
506
+
507
+ expect(onChange.mock.calls[0][0]).toBeNull();
508
+ });
509
+
510
+ it("does not pin the picker's own error state when the value is fine", () => {
511
+ // `error` passed through `slotProps.textField` wins over MUI's internal
512
+ // validation for BOTH values, so a hardcoded `false` silently suppressed
513
+ // the picker's real errors.
514
+ render(
515
+ <GivenInput given={DATE} value="2024-01-05" onChange={() => {}} />,
516
+ );
517
+ expect(screen.getByRole("textbox").getAttribute("aria-invalid")).not.toBe(
518
+ "true",
519
+ );
520
+ });
521
+
522
+ it("reads a plain date string as a date rather than an error", () => {
523
+ // `# drill { to=self }` onto a date given hands over a bare `YYYY-MM-DD`
524
+ // STRING, not a Date, so treating every non-Date as unreadable painted an
525
+ // error over a value the product itself had just produced.
526
+ render(
527
+ <GivenInput given={DATE} value="2024-01-05" onChange={() => {}} />,
528
+ );
529
+ expect(screen.queryAllByText(/Not a date/)).toHaveLength(0);
530
+ });
531
+
532
+ it("treats an empty date value as an empty box, not an error", () => {
533
+ render(<GivenInput given={DATE} value="" onChange={() => {}} />);
534
+ expect(screen.queryAllByText(/Not a date/)).toHaveLength(0);
535
+ });
536
+
537
+ it("says nothing when the given is simply unset", () => {
538
+ render(<GivenInput given={DATE} value={undefined} onChange={() => {}} />);
539
+ expect(screen.queryAllByText(/Not a date/)).toHaveLength(0);
540
+ expect(
541
+ screen.queryAllByRole("button", { name: "clear value" }),
542
+ ).toHaveLength(0);
543
+ });
544
+ });
545
+
546
+ describe("GivenInput: a number value the control cannot show", () => {
547
+ // The same hazard as the date branch, and for a long time handled a
548
+ // different way: the box substituted a blank, so the value went on filtering
549
+ // every cell while the control looked empty and said nothing about it.
550
+ const NUM: Given = { name: "N", type: "number" };
551
+
552
+ it("shows the offending value rather than a blank box", () => {
553
+ render(<GivenInput given={NUM} value="lots" onChange={() => {}} />);
554
+ expect(screen.getByDisplayValue("lots")).toBeDefined();
555
+ expect(screen.getByText(/Not a number/)).toBeDefined();
556
+ });
557
+
558
+ it("offers a revert", () => {
559
+ const onChange = mock((_next: GivenValue) => {});
560
+ render(<GivenInput given={NUM} value="lots" onChange={onChange} />);
561
+ fireEvent.click(screen.getByRole("button", { name: "clear value" }));
562
+ expect(onChange.mock.calls[0][0]).toBeNull();
563
+ });
564
+
565
+ it("treats an empty value as an empty box, not an error", () => {
566
+ // `?N=` in a URL arrives as the empty string. Calling that "Not a number"
567
+ // painted a red error over a field showing nothing at all.
568
+ render(<GivenInput given={NUM} value="" onChange={() => {}} />);
569
+ expect(screen.queryAllByText(/Not a number/)).toHaveLength(0);
570
+ });
571
+
572
+ it("leaves an ordinary number alone", () => {
573
+ render(<GivenInput given={NUM} value={42} onChange={() => {}} />);
574
+ expect(screen.queryAllByText(/Not a number/)).toHaveLength(0);
575
+ expect(screen.getByDisplayValue("42")).toBeDefined();
576
+ });
577
+ });
578
+
579
+ describe("GivenInput: a boolean value the control cannot show", () => {
580
+ const FLAG: Given = { name: "F", type: "boolean", default: "true" };
581
+
582
+ it("does not render the model default for a value it is still sending", () => {
583
+ // `?F=yes` reaches here as a string, which the codec passes through on
584
+ // purpose. The checkbox used to show the DEFAULT for it, so the box said
585
+ // one thing while the request carried "yes" and every cell failed.
586
+ render(<GivenInput given={FLAG} value="yes" onChange={() => {}} />);
587
+ expect(screen.getByDisplayValue("yes")).toBeDefined();
588
+ expect(screen.getByText(/Not a true or false/)).toBeDefined();
589
+ });
590
+
591
+ it("offers a revert", () => {
592
+ const onChange = mock((_next: GivenValue) => {});
593
+ render(<GivenInput given={FLAG} value="yes" onChange={onChange} />);
594
+ fireEvent.click(screen.getByRole("button", { name: "clear value" }));
595
+ expect(onChange.mock.calls[0][0]).toBeNull();
596
+ });
597
+
598
+ it("leaves a real boolean, and an unset given, alone", () => {
599
+ render(<GivenInput given={FLAG} value={false} onChange={() => {}} />);
600
+ expect(screen.queryAllByText(/Not a true or false/)).toHaveLength(0);
601
+ cleanup();
602
+ render(<GivenInput given={FLAG} value={undefined} onChange={() => {}} />);
603
+ expect(screen.queryAllByText(/Not a true or false/)).toHaveLength(0);
604
+ });
605
+ });
606
+
607
+ describe("GivenInput: a slider value the control cannot place", () => {
608
+ // Latent today, because nothing populates rangeMin/rangeMax, which is why it
609
+ // is worth pinning before anything does.
610
+ const SLIDER: Given = {
611
+ name: "MIN",
612
+ type: "number",
613
+ rangeMin: 0,
614
+ rangeMax: 100,
615
+ };
616
+
617
+ it('does not read as "Any" for a value it is still sending', () => {
618
+ render(<GivenInput given={SLIDER} value="lots" onChange={() => {}} />);
619
+ expect(screen.getByDisplayValue("lots")).toBeDefined();
620
+ expect(screen.getByText(/Not a number/)).toBeDefined();
621
+ });
622
+
623
+ it("still renders a slider for a value it can place", () => {
624
+ render(<GivenInput given={SLIDER} value={42} onChange={() => {}} />);
625
+ expect(screen.queryAllByText(/Not a number/)).toHaveLength(0);
626
+ expect(screen.getByRole("slider")).toBeDefined();
627
+ });
628
+ });
629
+
630
+ describe("GivenInput: a date renders its UTC day, whatever zone the runner is in", () => {
631
+ // The component hydrates with `dayjs.utc(value)`, so the box shows the day
632
+ // the server will be sent, not the day the viewer happens to be living in.
633
+ // These two literals exist because one alone can only catch half the bug: a
634
+ // late-UTC instant crosses the date line only for zones AHEAD of UTC, and an
635
+ // early-UTC one only for zones BEHIND it. Both UTC days below are 1 March.
636
+ //
637
+ // This is the trap that shipped once already: a fixture picked without
638
+ // checking which side of midnight it lands on in the runner's zone sits on
639
+ // the same UTC day and cannot fail, however exotic the zone.
640
+ const utcDay = "03/01/2024";
641
+
642
+ it("late in the UTC day, which is the next day east of UTC", () => {
643
+ render(
644
+ <GivenInput
645
+ given={{ name: "since", type: "date" }}
646
+ value={new Date("2024-03-01T23:30:00Z")}
647
+ onChange={() => {}}
648
+ />,
649
+ );
650
+ // Reading local time here shows 03/02/2024 anywhere ahead of UTC.
651
+ expect((screen.getByLabelText("since") as HTMLInputElement).value).toBe(
652
+ utcDay,
653
+ );
654
+ });
655
+
656
+ it("early in the UTC day, which is the day before west of UTC", () => {
657
+ render(
658
+ <GivenInput
659
+ given={{ name: "since", type: "date" }}
660
+ value={new Date("2024-03-01T00:30:00Z")}
661
+ onChange={() => {}}
662
+ />,
663
+ );
664
+ // Reading local time here shows 02/29/2024 anywhere behind UTC, and 2024
665
+ // being a leap year makes that a doubly wrong answer.
666
+ expect((screen.getByLabelText("since") as HTMLInputElement).value).toBe(
667
+ utcDay,
668
+ );
669
+ });
670
+
671
+ // One test case per type rather than a loop: a loop stops at the first failing
672
+ // type and its message names neither, so dropping both from the branch costs
673
+ // two round trips to diagnose instead of one.
674
+ it.each(["timestamp", "timestamptz"])(
675
+ "applies to %s, which shares the date branch",
676
+ (type) => {
677
+ render(
678
+ <GivenInput
679
+ given={{ name: "at", type }}
680
+ value={new Date("2024-03-01T23:30:00Z")}
681
+ onChange={() => {}}
682
+ />,
683
+ );
684
+ expect((screen.getByLabelText("at") as HTMLInputElement).value).toBe(
685
+ utcDay,
686
+ );
687
+ },
688
+ );
689
+ });