@malloy-publisher/sdk 0.0.248 → 0.0.250

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 (202) hide show
  1. package/README.md +37 -17
  2. package/TREE_SHAKING.md +5 -0
  3. package/bunfig.toml +3 -0
  4. package/dist/ServerProvider-CcfeBpt3.cjs.js +1 -0
  5. package/dist/{ServerProvider-BxEh3nFI.es.js → ServerProvider-EqBlMMqx.es.js} +1056 -905
  6. package/dist/client/api.d.ts +306 -9
  7. package/dist/client/index.cjs.js +1 -1
  8. package/dist/client/index.es.js +74 -70
  9. package/dist/components/Dashboard/Dashboard.d.ts +49 -0
  10. package/dist/components/Dashboard/DashboardTile.d.ts +48 -0
  11. package/dist/components/Dashboard/index.d.ts +2 -0
  12. package/dist/components/Notebook/Notebook.d.ts +46 -8
  13. package/dist/components/Notebook/NotebookCell.d.ts +37 -3
  14. package/dist/components/Notebook/runPlan.d.ts +29 -0
  15. package/dist/components/Notebook/types.d.ts +10 -0
  16. package/dist/components/Package/ContentTypeIcon.d.ts +17 -1
  17. package/dist/components/Package/Package.d.ts +1 -4
  18. package/dist/components/RenderedResult/RenderedResult.d.ts +7 -1
  19. package/dist/components/RenderedResult/ResultContainer.d.ts +3 -1
  20. package/dist/components/ResultsDialog.d.ts +4 -1
  21. package/dist/components/ServerProvider.d.ts +2 -1
  22. package/dist/components/click_helper.d.ts +10 -1
  23. package/dist/components/drill/index.d.ts +3 -0
  24. package/dist/components/drill/markDrillableCells.d.ts +55 -0
  25. package/dist/components/drill/resolveDrill.d.ts +139 -0
  26. package/dist/components/drill/useDrill.d.ts +63 -0
  27. package/dist/components/given/GivenInput.d.ts +27 -3
  28. package/dist/components/given/GivensPanel.d.ts +36 -7
  29. package/dist/components/given/filterValue.d.ts +97 -0
  30. package/dist/components/given/index.d.ts +1 -1
  31. package/dist/components/given/paramCodec.d.ts +60 -0
  32. package/dist/components/index.d.ts +4 -1
  33. package/dist/components/styles.d.ts +31 -0
  34. package/dist/constants/docLinks.d.ts +6 -0
  35. package/dist/{core-C86Rb7tJ.cjs.js → core-CVXEUnnm.cjs.js} +1 -1
  36. package/dist/{core-BuvlzSIX.es.js → core-Cr-9Wkp3.es.js} +1 -1
  37. package/dist/hooks/givenValue.d.ts +10 -0
  38. package/dist/hooks/index.d.ts +3 -1
  39. package/dist/hooks/useGivensState.d.ts +64 -0
  40. package/dist/hooks/useSuggestOptions.d.ts +78 -0
  41. package/dist/index-C-KeIwsG.cjs.js +339 -0
  42. package/dist/{index-BdtAZ5k6.es.js → index-DVkelll3.es.js} +40981 -39669
  43. package/dist/index.cjs.js +1 -1
  44. package/dist/index.es.js +77 -62
  45. package/dist/theme/types.d.ts +9 -0
  46. package/dist/utils/malloyString.d.ts +7 -0
  47. package/package.json +3 -1
  48. package/src/client-entry.ts +3 -0
  49. package/src/components/AnalyzePackageButton.tsx +3 -0
  50. package/src/components/ApiErrorDisplay.tsx +3 -0
  51. package/src/components/Connections/AddConnectionDialog.tsx +13 -1
  52. package/src/components/Connections/DeleteConnectionDialog.tsx +3 -0
  53. package/src/components/Connections/EditConnectionDialog.tsx +3 -0
  54. package/src/components/Connections/common.ts +3 -0
  55. package/src/components/DOMElement/DOMElement.tsx +3 -0
  56. package/src/components/DOMElement/index.ts +3 -0
  57. package/src/components/Dashboard/Dashboard.tsx +398 -0
  58. package/src/components/Dashboard/DashboardTile.tsx +153 -0
  59. package/src/components/Dashboard/index.ts +5 -0
  60. package/src/components/DataAppViewer/DataAppViewer.tsx +3 -0
  61. package/src/components/DataAppViewer/index.ts +3 -0
  62. package/src/components/Environment/About.tsx +3 -0
  63. package/src/components/Environment/AddPackageDialog.tsx +3 -0
  64. package/src/components/Environment/ConnectionExplorer.tsx +3 -0
  65. package/src/components/Environment/Connections.tsx +3 -0
  66. package/src/components/Environment/DeletePackageDialog.tsx +3 -0
  67. package/src/components/Environment/EditPackageDialog.tsx +3 -0
  68. package/src/components/Environment/Environment.tsx +3 -0
  69. package/src/components/Environment/Packages.tsx +3 -0
  70. package/src/components/Environment/index.ts +3 -0
  71. package/src/components/Home/AddEnvironmentDialog.tsx +3 -0
  72. package/src/components/Home/DeleteEnvironmentDialog.tsx +3 -0
  73. package/src/components/Home/EditEnvironmentDialog.tsx +3 -0
  74. package/src/components/Home/Home.tsx +113 -23
  75. package/src/components/Home/index.ts +3 -0
  76. package/src/components/Loading.tsx +3 -0
  77. package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +3 -0
  78. package/src/components/Materializations/CreateMaterializationDialog.tsx +3 -0
  79. package/src/components/Materializations/DeleteMaterializationDialog.tsx +3 -0
  80. package/src/components/Materializations/EnvironmentMaterializations.tsx +3 -0
  81. package/src/components/Materializations/ManifestView.tsx +3 -0
  82. package/src/components/Materializations/MaterializationDetailDialog.tsx +3 -0
  83. package/src/components/Materializations/MaterializationRunsList.tsx +3 -0
  84. package/src/components/Materializations/Materializations.tsx +3 -0
  85. package/src/components/Materializations/ScheduleCard.tsx +3 -0
  86. package/src/components/Materializations/SectionLabel.tsx +3 -0
  87. package/src/components/Materializations/SetScheduleDialog.tsx +3 -0
  88. package/src/components/Materializations/TriggerChip.tsx +3 -0
  89. package/src/components/Materializations/cron.ts +3 -0
  90. package/src/components/Materializations/index.ts +3 -0
  91. package/src/components/Materializations/utils.ts +3 -0
  92. package/src/components/Model/Model.tsx +3 -0
  93. package/src/components/Model/ModelCell.tsx +3 -0
  94. package/src/components/Model/ModelExplorer.tsx +3 -0
  95. package/src/components/Model/ModelExplorerDialog.tsx +3 -0
  96. package/src/components/Model/SourcesExplorer.tsx +3 -0
  97. package/src/components/Model/index.ts +3 -0
  98. package/src/components/Model/useModelData.ts +3 -0
  99. package/src/components/Notebook/Notebook.tsx +447 -390
  100. package/src/components/Notebook/NotebookCell.tsx +120 -3
  101. package/src/components/Notebook/index.ts +3 -0
  102. package/src/components/Notebook/runPlan.spec.ts +155 -0
  103. package/src/components/Notebook/runPlan.ts +67 -0
  104. package/src/components/Notebook/types.ts +14 -0
  105. package/src/components/Package/ContentTypeIcon.spec.ts +91 -0
  106. package/src/components/Package/ContentTypeIcon.tsx +80 -6
  107. package/src/components/Package/FileTreeView.tsx +3 -0
  108. package/src/components/Package/Models.tsx +3 -0
  109. package/src/components/Package/Package.tsx +151 -38
  110. package/src/components/Package/index.ts +3 -0
  111. package/src/components/QueryResult/QueryResult.tsx +3 -0
  112. package/src/components/QueryResult/index.ts +3 -0
  113. package/src/components/RenderedResult/RenderedResult.tsx +312 -19
  114. package/src/components/RenderedResult/ResultContainer.tsx +31 -1
  115. package/src/components/RenderedResult/index.ts +3 -0
  116. package/src/components/RenderedResult/renderLogs.spec.ts +3 -0
  117. package/src/components/RenderedResult/renderLogs.ts +3 -0
  118. package/src/components/ResultsDialog.tsx +8 -0
  119. package/src/components/ServerProvider.tsx +5 -0
  120. package/src/components/Workbook/BrowserWorkbookStorage.ts +3 -0
  121. package/src/components/Workbook/EditableMalloyCell.tsx +3 -0
  122. package/src/components/Workbook/ModelPicker.tsx +3 -0
  123. package/src/components/Workbook/MutableCell.tsx +3 -0
  124. package/src/components/Workbook/Workbook.tsx +3 -0
  125. package/src/components/Workbook/WorkbookList.tsx +3 -0
  126. package/src/components/Workbook/WorkbookManager.ts +3 -0
  127. package/src/components/Workbook/WorkbookStorage.ts +3 -0
  128. package/src/components/Workbook/WorkbookStorageProvider.tsx +3 -0
  129. package/src/components/Workbook/index.ts +3 -0
  130. package/src/components/click_helper.ts +17 -1
  131. package/src/components/drill/index.ts +28 -0
  132. package/src/components/drill/markDrillableCells.dom.spec.ts +313 -0
  133. package/src/components/drill/markDrillableCells.spec.ts +109 -0
  134. package/src/components/drill/markDrillableCells.ts +314 -0
  135. package/src/components/drill/resolveDrill.spec.ts +449 -0
  136. package/src/components/drill/resolveDrill.ts +375 -0
  137. package/src/components/drill/useDrill.tsx +203 -0
  138. package/src/components/filter/DimensionFilter.tsx +3 -0
  139. package/src/components/filter/index.ts +3 -0
  140. package/src/components/filter/utils.ts +16 -5
  141. package/src/components/given/GivenInput.spec.tsx +498 -15
  142. package/src/components/given/GivenInput.tsx +565 -30
  143. package/src/components/given/GivensPanel.spec.tsx +175 -0
  144. package/src/components/given/GivensPanel.tsx +142 -32
  145. package/src/components/given/filterValue.spec.ts +364 -0
  146. package/src/components/given/filterValue.ts +207 -0
  147. package/src/components/given/index.ts +8 -1
  148. package/src/components/given/paramCodec.spec.ts +857 -0
  149. package/src/components/given/paramCodec.ts +483 -0
  150. package/src/components/given/utils.spec.ts +3 -0
  151. package/src/components/given/utils.ts +3 -0
  152. package/src/components/highlighter.ts +3 -0
  153. package/src/components/index.ts +7 -1
  154. package/src/components/styles.ts +38 -3
  155. package/src/constants/docLinks.spec.ts +54 -0
  156. package/src/constants/docLinks.ts +29 -0
  157. package/src/hooks/givenValue.ts +13 -0
  158. package/src/hooks/index.ts +9 -4
  159. package/src/hooks/useDimensionFilters.ts +4 -7
  160. package/src/hooks/useDimensionFiltersFromSpec.ts +3 -0
  161. package/src/hooks/useDimensionFiltersQuery.ts +4 -7
  162. package/src/hooks/useDimensionalFilterRangeData.ts +4 -7
  163. package/src/hooks/useGivensState.spec.ts +449 -0
  164. package/src/hooks/useGivensState.ts +340 -0
  165. package/src/hooks/useModelGivens.ts +3 -0
  166. package/src/hooks/useQueryWithApiError.ts +3 -0
  167. package/src/hooks/useRawQueryData.ts +3 -0
  168. package/src/hooks/useSuggestOptions.spec.ts +112 -0
  169. package/src/hooks/useSuggestOptions.ts +263 -0
  170. package/src/index.ts +3 -0
  171. package/src/react-app-env.d.ts +3 -0
  172. package/src/theme/ThemeContext.tsx +3 -0
  173. package/src/theme/buildMalloyExplicitTheme.ts +3 -0
  174. package/src/theme/buildTableCssVars.spec.ts +3 -0
  175. package/src/theme/buildTableCssVars.ts +7 -0
  176. package/src/theme/buildVegaThemeOverride.spec.ts +3 -0
  177. package/src/theme/buildVegaThemeOverride.ts +3 -0
  178. package/src/theme/defaults.ts +3 -0
  179. package/src/theme/index.ts +3 -0
  180. package/src/theme/keys.ts +3 -0
  181. package/src/theme/readChartAnnotations.spec.ts +3 -0
  182. package/src/theme/readChartAnnotations.ts +3 -0
  183. package/src/theme/resolveTheme.spec.ts +16 -0
  184. package/src/theme/resolveTheme.ts +6 -0
  185. package/src/theme/types.ts +12 -0
  186. package/src/utils/dataAppEmbed.spec.ts +3 -0
  187. package/src/utils/dataAppEmbed.ts +3 -0
  188. package/src/utils/formatting.spec.ts +3 -0
  189. package/src/utils/formatting.ts +3 -0
  190. package/src/utils/malloyString.spec.ts +24 -0
  191. package/src/utils/malloyString.ts +12 -0
  192. package/src/utils/parsing.spec.ts +3 -0
  193. package/src/utils/parsing.ts +3 -0
  194. package/src/utils/queryClient.ts +3 -0
  195. package/test/README.md +21 -10
  196. package/test/setup.ts +3 -0
  197. package/vite.config.ts +3 -0
  198. package/dist/ServerProvider-Dg5S1qBU.cjs.js +0 -1
  199. package/dist/hooks/useGivensForm.d.ts +0 -35
  200. package/dist/index-MES4MGpQ.cjs.js +0 -309
  201. package/src/hooks/useGivensForm.spec.ts +0 -99
  202. package/src/hooks/useGivensForm.ts +0 -107
