@malloy-publisher/sdk 0.0.247 → 0.0.249
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.
- package/README.md +32 -17
- package/dist/ServerProvider-CcfeBpt3.cjs.js +1 -0
- package/dist/{ServerProvider-BxEh3nFI.es.js → ServerProvider-EqBlMMqx.es.js} +1056 -905
- package/dist/client/api.d.ts +298 -7
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +74 -70
- package/dist/components/Dashboard/Dashboard.d.ts +49 -0
- package/dist/components/Dashboard/DashboardTile.d.ts +48 -0
- package/dist/components/Dashboard/index.d.ts +2 -0
- package/dist/components/Notebook/Notebook.d.ts +46 -8
- package/dist/components/Notebook/NotebookCell.d.ts +37 -3
- package/dist/components/Notebook/runPlan.d.ts +29 -0
- package/dist/components/Notebook/types.d.ts +10 -0
- package/dist/components/Package/ContentTypeIcon.d.ts +17 -1
- package/dist/components/Package/Package.d.ts +1 -4
- package/dist/components/RenderedResult/RenderedResult.d.ts +7 -1
- package/dist/components/RenderedResult/ResultContainer.d.ts +3 -1
- package/dist/components/ResultsDialog.d.ts +4 -1
- package/dist/components/ServerProvider.d.ts +2 -1
- package/dist/components/click_helper.d.ts +10 -1
- package/dist/components/drill/index.d.ts +3 -0
- package/dist/components/drill/markDrillableCells.d.ts +55 -0
- package/dist/components/drill/resolveDrill.d.ts +159 -0
- package/dist/components/drill/useDrill.d.ts +63 -0
- package/dist/components/given/GivenInput.d.ts +27 -3
- package/dist/components/given/GivensPanel.d.ts +36 -7
- package/dist/components/given/filterValue.d.ts +117 -0
- package/dist/components/given/index.d.ts +1 -1
- package/dist/components/given/paramCodec.d.ts +60 -0
- package/dist/components/index.d.ts +4 -1
- package/dist/components/styles.d.ts +23 -0
- package/dist/constants/docLinks.d.ts +6 -0
- package/dist/{core-BuvlzSIX.es.js → core-DFBwNhvb.es.js} +1 -1
- package/dist/{core-C86Rb7tJ.cjs.js → core-DZk7z7ko.cjs.js} +1 -1
- package/dist/hooks/givenValue.d.ts +10 -0
- package/dist/hooks/index.d.ts +3 -1
- package/dist/hooks/useGivensState.d.ts +64 -0
- package/dist/hooks/useSuggestOptions.d.ts +78 -0
- package/dist/{index-BdtAZ5k6.es.js → index-CLcRrkxd.es.js} +41221 -39894
- package/dist/index-CWQXhe0D.cjs.js +338 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +77 -62
- package/dist/theme/types.d.ts +9 -0
- package/package.json +3 -1
- package/src/components/Connections/AddConnectionDialog.tsx +10 -1
- package/src/components/Dashboard/Dashboard.tsx +395 -0
- package/src/components/Dashboard/DashboardTile.tsx +150 -0
- package/src/components/Dashboard/index.ts +2 -0
- package/src/components/Home/Home.tsx +114 -23
- package/src/components/Notebook/Notebook.tsx +444 -390
- package/src/components/Notebook/NotebookCell.tsx +117 -3
- package/src/components/Notebook/runPlan.spec.ts +152 -0
- package/src/components/Notebook/runPlan.ts +64 -0
- package/src/components/Notebook/types.ts +11 -0
- package/src/components/Package/ContentTypeIcon.spec.ts +88 -0
- package/src/components/Package/ContentTypeIcon.tsx +77 -6
- package/src/components/Package/Package.tsx +148 -38
- package/src/components/RenderedResult/RenderedResult.tsx +309 -19
- package/src/components/RenderedResult/ResultContainer.tsx +28 -1
- package/src/components/ResultsDialog.tsx +5 -0
- package/src/components/ServerProvider.tsx +2 -0
- package/src/components/click_helper.ts +14 -1
- package/src/components/drill/index.ts +25 -0
- package/src/components/drill/markDrillableCells.dom.spec.ts +310 -0
- package/src/components/drill/markDrillableCells.spec.ts +106 -0
- package/src/components/drill/markDrillableCells.ts +311 -0
- package/src/components/drill/resolveDrill.spec.ts +446 -0
- package/src/components/drill/resolveDrill.ts +372 -0
- package/src/components/drill/useDrill.tsx +200 -0
- package/src/components/given/GivenInput.spec.tsx +495 -15
- package/src/components/given/GivenInput.tsx +562 -30
- package/src/components/given/GivensPanel.spec.tsx +172 -0
- package/src/components/given/GivensPanel.tsx +139 -32
- package/src/components/given/filterValue.spec.ts +361 -0
- package/src/components/given/filterValue.ts +204 -0
- package/src/components/given/index.ts +5 -1
- package/src/components/given/paramCodec.spec.ts +854 -0
- package/src/components/given/paramCodec.ts +480 -0
- package/src/components/index.ts +4 -1
- package/src/components/styles.ts +27 -3
- package/src/constants/docLinks.spec.ts +51 -0
- package/src/constants/docLinks.ts +26 -0
- package/src/hooks/givenValue.ts +10 -0
- package/src/hooks/index.ts +6 -4
- package/src/hooks/useGivensState.spec.ts +446 -0
- package/src/hooks/useGivensState.ts +337 -0
- package/src/hooks/useSuggestOptions.spec.ts +109 -0
- package/src/hooks/useSuggestOptions.ts +260 -0
- package/src/theme/buildTableCssVars.ts +4 -0
- package/src/theme/resolveTheme.spec.ts +13 -0
- package/src/theme/resolveTheme.ts +3 -0
- package/src/theme/types.ts +9 -0
- package/test/README.md +16 -10
- package/dist/ServerProvider-Dg5S1qBU.cjs.js +0 -1
- package/dist/hooks/useGivensForm.d.ts +0 -35
- package/dist/index-MES4MGpQ.cjs.js +0 -309
- package/src/hooks/useGivensForm.spec.ts +0 -99
- package/src/hooks/useGivensForm.ts +0 -107
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it, mock } from "bun:test";
|
|
2
|
-
import { fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
-
import type {
|
|
2
|
+
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import type { Given } from "../../client";
|
|
4
|
+
import type { GivenValue } from "../../hooks/givenValue";
|
|
4
5
|
import { GivenInput } from "./GivenInput";
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -66,7 +67,7 @@ describe("GivenInput: unset vs. explicit override", () => {
|
|
|
66
67
|
|
|
67
68
|
fireEvent.click(clearButtons()[0]);
|
|
68
69
|
|
|
69
|
-
// null, not "". `
|
|
70
|
+
// null, not "". `useGivensState` deletes the key on null, which is what
|
|
70
71
|
// returns the given to "use the model default".
|
|
71
72
|
expect(onChange).toHaveBeenCalledTimes(1);
|
|
72
73
|
expect(onChange.mock.calls[0][0]).toBeNull();
|
|
@@ -176,31 +177,510 @@ describe("GivenInput: number", () => {
|
|
|
176
177
|
});
|
|
177
178
|
});
|
|
178
179
|
|
|
179
|
-
describe("GivenInput
|
|
180
|
-
|
|
180
|
+
describe("GivenInput, which types are actually reachable", () => {
|
|
181
|
+
// There used to be an `array<...>` branch here rendering a multi-value
|
|
182
|
+
// widget, and it was unreachable twice over. Malloy's grammar emits only
|
|
183
|
+
// scalar parameter types, so no array given exists to send; and if one did,
|
|
184
|
+
// `given.ts` renders the wire type as the bare discriminator "array", which
|
|
185
|
+
// never matched that branch's `startsWith("array<")` test. It is gone, and
|
|
186
|
+
// both spellings now land on the text box every unknown type gets.
|
|
187
|
+
for (const type of ["array<string>", "array", "record", "geography"]) {
|
|
188
|
+
it(`falls back to a text box for ${type}`, () => {
|
|
189
|
+
render(
|
|
190
|
+
<GivenInput
|
|
191
|
+
given={{ name: "tags", type }}
|
|
192
|
+
value={undefined}
|
|
193
|
+
onChange={() => {}}
|
|
194
|
+
/>,
|
|
195
|
+
);
|
|
196
|
+
expect(screen.queryAllByRole("combobox")).toHaveLength(0);
|
|
197
|
+
expect(screen.getByLabelText("tags")).toBeDefined();
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
describe("GivenInput: a control= the widget cannot honour falls through", () => {
|
|
203
|
+
// The picker speaks two languages: plain strings and the STRING filter
|
|
204
|
+
// grammar. Honouring `control=select` on anything else corrupts the value,
|
|
205
|
+
// a `filter<date>` would get string-grammar escaping the temporal parser
|
|
206
|
+
// rejects, and a `number` given would get a string `givensToRequest` forwards
|
|
207
|
+
// verbatim for Malloy to refuse. Nothing populates `control` yet, so these
|
|
208
|
+
// pin the refusal before the slice that starts populating it.
|
|
209
|
+
const pickerCount = () => screen.queryAllByRole("combobox").length;
|
|
210
|
+
|
|
211
|
+
for (const type of ["string", "filter<string>"]) {
|
|
212
|
+
it(`renders a picker for ${type}`, () => {
|
|
213
|
+
render(
|
|
214
|
+
<GivenInput
|
|
215
|
+
given={{ name: "g", type, control: "select" }}
|
|
216
|
+
value={undefined}
|
|
217
|
+
onChange={() => {}}
|
|
218
|
+
/>,
|
|
219
|
+
);
|
|
220
|
+
expect(pickerCount()).toBe(1);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
for (const type of [
|
|
225
|
+
"number",
|
|
226
|
+
"boolean",
|
|
227
|
+
"date",
|
|
228
|
+
"timestamp",
|
|
229
|
+
"filter<number>",
|
|
230
|
+
"filter<date>",
|
|
231
|
+
]) {
|
|
232
|
+
it(`refuses a picker for ${type} and uses the type's own widget`, () => {
|
|
233
|
+
render(
|
|
234
|
+
<GivenInput
|
|
235
|
+
given={{ name: "g", type, control: "multiselect" }}
|
|
236
|
+
value={undefined}
|
|
237
|
+
onChange={() => {}}
|
|
238
|
+
/>,
|
|
239
|
+
);
|
|
240
|
+
expect(pickerCount()).toBe(0);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
describe("GivenInput: a slider only claims a filter it can represent", () => {
|
|
246
|
+
it("renders a slider for a lower-bound filter", () => {
|
|
247
|
+
render(
|
|
248
|
+
<GivenInput
|
|
249
|
+
given={{
|
|
250
|
+
name: "n",
|
|
251
|
+
type: "filter<number>",
|
|
252
|
+
rangeMin: 0,
|
|
253
|
+
rangeMax: 10,
|
|
254
|
+
}}
|
|
255
|
+
value=">= 5"
|
|
256
|
+
onChange={() => {}}
|
|
257
|
+
/>,
|
|
258
|
+
);
|
|
259
|
+
expect(screen.queryAllByRole("slider")).toHaveLength(1);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it("falls through for a filter it cannot represent", () => {
|
|
263
|
+
// Otherwise `decodeAtLeast` returns undefined, the control reads "Any"
|
|
264
|
+
// while a range is in force, and the first drag replaces it silently.
|
|
265
|
+
render(
|
|
266
|
+
<GivenInput
|
|
267
|
+
given={{
|
|
268
|
+
name: "n",
|
|
269
|
+
type: "filter<number>",
|
|
270
|
+
rangeMin: 0,
|
|
271
|
+
rangeMax: 10,
|
|
272
|
+
}}
|
|
273
|
+
value="1 to 5"
|
|
274
|
+
onChange={() => {}}
|
|
275
|
+
/>,
|
|
276
|
+
);
|
|
277
|
+
expect(screen.queryAllByRole("slider")).toHaveLength(0);
|
|
278
|
+
expect((screen.getByLabelText("n") as HTMLInputElement).value).toBe(
|
|
279
|
+
"1 to 5",
|
|
280
|
+
);
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
describe("GivenInput: multi-pick needs a type that can carry several values", () => {
|
|
285
|
+
it("is single-pick for a plain string given, even when asked for multi", () => {
|
|
286
|
+
// A real array cannot survive the URL: `givenToParam` joins on `,` and
|
|
287
|
+
// reading it back yields the joined string, not the list. So a plain
|
|
288
|
+
// `string` given renders single-pick rather than emitting something the
|
|
289
|
+
// address bar would corrupt.
|
|
290
|
+
const onChange = mock((_next: GivenValue) => {});
|
|
181
291
|
render(
|
|
182
292
|
<GivenInput
|
|
183
|
-
given={{ name: "
|
|
293
|
+
given={{ name: "g", type: "string", control: "multiselect" }}
|
|
294
|
+
value={undefined}
|
|
295
|
+
onChange={onChange}
|
|
296
|
+
/>,
|
|
297
|
+
);
|
|
298
|
+
const input = screen.getByRole("combobox");
|
|
299
|
+
fireEvent.keyDown(input, { key: "ArrowDown" });
|
|
300
|
+
// No chips container: a single-pick Autocomplete has no multiple slot.
|
|
301
|
+
expect(screen.queryAllByRole("button", { name: /^g/ })).toHaveLength(0);
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it("is multi-pick for a filter<string> given", () => {
|
|
305
|
+
render(
|
|
306
|
+
<GivenInput
|
|
307
|
+
given={{
|
|
308
|
+
name: "g",
|
|
309
|
+
type: "filter<string>",
|
|
310
|
+
control: "multiselect",
|
|
311
|
+
}}
|
|
184
312
|
value={undefined}
|
|
185
313
|
onChange={() => {}}
|
|
314
|
+
options={["a", "b"]}
|
|
186
315
|
/>,
|
|
187
316
|
);
|
|
188
317
|
expect(screen.queryAllByRole("combobox")).toHaveLength(1);
|
|
189
318
|
});
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
describe("GivenInput: the whole type x control matrix", () => {
|
|
322
|
+
// Six guards decide which widget a given gets (`pickableType`,
|
|
323
|
+
// `multiplePickable`, `filterIsPickable`, `bareDate`, `dateIsPickable`,
|
|
324
|
+
// `sliderIsRepresentable`), each added for its own reason. Read one at a
|
|
325
|
+
// time they are each defensible. What nothing checked is what they do as a
|
|
326
|
+
// SET, so this enumerates every combination rather than sampling, and
|
|
327
|
+
// the property that matters most is the last assertion: no combination falls
|
|
328
|
+
// through every branch and renders nothing at all.
|
|
329
|
+
const widget = () => {
|
|
330
|
+
if (screen.queryAllByRole("combobox").length) return "picker";
|
|
331
|
+
if (screen.queryAllByRole("slider").length) return "slider";
|
|
332
|
+
if (screen.queryAllByRole("checkbox").length) return "checkbox";
|
|
333
|
+
if (screen.queryAllByRole("spinbutton").length) return "number";
|
|
334
|
+
if (screen.queryAllByRole("textbox").length) return "text";
|
|
335
|
+
return "NONE";
|
|
336
|
+
};
|
|
190
337
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
338
|
+
const show = (
|
|
339
|
+
type: string | undefined,
|
|
340
|
+
control?: string,
|
|
341
|
+
range?: boolean,
|
|
342
|
+
value?: GivenValue,
|
|
343
|
+
) => {
|
|
344
|
+
// Explicitly, because Testing Library's automatic cleanup runs BETWEEN
|
|
345
|
+
// tests: several renders inside one test otherwise stack up and every
|
|
346
|
+
// query sees the previous widget too.
|
|
347
|
+
cleanup();
|
|
196
348
|
render(
|
|
197
349
|
<GivenInput
|
|
198
|
-
given={
|
|
199
|
-
|
|
350
|
+
given={
|
|
351
|
+
{
|
|
352
|
+
name: "g",
|
|
353
|
+
type,
|
|
354
|
+
control,
|
|
355
|
+
...(range ? { rangeMin: 0, rangeMax: 10 } : {}),
|
|
356
|
+
} as Given
|
|
357
|
+
}
|
|
358
|
+
value={value}
|
|
200
359
|
onChange={() => {}}
|
|
201
360
|
/>,
|
|
202
361
|
);
|
|
203
|
-
|
|
204
|
-
|
|
362
|
+
return widget();
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
it("gives a picker only to the string family", () => {
|
|
366
|
+
expect(show("string", "select")).toBe("picker");
|
|
367
|
+
expect(show("filter<string>", "multiselect")).toBe("picker");
|
|
368
|
+
// An undeclared type defaults to string, so it may pick too.
|
|
369
|
+
expect(show(undefined, "select")).toBe("picker");
|
|
370
|
+
// Everything else refuses, because the picker only speaks strings.
|
|
371
|
+
for (const type of [
|
|
372
|
+
"number",
|
|
373
|
+
"boolean",
|
|
374
|
+
"date",
|
|
375
|
+
"timestamp",
|
|
376
|
+
"timestamptz",
|
|
377
|
+
"filter<number>",
|
|
378
|
+
"filter<date>",
|
|
379
|
+
]) {
|
|
380
|
+
expect(show(type, "select")).not.toBe("picker");
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it("gives a slider to a bounded number, control= or not", () => {
|
|
385
|
+
expect(show("number", undefined, true)).toBe("slider");
|
|
386
|
+
expect(show("filter<number>", undefined, true)).toBe("slider");
|
|
387
|
+
// A `control=select` on a bounded number still gets the slider: the
|
|
388
|
+
// picker refuses the type, and the slider is what the type implies.
|
|
389
|
+
expect(show("number", "select", true)).toBe("slider");
|
|
390
|
+
// Without bounds there is no slider to give.
|
|
391
|
+
expect(show("number", undefined, false)).toBe("number");
|
|
205
392
|
});
|
|
393
|
+
|
|
394
|
+
it("leaves every other combination on its type's own widget", () => {
|
|
395
|
+
expect(show("boolean", "multiselect")).toBe("checkbox");
|
|
396
|
+
expect(show("date", "select")).toBe("text");
|
|
397
|
+
expect(show("record", "select")).toBe("text");
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
it("routes on the VALUE too, not just the type and control", () => {
|
|
401
|
+
// Three of the six guards read the value rather than the declaration, so
|
|
402
|
+
// a matrix that only ever passes `undefined` cannot see them.
|
|
403
|
+
expect(show("filter<string>", "select", false, "Nike")).toBe("picker");
|
|
404
|
+
// A filter the picker cannot represent falls through to the text box, so
|
|
405
|
+
// the author's filter stays visible rather than being re-encoded.
|
|
406
|
+
expect(show("filter<string>", "select", false, "-Nike")).toBe("text");
|
|
407
|
+
// A lower-bound filter keeps the slider; a range cannot be a threshold.
|
|
408
|
+
expect(show("filter<number>", undefined, true, ">= 5")).toBe("slider");
|
|
409
|
+
expect(show("filter<number>", undefined, true, "1 to 5")).toBe("text");
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
// One test per type rather than one test for the whole matrix. The matrix is
|
|
413
|
+
// 13 types x 3 controls x 2 range states x 9 values, so a single `it` runs
|
|
414
|
+
// 702 renders against bun's 5s default and tipped over it on a CI runner
|
|
415
|
+
// already executing three timezone passes (5872ms, measured). Splitting also
|
|
416
|
+
// means a failure names the type, which the combined assertion could not.
|
|
417
|
+
const MATRIX_TYPES = [
|
|
418
|
+
"string",
|
|
419
|
+
"number",
|
|
420
|
+
"boolean",
|
|
421
|
+
"date",
|
|
422
|
+
"timestamp",
|
|
423
|
+
"timestamptz",
|
|
424
|
+
"filter<string>",
|
|
425
|
+
"filter<number>",
|
|
426
|
+
"filter<date>",
|
|
427
|
+
"filter<timestamp>",
|
|
428
|
+
"array<string>",
|
|
429
|
+
"record",
|
|
430
|
+
undefined,
|
|
431
|
+
];
|
|
432
|
+
|
|
433
|
+
it.each(MATRIX_TYPES)("never renders nothing, for %s", (type) => {
|
|
434
|
+
const values = [
|
|
435
|
+
undefined,
|
|
436
|
+
"",
|
|
437
|
+
"Nike",
|
|
438
|
+
"-Nike",
|
|
439
|
+
">= 5",
|
|
440
|
+
"1 to 5",
|
|
441
|
+
"2024-01-15",
|
|
442
|
+
5,
|
|
443
|
+
true,
|
|
444
|
+
] as GivenValue[];
|
|
445
|
+
for (const control of [undefined, "select", "multiselect"]) {
|
|
446
|
+
for (const range of [false, true]) {
|
|
447
|
+
for (const value of values) {
|
|
448
|
+
expect(show(type, control, range, value)).not.toBe("NONE");
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
describe("GivenInput: a date value the codec cannot read", () => {
|
|
456
|
+
// Four states (readable, unreadable, empty, unset) and only two of them,
|
|
457
|
+
// empty and unset, look alike: both render a blank picker. The state worth
|
|
458
|
+
// pinning is UNREADABLE, because a DatePicker can only display a date, so
|
|
459
|
+
// the obvious rendering of `?D=last month` is a blank picker whose own
|
|
460
|
+
// `clearable` never appears, which would filter every cell while being
|
|
461
|
+
// invisible and impossible to revert. What this branch must do instead is
|
|
462
|
+
// show the offending value and offer a revert, which is what follows.
|
|
463
|
+
const DATE: Given = { name: "D", type: "date" };
|
|
464
|
+
|
|
465
|
+
it("shows the offending value instead of rendering blank", () => {
|
|
466
|
+
render(
|
|
467
|
+
<GivenInput given={DATE} value="last month" onChange={() => {}} />,
|
|
468
|
+
);
|
|
469
|
+
expect(screen.getByDisplayValue("last month")).toBeDefined();
|
|
470
|
+
expect(screen.getByText(/Not a date/)).toBeDefined();
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
it("does not let the user edit the unreadable value in place", () => {
|
|
474
|
+
// An editable version of this field swapped itself for the picker the
|
|
475
|
+
// moment the typed text first parsed, taking the cursor with it.
|
|
476
|
+
render(
|
|
477
|
+
<GivenInput given={DATE} value="last month" onChange={() => {}} />,
|
|
478
|
+
);
|
|
479
|
+
expect(screen.getByDisplayValue("last month")).toHaveProperty(
|
|
480
|
+
"readOnly",
|
|
481
|
+
true,
|
|
482
|
+
);
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
it("keeps the calendar button on a readable value", () => {
|
|
486
|
+
// Putting the revert in the picker's own `InputProps` REPLACED this
|
|
487
|
+
// button, leaving a date control with no way to open a calendar.
|
|
488
|
+
render(
|
|
489
|
+
<GivenInput given={DATE} value="2024-01-05" onChange={() => {}} />,
|
|
490
|
+
);
|
|
491
|
+
expect(
|
|
492
|
+
screen.getByRole("button", { name: /choose date/i }),
|
|
493
|
+
).toBeDefined();
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
it("offers a revert, which the picker's own clearable does not", () => {
|
|
497
|
+
const onChange = mock((_next: GivenValue) => {});
|
|
498
|
+
render(
|
|
499
|
+
<GivenInput given={DATE} value="last month" onChange={onChange} />,
|
|
500
|
+
);
|
|
501
|
+
|
|
502
|
+
fireEvent.click(screen.getByRole("button", { name: "clear value" }));
|
|
503
|
+
|
|
504
|
+
expect(onChange.mock.calls[0][0]).toBeNull();
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
it("does not pin the picker's own error state when the value is fine", () => {
|
|
508
|
+
// `error` passed through `slotProps.textField` wins over MUI's internal
|
|
509
|
+
// validation for BOTH values, so a hardcoded `false` silently suppressed
|
|
510
|
+
// the picker's real errors.
|
|
511
|
+
render(
|
|
512
|
+
<GivenInput given={DATE} value="2024-01-05" onChange={() => {}} />,
|
|
513
|
+
);
|
|
514
|
+
expect(screen.getByRole("textbox").getAttribute("aria-invalid")).not.toBe(
|
|
515
|
+
"true",
|
|
516
|
+
);
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
it("reads a plain date string as a date rather than an error", () => {
|
|
520
|
+
// `# drill { to=self }` onto a date given hands over a bare `YYYY-MM-DD`
|
|
521
|
+
// STRING, not a Date, so treating every non-Date as unreadable painted an
|
|
522
|
+
// error over a value the product itself had just produced.
|
|
523
|
+
render(
|
|
524
|
+
<GivenInput given={DATE} value="2024-01-05" onChange={() => {}} />,
|
|
525
|
+
);
|
|
526
|
+
expect(screen.queryAllByText(/Not a date/)).toHaveLength(0);
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
it("treats an empty date value as an empty box, not an error", () => {
|
|
530
|
+
render(<GivenInput given={DATE} value="" onChange={() => {}} />);
|
|
531
|
+
expect(screen.queryAllByText(/Not a date/)).toHaveLength(0);
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
it("says nothing when the given is simply unset", () => {
|
|
535
|
+
render(<GivenInput given={DATE} value={undefined} onChange={() => {}} />);
|
|
536
|
+
expect(screen.queryAllByText(/Not a date/)).toHaveLength(0);
|
|
537
|
+
expect(
|
|
538
|
+
screen.queryAllByRole("button", { name: "clear value" }),
|
|
539
|
+
).toHaveLength(0);
|
|
540
|
+
});
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
describe("GivenInput: a number value the control cannot show", () => {
|
|
544
|
+
// The same hazard as the date branch, and for a long time handled a
|
|
545
|
+
// different way: the box substituted a blank, so the value went on filtering
|
|
546
|
+
// every cell while the control looked empty and said nothing about it.
|
|
547
|
+
const NUM: Given = { name: "N", type: "number" };
|
|
548
|
+
|
|
549
|
+
it("shows the offending value rather than a blank box", () => {
|
|
550
|
+
render(<GivenInput given={NUM} value="lots" onChange={() => {}} />);
|
|
551
|
+
expect(screen.getByDisplayValue("lots")).toBeDefined();
|
|
552
|
+
expect(screen.getByText(/Not a number/)).toBeDefined();
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
it("offers a revert", () => {
|
|
556
|
+
const onChange = mock((_next: GivenValue) => {});
|
|
557
|
+
render(<GivenInput given={NUM} value="lots" onChange={onChange} />);
|
|
558
|
+
fireEvent.click(screen.getByRole("button", { name: "clear value" }));
|
|
559
|
+
expect(onChange.mock.calls[0][0]).toBeNull();
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
it("treats an empty value as an empty box, not an error", () => {
|
|
563
|
+
// `?N=` in a URL arrives as the empty string. Calling that "Not a number"
|
|
564
|
+
// painted a red error over a field showing nothing at all.
|
|
565
|
+
render(<GivenInput given={NUM} value="" onChange={() => {}} />);
|
|
566
|
+
expect(screen.queryAllByText(/Not a number/)).toHaveLength(0);
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
it("leaves an ordinary number alone", () => {
|
|
570
|
+
render(<GivenInput given={NUM} value={42} onChange={() => {}} />);
|
|
571
|
+
expect(screen.queryAllByText(/Not a number/)).toHaveLength(0);
|
|
572
|
+
expect(screen.getByDisplayValue("42")).toBeDefined();
|
|
573
|
+
});
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
describe("GivenInput: a boolean value the control cannot show", () => {
|
|
577
|
+
const FLAG: Given = { name: "F", type: "boolean", default: "true" };
|
|
578
|
+
|
|
579
|
+
it("does not render the model default for a value it is still sending", () => {
|
|
580
|
+
// `?F=yes` reaches here as a string, which the codec passes through on
|
|
581
|
+
// purpose. The checkbox used to show the DEFAULT for it, so the box said
|
|
582
|
+
// one thing while the request carried "yes" and every cell failed.
|
|
583
|
+
render(<GivenInput given={FLAG} value="yes" onChange={() => {}} />);
|
|
584
|
+
expect(screen.getByDisplayValue("yes")).toBeDefined();
|
|
585
|
+
expect(screen.getByText(/Not a true or false/)).toBeDefined();
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
it("offers a revert", () => {
|
|
589
|
+
const onChange = mock((_next: GivenValue) => {});
|
|
590
|
+
render(<GivenInput given={FLAG} value="yes" onChange={onChange} />);
|
|
591
|
+
fireEvent.click(screen.getByRole("button", { name: "clear value" }));
|
|
592
|
+
expect(onChange.mock.calls[0][0]).toBeNull();
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
it("leaves a real boolean, and an unset given, alone", () => {
|
|
596
|
+
render(<GivenInput given={FLAG} value={false} onChange={() => {}} />);
|
|
597
|
+
expect(screen.queryAllByText(/Not a true or false/)).toHaveLength(0);
|
|
598
|
+
cleanup();
|
|
599
|
+
render(<GivenInput given={FLAG} value={undefined} onChange={() => {}} />);
|
|
600
|
+
expect(screen.queryAllByText(/Not a true or false/)).toHaveLength(0);
|
|
601
|
+
});
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
describe("GivenInput: a slider value the control cannot place", () => {
|
|
605
|
+
// Latent today, because nothing populates rangeMin/rangeMax, which is why it
|
|
606
|
+
// is worth pinning before anything does.
|
|
607
|
+
const SLIDER: Given = {
|
|
608
|
+
name: "MIN",
|
|
609
|
+
type: "number",
|
|
610
|
+
rangeMin: 0,
|
|
611
|
+
rangeMax: 100,
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
it('does not read as "Any" for a value it is still sending', () => {
|
|
615
|
+
render(<GivenInput given={SLIDER} value="lots" onChange={() => {}} />);
|
|
616
|
+
expect(screen.getByDisplayValue("lots")).toBeDefined();
|
|
617
|
+
expect(screen.getByText(/Not a number/)).toBeDefined();
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
it("still renders a slider for a value it can place", () => {
|
|
621
|
+
render(<GivenInput given={SLIDER} value={42} onChange={() => {}} />);
|
|
622
|
+
expect(screen.queryAllByText(/Not a number/)).toHaveLength(0);
|
|
623
|
+
expect(screen.getByRole("slider")).toBeDefined();
|
|
624
|
+
});
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
describe("GivenInput: a date renders its UTC day, whatever zone the runner is in", () => {
|
|
628
|
+
// The component hydrates with `dayjs.utc(value)`, so the box shows the day
|
|
629
|
+
// the server will be sent, not the day the viewer happens to be living in.
|
|
630
|
+
// These two literals exist because one alone can only catch half the bug: a
|
|
631
|
+
// late-UTC instant crosses the date line only for zones AHEAD of UTC, and an
|
|
632
|
+
// early-UTC one only for zones BEHIND it. Both UTC days below are 1 March.
|
|
633
|
+
//
|
|
634
|
+
// This is the trap that shipped once already: a fixture picked without
|
|
635
|
+
// checking which side of midnight it lands on in the runner's zone sits on
|
|
636
|
+
// the same UTC day and cannot fail, however exotic the zone.
|
|
637
|
+
const utcDay = "03/01/2024";
|
|
638
|
+
|
|
639
|
+
it("late in the UTC day, which is the next day east of UTC", () => {
|
|
640
|
+
render(
|
|
641
|
+
<GivenInput
|
|
642
|
+
given={{ name: "since", type: "date" }}
|
|
643
|
+
value={new Date("2024-03-01T23:30:00Z")}
|
|
644
|
+
onChange={() => {}}
|
|
645
|
+
/>,
|
|
646
|
+
);
|
|
647
|
+
// Reading local time here shows 03/02/2024 anywhere ahead of UTC.
|
|
648
|
+
expect((screen.getByLabelText("since") as HTMLInputElement).value).toBe(
|
|
649
|
+
utcDay,
|
|
650
|
+
);
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
it("early in the UTC day, which is the day before west of UTC", () => {
|
|
654
|
+
render(
|
|
655
|
+
<GivenInput
|
|
656
|
+
given={{ name: "since", type: "date" }}
|
|
657
|
+
value={new Date("2024-03-01T00:30:00Z")}
|
|
658
|
+
onChange={() => {}}
|
|
659
|
+
/>,
|
|
660
|
+
);
|
|
661
|
+
// Reading local time here shows 02/29/2024 anywhere behind UTC, and 2024
|
|
662
|
+
// being a leap year makes that a doubly wrong answer.
|
|
663
|
+
expect((screen.getByLabelText("since") as HTMLInputElement).value).toBe(
|
|
664
|
+
utcDay,
|
|
665
|
+
);
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
// One test case per type rather than a loop: a loop stops at the first failing
|
|
669
|
+
// type and its message names neither, so dropping both from the branch costs
|
|
670
|
+
// two round trips to diagnose instead of one.
|
|
671
|
+
it.each(["timestamp", "timestamptz"])(
|
|
672
|
+
"applies to %s, which shares the date branch",
|
|
673
|
+
(type) => {
|
|
674
|
+
render(
|
|
675
|
+
<GivenInput
|
|
676
|
+
given={{ name: "at", type }}
|
|
677
|
+
value={new Date("2024-03-01T23:30:00Z")}
|
|
678
|
+
onChange={() => {}}
|
|
679
|
+
/>,
|
|
680
|
+
);
|
|
681
|
+
expect((screen.getByLabelText("at") as HTMLInputElement).value).toBe(
|
|
682
|
+
utcDay,
|
|
683
|
+
);
|
|
684
|
+
},
|
|
685
|
+
);
|
|
206
686
|
});
|