@malloy-publisher/sdk 0.9.15 → 0.10.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 (94) hide show
  1. package/dist/{RenderedResult-BClN_PG6.cjs.js → RenderedResult-B5f4qOjp.cjs.js} +21 -4
  2. package/dist/{RenderedResult-YBzVMVH2.es.js → RenderedResult-DiDsN6JE.es.js} +204 -187
  3. package/dist/builder/index.cjs.js +75 -75
  4. package/dist/builder/index.es.js +5304 -5156
  5. package/dist/builder-entry.d.ts +1 -1
  6. package/dist/client/api.d.ts +1 -1
  7. package/dist/components/Dashboard/DashboardGrid.d.ts +2 -0
  8. package/dist/components/Dashboard/DashboardTile.d.ts +3 -1
  9. package/dist/components/RenderedResult/ResultContainer.d.ts +8 -1
  10. package/dist/components/RenderedResult/ResultPanel.d.ts +3 -1
  11. package/dist/components/RenderedResult/resultSizing.d.ts +5 -0
  12. package/dist/components/ReportBuilder/ArrangeMenu.d.ts +9 -0
  13. package/dist/components/ReportBuilder/BuilderGrid.d.ts +5 -7
  14. package/dist/components/ReportBuilder/BuilderToolbar.d.ts +3 -1
  15. package/dist/components/ReportBuilder/ReportBuilder.d.ts +1 -1
  16. package/dist/components/ReportBuilder/TextTileBody.d.ts +9 -2
  17. package/dist/components/ReportBuilder/TileFrame.d.ts +34 -22
  18. package/dist/components/ReportBuilder/builderControls.d.ts +19 -0
  19. package/dist/components/ReportBuilder/placement.d.ts +48 -2
  20. package/dist/components/ReportBuilder/sortable.d.ts +9 -0
  21. package/dist/components/ReportBuilder/useBuilderSession.d.ts +1 -1
  22. package/dist/components/ReportBuilder/useBuilderShortcuts.d.ts +9 -1
  23. package/dist/components/ReportBuilder/useEdgeResize.d.ts +84 -0
  24. package/dist/components/ReportBuilder/useTileReorder.d.ts +3 -0
  25. package/dist/components/legacy/malloynb/CellRunnerView.d.ts +6 -6
  26. package/dist/hooks/useSettled.d.ts +5 -8
  27. package/dist/hooks/useSettledDraft.d.ts +33 -0
  28. package/dist/index.cjs.js +10 -10
  29. package/dist/index.es.js +3861 -3870
  30. package/dist/theme/classes.d.ts +1 -1
  31. package/dist/useCompiledDocument-C995sQ3j.cjs.js +142 -0
  32. package/dist/{useCompiledDocument-BGk38oaW.es.js → useCompiledDocument-CRmmbUza.es.js} +6426 -6257
  33. package/dist/utils/malloyLiteral.d.ts +2 -0
  34. package/package.json +11 -16
  35. package/src/builder-entry.ts +1 -0
  36. package/src/components/Dashboard/DashboardGrid.tsx +2 -0
  37. package/src/components/Dashboard/DashboardTile.tsx +4 -0
  38. package/src/components/Dashboard/DashboardView.tsx +1 -0
  39. package/src/components/RenderedResult/RenderedResult.tsx +18 -0
  40. package/src/components/RenderedResult/ResultContainer.tsx +39 -3
  41. package/src/components/RenderedResult/ResultPanel.tsx +4 -0
  42. package/src/components/RenderedResult/resultSizing.ts +6 -0
  43. package/src/components/ReportBuilder/ArrangeMenu.tsx +80 -0
  44. package/src/components/ReportBuilder/BuilderBar.tsx +4 -0
  45. package/src/components/ReportBuilder/BuilderDialogs.tsx +8 -1
  46. package/src/components/ReportBuilder/BuilderGrid.tsx +62 -60
  47. package/src/components/ReportBuilder/BuilderToolbar.tsx +4 -0
  48. package/src/components/ReportBuilder/EditorSurface.tsx +9 -2
  49. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +99 -0
  50. package/src/components/ReportBuilder/ReportBuilder.tsx +110 -30
  51. package/src/components/ReportBuilder/TextTileBody.tsx +24 -4
  52. package/src/components/ReportBuilder/TileFrame.tsx +261 -310
  53. package/src/components/ReportBuilder/builderControls.ts +34 -0
  54. package/src/components/ReportBuilder/placement.spec.ts +235 -0
  55. package/src/components/ReportBuilder/placement.ts +179 -9
  56. package/src/components/ReportBuilder/readDocument.spec.ts +7 -17
  57. package/src/components/ReportBuilder/readDocument.ts +3 -6
  58. package/src/components/ReportBuilder/sortable.tsx +26 -2
  59. package/src/components/ReportBuilder/spliceDocument.spec.ts +0 -40
  60. package/src/components/ReportBuilder/spliceDocument.ts +0 -39
  61. package/src/components/ReportBuilder/useBuilderSession.ts +7 -2
  62. package/src/components/ReportBuilder/useBuilderShortcuts.ts +25 -1
  63. package/src/components/ReportBuilder/useEdgeResize.spec.tsx +324 -0
  64. package/src/components/ReportBuilder/useEdgeResize.ts +397 -0
  65. package/src/components/ReportBuilder/useTileReorder.ts +1 -1
  66. package/src/components/given/GivenInput.spec.tsx +447 -2
  67. package/src/components/given/GivenInput.tsx +192 -80
  68. package/src/components/given/GivensPanel.spec.tsx +59 -0
  69. package/src/components/given/GivensPanel.tsx +14 -2
  70. package/src/components/legacy/malloynb/CellRunnerView.tsx +6 -6
  71. package/src/hooks/useDimensionFilters.ts +1 -35
  72. package/src/hooks/useDimensionFiltersQuery.ts +2 -36
  73. package/src/hooks/useDimensionalFilterRangeData.ts +1 -35
  74. package/src/hooks/useGivensState.spec.ts +106 -1
  75. package/src/hooks/useGivensState.ts +48 -13
  76. package/src/hooks/useSettled.ts +5 -8
  77. package/src/hooks/useSettledDraft.ts +127 -0
  78. package/src/theme/classes.ts +1 -1
  79. package/src/utils/malloyLiteral.spec.ts +12 -1
  80. package/src/utils/malloyLiteral.ts +32 -0
  81. package/vite.config.ts +0 -2
  82. package/.eslintrc +0 -36
  83. package/dist/components/DOMElement/DOMElement.d.ts +0 -5
  84. package/dist/components/DOMElement/index.d.ts +0 -1
  85. package/dist/components/Package/FileTreeView.d.ts +0 -9
  86. package/dist/components/ReportBuilder/useTileHeight.d.ts +0 -39
  87. package/dist/components/ReportBuilder/useTileResize.d.ts +0 -40
  88. package/dist/useCompiledDocument-D9t5ry_t.cjs.js +0 -142
  89. package/src/components/DOMElement/DOMElement.tsx +0 -22
  90. package/src/components/DOMElement/index.ts +0 -4
  91. package/src/components/Package/FileTreeView.tsx +0 -244
  92. package/src/components/ReportBuilder/useTileHeight.ts +0 -149
  93. package/src/components/ReportBuilder/useTileResize.spec.tsx +0 -146
  94. package/src/components/ReportBuilder/useTileResize.ts +0 -148