@@ -1,6 +1,10 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import { describe, expect, it, mock } from "bun:test";
2
- import { fireEvent, render, screen } from "@testing-library/react";
3
- import type { GivenValue } from "../../hooks/useGivensForm";
5
+ import { cleanup, fireEvent, render, screen } from "@testing-library/react";
6
+ import type { Given } from "../../client";
7
+ import type { GivenValue } from "../../hooks/givenValue";
4
8
  import { GivenInput } from "./GivenInput";
5
9
 
6
10
  /**
@@ -66,7 +70,7 @@ describe("GivenInput: unset vs. explicit override", () => {
66
70
 
67
71
  fireEvent.click(clearButtons()[0]);
68
72
 
69
- // null, not "". `useGivensForm` deletes the key on null, which is what
73
+ // null, not "". `useGivensState` deletes the key on null, which is what
70
74
  // returns the given to "use the model default".
71
75
  expect(onChange).toHaveBeenCalledTimes(1);
72
76
  expect(onChange.mock.calls[0][0]).toBeNull();
@@ -176,31 +180,510 @@ describe("GivenInput: number", () => {
176
180
  });
177
181
  });
178
182
 
179
- describe("GivenInput: which types are actually reachable", () => {
180
- it("renders a multi-value widget only for the array<...> spelling", () => {
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) => {});
181
294
  render(
182
295
  <GivenInput
183
- given={{ name: "tags", type: "array<string>" }}
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
+ }}
184
315
  value={undefined}
185
316
  onChange={() => {}}
317
+ options={["a", "b"]}
186
318
  />,
187
319
  );
188
320
  expect(screen.queryAllByRole("combobox")).toHaveLength(1);
189
321
  });
322
+ });
190
323
 
191
- it("falls back to a text box for the bare array type the server emits", () => {
192
- // The array<...> branch is unreachable twice over. Malloy's grammar emits
193
- // only scalar parameter types, so no array given exists to send; and if
194
- // one did, `given.ts` renders the wire type as the bare discriminator
195
- // "array", which does not match the component's `startsWith("array<")`.
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();
196
351
  render(
197
352
  <GivenInput
198
- given={{ name: "tags", type: "array" }}
199
- value={undefined}
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")}
200
661
  onChange={() => {}}
201
662
  />,
202
663
  );
203
- expect(screen.queryAllByRole("combobox")).toHaveLength(0);
204
- expect(screen.getByLabelText("tags")).toBeDefined();
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
+ );
205
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
+ );
206
689
  });