@malloy-publisher/sdk 0.0.248 → 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.
Files changed (98) hide show
  1. package/README.md +32 -17
  2. package/dist/ServerProvider-CcfeBpt3.cjs.js +1 -0
  3. package/dist/{ServerProvider-BxEh3nFI.es.js → ServerProvider-EqBlMMqx.es.js} +1056 -905
  4. package/dist/client/api.d.ts +297 -6
  5. package/dist/client/index.cjs.js +1 -1
  6. package/dist/client/index.es.js +74 -70
  7. package/dist/components/Dashboard/Dashboard.d.ts +49 -0
  8. package/dist/components/Dashboard/DashboardTile.d.ts +48 -0
  9. package/dist/components/Dashboard/index.d.ts +2 -0
  10. package/dist/components/Notebook/Notebook.d.ts +46 -8
  11. package/dist/components/Notebook/NotebookCell.d.ts +37 -3
  12. package/dist/components/Notebook/runPlan.d.ts +29 -0
  13. package/dist/components/Notebook/types.d.ts +10 -0
  14. package/dist/components/Package/ContentTypeIcon.d.ts +17 -1
  15. package/dist/components/Package/Package.d.ts +1 -4
  16. package/dist/components/RenderedResult/RenderedResult.d.ts +7 -1
  17. package/dist/components/RenderedResult/ResultContainer.d.ts +3 -1
  18. package/dist/components/ResultsDialog.d.ts +4 -1
  19. package/dist/components/ServerProvider.d.ts +2 -1
  20. package/dist/components/click_helper.d.ts +10 -1
  21. package/dist/components/drill/index.d.ts +3 -0
  22. package/dist/components/drill/markDrillableCells.d.ts +55 -0
  23. package/dist/components/drill/resolveDrill.d.ts +159 -0
  24. package/dist/components/drill/useDrill.d.ts +63 -0
  25. package/dist/components/given/GivenInput.d.ts +27 -3
  26. package/dist/components/given/GivensPanel.d.ts +36 -7
  27. package/dist/components/given/filterValue.d.ts +117 -0
  28. package/dist/components/given/index.d.ts +1 -1
  29. package/dist/components/given/paramCodec.d.ts +60 -0
  30. package/dist/components/index.d.ts +4 -1
  31. package/dist/components/styles.d.ts +23 -0
  32. package/dist/constants/docLinks.d.ts +6 -0
  33. package/dist/{core-BuvlzSIX.es.js → core-DFBwNhvb.es.js} +1 -1
  34. package/dist/{core-C86Rb7tJ.cjs.js → core-DZk7z7ko.cjs.js} +1 -1
  35. package/dist/hooks/givenValue.d.ts +10 -0
  36. package/dist/hooks/index.d.ts +3 -1
  37. package/dist/hooks/useGivensState.d.ts +64 -0
  38. package/dist/hooks/useSuggestOptions.d.ts +78 -0
  39. package/dist/{index-BdtAZ5k6.es.js → index-CLcRrkxd.es.js} +41221 -39894
  40. package/dist/index-CWQXhe0D.cjs.js +338 -0
  41. package/dist/index.cjs.js +1 -1
  42. package/dist/index.es.js +77 -62
  43. package/dist/theme/types.d.ts +9 -0
  44. package/package.json +3 -1
  45. package/src/components/Connections/AddConnectionDialog.tsx +10 -1
  46. package/src/components/Dashboard/Dashboard.tsx +395 -0
  47. package/src/components/Dashboard/DashboardTile.tsx +150 -0
  48. package/src/components/Dashboard/index.ts +2 -0
  49. package/src/components/Home/Home.tsx +114 -23
  50. package/src/components/Notebook/Notebook.tsx +444 -390
  51. package/src/components/Notebook/NotebookCell.tsx +117 -3
  52. package/src/components/Notebook/runPlan.spec.ts +152 -0
  53. package/src/components/Notebook/runPlan.ts +64 -0
  54. package/src/components/Notebook/types.ts +11 -0
  55. package/src/components/Package/ContentTypeIcon.spec.ts +88 -0
  56. package/src/components/Package/ContentTypeIcon.tsx +77 -6
  57. package/src/components/Package/Package.tsx +148 -38
  58. package/src/components/RenderedResult/RenderedResult.tsx +309 -19
  59. package/src/components/RenderedResult/ResultContainer.tsx +28 -1
  60. package/src/components/ResultsDialog.tsx +5 -0
  61. package/src/components/ServerProvider.tsx +2 -0
  62. package/src/components/click_helper.ts +14 -1
  63. package/src/components/drill/index.ts +25 -0
  64. package/src/components/drill/markDrillableCells.dom.spec.ts +310 -0
  65. package/src/components/drill/markDrillableCells.spec.ts +106 -0
  66. package/src/components/drill/markDrillableCells.ts +311 -0
  67. package/src/components/drill/resolveDrill.spec.ts +446 -0
  68. package/src/components/drill/resolveDrill.ts +372 -0
  69. package/src/components/drill/useDrill.tsx +200 -0
  70. package/src/components/given/GivenInput.spec.tsx +495 -15
  71. package/src/components/given/GivenInput.tsx +562 -30
  72. package/src/components/given/GivensPanel.spec.tsx +172 -0
  73. package/src/components/given/GivensPanel.tsx +139 -32
  74. package/src/components/given/filterValue.spec.ts +361 -0
  75. package/src/components/given/filterValue.ts +204 -0
  76. package/src/components/given/index.ts +5 -1
  77. package/src/components/given/paramCodec.spec.ts +854 -0
  78. package/src/components/given/paramCodec.ts +480 -0
  79. package/src/components/index.ts +4 -1
  80. package/src/components/styles.ts +27 -3
  81. package/src/constants/docLinks.spec.ts +51 -0
  82. package/src/constants/docLinks.ts +26 -0
  83. package/src/hooks/givenValue.ts +10 -0
  84. package/src/hooks/index.ts +6 -4
  85. package/src/hooks/useGivensState.spec.ts +446 -0
  86. package/src/hooks/useGivensState.ts +337 -0
  87. package/src/hooks/useSuggestOptions.spec.ts +109 -0
  88. package/src/hooks/useSuggestOptions.ts +260 -0
  89. package/src/theme/buildTableCssVars.ts +4 -0
  90. package/src/theme/resolveTheme.spec.ts +13 -0
  91. package/src/theme/resolveTheme.ts +3 -0
  92. package/src/theme/types.ts +9 -0
  93. package/test/README.md +16 -10
  94. package/dist/ServerProvider-Dg5S1qBU.cjs.js +0 -1
  95. package/dist/hooks/useGivensForm.d.ts +0 -35
  96. package/dist/index-MES4MGpQ.cjs.js +0 -309
  97. package/src/hooks/useGivensForm.spec.ts +0 -99
  98. package/src/hooks/useGivensForm.ts +0 -107
