@malloy-publisher/sdk 0.2.7 → 0.3.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 (99) hide show
  1. package/README.md +172 -204
  2. package/dist/ServerProvider-CGnLjzag.cjs.js +1 -0
  3. package/dist/{ServerProvider-ksC5Su_x.es.js → ServerProvider-DSK9rfSY.es.js} +245 -245
  4. package/dist/client/api.d.ts +13 -1
  5. package/dist/client/index.cjs.js +1 -1
  6. package/dist/client/index.es.js +1 -1
  7. package/dist/components/ApiErrorDisplay.d.ts +1 -2
  8. package/dist/components/Dashboard/Dashboard.d.ts +4 -2
  9. package/dist/components/Dashboard/promoteMeasureRow.d.ts +36 -0
  10. package/dist/components/DocumentStorage/BrowserDocumentStorage.d.ts +14 -0
  11. package/dist/components/DocumentStorage/DocumentStorage.d.ts +58 -0
  12. package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +18 -0
  13. package/dist/components/DocumentStorage/index.d.ts +3 -0
  14. package/dist/components/Model/index.d.ts +0 -1
  15. package/dist/components/RenderedResult/RenderedResult.d.ts +12 -0
  16. package/dist/components/RenderedResult/ResultContainer.d.ts +7 -1
  17. package/dist/components/RenderedResult/index.d.ts +1 -0
  18. package/dist/components/RenderedResult/resultSizing.d.ts +183 -0
  19. package/dist/components/drill/index.d.ts +1 -0
  20. package/dist/components/drill/useDrillSelf.d.ts +46 -0
  21. package/dist/components/given/filterValue.d.ts +63 -0
  22. package/dist/components/given/index.d.ts +1 -0
  23. package/dist/components/given/useGivenUrlParams.d.ts +39 -0
  24. package/dist/components/index.d.ts +2 -3
  25. package/dist/components/styles.d.ts +3 -3
  26. package/dist/core-8NVBCLZh.cjs.js +148 -0
  27. package/dist/{core-BY7vB5gN.es.js → core-B8oMW4sm.es.js} +3540 -2335
  28. package/dist/hooks/index.d.ts +1 -1
  29. package/dist/hooks/useSuggestOptions.d.ts +28 -12
  30. package/dist/index.cjs.js +281 -1
  31. package/dist/index.es.js +45803 -79
  32. package/dist/sdk.css +1 -1
  33. package/dist/styles.css +0 -1
  34. package/package.json +2 -6
  35. package/src/components/ApiErrorDisplay.tsx +1 -1
  36. package/src/components/Connections/EditConnectionDialog.tsx +96 -86
  37. package/src/components/Dashboard/Dashboard.tsx +60 -95
  38. package/src/components/Dashboard/DashboardTile.tsx +25 -2
  39. package/src/components/Dashboard/promoteMeasureRow.spec.ts +137 -0
  40. package/src/components/Dashboard/promoteMeasureRow.ts +129 -0
  41. package/src/components/DocumentStorage/BrowserDocumentStorage.spec.ts +81 -0
  42. package/src/components/DocumentStorage/BrowserDocumentStorage.ts +105 -0
  43. package/src/components/DocumentStorage/DocumentStorage.ts +73 -0
  44. package/src/components/DocumentStorage/DocumentStorageProvider.tsx +46 -0
  45. package/src/components/DocumentStorage/index.ts +15 -0
  46. package/src/components/Model/ModelCell.tsx +2 -1
  47. package/src/components/Model/index.ts +0 -1
  48. package/src/components/Notebook/Notebook.tsx +10 -76
  49. package/src/components/Notebook/NotebookCell.tsx +2 -8
  50. package/src/components/RenderedResult/RenderedResult.tsx +86 -76
  51. package/src/components/RenderedResult/ResultContainer.tsx +21 -24
  52. package/src/components/RenderedResult/index.ts +15 -0
  53. package/src/components/RenderedResult/resultSizing.spec.ts +249 -0
  54. package/src/components/RenderedResult/resultSizing.ts +308 -0
  55. package/src/components/ResultsDialog.tsx +2 -1
  56. package/src/components/drill/index.ts +5 -0
  57. package/src/components/drill/useDrillSelf.spec.tsx +64 -0
  58. package/src/components/drill/useDrillSelf.ts +110 -0
  59. package/src/components/given/GivenInput.spec.tsx +196 -2
  60. package/src/components/given/GivenInput.tsx +300 -25
  61. package/src/components/given/filterValue.spec.ts +112 -0
  62. package/src/components/given/filterValue.ts +188 -0
  63. package/src/components/given/index.ts +4 -0
  64. package/src/components/given/useGivenUrlParams.spec.tsx +74 -0
  65. package/src/components/given/useGivenUrlParams.ts +87 -0
  66. package/src/components/index.ts +5 -3
  67. package/src/hooks/index.ts +0 -1
  68. package/src/hooks/useGivensState.spec.ts +158 -0
  69. package/src/hooks/useGivensState.ts +114 -23
  70. package/src/hooks/useSuggestOptions.dom.spec.ts +60 -1
  71. package/src/hooks/useSuggestOptions.ts +94 -51
  72. package/vite.config.ts +0 -1
  73. package/dist/ServerProvider-xXW1HJOJ.cjs.js +0 -1
  74. package/dist/components/AnalyzePackageButton.d.ts +0 -6
  75. package/dist/components/Workbook/BrowserWorkbookStorage.d.ts +0 -9
  76. package/dist/components/Workbook/EditableMalloyCell.d.ts +0 -11
  77. package/dist/components/Workbook/ModelPicker.d.ts +0 -11
  78. package/dist/components/Workbook/MutableCell.d.ts +0 -17
  79. package/dist/components/Workbook/Workbook.d.ts +0 -7
  80. package/dist/components/Workbook/WorkbookList.d.ts +0 -7
  81. package/dist/components/Workbook/WorkbookManager.d.ts +0 -84
  82. package/dist/components/Workbook/WorkbookStorage.d.ts +0 -17
  83. package/dist/components/Workbook/WorkbookStorageProvider.d.ts +0 -12
  84. package/dist/components/Workbook/index.d.ts +0 -7
  85. package/dist/core-CWKmWEg2.cjs.js +0 -148
  86. package/dist/index-B0WyZAUA.es.js +0 -66412
  87. package/dist/index-kxVD1RjY.cjs.js +0 -356
  88. package/dist/markdown-editor.css +0 -341
  89. package/src/components/AnalyzePackageButton.tsx +0 -319
  90. package/src/components/Workbook/BrowserWorkbookStorage.ts +0 -64
  91. package/src/components/Workbook/EditableMalloyCell.tsx +0 -49
  92. package/src/components/Workbook/ModelPicker.tsx +0 -134
  93. package/src/components/Workbook/MutableCell.tsx +0 -458
  94. package/src/components/Workbook/Workbook.tsx +0 -501
  95. package/src/components/Workbook/WorkbookList.tsx +0 -110
  96. package/src/components/Workbook/WorkbookManager.ts +0 -214
  97. package/src/components/Workbook/WorkbookStorage.ts +0 -35
  98. package/src/components/Workbook/WorkbookStorageProvider.tsx +0 -40
  99. package/src/components/Workbook/index.ts +0 -10
