@malloy-publisher/sdk 0.8.1 → 0.8.2

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 (34) hide show
  1. package/dist/{DocumentStorage-D7yF4_T3.cjs.js → DocumentStorage-B0_YgSzt.cjs.js} +32 -32
  2. package/dist/{DocumentStorage-BCpTBa7U.es.js → DocumentStorage-BZqn0x5r.es.js} +3826 -3741
  3. package/dist/{RenderedResult-ChkvK7b2.cjs.js → RenderedResult-Bu25oAAr.cjs.js} +1 -1
  4. package/dist/{RenderedResult-CDA9mN_6.es.js → RenderedResult-DKOl0FQ8.es.js} +2 -2
  5. package/dist/{ServerProvider-CvMqBhuj.es.js → ServerProvider-CfUFleYe.es.js} +4 -4
  6. package/dist/builder/index.cjs.js +1 -1
  7. package/dist/builder/index.es.js +2 -2
  8. package/dist/client/api.d.ts +10 -4
  9. package/dist/client/index.es.js +1 -1
  10. package/dist/components/Dashboard/ExploreDialog.d.ts +3 -1
  11. package/dist/components/Model/Model.d.ts +10 -3
  12. package/dist/components/Model/ModelExplorer.d.ts +21 -1
  13. package/dist/components/Model/ModelExplorerDialog.d.ts +4 -1
  14. package/dist/components/Model/SourcesExplorer.d.ts +8 -1
  15. package/dist/components/Model/index.d.ts +1 -0
  16. package/dist/components/Model/runGate.d.ts +19 -0
  17. package/dist/components/Notebook/NotebookCell.d.ts +10 -1
  18. package/dist/index.cjs.js +13 -13
  19. package/dist/index.es.js +3754 -3732
  20. package/package.json +1 -1
  21. package/src/components/Dashboard/Dashboard.spec.tsx +58 -2
  22. package/src/components/Dashboard/Dashboard.tsx +8 -1
  23. package/src/components/Dashboard/ExploreDialog.tsx +5 -0
  24. package/src/components/Model/Model.tsx +28 -1
  25. package/src/components/Model/ModelExplorer.spec.tsx +404 -0
  26. package/src/components/Model/ModelExplorer.tsx +65 -2
  27. package/src/components/Model/ModelExplorerDialog.tsx +12 -0
  28. package/src/components/Model/SourcesExplorer.tsx +70 -15
  29. package/src/components/Model/index.ts +1 -0
  30. package/src/components/Model/runGate.spec.ts +102 -0
  31. package/src/components/Model/runGate.ts +67 -0
  32. package/src/components/Notebook/Notebook.spec.tsx +67 -3
  33. package/src/components/Notebook/Notebook.tsx +12 -2
  34. package/src/components/Notebook/NotebookCell.tsx +26 -7
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@malloy-publisher/sdk",
3
3
  "description": "Malloy Publisher SDK",
4
- "version": "0.8.1",
4
+ "version": "0.8.2",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
7
7
  "module": "dist/index.es.js",
@@ -11,6 +11,7 @@
11
11
  */
12
12
  import { beforeEach, describe, expect, it, mock } from "bun:test";
13
13
  import { fireEvent, render, screen, waitFor } from "@testing-library/react";