@@ -1,10 +1,26 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
- import { describe, expect, it, mock } from "bun:test";
5
- import { cleanup, fireEvent, render, screen } from "@testing-library/react";
4
+ import {
5
+ afterEach,
6
+ beforeEach,
7
+ describe,
8
+ expect,
9
+ it,
10
+ jest,
11
+ mock,
12
+ } from "bun:test";
13
+ import {
14
+ act,
15
+ cleanup,
16
+ fireEvent,
17
+ render,
18
+ screen,
19
+ } from "@testing-library/react";
20
+ import { useState } from "react";
6
21
  import type { Given } from "../../client";
7
22
  import type { GivenValue } from "../../hooks/givenValue";
23
+ import { GIVEN_SETTLE_MS } from "../../hooks/useSettled";
8
24
  import { GivenInput } from "./GivenInput";
9
25
 
10
26
  /**
@@ -994,3 +1010,432 @@ describe("GivenInput: the range slider's commits", () => {
994
1010
  expect(onChange).toHaveBeenCalledWith(null);
995
1011
  });
996
1012
  });
1013
+
1014
+ // Bun runs it; its typings do not declare it.
1015
+ const advance = (ms: number) =>
1016
+ (
1017
+ jest as unknown as { advanceTimersByTime(ms: number): void }
1018
+ ).advanceTimersByTime(ms);
1019
+
1020
+ /** A host that feeds each commit back in as `value`, the way a dashboard does. */
1021
+ function Host({
1022
+ given,
1023
+ initial,
1024
+ onChange,
1025
+ }: {
1026
+ given: Given;
1027
+ initial: GivenValue | undefined;
1028
+ onChange: (next: GivenValue) => void;
1029
+ }) {
1030
+ const [value, setValue] = useState<GivenValue | undefined>(initial);
1031
+ return (
1032
+ <GivenInput
1033
+ given={given}
1034
+ value={value}
1035
+ onChange={(next) => {
1036
+ onChange(next);
1037
+ setValue(next);
1038
+ }}
1039
+ />
1040
+ );
1041
+ }
1042
+
1043
+ describe("GivenInput: typing commits once the field settles", () => {
1044
+ beforeEach(() => {
1045
+ jest.useFakeTimers();
1046
+ });
1047
+ afterEach(() => {
1048
+ jest.useRealTimers();
1049
+ cleanup();
1050
+ });
1051
+
1052
+ const text: Given = { name: "brand", type: "filter<string>" };
1053
+ const type = (input: HTMLElement, value: string) => {
1054
+ fireEvent.focus(input);
1055
+ fireEvent.change(input, { target: { value } });
1056
+ };
1057
+
1058
+ it("sends one change for a burst of keystrokes, after the burst", () => {
1059
+ const onChange = mock((_next: GivenValue) => {});
1060
+ render(<Host given={text} initial={undefined} onChange={onChange} />);
1061
+ const input = screen.getByLabelText("brand") as HTMLInputElement;
1062
+ for (const value of ["F", "Fo", "For", "Ford"]) {
1063
+ type(input, value);
1064
+ act(() => advance(GIVEN_SETTLE_MS - 1));
1065
+ }
1066
+ expect(onChange).toHaveBeenCalledTimes(0);
1067
+ act(() => advance(1));
1068
+ expect(onChange).toHaveBeenCalledTimes(1);
1069
+ expect(onChange).toHaveBeenCalledWith("Ford");
1070
+ act(() => advance(GIVEN_SETTLE_MS * 3));
1071
+ expect(onChange).toHaveBeenCalledTimes(1);
1072
+ });
1073
+
1074
+ it("commits on Enter without waiting", () => {
1075
+ const onChange = mock((_next: GivenValue) => {});
1076
+ render(<Host given={text} initial={undefined} onChange={onChange} />);
1077
+ const input = screen.getByLabelText("brand");
1078
+ type(input, "Ford");
1079
+ fireEvent.keyDown(input, { key: "Enter" });
1080
+ expect(onChange).toHaveBeenCalledTimes(1);
1081
+ expect(onChange).toHaveBeenCalledWith("Ford");
1082
+ act(() => advance(GIVEN_SETTLE_MS * 3));
1083
+ expect(onChange).toHaveBeenCalledTimes(1);
1084
+ });
1085
+
1086
+ it("commits a draft that settled mid-composition once the composition ends", () => {
1087
+ const onChange = mock((_next: GivenValue) => {});
1088
+ render(<Host given={text} initial={undefined} onChange={onChange} />);
1089
+ const input = screen.getByLabelText("brand");
1090
+ fireEvent.focus(input);
1091
+ fireEvent.compositionStart(input);
1092
+ fireEvent.change(input, { target: { value: "日本" } });
1093
+ act(() => advance(GIVEN_SETTLE_MS * 2));
1094
+ expect(onChange).toHaveBeenCalledTimes(0);
1095
+ fireEvent.compositionEnd(input);
1096
+ act(() => advance(GIVEN_SETTLE_MS));
1097
+ expect(onChange).toHaveBeenCalledTimes(1);
1098
+ expect(onChange).toHaveBeenCalledWith("日本");
1099
+ });
1100
+
1101
+ it("commits a pending draft when the field unmounts", () => {
1102
+ const onChange = mock((_next: GivenValue) => {});
1103
+ const view = render(
1104
+ <Host given={text} initial={undefined} onChange={onChange} />,
1105
+ );
1106
+ type(screen.getByLabelText("brand"), "Ford");
1107
+ view.unmount();
1108
+ expect(onChange).toHaveBeenCalledTimes(1);
1109
+ expect(onChange).toHaveBeenCalledWith("Ford");
1110
+ });
1111
+
1112
+ it("follows the host while focused when nothing has been typed", () => {
1113
+ const onChange = mock((_next: GivenValue) => {});
1114
+ const view = render(
1115
+ <GivenInput given={text} value="East" onChange={onChange} />,
1116
+ );
1117
+ const input = screen.getByLabelText("brand") as HTMLInputElement;
1118
+ fireEvent.focus(input);
1119
+ view.rerender(
1120
+ <GivenInput given={text} value="West" onChange={onChange} />,
1121
+ );
1122
+ expect(input.value).toBe("West");
1123
+ fireEvent.blur(input);
1124
+ expect(onChange).toHaveBeenCalledTimes(0);
1125
+ });
1126
+
1127
+ it("reverts an emptied number once, and an untouched blur sends nothing more", () => {
1128
+ const onChange = mock((_next: GivenValue) => {});
1129
+ render(
1130
+ <Host
1131
+ given={{ name: "n", type: "number" }}
1132
+ initial={5}
1133
+ onChange={onChange}
1134
+ />,
1135
+ );
1136
+ const input = screen.getByLabelText("n");
1137
+ type(input, "");
1138
+ fireEvent.blur(input);
1139
+ fireEvent.focus(input);
1140
+ fireEvent.blur(input);
1141
+ fireEvent.focus(input);
1142
+ fireEvent.keyDown(input, { key: "Enter" });
1143
+ act(() => advance(GIVEN_SETTLE_MS * 3));
1144
+ expect(onChange.mock.calls.map((c) => c[0])).toEqual([null]);
1145
+ });
1146
+
1147
+ it("keeps a backspace typed while the host still shows the older commit", () => {
1148
+ const onChange = mock((_next: GivenValue) => {});
1149
+ const view = render(
1150
+ <GivenInput given={text} value="ab" onChange={onChange} />,
1151
+ );
1152
+ const input = screen.getByLabelText("brand") as HTMLInputElement;
1153
+ type(input, "abc");
1154
+ act(() => advance(GIVEN_SETTLE_MS));
1155
+ expect(onChange).toHaveBeenCalledWith("abc");
1156
+ // The host has not adopted "abc" yet when the reader backspaces.
1157
+ fireEvent.change(input, { target: { value: "ab" } });
1158
+ view.rerender(
1159
+ <GivenInput given={text} value="abc" onChange={onChange} />,
1160
+ );
1161
+ expect(input.value).toBe("ab");
1162
+ act(() => advance(GIVEN_SETTLE_MS));
1163
+ expect(onChange).toHaveBeenLastCalledWith("ab");
1164
+ });
1165
+
1166
+ it("does not send a settled draft again when the control unmounts before the host echoes it", () => {
1167
+ const onChange = mock((_next: GivenValue) => {});
1168
+ const view = render(
1169
+ <GivenInput given={text} value="ab" onChange={onChange} />,
1170
+ );
1171
+ type(screen.getByLabelText("brand"), "abc");
1172
+ act(() => advance(GIVEN_SETTLE_MS));
1173
+ view.unmount();
1174
+ expect(onChange).toHaveBeenCalledTimes(1);
1175
+ });
1176
+
1177
+ it("commits a backspace back to the stale committed value when the host echo is late", () => {
1178
+ const onChange = mock((_next: GivenValue) => {});
1179
+ const view = render(
1180
+ <GivenInput given={text} value="ab" onChange={onChange} />,
1181
+ );
1182
+ const input = screen.getByLabelText("brand") as HTMLInputElement;
1183
+ fireEvent.focus(input);
1184
+ type(input, "abc");
1185
+ act(() => advance(GIVEN_SETTLE_MS));
1186
+ fireEvent.change(input, { target: { value: "ab" } });
1187
+ fireEvent.blur(input);
1188
+ expect(onChange).toHaveBeenLastCalledWith("ab");
1189
+ view.rerender(
1190
+ <GivenInput given={text} value="abc" onChange={onChange} />,
1191
+ );
1192
+ view.rerender(<GivenInput given={text} value="ab" onChange={onChange} />);
1193
+ expect(input.value).toBe("ab");
1194
+ expect(onChange).toHaveBeenCalledTimes(2);
1195
+ });
1196
+
1197
+ it("sends an explicit empty value when an unset field is typed in and emptied", () => {
1198
+ const onChange = mock((_next: GivenValue) => {});
1199
+ render(<Host given={text} initial={undefined} onChange={onChange} />);
1200
+ const input = screen.getByLabelText("brand");
1201
+ fireEvent.focus(input);
1202
+ fireEvent.blur(input);
1203
+ expect(onChange).toHaveBeenCalledTimes(0);
1204
+ type(input, "x");
1205
+ type(input, "");
1206
+ act(() => advance(GIVEN_SETTLE_MS));
1207
+ expect(onChange).toHaveBeenCalledTimes(1);
1208
+ expect(onChange).toHaveBeenCalledWith("");
1209
+ });
1210
+
1211
+ it("does not send the draft after a clear that swaps the control", () => {
1212
+ const onChange = mock((_next: GivenValue) => {});
1213
+ render(
1214
+ <Host
1215
+ given={{
1216
+ name: "n",
1217
+ type: "filter<number>",
1218
+ rangeMin: 0,
1219
+ rangeMax: 10,
1220
+ }}
1221
+ initial="!= 3"
1222
+ onChange={onChange}
1223
+ />,
1224
+ );
1225
+ const input = screen.getByRole("textbox");
1226
+ type(input, "!= 4");
1227
+ fireEvent.click(clearButtons()[0]);
1228
+ expect(onChange.mock.calls.map((c) => c[0])).toEqual([null]);
1229
+ });
1230
+
1231
+ it("commits on blur without waiting", () => {
1232
+ const onChange = mock((_next: GivenValue) => {});
1233
+ render(<Host given={text} initial={undefined} onChange={onChange} />);
1234
+ const input = screen.getByLabelText("brand");
1235
+ type(input, "Ford");
1236
+ fireEvent.blur(input);
1237
+ expect(onChange).toHaveBeenCalledTimes(1);
1238
+ expect(onChange).toHaveBeenCalledWith("Ford");
1239
+ act(() => advance(GIVEN_SETTLE_MS * 3));
1240
+ expect(onChange).toHaveBeenCalledTimes(1);
1241
+ });
1242
+
1243
+ it("does not overwrite typed text when the value changes under a focused field", () => {
1244
+ const view = render(
1245
+ <GivenInput given={text} value={undefined} onChange={() => {}} />,
1246
+ );
1247
+ const input = screen.getByLabelText("brand") as HTMLInputElement;
1248
+ type(input, "Fordo");
1249
+ // The URL echoing back an earlier keystroke.
1250
+ view.rerender(
1251
+ <GivenInput given={text} value="Ford" onChange={() => {}} />,
1252
+ );
1253
+ expect(input.value).toBe("Fordo");
1254
+ });
1255
+
1256
+ it("shows a new value once the field is no longer focused", () => {
1257
+ const view = render(
1258
+ <GivenInput given={text} value="Ford" onChange={() => {}} />,
1259
+ );
1260
+ const input = screen.getByLabelText("brand") as HTMLInputElement;
1261
+ view.rerender(
1262
+ <GivenInput given={text} value="Audi" onChange={() => {}} />,
1263
+ );
1264
+ expect(input.value).toBe("Audi");
1265
+ });
1266
+
1267
+ it("never commits on mount, for an unset filter given", () => {
1268
+ const onChange = mock((_next: GivenValue) => {});
1269
+ render(<GivenInput given={text} value={undefined} onChange={onChange} />);
1270
+ act(() => advance(GIVEN_SETTLE_MS * 3));
1271
+ expect(onChange).toHaveBeenCalledTimes(0);
1272
+ });
1273
+
1274
+ it("clears without sending the half-typed text first", () => {
1275
+ const onChange = mock((_next: GivenValue) => {});
1276
+ render(<Host given={text} initial="Audi" onChange={onChange} />);
1277
+ const input = screen.getByLabelText("brand") as HTMLInputElement;
1278
+ type(input, "Ford");
1279
+ fireEvent.click(clearButtons()[0]);
1280
+ fireEvent.blur(input);
1281
+ act(() => advance(GIVEN_SETTLE_MS * 3));
1282
+ expect(onChange).toHaveBeenCalledTimes(1);
1283
+ expect(onChange.mock.calls[0][0]).toBeNull();
1284
+ expect(input.value).toBe("");
1285
+ });
1286
+
1287
+ it("sends one change for a burst typed into a number field", () => {
1288
+ const onChange = mock((_next: GivenValue) => {});
1289
+ render(
1290
+ <Host
1291
+ given={{ name: "n", type: "number" }}
1292
+ initial={undefined}
1293
+ onChange={onChange}
1294
+ />,
1295
+ );
1296
+ const input = screen.getByLabelText("n");
1297
+ for (const value of ["1", "12", "123"]) {
1298
+ type(input, value);
1299
+ act(() => advance(100));
1300
+ }
1301
+ expect(onChange).toHaveBeenCalledTimes(0);
1302
+ act(() => advance(GIVEN_SETTLE_MS));
1303
+ expect(onChange).toHaveBeenCalledTimes(1);
1304
+ expect(onChange).toHaveBeenCalledWith(123);
1305
+ });
1306
+ });
1307
+
1308
+ describe("GivenInput: a date typed into the field", () => {
1309
+ beforeEach(() => {
1310
+ jest.useFakeTimers();
1311
+ });
1312
+ afterEach(() => {
1313
+ jest.useRealTimers();
1314
+ cleanup();
1315
+ });
1316
+
1317
+ it("commits once it settles, not for each edit", () => {
1318
+ const onChange = mock((_next: GivenValue) => {});
1319
+ render(
1320
+ <Host
1321
+ given={{ name: "d", type: "date" }}
1322
+ initial={undefined}
1323
+ onChange={onChange}
1324
+ />,
1325
+ );
1326
+ const input = screen.getByRole("textbox") as HTMLInputElement;
1327
+ fireEvent.focus(input);
1328
+ fireEvent.change(input, { target: { value: "01/15/2024" } });
1329
+ fireEvent.change(input, { target: { value: "01/16/2024" } });
1330
+ expect(onChange).toHaveBeenCalledTimes(0);
1331
+ act(() => advance(GIVEN_SETTLE_MS));
1332
+ expect(onChange).toHaveBeenCalledTimes(1);
1333
+ expect((onChange.mock.calls[0][0] as Date).toISOString()).toBe(
1334
+ "2024-01-16T00:00:00.000Z",
1335
+ );
1336
+ // The committed day is UTC and the typed one is local, equal days that
1337
+ // are different instants outside UTC: blurring must not send it again.
1338
+ fireEvent.blur(input);
1339
+ expect(onChange).toHaveBeenCalledTimes(1);
1340
+ });
1341
+
1342
+ it("commits at once when the field is not focused, as a calendar pick is", () => {
1343
+ const onChange = mock((_next: GivenValue) => {});
1344
+ render(
1345
+ <Host
1346
+ given={{ name: "d", type: "date" }}
1347
+ initial={undefined}
1348
+ onChange={onChange}
1349
+ />,
1350
+ );
1351
+ const input = screen.getByRole("textbox") as HTMLInputElement;
1352
+ fireEvent.change(input, { target: { value: "01/15/2024" } });
1353
+ expect(onChange).toHaveBeenCalledTimes(1);
1354
+ });
1355
+
1356
+ it("keeps focus on the field when the clear button is pressed", () => {
1357
+ render(
1358
+ <Host
1359
+ given={{ name: "d", type: "date" }}
1360
+ initial={new Date("2024-01-16T00:00:00Z")}
1361
+ onChange={() => {}}
1362
+ />,
1363
+ );
1364
+ const clear = screen.getByRole("button", { name: "Clear" });
1365
+ expect(fireEvent.mouseDown(clear)).toBe(false);
1366
+ });
1367
+
1368
+ it("sends one change for a custom range edited in a burst", () => {
1369
+ const onChange = mock((_next: GivenValue) => {});
1370
+ render(
1371
+ <Host
1372
+ given={{ name: "p", type: "filter<timestamp>" }}
1373
+ initial="2024-01-01 to 2024-02-01"
1374
+ onChange={onChange}
1375
+ />,
1376
+ );
1377
+ const to = screen.getByLabelText("To") as HTMLInputElement;
1378
+ fireEvent.focus(to);
1379
+ fireEvent.change(to, { target: { value: "01/15/2024" } });
1380
+ fireEvent.change(to, { target: { value: "01/20/2024" } });
1381
+ expect(onChange).toHaveBeenCalledTimes(0);
1382
+ act(() => advance(GIVEN_SETTLE_MS));
1383
+ expect(onChange).toHaveBeenCalledTimes(1);
1384
+ });
1385
+ });
1386
+
1387
+ describe("GivenInput: a slider commits on release, not on every move", () => {
1388
+ afterEach(cleanup);
1389
+
1390
+ it("sends nothing while the thumb is dragged and one change on release", () => {
1391
+ const onChange = mock((_next: GivenValue) => {});
1392
+ render(
1393
+ <GivenInput
1394
+ given={{ name: "n", type: "number", rangeMin: 0, rangeMax: 10 }}
1395
+ value={2}
1396
+ onChange={onChange}
1397
+ />,
1398
+ );
1399
+ const root = document.querySelector(".MuiSlider-root") as HTMLElement;
1400
+ root.getBoundingClientRect = () =>
1401
+ ({
1402
+ left: 0,
1403
+ width: 100,
1404
+ top: 0,
1405
+ height: 10,
1406
+ right: 100,
1407
+ bottom: 10,
1408
+ }) as DOMRect;
1409
+ fireEvent.mouseDown(root, { clientX: 30, button: 0 });
1410
+ fireEvent.mouseMove(document, { clientX: 50, buttons: 1 });
1411
+ fireEvent.mouseMove(document, { clientX: 70, buttons: 1 });
1412
+ expect(onChange).toHaveBeenCalledTimes(0);
1413
+ fireEvent.mouseUp(document, { clientX: 70, buttons: 1 });
1414
+ expect(onChange).toHaveBeenCalledTimes(1);
1415
+ expect(onChange).toHaveBeenCalledWith(7);
1416
+ });
1417
+
1418
+ it("sends nothing for a press that moves nothing", () => {
1419
+ const onChange = mock((_next: GivenValue) => {});
1420
+ render(
1421
+ <GivenInput
1422
+ given={{ name: "n", type: "number", rangeMin: 0, rangeMax: 10 }}
1423
+ value={undefined}
1424
+ onChange={onChange}
1425
+ />,
1426
+ );
1427
+ const root = document.querySelector(".MuiSlider-root") as HTMLElement;
1428
+ root.getBoundingClientRect = () =>
1429
+ ({
1430
+ left: 0,
1431
+ width: 100,
1432
+ top: 0,
1433
+ height: 10,
1434
+ right: 100,
1435
+ bottom: 10,
1436
+ }) as DOMRect;
1437
+ fireEvent.mouseDown(root, { clientX: 0, button: 0 });
1438
+ fireEvent.mouseUp(document, { clientX: 0, buttons: 1 });
1439
+ expect(onChange).toHaveBeenCalledTimes(0);
1440
+ });
1441
+ });