@@ -0,0 +1,64 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { afterEach, describe, expect, it, mock, spyOn } from "bun:test";
5
+ import { renderHook } from "@testing-library/react";
6
+ import type { GivenValue } from "../../hooks/givenValue";
7
+ import { useDrillSelf } from "./useDrillSelf";
8
+
9
+ const TYPES = new Map<string, string | undefined>([
10
+ ["REGION", "filter<string>"],
11
+ ["MIN_AMOUNT", "number"],
12
+ ]);
13
+
14
+ function hook(setGiven = mock((_n: string, _v: GivenValue) => {})) {
15
+ const view = renderHook(() =>
16
+ useDrillSelf({
17
+ declaredTypes: TYPES,
18
+ setGiven,
19
+ documentName: "overview",
20
+ }),
21
+ );
22
+ return { ...view.result.current, setGiven };
23
+ }
24
+
25
+ describe("useDrillSelf", () => {
26
+ let warn: ReturnType<typeof spyOn> | undefined;
27
+ afterEach(() => warn?.mockRestore());
28
+
29
+ it("resolves a tag's name as declared, or by folding case", () => {
30
+ const { resolveGiven, canSelf } = hook();
31
+ expect(resolveGiven("REGION")).toBe("REGION");
32
+ expect(resolveGiven("region")).toBe("REGION");
33
+ expect(resolveGiven("Min_Amount")).toBe("MIN_AMOUNT");
34
+ expect(resolveGiven("STATE")).toBeUndefined();
35
+ expect(canSelf("region")).toBe(true);
36
+ expect(canSelf("STATE")).toBe(false);
37
+ });
38
+
39
+ it("sets the given under the DECLARED name, encoded for its type", () => {
40
+ const { onSelf, setGiven } = hook();
41
+ onSelf("region", "West");
42
+ expect(setGiven).toHaveBeenCalledWith("REGION", "West");
43
+ onSelf("min_amount", 42);
44
+ expect(setGiven).toHaveBeenLastCalledWith("MIN_AMOUNT", 42);
45
+ });
46
+
47
+ it("declines, aloud, a name the document does not declare", () => {
48
+ warn = spyOn(console, "warn").mockImplementation(() => {});
49
+ const { onSelf, setGiven } = hook();
50
+ onSelf("STATE", "CA");
51
+ expect(setGiven).not.toHaveBeenCalled();
52
+ expect(warn).toHaveBeenCalledWith(expect.stringContaining("'overview'"));
53
+ });
54
+
55
+ it("declines, aloud, a value the given's type cannot hold", () => {
56
+ warn = spyOn(console, "warn").mockImplementation(() => {});
57
+ const { onSelf, setGiven } = hook();
58
+ onSelf("MIN_AMOUNT", "not a number");
59
+ expect(setGiven).not.toHaveBeenCalled();
60
+ expect(warn).toHaveBeenCalledWith(
61
+ expect.stringContaining("Drill declined"),
62
+ );
63
+ });
64
+ });
@@ -0,0 +1,110 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { useCallback, useMemo } from "react";
5
+ import type { GivenValue } from "../../hooks/givenValue";
6
+ import { encodeDrillValue } from "./resolveDrill";
7
+
8
+ export interface UseDrillSelfOptions {
9
+ /** Declared type per given name: what this document can set. */
10
+ declaredTypes: ReadonlyMap<string, string | undefined>;
11
+ /** The control row's setter, from `useGivensState`. */
12
+ setGiven: (name: string, value: GivenValue) => void;
13
+ /**
14
+ * How the document names itself in the warning for a tag that names a given
15
+ * it does not declare: a dashboard's slug, a notebook's path.
16
+ */
17
+ documentName: string;
18
+ }
19
+
20
+ export interface UseDrillSelfResult {
21
+ /** The declared given a drill tag's name refers to, or undefined. */
22
+ resolveGiven: (given: string) => string | undefined;
23
+ /** For `useDrill`: whether a `to=self` on this given can be honoured. */
24
+ canSelf: (given: string) => boolean;
25
+ /** For `useDrill`: set the given to the clicked value, encoded for its type. */
26
+ onSelf: (given: string, rawValue: unknown) => void;
27
+ }
28
+
29
+ /**
30
+ * The `# drill { to=self }` half of a document's drill wiring: which of its
31
+ * givens a tag can set, and setting one from a clicked cell.
32
+ *
33
+ * Shared by the dashboard and the notebook so one tag behaves identically on
34
+ * both surfaces, which used to be two copies of this code with the same
35
+ * warning string in each. Three rules live here:
36
+ *
37
+ * - **Names fold case.** `# drill` with no `given=` falls back to the
38
+ * DIMENSION's spelling, conventionally lower_snake, while givens are
39
+ * conventionally SHOUTED; neither convention can be assumed, so a tag naming
40
+ * `region` finds a declared `REGION` and vice versa. First declaration wins
41
+ * when a model declares both spellings.
42
+ * - **The value is encoded against the DECLARED type**, which is knowable here
43
+ * and is not knowable at the click: `useDrill` hands over the raw cell value
44
+ * for exactly this reason. Passing it straight to `setGiven` skipped the
45
+ * encoder, so a clicked date reached a `number` given as epoch milliseconds
46
+ * and a filter value went unescaped. It is set under the name the MODEL
47
+ * declares, so it reaches the URL and the request under the one name the
48
+ * server knows.
49
+ * - **A refusal is said aloud.** `canSelf` checks only that the name resolves,
50
+ * so a `given=` naming a type the clicked value cannot become still paints a
51
+ * whole column clickable and would then drop every click in silence. Both
52
+ * refusals warn, because each is an authoring mistake with no other symptom.
53
+ */
54
+ export function useDrillSelf({
55
+ declaredTypes,
56
+ setGiven,
57
+ documentName,
58
+ }: UseDrillSelfOptions): UseDrillSelfResult {
59
+ const givenNamesByFold = useMemo(() => {
60
+ const byFold = new Map<string, string>();
61
+ for (const name of declaredTypes.keys()) {
62
+ if (!byFold.has(name.toLowerCase()))
63
+ byFold.set(name.toLowerCase(), name);
64
+ }
65
+ return byFold;
66
+ }, [declaredTypes]);
67
+
68
+ const resolveGiven = useCallback(
69
+ (given: string) =>
70
+ declaredTypes.has(given)
71
+ ? given
72
+ : givenNamesByFold.get(given.toLowerCase()),
73
+ [declaredTypes, givenNamesByFold],
74
+ );
75
+
76
+ // Asked before a cell is painted as drillable, so the affordance matches
77
+ // what a click can do: sending a given the document cannot bind would fail
78
+ // every query on the page.
79
+ const canSelf = useCallback(
80
+ (given: string) => resolveGiven(given) !== undefined,
81
+ [resolveGiven],
82
+ );
83
+
84
+ const onSelf = useCallback(
85
+ (given: string, rawValue: unknown) => {
86
+ const declared = resolveGiven(given);
87
+ if (declared === undefined) {
88
+ console.warn(
89
+ `# drill { to=self } tried to set '${given}', which ` +
90
+ `'${documentName}' does not declare as a given. Name the ` +
91
+ `given with 'given=' on the drill tag.`,
92
+ );
93
+ return;
94
+ }
95
+ const declaredType = declaredTypes.get(declared);
96
+ const value = encodeDrillValue(rawValue, declaredType);
97
+ if (value === undefined) {
98
+ console.warn(
99
+ `Drill declined: ${JSON.stringify(rawValue)} cannot be a value for given "${declared}"` +
100
+ (declaredType ? ` of type ${declaredType}` : ""),
101
+ );
102
+ return;
103
+ }
104
+ setGiven(declared, value);
105
+ },
106
+ [declaredTypes, documentName, resolveGiven, setGiven],
107
+ );
108
+
109
+ return { resolveGiven, canSelf, onSelf };
110
+ }
@@ -209,7 +209,11 @@ describe("GivenInput: a control= the widget cannot honour falls through", () =>
209
209
  // rejects, and a `number` given would get a string `givensToRequest` forwards
210
210
  // verbatim for Malloy to refuse. Nothing populates `control` yet, so these
211
211
  // pin the refusal before the slice that starts populating it.
212
- const pickerCount = () => screen.queryAllByRole("combobox").length;
212
+ // Autocomplete pickers only. The time-range control's dropdown is a
213
+ // combobox too, on a `<div>`; the picker this suite is about is an `<input>`.
214
+ const pickerCount = () =>
215
+ screen.queryAllByRole("combobox").filter((el) => el.tagName === "INPUT")
216
+ .length;
213
217
 
214
218
  for (const type of ["string", "filter<string>"]) {
215
219
  it(`renders a picker for ${type}`, () => {
@@ -259,6 +263,54 @@ describe("GivenInput: a slider only claims a filter it can represent", () => {
259
263
  onChange={() => {}}
260
264
  />,
261
265
  );
266
+ // Two handles, the lower at the bound and the upper at the ceiling.
267
+ const sliders = screen.queryAllByRole("slider") as HTMLInputElement[];
268
+ expect(sliders.map((s) => s.value)).toEqual(["5", "10"]);
269
+ expect(screen.getByText("≥ 5")).toBeDefined();
270
+ });
271
+
272
+ it("renders a closed range on both handles", () => {
273
+ render(
274
+ <GivenInput
275
+ given={{
276
+ name: "n",
277
+ type: "filter<number>",
278
+ rangeMin: 0,
279
+ rangeMax: 10,
280
+ }}
281
+ value="[2 to 7]"
282
+ onChange={() => {}}
283
+ />,
284
+ );
285
+ const sliders = screen.queryAllByRole("slider") as HTMLInputElement[];
286
+ expect(sliders.map((s) => s.value)).toEqual(["2", "7"]);
287
+ expect(screen.getByText("2 to 7")).toBeDefined();
288
+ });
289
+
290
+ it("still refuses a half-open range", () => {
291
+ render(
292
+ <GivenInput
293
+ given={{
294
+ name: "n",
295
+ type: "filter<number>",
296
+ rangeMin: 0,
297
+ rangeMax: 10,
298
+ }}
299
+ value="(2 to 7]"
300
+ onChange={() => {}}
301
+ />,
302
+ );
303
+ expect(screen.queryAllByRole("slider")).toHaveLength(0);
304
+ });
305
+
306
+ it("keeps one handle for a plain number given", () => {
307
+ render(
308
+ <GivenInput
309
+ given={{ name: "n", type: "number", rangeMin: 0, rangeMax: 10 }}
310
+ value={4}
311
+ onChange={() => {}}
312
+ />,
313
+ );
262
314
  expect(screen.queryAllByRole("slider")).toHaveLength(1);
263
315
  });
264
316
 
@@ -330,6 +382,7 @@ describe("GivenInput: the whole type x control matrix", () => {
330
382
  // the property that matters most is the last assertion: no combination falls
331
383
  // through every branch and renders nothing at all.
332
384
  const widget = () => {
385
+ if (screen.queryAllByTestId("time-range").length) return "timerange";
333
386
  if (screen.queryAllByRole("combobox").length) return "picker";
334
387
  if (screen.queryAllByRole("slider").length) return "slider";
335
388
  if (screen.queryAllByRole("checkbox").length) return "checkbox";
@@ -407,9 +460,31 @@ describe("GivenInput: the whole type x control matrix", () => {
407
460
  // A filter the picker cannot represent falls through to the text box, so
408
461
  // the author's filter stays visible rather than being re-encoded.
409
462
  expect(show("filter<string>", "select", false, "-Nike")).toBe("text");
410
- // A lower-bound filter keeps the slider; a range cannot be a threshold.
463
+ // A lower bound and a closed range both fit the handles; `1 to 5` is not
464
+ // number-filter syntax at all and stays visible as written.
411
465
  expect(show("filter<number>", undefined, true, ">= 5")).toBe("slider");
466
+ expect(show("filter<number>", undefined, true, "[1 to 5]")).toBe(
467
+ "slider",
468
+ );
412
469
  expect(show("filter<number>", undefined, true, "1 to 5")).toBe("text");
470
+ // A date filter gets the time-range control for a window or a day range,
471
+ // the single day picker for one day, and the text box for the rest.
472
+ expect(show("filter<date>", undefined, false, undefined)).toBe(
473
+ "timerange",
474
+ );
475
+ expect(show("filter<date>", undefined, false, "7 days")).toBe(
476
+ "timerange",
477
+ );
478
+ expect(
479
+ show(
480
+ "filter<timestamp>",
481
+ undefined,
482
+ false,
483
+ "2024-01-01 to 2024-02-01",
484
+ ),
485
+ ).toBe("timerange");
486
+ expect(show("filter<date>", undefined, false, "2024-01-15")).toBe("text");
487
+ expect(show("filter<date>", undefined, false, "last month")).toBe("text");
413
488
  });
414
489
 
415
490
  // One test per type rather than one test for the whole matrix. The matrix is
@@ -687,3 +762,122 @@ describe("GivenInput: a date renders its UTC day, whatever zone the runner is in
687
762
  },
688
763
  );
689
764
  });
765
+
766
+ describe("GivenInput: the time-range control for a date filter", () => {
767
+ const given: Given = { name: "PERIOD", type: "filter<timestamp>" };
768
+ const dropdown = () =>
769
+ screen
770
+ .getAllByRole("combobox")
771
+ .find((el) => el.tagName !== "INPUT") as HTMLElement;
772
+
773
+ it("shows an unset given as blank, with no revert", () => {
774
+ render(
775
+ <GivenInput given={given} value={undefined} onChange={() => {}} />,
776
+ );
777
+ expect(screen.getByTestId("time-range")).toBeDefined();
778
+ expect(clearButtons()).toHaveLength(0);
779
+ expect(screen.queryAllByLabelText("From")).toHaveLength(0);
780
+ });
781
+
782
+ it("shows the preset a value spells, however it is spelled", () => {
783
+ render(<GivenInput given={given} value="30 day" onChange={() => {}} />);
784
+ expect(dropdown().textContent).toBe("Last 30 days");
785
+ expect(clearButtons()).toHaveLength(1);
786
+ });
787
+
788
+ it("commits a picked preset in Malloy's filter grammar", () => {
789
+ const onChange = mock((_next: GivenValue) => {});
790
+ render(
791
+ <GivenInput given={given} value={undefined} onChange={onChange} />,
792
+ );
793
+ fireEvent.mouseDown(dropdown());
794
+ fireEvent.click(screen.getByRole("option", { name: "Last 7 days" }));
795
+ expect(onChange).toHaveBeenCalledWith("7 days");
796
+ });
797
+
798
+ it("opens two day pickers for a custom range, committing nothing yet", () => {
799
+ const onChange = mock((_next: GivenValue) => {});
800
+ render(
801
+ <GivenInput given={given} value={undefined} onChange={onChange} />,
802
+ );
803
+ fireEvent.mouseDown(dropdown());
804
+ fireEvent.click(screen.getByRole("option", { name: "Custom range" }));
805
+ expect(screen.getByLabelText("From")).toBeDefined();
806
+ expect(screen.getByLabelText("To")).toBeDefined();
807
+ expect(onChange).not.toHaveBeenCalled();
808
+ });
809
+
810
+ it("shows a day range as the inclusive days it selects", () => {
811
+ render(
812
+ <GivenInput
813
+ given={given}
814
+ value="2024-01-01 to 2024-02-01"
815
+ onChange={() => {}}
816
+ />,
817
+ );
818
+ expect(dropdown().textContent).toBe("Custom range");
819
+ expect((screen.getByLabelText("From") as HTMLInputElement).value).toBe(
820
+ "01/01/2024",
821
+ );
822
+ expect((screen.getByLabelText("To") as HTMLInputElement).value).toBe(
823
+ "01/31/2024",
824
+ );
825
+ });
826
+
827
+ it("shows the empty filter as an override it can revert", () => {
828
+ const onChange = mock((_next: GivenValue) => {});
829
+ render(<GivenInput given={given} value="" onChange={onChange} />);
830
+ expect(dropdown().textContent).toBe("Any time");
831
+ fireEvent.click(clearButtons()[0]);
832
+ expect(onChange).toHaveBeenCalledWith(null);
833
+ });
834
+
835
+ it("leaves a filter it cannot show in the text box, as written", () => {
836
+ render(
837
+ <GivenInput given={given} value="last month" onChange={() => {}} />,
838
+ );
839
+ expect(screen.queryAllByTestId("time-range")).toHaveLength(0);
840
+ expect((screen.getByLabelText("PERIOD") as HTMLInputElement).value).toBe(
841
+ "last month",
842
+ );
843
+ });
844
+
845
+ it("keeps the single day picker for one day", () => {
846
+ render(
847
+ <GivenInput given={given} value="2024-01-15" onChange={() => {}} />,
848
+ );
849
+ expect(screen.queryAllByTestId("time-range")).toHaveLength(0);
850
+ expect(screen.getByLabelText("PERIOD")).toBeDefined();
851
+ });
852
+ });
853
+
854
+ describe("GivenInput: the range slider's commits", () => {
855
+ const given: Given = {
856
+ name: "n",
857
+ type: "filter<number>",
858
+ rangeMin: 0,
859
+ rangeMax: 10,
860
+ };
861
+ const handles = () => screen.getAllByRole("slider") as HTMLInputElement[];
862
+
863
+ it("writes a closed range when the upper handle is inside the track", () => {
864
+ const onChange = mock((_next: GivenValue) => {});
865
+ render(<GivenInput given={given} value="[2 to 7]" onChange={onChange} />);
866
+ fireEvent.change(handles()[1], { target: { value: "6" } });
867
+ expect(onChange).toHaveBeenCalledWith("[2 to 6]");
868
+ });
869
+
870
+ it("collapses to a threshold once the upper handle reaches the ceiling", () => {
871
+ const onChange = mock((_next: GivenValue) => {});
872
+ render(<GivenInput given={given} value="[2 to 7]" onChange={onChange} />);
873
+ fireEvent.change(handles()[1], { target: { value: "10" } });
874
+ expect(onChange).toHaveBeenCalledWith(">= 2");
875
+ });
876
+
877
+ it("reverts when both handles are at the ends", () => {
878
+ const onChange = mock((_next: GivenValue) => {});
879
+ render(<GivenInput given={given} value=">= 2" onChange={onChange} />);
880
+ fireEvent.change(handles()[0], { target: { value: "0" } });
881
+ expect(onChange).toHaveBeenCalledWith(null);
882
+ });
883
+ });