14
+ import type { ReactNode } from "react";
14
15
  import {
15
16
  cacheKeys,
16
17
  clearCache,
@@ -18,7 +19,7 @@ import {
18
19
  pending,
19
20
  serverWrapper,
20
21
  } from "../../../test/serverProvider";
21
- import type { DashboardManifest } from "../../client";
22
+ import type { CompiledModel, DashboardManifest } from "../../client";
22
23
 
23
24
  const getDashboard = mock(
24
25
  (
@@ -36,10 +37,35 @@ const executeQueryModel = mock(
36
37
  _request: { versionId?: string; givens?: Record<string, string> },
37
38
  ) => pending(),
38
39
  );
40
+ const getModel = mock(
41
+ (
42
+ _environmentName: string,
43
+ _packageName: string,
44
+ _modelPath: string,
45
+ _versionId?: string,
46
+ ) => pending<{ data: CompiledModel }>(),
47
+ );
48
+
49
+ // Stubbed rather than let "Explore from here" reach the real ModelExplorer:
50
+ // that pulls in the lazy-loaded, WASM-backed `@malloydata/malloy-explorer`,
51
+ // which is not this file's business. Only what the dashboard hands it matters
52
+ // here, so the stub just records its props.
53
+ const exploreDialogProps = mock(
54
+ (_props: { open: boolean; startingGivens?: Record<string, string> }) => {},
55
+ );
56
+ mock.module("../Model/ModelExplorerDialog", () => ({
57
+ ModelExplorerDialog: (props: {
58
+ open: boolean;
59
+ startingGivens?: Record<string, string>;
60
+ }) => {
61
+ exploreDialogProps(props);
62
+ return null as ReactNode;
63
+ },
64
+ }));
39
65
 
40
66
  mockServerProvider({
41
67
  dashboards: { getDashboard },
42
- models: { executeQueryModel },
68
+ models: { executeQueryModel, getModel },
43
69
  });
44
70
 
45
71
  // Imported after the stub is registered: a static import would hoist above it.
@@ -70,6 +96,9 @@ beforeEach(() => {
70
96
  getDashboard.mockImplementation(() => pending());
71
97
  executeQueryModel.mockReset();
72
98
  executeQueryModel.mockImplementation(() => pending());
99
+ getModel.mockReset();
100
+ getModel.mockImplementation(() => pending());
101
+ exploreDialogProps.mockClear();
73
102
  });
74
103
 
75
104
  describe("the manifest fetch", () => {
@@ -210,4 +239,31 @@ describe("the version reaches what the manifest drives", () => {
210
239
  expect(v2).toHaveLength(1);
211
240
  expect(v2[0]).not.toContain("CA");
212
241
  });
242
+
243
+ it("opens 'Explore from here' with the dashboard's current values", async () => {
244
+ getDashboard.mockImplementation(() =>
245
+ Promise.resolve({
246
+ data: {
247
+ ...manifest,
248
+ query: undefined,
249
+ tiles: [{ query: "by_month" }],
250
+ },
251
+ }),
252
+ );
253
+ getModel.mockImplementation(() =>
254
+ Promise.resolve({ data: { sourceInfos: [] } }),
255
+ );
256
+
257
+ render(dashboardAt(), { wrapper: serverWrapper });
258
+
259
+ fireEvent.change(await screen.findByLabelText("REGION"), {
260
+ target: { value: "CA" },
261
+ });
262
+ fireEvent.click(await screen.findByRole("button", { name: /Explore/ }));
263
+
264
+ await waitFor(() => expect(exploreDialogProps).toHaveBeenCalled());
265
+ const lastCall = exploreDialogProps.mock.calls.at(-1)?.[0];
266
+ expect(lastCall?.open).toBe(true);
267
+ expect(lastCall?.startingGivens).toEqual({ REGION: "CA" });
268
+ });
213
269
  });
@@ -17,7 +17,7 @@ import {
17
17
  } from "../drill";
18
18
  import { GivensPanel } from "../given";
19
19
  import { Prose } from "../Prose";
20
- import { givensToRequest } from "../given/paramCodec";
20
+ import { givensToParams, givensToRequest } from "../given/paramCodec";
21
21
  import { Loading } from "../Loading";
22
22
  import { TILE_MAX_HEIGHT } from "../RenderedResult/resultSizing";
23
23
  import { useServer } from "../ServerProvider";
@@ -189,6 +189,12 @@ export function Dashboard({
189
189
  [applied, declaredTypes],
190
190
  );
191
191
 
192
+ // The explorer's controls take the URL-string form, not the request form.
193
+ const exploreGivens = useMemo(
194
+ () => givensToParams(applied, declaredTypes),
195
+ [applied, declaredTypes],
196
+ );
197
+
192
198
  const { drill, drillMenu } = useDrill({
193
199
  onNavigate,
194
200
  onSelf,
@@ -350,6 +356,7 @@ export function Dashboard({
350
356
  packageName={packageName}
351
357
  {...(versionId === undefined ? {} : { versionId })}
352
358
  modelPath={modelPath}
359
+ givens={exploreGivens}
353
360
  onClose={() => setExploring(undefined)}
354
361
  />
355
362
  </>
@@ -23,6 +23,7 @@ export function ExploreDialog({
23
23
  packageName,
24
24
  versionId,
25
25
  modelPath,
26
+ givens,
26
27
  onClose,
27
28
  }: {
28
29
  /** The tile expression to open, or undefined when closed. */
@@ -31,6 +32,8 @@ export function ExploreDialog({
31
32
  packageName: string;
32
33
  versionId?: string;
33
34
  modelPath: string;
35
+ /** The dashboard's current control values, to seed the explorer's own. */
36
+ givens?: Record<string, string>;
34
37
  onClose: () => void;
35
38
  }) {
36
39
  const resourceUri = encodeResourceUri({
@@ -79,6 +82,8 @@ export function ExploreDialog({
79
82
  title={`Explore: ${tile}`}
80
83
  existingQuery={existingQuery}
81
84
  initialSelectedSourceIndex={sourceIndex}
85
+ // Reset returns to the dashboard's values, not the model's defaults.
86
+ startingGivens={givens}
82
87
  />
83
88
  );
84
89
  }
@@ -16,11 +16,22 @@ import { ModelExplorerDialog } from "./ModelExplorerDialog";
16
16
  import { QueryExplorerResult } from "./SourcesExplorer";
17
17
  import { useModelData } from "./useModelData";
18
18
 
19
- interface ModelProps {
19
+ export interface ModelProps {
20
20
  onChange?: (query: QueryExplorerResult) => void;
21
21
  resourceUri: string;
22
22
  runOnDemand?: boolean;
23
23
  maxResultSize?: number;
24
+ /**
25
+ * Control values from the host, typically its URL query parameters. When
26
+ * omitted, `Model` holds them itself, so the embedded explorer and the
27
+ * maximized dialog still agree with each other.
28
+ */
29
+ givens?: Record<string, string>;
30
+ /** Applied control values, for a host that wants them in its URL. */
31
+ onGivensChange?: (
32
+ givens: Record<string, string>,
33
+ managed: readonly string[],
34
+ ) => void;
24
35
  }
25
36
 
26
37
  // Note: For this to properly render outside of publisher,
@@ -32,6 +43,8 @@ export default function Model({
32
43
  resourceUri,
33
44
  runOnDemand = false,
34
45
  maxResultSize = 0,
46
+ givens,
47
+ onGivensChange,
35
48
  }: ModelProps) {
36
49
  const { modelPath } = parseResourceUri(resourceUri);
37
50
  const { data, isError, isLoading, error } = useModelData(resourceUri);
@@ -41,6 +54,16 @@ export default function Model({
41
54
  >();
42
55
  const [sharedSourceIndex, setSharedSourceIndex] = React.useState(0);
43
56
  const [copyMessage, setCopyMessage] = useState("");
57
+ // Held here only when the host passes neither prop, so the embedded
58
+ // explorer and the maximized dialog still agree on one set of values
59
+ // rather than each defaulting independently.
60
+ const [localGivens, setLocalGivens] = React.useState<Record<string, string>>(
61
+ {},
62
+ );
63
+ const effectiveGivens = givens ?? localGivens;
64
+ const effectiveOnGivensChange =
65
+ onGivensChange ??
66
+ ((applied: Record<string, string>) => setLocalGivens(applied));
44
67
 
45
68
  // Whether the model imports other files — drives the empty-state hint for
46
69
  // import-only models, whose discovery surface is legitimately empty (no
@@ -142,6 +165,8 @@ export default function Model({
142
165
  existingQuery={sharedQuery}
143
166
  initialSelectedSourceIndex={sharedSourceIndex}
144
167
  resourceUri={resourceUri}
168
+ givens={effectiveGivens}
169
+ onGivensChange={effectiveOnGivensChange}
145
170
  />
146
171
 
147
172
  {/* Magnifying glass icon */}
@@ -232,6 +257,8 @@ export default function Model({
232
257
  initialSelectedSourceIndex={sharedSourceIndex}
233
258
  onChange={handleQueryChange}
234
259
  onSourceChange={handleSourceChange}
260
+ givens={effectiveGivens}
261
+ onGivensChange={effectiveOnGivensChange}
235
262
  />
236
263
  </Box>
237
264
  <Snackbar
@@ -0,0 +1,404 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ /**
5
+ * The Explorer sends the control row's values with every Run, and surfaces a
6
+ * default note, a server error and a missing-given hint as banners rather than
7
+ * swallowing them.
8
+ *
9
+ * `@malloydata/malloy-explorer` is stubbed because it is lazy-loaded (a
10
+ * dynamic `import()` inside `SourceExplorerComponent`) and pulls in a real
11
+ * query-builder and renderer this spec has no business exercising; only
12
+ * `mock.module` reaches a dynamic import the same way it reaches a static one.
13
+ * It is process-global, so this is the one spec in the package allowed to
14
+ * import either module — see test/README.md.
15
+ */
16
+ import { beforeEach, describe, expect, it, mock } from "bun:test";
17
+ import { fireEvent, render, screen, waitFor } from "@testing-library/react";
18
+ import type { ReactNode } from "react";
19
+ import {
20
+ clearCache,
21
+ mockServerProvider,
22
+ pending,
23
+ serverWrapper,
24
+ } from "../../../test/serverProvider";
25
+ import type { CompiledModel } from "../../client";
26
+
27
+ mock.module("@malloydata/malloy-explorer", () => ({
28
+ MalloyExplorerProvider: ({ children }: { children: ReactNode }) => (
29
+ <>{children}</>
30
+ ),
31
+ QueryPanel: ({ runQuery }: { runQuery: () => void }) => (
32
+ <button onClick={runQuery}>Run</button>
33
+ ),
34
+ ResizableCollapsiblePanel: ({ children }: { children: ReactNode }) => (
35
+ <>{children}</>
36
+ ),
37
+ SourcePanel: () => null,
38
+ ResultPanel: ({
39
+ submittedQuery,
40
+ }: {
41
+ submittedQuery?: {
42
+ response?: { messages?: { title: string }[] };
43
+ onCancel: () => void;
44
+ };
45
+ }) => (
46
+ <div data-testid="result-panel">
47
+ {submittedQuery && (
48
+ <button onClick={submittedQuery.onCancel}>Cancel</button>
49
+ )}
50
+ {submittedQuery?.response?.messages?.map((message) => (
51
+ <div key={message.title}>{message.title}</div>
52
+ ))}
53
+ </div>
54
+ ),
55
+ }));
56
+
57
+ // Never reached when every test's query is a plain string (see below), but
58
+ // stubbed anyway so the module's own dynamic import resolves to something
59
+ // light rather than the real WASM-backed builder.
60
+ mock.module("@malloydata/malloy-query-builder", () => ({
61
+ ASTQuery: class {
62
+ toMalloy() {
63
+ return "run: orders -> by_month";
64
+ }
65
+ },
66
+ }));
67
+
68
+ const executeQueryModel = mock(
69
+ (
70
+ _environmentName: string,
71
+ _packageName: string,
72
+ _modelPath: string,
73
+ _request: { versionId?: string; givens?: Record<string, unknown> },
74
+ ) => pending<{ data: { result: string } }>(),
75
+ );
76
+
77
+ mockServerProvider({ models: { executeQueryModel } });
78
+
79
+ // Imported after the stubs above: a static import would hoist above them.
80
+ const { ModelExplorer } = await import("./ModelExplorer");
81
+
82
+ const URI = "publisher://environments/env/packages/pkg/models/orders.malloy";
83
+
84
+ const modelWith = (givens?: CompiledModel["givens"]): CompiledModel => ({
85
+ sourceInfos: [JSON.stringify({ name: "orders" })],
86
+ ...(givens ? { givens } : {}),
87
+ });
88
+
89
+ /** As a string, so `SourceExplorerComponentInner` never reaches `ASTQuery`. */
90
+ const EXISTING_QUERY = {
91
+ query: "run: orders -> by_month",
92
+ malloyQuery: "run: orders -> by_month",
93
+ malloyResult: undefined,
94
+ };
95
+
96
+ const run = () => fireEvent.click(screen.getByRole("button", { name: "Run" }));
97
+
98
+ beforeEach(() => {
99
+ clearCache();
100
+ executeQueryModel.mockReset();
101
+ executeQueryModel.mockImplementation(() => pending());
102
+ });
103
+
104
+ const reject = (status: number, message: string) =>
105
+ executeQueryModel.mockImplementation(() =>
106
+ Promise.reject(
107
+ Object.assign(new Error("fallback"), {
108
+ status,
109
+ data: { code: status, message },
110
+ }),
111
+ ),
112
+ );
113
+
114
+ describe("a given with no value and no default", () => {
115
+ // Givens are model-wide but read per source, so a blank one may be fine for
116
+ // the source being explored: the server decides, not the client.
117
+ it("still sends Run, and names the given when the server refuses", async () => {
118
+ reject(403, 'Access denied for source "regions".');
119
+ render(
120
+ <ModelExplorer
121
+ data={modelWith([{ name: "TENANT", type: "string" }])}
122
+ existingQuery={EXISTING_QUERY}
123
+ resourceUri={URI}
124
+ />,
125
+ { wrapper: serverWrapper },
126
+ );
127
+
128
+ await screen.findByLabelText("TENANT");
129
+ run();
130
+
131
+ expect(
132
+ await screen.findByText('Access denied for source "regions".'),
133
+ ).toBeTruthy();
134
+ expect(
135
+ screen.getByText(
136
+ "This source may need a value for the given TENANT. Set it in the parameters above.",
137
+ ),
138
+ ).toBeTruthy();
139
+ expect(executeQueryModel).toHaveBeenCalledTimes(1);
140
+ });
141
+
142
+ // The refusal check is status OR message; each case below pins one half alone.
143
+ it("names the given on a 403 whatever its message says", async () => {
144
+ reject(403, "Forbidden");
145
+ render(
146
+ <ModelExplorer
147
+ data={modelWith([{ name: "TENANT", type: "string" }])}
148
+ existingQuery={EXISTING_QUERY}
149
+ resourceUri={URI}
150
+ />,
151
+ { wrapper: serverWrapper },
152
+ );
153
+
154
+ await screen.findByLabelText("TENANT");
155
+ run();
156
+
157
+ expect(await screen.findByText("Forbidden")).toBeTruthy();
158
+ expect(
159
+ screen.getByText(/may need a value for the given TENANT/),
160
+ ).toBeTruthy();
161
+ });
162
+
163
+ it("names the given on a gate's message that carries no status", async () => {
164
+ executeQueryModel.mockImplementation(() =>
165
+ Promise.reject(new Error('Access denied for source "regions".')),
166
+ );
167
+ render(
168
+ <ModelExplorer
169
+ data={modelWith([{ name: "TENANT", type: "string" }])}
170
+ existingQuery={EXISTING_QUERY}
171
+ resourceUri={URI}
172
+ />,
173
+ { wrapper: serverWrapper },
174
+ );
175
+
176
+ await screen.findByLabelText("TENANT");
177
+ run();
178
+
179
+ expect(
180
+ await screen.findByText('Access denied for source "regions".'),
181
+ ).toBeTruthy();
182
+ expect(
183
+ screen.getByText(/may need a value for the given TENANT/),
184
+ ).toBeTruthy();
185
+ });
186
+
187
+ it("adds no hint to an error that is not a refusal", async () => {
188
+ reject(400, "syntax error near 'aggregat'");
189
+ render(
190
+ <ModelExplorer
191
+ data={modelWith([{ name: "TENANT", type: "string" }])}
192
+ existingQuery={EXISTING_QUERY}
193
+ resourceUri={URI}
194
+ />,
195
+ { wrapper: serverWrapper },
196
+ );
197
+
198
+ await screen.findByLabelText("TENANT");
199
+ run();
200
+
201
+ expect(
202
+ await screen.findByText("syntax error near 'aggregat'"),
203
+ ).toBeTruthy();
204
+ expect(screen.queryByText(/may need a value/)).toBeNull();
205
+ });
206
+ });
207
+
208
+ describe("a given left blank with a default", () => {
209
+ it("runs, and notes the default that was used", async () => {
210
+ executeQueryModel.mockImplementation(() =>
211
+ Promise.resolve({ data: { result: JSON.stringify({}) } }),
212
+ );
213
+ render(
214
+ <ModelExplorer
215
+ data={modelWith([
216
+ { name: "TENANT", type: "string", default: "'acme'" },
217
+ ])}
218
+ existingQuery={EXISTING_QUERY}
219
+ resourceUri={URI}
220
+ />,
221
+ { wrapper: serverWrapper },
222
+ );
223
+
224
+ await screen.findByLabelText("TENANT");
225
+ run();
226
+
227
+ await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
228
+ expect(
229
+ await screen.findByText("Ran with the default TENANT = acme"),
230
+ ).toBeTruthy();
231
+ });
232
+ });
233
+
234
+ describe("a model that declares givens", () => {
235
+ it("sends the control's value with Run", async () => {
236
+ executeQueryModel.mockImplementation(() =>
237
+ Promise.resolve({ data: { result: JSON.stringify({}) } }),
238
+ );
239
+ render(
240
+ <ModelExplorer
241
+ data={modelWith([{ name: "TENANT", type: "string" }])}
242
+ existingQuery={EXISTING_QUERY}
243
+ resourceUri={URI}
244
+ />,
245
+ { wrapper: serverWrapper },
246
+ );
247
+
248
+ fireEvent.change(await screen.findByLabelText("TENANT"), {
249
+ target: { value: "acme" },
250
+ });
251
+ run();
252
+
253
+ await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
254
+ expect(executeQueryModel.mock.calls[0][3].givens).toEqual({
255
+ TENANT: "acme",
256
+ });
257
+ });
258
+ });
259
+
260
+ describe("a model with no givens", () => {
261
+ it("renders no Parameters row, and sends no givens key", async () => {
262
+ executeQueryModel.mockImplementation(() =>
263
+ Promise.resolve({ data: { result: JSON.stringify({}) } }),
264
+ );
265
+ render(
266
+ <ModelExplorer
267
+ data={modelWith()}
268
+ existingQuery={EXISTING_QUERY}
269
+ resourceUri={URI}
270
+ />,
271
+ { wrapper: serverWrapper },
272
+ );
273
+
274
+ // Nothing to wait on the label for, so wait on the button instead.
275
+ await screen.findByRole("button", { name: "Run" });
276
+ expect(screen.queryByText("Parameters")).toBeNull();
277
+ run();
278
+
279
+ await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
280
+ expect(executeQueryModel.mock.calls[0][3]).not.toHaveProperty("givens");
281
+ });
282
+ });
283
+
284
+ describe("a rejected run", () => {
285
+ it("shows the server's message rather than clearing the pane", async () => {
286
+ const apiError = Object.assign(new Error("fallback"), {
287
+ status: 403,
288
+ data: { code: 403, message: "Not authorized: missing TENANT" },
289
+ });
290
+ executeQueryModel.mockImplementation(() => Promise.reject(apiError));
291
+ render(
292
+ <ModelExplorer
293
+ data={modelWith([
294
+ { name: "TENANT", type: "string", default: "'x'" },
295
+ ])}
296
+ existingQuery={EXISTING_QUERY}
297
+ resourceUri={URI}
298
+ />,
299
+ { wrapper: serverWrapper },
300
+ );
301
+
302
+ await screen.findByLabelText("TENANT");
303
+ run();
304
+
305
+ expect(
306
+ await screen.findByText("Not authorized: missing TENANT"),
307
+ ).toBeTruthy();
308
+ });
309
+ });
310
+
311
+ describe("a cancelled run", () => {
312
+ it("stays cleared when its request fails afterwards", async () => {
313
+ let fail: (reason: unknown) => void = () => {};
314
+ executeQueryModel.mockImplementation(
315
+ () =>
316
+ new Promise((_resolve, reject) => {
317
+ fail = reject;
318
+ }),
319
+ );
320
+ render(
321
+ <ModelExplorer
322
+ data={modelWith()}
323
+ existingQuery={EXISTING_QUERY}
324
+ resourceUri={URI}
325
+ />,
326
+ { wrapper: serverWrapper },
327
+ );
328
+
329
+ await screen.findByRole("button", { name: "Run" });
330
+ run();
331
+ fireEvent.click(await screen.findByRole("button", { name: "Cancel" }));
332
+ fail(
333
+ Object.assign(new Error("fallback"), {
334
+ status: 500,
335
+ data: { code: 500, message: "late failure" },
336
+ }),
337
+ );
338
+
339
+ // Give the rejection a chance to land before asserting it changed nothing.
340
+ await new Promise((resolve) => setTimeout(resolve, 50));
341
+ expect(screen.queryByText("late failure")).toBeNull();
342
+ expect(screen.queryByRole("button", { name: "Cancel" })).toBeNull();
343
+ });
344
+ });
345
+
346
+ describe("host-supplied givens", () => {
347
+ it("seeds the control, and reports a change with the given in `managed`", async () => {
348
+ const onGivensChange = mock(
349
+ (_givens: Record<string, string>, _managed: readonly string[]) => {},
350
+ );
351
+ render(
352
+ <ModelExplorer
353
+ data={modelWith([{ name: "TENANT", type: "string" }])}
354
+ existingQuery={EXISTING_QUERY}
355
+ resourceUri={URI}
356
+ givens={{ TENANT: "acme" }}
357
+ onGivensChange={onGivensChange}
358
+ />,
359
+ { wrapper: serverWrapper },
360
+ );
361
+
362
+ const input = (await screen.findByLabelText(
363
+ "TENANT",
364
+ )) as HTMLInputElement;
365
+ expect(input.value).toBe("acme");
366
+
367
+ fireEvent.change(input, { target: { value: "beta" } });
368
+
369
+ await waitFor(() =>
370
+ expect(onGivensChange).toHaveBeenCalledWith({ TENANT: "beta" }, [
371
+ "TENANT",
372
+ ]),
373
+ );
374
+ });
375
+ });
376
+
377
+ describe("startingGivens", () => {
378
+ it("seeds the control, and Run sends it", async () => {
379
+ executeQueryModel.mockImplementation(() =>
380
+ Promise.resolve({ data: { result: JSON.stringify({}) } }),
381
+ );
382
+ render(
383
+ <ModelExplorer
384
+ data={modelWith([{ name: "TENANT", type: "string" }])}
385
+ existingQuery={EXISTING_QUERY}
386
+ resourceUri={URI}
387
+ startingGivens={{ TENANT: "acme" }}
388
+ />,
389
+ { wrapper: serverWrapper },
390
+ );
391
+
392
+ const input = (await screen.findByLabelText(
393
+ "TENANT",
394
+ )) as HTMLInputElement;
395
+ expect(input.value).toBe("acme");
396
+
397
+ run();
398
+
399
+ await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
400
+ expect(executeQueryModel.mock.calls[0][3].givens).toEqual({
401
+ TENANT: "acme",
402
+ });
403
+ });
404
+ });