@@ -0,0 +1,310 @@
1
+ import { describe, expect, it } from "bun:test";
2
+ import {
3
+ DRILL_CELL_CLASS,
4
+ drillColumnSiblings,
5
+ moveDrillStop,
6
+ markDrillableCells,
7
+ } from "./markDrillableCells";
8
+
9
+ /**
10
+ * The DOM half of the marking, which the sibling spec deliberately does not
11
+ * cover. Added because a guard written against rendered TEXT missed the case it
12
+ * existed for: the renderer draws a null cell as the glyph `∅` inside a
13
+ * `.value-null` span, so its `textContent` is not empty and every null cell
14
+ * stayed marked as a link whose click `resolveDrill` then refused.
15
+ */
16
+ describe("markDrillableCells and cells with no value", () => {
17
+ /** The renderer's own shape: a grid table with an inline grid-column per cell. */
18
+ const table = (cells: string[]) => {
19
+ const root = document.createElement("div");
20
+ root.innerHTML = `
21
+ <div class="malloy-table">
22
+ <div class="column-cell th" style="grid-column: 1 / 2;">region</div>
23
+ ${cells.join("")}
24
+ </div>`;
25
+ return root;
26
+ };
27
+ const cell = (inner: string) =>
28
+ `<div class="column-cell td" style="grid-column: 1 / 2;">${inner}</div>`;
29
+
30
+ it("marks a cell with a value and skips a null one", () => {
31
+ const root = table([
32
+ cell("West"),
33
+ cell('<span class="value-null">∅</span>'),
34
+ cell(""),
35
+ cell("0"),
36
+ ]);
37
+ markDrillableCells(root, new Set(["region"]));
38
+
39
+ const marked = Array.from(
40
+ root.querySelectorAll<HTMLElement>(".column-cell.td"),
41
+ ).map((node) => node.classList.contains(DRILL_CELL_CLASS));
42
+ // West and 0 are values; the null glyph and the empty cell are not.
43
+ expect(marked).toEqual([true, false, false, true]);
44
+ });
45
+ });
46
+
47
+ describe("markDrillableCells and the tab order", () => {
48
+ const table = (rows: number) => {
49
+ const root = document.createElement("div");
50
+ const cells = Array.from(
51
+ { length: rows },
52
+ (_unused, index) =>
53
+ `<div class="column-cell td" style="grid-column: 1 / 2;">v${index}</div>` +
54
+ `<div class="column-cell td" style="grid-column: 2 / 3;">n${index}</div>`,
55
+ ).join("");
56
+ root.innerHTML = `
57
+ <div class="malloy-table">
58
+ <div class="column-cell th" style="grid-column: 1 / 2;">region</div>
59
+ <div class="column-cell th" style="grid-column: 2 / 3;">sales</div>
60
+ ${cells}
61
+ </div>`;
62
+ return root;
63
+ };
64
+ const stops = (root: HTMLElement) =>
65
+ Array.from(root.querySelectorAll<HTMLElement>(`.${DRILL_CELL_CLASS}`))
66
+ .filter((node) => node.getAttribute("tabindex") === "0")
67
+ .map((node) => node.textContent);
68
+
69
+ // Marking every cell tabbable put a whole column in the tab order, so a
70
+ // result at the row cap cost a keyboard reader hundreds of presses to get
71
+ // past it. One stop per column, arrow keys within.
72
+ it("gives a drillable column one tab stop, not one per cell", () => {
73
+ const root = table(12);
74
+ markDrillableCells(root, new Set(["region"]));
75
+
76
+ const marked = root.querySelectorAll(`.${DRILL_CELL_CLASS}`);
77
+ expect(marked.length).toBe(12);
78
+ expect(stops(root)).toEqual(["v0"]);
79
+ // The rest are reachable by arrow key, so they are focusable but skipped.
80
+ const rest = Array.from(marked).slice(1);
81
+ expect(rest.every((n) => n.getAttribute("tabindex") === "-1")).toBe(true);
82
+ // The non-drillable column is left alone entirely.
83
+ expect(
84
+ root.querySelectorAll('[style*="grid-column: 2"][tabindex]').length,
85
+ ).toBe(0);
86
+ });
87
+
88
+ // A `# dashboard` settles over several frames, so the caller re-runs the
89
+ // marking. Rebuilding the stop from scratch each pass would snap it back to
90
+ // the first row under a reader who had arrowed down.
91
+ it("keeps the roving position across a re-run", () => {
92
+ const root = table(5);
93
+ markDrillableCells(root, new Set(["region"]));
94
+
95
+ const cells = Array.from(
96
+ root.querySelectorAll<HTMLElement>(`.${DRILL_CELL_CLASS}`),
97
+ );
98
+ // Move the stop the way the arrow handler does.
99
+ cells[0].tabIndex = -1;
100
+ cells[3].tabIndex = 0;
101
+
102
+ markDrillableCells(root, new Set(["region"]));
103
+ expect(stops(root)).toEqual(["v3"]);
104
+ });
105
+
106
+ it("reports a column's marked cells in row order", () => {
107
+ const root = table(4);
108
+ markDrillableCells(root, new Set(["region"]));
109
+ const first = root.querySelector<HTMLElement>(`.${DRILL_CELL_CLASS}`);
110
+ expect(first).not.toBeNull();
111
+ expect(
112
+ drillColumnSiblings(first as HTMLElement).map((n) => n.textContent),
113
+ ).toEqual(["v0", "v1", "v2", "v3"]);
114
+ });
115
+
116
+ it("reports nothing for a cell that is not in a table", () => {
117
+ const orphan = document.createElement("div");
118
+ orphan.className = DRILL_CELL_CLASS;
119
+ expect(drillColumnSiblings(orphan)).toEqual([]);
120
+ });
121
+ });
122
+
123
+ describe("markDrillableCells across two drillable columns", () => {
124
+ // The stop is per drillable COLUMN, scoped to its table, not per table. The
125
+ // guide said "one stop per TABLE" for two rounds, which is wrong the moment a
126
+ // dashboard groups by two drilled dimensions.
127
+ it("gives each drillable column its own stop", () => {
128
+ const root = document.createElement("div");
129
+ root.innerHTML = `
130
+ <div class="malloy-table">
131
+ <div class="column-cell th" style="grid-column: 1 / 2;">category</div>
132
+ <div class="column-cell th" style="grid-column: 2 / 3;">brand</div>
133
+ <div class="column-cell th" style="grid-column: 3 / 4;">sales</div>
134
+ <div class="column-cell td" style="grid-column: 1 / 2;">c0</div>
135
+ <div class="column-cell td" style="grid-column: 2 / 3;">b0</div>
136
+ <div class="column-cell td" style="grid-column: 3 / 4;">1</div>
137
+ <div class="column-cell td" style="grid-column: 1 / 2;">c1</div>
138
+ <div class="column-cell td" style="grid-column: 2 / 3;">b1</div>
139
+ <div class="column-cell td" style="grid-column: 3 / 4;">2</div>
140
+ </div>`;
141
+ markDrillableCells(root, new Set(["category", "brand"]));
142
+
143
+ const stops = Array.from(
144
+ root.querySelectorAll<HTMLElement>(`.${DRILL_CELL_CLASS}`),
145
+ )
146
+ .filter((n) => n.getAttribute("tabindex") === "0")
147
+ .map((n) => n.textContent);
148
+ // One per column, both on the first row, and the undrilled column
149
+ // contributes none.
150
+ expect(stops).toEqual(["c0", "b0"]);
151
+ expect(root.querySelectorAll(`.${DRILL_CELL_CLASS}`).length).toBe(4);
152
+ });
153
+ });
154
+
155
+ describe("moveDrillStop keeps a column to exactly one tab stop", () => {
156
+ const table = (rows: number) => {
157
+ const root = document.createElement("div");
158
+ const cells = Array.from(
159
+ { length: rows },
160
+ (_unused, index) =>
161
+ `<div class="column-cell td" style="grid-column: 1 / 2;">v${index}</div>`,
162
+ ).join("");
163
+ root.innerHTML = `
164
+ <div class="malloy-table">
165
+ <div class="column-cell th" style="grid-column: 1 / 2;">region</div>
166
+ ${cells}
167
+ </div>`;
168
+ markDrillableCells(root, new Set(["region"]));
169
+ return root;
170
+ };
171
+ const marked = (root: HTMLElement) =>
172
+ Array.from(root.querySelectorAll<HTMLElement>(`.${DRILL_CELL_CLASS}`));
173
+ const stops = (root: HTMLElement) =>
174
+ marked(root)
175
+ .filter((n) => n.getAttribute("tabindex") === "0")
176
+ .map((n) => n.textContent);
177
+
178
+ // The case both earlier tests missed, because each simulated the move by
179
+ // hand-setting tabIndex on the cell that already held the stop. A cell with
180
+ // `tabindex="-1"` is still CLICK-focusable, so the cell an arrow moves from
181
+ // is frequently not the one holding the stop.
182
+ it("moves from a click-focused cell without leaving a second stop", () => {
183
+ const root = table(6);
184
+ const cells = marked(root);
185
+ expect(stops(root)).toEqual(["v0"]);
186
+
187
+ // The reader clicks row 3. Focus is there; the stop is still on row 0.
188
+ const next = moveDrillStop(cells[3], 1);
189
+
190
+ expect(next?.textContent).toBe("v4");
191
+ expect(stops(root)).toEqual(["v4"]);
192
+ });
193
+
194
+ it("repeating that gesture cannot accumulate stops", () => {
195
+ const root = table(6);
196
+ const cells = marked(root);
197
+ moveDrillStop(cells[3], 1);
198
+ moveDrillStop(cells[1], 1);
199
+ moveDrillStop(cells[5], -1);
200
+ expect(stops(root)).toEqual(["v4"]);
201
+ });
202
+
203
+ it("a clamped move at the end repairs a column rather than doing nothing", () => {
204
+ const root = table(4);
205
+ const cells = marked(root);
206
+ // Drift the column into two stops by hand, the state the old move left.
207
+ cells[2].tabIndex = 0;
208
+ expect(stops(root)).toEqual(["v0", "v2"]);
209
+
210
+ moveDrillStop(cells[3], 1); // already last, so it clamps to itself
211
+ expect(stops(root)).toEqual(["v3"]);
212
+ });
213
+
214
+ it("reports nothing for a cell outside a table", () => {
215
+ const orphan = document.createElement("div");
216
+ orphan.className = DRILL_CELL_CLASS;
217
+ expect(moveDrillStop(orphan, 1)).toBeUndefined();
218
+ });
219
+
220
+ // Home and End. Untested until a mutation sweep showed that making "first"
221
+ // resolve to the LAST cell kept every other test green, so Home would have
222
+ // jumped a reader to the bottom row with nothing to catch it.
223
+ it("Home goes to the first row and End to the last", () => {
224
+ const root = table(5);
225
+ const cells = marked(root);
226
+
227
+ expect(moveDrillStop(cells[2], "first")?.textContent).toBe("v0");
228
+ expect(stops(root)).toEqual(["v0"]);
229
+
230
+ expect(moveDrillStop(cells[2], "last")?.textContent).toBe("v4");
231
+ expect(stops(root)).toEqual(["v4"]);
232
+ });
233
+
234
+ // A nested table has its own grid and its own column numbering. Untested
235
+ // until a mutation sweep showed that dropping the own-table filter kept
236
+ // everything green, because no fixture anywhere had a nested table: arrow
237
+ // keys would have walked out of the outer column into the inner one and
238
+ // stripped the outer column's stop on the way.
239
+ it("does not walk into a nested table that shares a column number", () => {
240
+ const root = document.createElement("div");
241
+ root.innerHTML = `
242
+ <div class="malloy-table">
243
+ <div class="column-cell th" style="grid-column: 1 / 2;">region</div>
244
+ <div class="column-cell td" style="grid-column: 1 / 2;">outer0</div>
245
+ <div class="column-cell td" style="grid-column: 1 / 2;">outer1</div>
246
+ <div class="column-cell td" style="grid-column: 1 / 2;">
247
+ <div class="malloy-table">
248
+ <div class="column-cell th" style="grid-column: 1 / 2;">region</div>
249
+ <div class="column-cell td" style="grid-column: 1 / 2;">inner0</div>
250
+ <div class="column-cell td" style="grid-column: 1 / 2;">inner1</div>
251
+ </div>
252
+ </div>
253
+ </div>`;
254
+ markDrillableCells(root, new Set(["region"]));
255
+
256
+ const outer = Array.from(
257
+ root.querySelectorAll<HTMLElement>(`.${DRILL_CELL_CLASS}`),
258
+ ).filter((n) => n.textContent === "outer0");
259
+ expect(outer).toHaveLength(1);
260
+
261
+ // The outer column's siblings are its own rows only. The cell wrapping the
262
+ // nested table is not marked at all, so it is not among them either.
263
+ expect(
264
+ drillColumnSiblings(outer[0]).map((n) => n.textContent?.trim()),
265
+ ).toEqual(["outer0", "outer1"]);
266
+
267
+ // Each table keeps its own stop, so the nested one does not steal the
268
+ // outer one's.
269
+ const inner = Array.from(
270
+ root.querySelectorAll<HTMLElement>(`.${DRILL_CELL_CLASS}`),
271
+ ).filter((n) => n.textContent === "inner0");
272
+ expect(inner).toHaveLength(1);
273
+ expect(outer[0].getAttribute("tabindex")).toBe("0");
274
+ expect(inner[0].getAttribute("tabindex")).toBe("0");
275
+
276
+ // The case that matters is a re-mark with the nested stop MOVED OFF row
277
+ // zero. Asserting only that `inner0` still holds it proves nothing: that
278
+ // is where the fallback promotion lands anyway, so the assertion passes
279
+ // with the guard deleted. This is the shape that fails without it.
280
+ const inner1 = Array.from(
281
+ root.querySelectorAll<HTMLElement>(`.${DRILL_CELL_CLASS}`),
282
+ ).find((n) => n.textContent === "inner1");
283
+ expect(inner1).toBeDefined();
284
+ inner[0].tabIndex = -1;
285
+ (inner1 as HTMLElement).tabIndex = 0;
286
+
287
+ markDrillableCells(root, new Set(["region"]));
288
+
289
+ // The outer pass sees the nested stop as a duplicate of its own column and
290
+ // demotes it; the nested pass then re-promotes the FIRST row rather than
291
+ // the roved one, so a reader who had arrowed down inside a nested table
292
+ // would be thrown back to its top on every re-mark, and a settling
293
+ // `# dashboard` re-marks repeatedly.
294
+ expect(outer[0].getAttribute("tabindex")).toBe("0");
295
+ expect(inner[0].getAttribute("tabindex")).toBe("-1");
296
+ expect((inner1 as HTMLElement).getAttribute("tabindex")).toBe("0");
297
+ });
298
+
299
+ // Belt and braces: even if some other path drifts a column, the next mark
300
+ // pass demotes the extra rather than preserving both for good.
301
+ it("a re-mark demotes a duplicate stop instead of keeping it", () => {
302
+ const root = table(4);
303
+ const cells = marked(root);
304
+ cells[2].tabIndex = 0;
305
+ expect(stops(root)).toEqual(["v0", "v2"]);
306
+
307
+ markDrillableCells(root, new Set(["region"]));
308
+ expect(stops(root)).toEqual(["v0"]);
309
+ });
310
+ });
@@ -0,0 +1,106 @@
1
+ import { parseAnnotation } from "@malloydata/malloy-tag";
2
+ import { describe, expect, it } from "bun:test";
3
+ import { drillableFieldNames } from "./markDrillableCells";
4
+ import { drillDestinations, type DrillField } from "./resolveDrill";
5
+
6
+ /**
7
+ * Which columns the affordance marks. The marking itself walks the renderer's
8
+ * own table DOM, and stubbing that markup would only test our idea of it, so
9
+ * this file covers the field-name decision and not the DOM walk.
10
+ *
11
+ * The DOM walk is currently verified BY HAND against the real renderer, not by a
12
+ * committed spec: on a notebook whose model carries two `# drill` dimensions,
13
+ * the reachable one's column marks all 10 of its cells and the unreachable one's
14
+ * marks none. Recorded here rather than left implied, and deliberately NOT as a
15
+ * pointer to `packages/app/tests/playwright/package-dashboards.spec.ts`, which
16
+ * does not exist in this repository: it arrives with the dashboard slice. That
17
+ * spec is
18
+ * the natural home for pinning it, since it will have a drill-carrying fixture
19
+ * to assert against; until then, treat the DOM half as unpinned.
20
+ */
21
+ describe("drillableFieldNames", () => {
22
+ const field = (name: string, annotations: string[]): DrillField => ({
23
+ name,
24
+ tag: parseAnnotation(annotations).tag,
25
+ });
26
+ const viz = (fields: DrillField[]) => ({
27
+ getMetadata: () => ({ getAllFields: () => fields }),
28
+ });
29
+ /** A surface that can navigate but cannot filter itself. */
30
+ const navigateOnly = (f: DrillField) =>
31
+ drillDestinations(f).some((destination) => destination !== "self");
32
+
33
+ it("collects the one spelling a drillable field renders", () => {
34
+ // The label when the author set one, the name otherwise, which is what
35
+ // the header this is matched against actually shows. Adding the raw name
36
+ // as WELL used to look defensive and was not: a labelled field never puts
37
+ // its name on screen, so that key could only ever match some other
38
+ // column and paint it as a link that does nothing.
39
+ const names = drillableFieldNames(
40
+ viz([
41
+ field("category", ['# drill { to=overview } label="Category"\n']),
42
+ field("total_sales", ["# currency\n"]),
43
+ ]),
44
+ navigateOnly,
45
+ );
46
+ expect([...names].sort()).toEqual(["Category"]);
47
+ });
48
+
49
+ it("leaves out a drill this surface cannot honor", () => {
50
+ // Malloyyo's rule, and the reason the predicate belongs to the host: a
51
+ // dead link is worse than none, so a `to=self` on a surface with no
52
+ // controls to write to stays plain text rather than promising a click it
53
+ // would then swallow.
54
+ const names = drillableFieldNames(
55
+ viz([field("region", ["# drill { to=self }\n"])]),
56
+ navigateOnly,
57
+ );
58
+ expect(names.size).toBe(0);
59
+ });
60
+
61
+ it("survives a viz with no metadata", () => {
62
+ // Clicks still resolve in this case; only the affordance is missing, so a
63
+ // renderer that has not published metadata yet must not throw here.
64
+ expect(
65
+ drillableFieldNames({ getMetadata: () => null }, () => true).size,
66
+ ).toBe(0);
67
+ expect(
68
+ drillableFieldNames(
69
+ {
70
+ getMetadata: () => {
71
+ throw new Error("not ready");
72
+ },
73
+ },
74
+ () => true,
75
+ ).size,
76
+ ).toBe(0);
77
+ });
78
+
79
+ it("drops a spelling a non-drillable field also renders", () => {
80
+ // Matching on header TEXT cannot tell the two columns apart, so marking
81
+ // `Region` would paint the non-drillable column as a link that does
82
+ // nothing. The affordance is given up instead, on both columns.
83
+ const names = drillableFieldNames(
84
+ viz([
85
+ field("region", ['# drill { to=overview } label="Region"\n']),
86
+ field("ship_from", ['# label="Region"\n']),
87
+ ]),
88
+ navigateOnly,
89
+ );
90
+ // Nothing marked: the drillable field's only rendered spelling is the
91
+ // one the non-drillable field also renders, so the affordance is given up
92
+ // rather than painted on a column whose click does nothing.
93
+ expect([...names].sort()).toEqual([]);
94
+ });
95
+
96
+ it("still marks a label no other field renders", () => {
97
+ const names = drillableFieldNames(
98
+ viz([
99
+ field("region", ['# drill { to=overview } label="Region"\n']),
100
+ field("ship_from", ['# label="Origin"\n']),
101
+ ]),
102
+ navigateOnly,
103
+ );
104
+ expect([...names].sort()).toEqual(["Region"]);
105
+ });
106
+ });