@malloy-publisher/sdk 0.9.1 → 0.9.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 (292) hide show
  1. package/dist/{Dashboard-H1kJlDFo.es.js → DashboardTile-BFcxdv7R.es.js} +15918 -17760
  2. package/dist/DashboardTile-sg8LjUk8.cjs.js +137 -0
  3. package/dist/RenderedResult-B48wAjM8.cjs.js +141 -0
  4. package/dist/{RenderedResult-BRgIgxWh.es.js → RenderedResult-CBLHr32C.es.js} +193 -183
  5. package/dist/{ServerProvider-Boxrv6Ym.es.js → ServerProvider-DCV8BUWD.es.js} +529 -521
  6. package/dist/ServerProvider-HRqT3w1C.cjs.js +1 -0
  7. package/dist/builder/index.cjs.js +146 -58
  8. package/dist/builder/index.es.js +9076 -6479
  9. package/dist/builder-entry.d.ts +4 -0
  10. package/dist/client/api.d.ts +77 -47
  11. package/dist/client/configuration.d.ts +1 -1
  12. package/dist/client/index.cjs.js +1 -1
  13. package/dist/client/index.d.ts +1 -1
  14. package/dist/client/index.es.js +84 -82
  15. package/dist/components/Dashboard/Dashboard.d.ts +8 -15
  16. package/dist/components/Dashboard/DashboardGrid.d.ts +23 -6
  17. package/dist/components/Dashboard/DashboardTile.d.ts +10 -1
  18. package/dist/components/Dashboard/DashboardView.d.ts +36 -0
  19. package/dist/components/Dashboard/TileCard.d.ts +15 -4
  20. package/dist/components/Dashboard/TileFilterTag.d.ts +12 -0
  21. package/dist/components/Dashboard/index.d.ts +3 -0
  22. package/dist/components/Dashboard/telemetry.d.ts +15 -3
  23. package/dist/components/DashboardBuilder/AddTileDialog.d.ts +8 -1
  24. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +16 -5
  25. package/dist/components/DashboardBuilder/ChartPicker.d.ts +29 -0
  26. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +48 -21
  27. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +17 -4
  28. package/dist/components/DashboardBuilder/DiffDialog.d.ts +2 -10
  29. package/dist/components/DashboardBuilder/FilterDialog.d.ts +2 -2
  30. package/dist/components/DashboardBuilder/FilterStrip.d.ts +3 -1
  31. package/dist/components/DashboardBuilder/InlineMarkdown.d.ts +18 -0
  32. package/dist/components/DashboardBuilder/InlineText.d.ts +19 -0
  33. package/dist/components/DashboardBuilder/NotebookEditor.d.ts +15 -0
  34. package/dist/components/DashboardBuilder/SaveNotice.d.ts +27 -0
  35. package/dist/components/DashboardBuilder/SettingsPopover.d.ts +19 -7
  36. package/dist/components/DashboardBuilder/SourceViewPicker.d.ts +9 -0
  37. package/dist/components/DashboardBuilder/TextTileBody.d.ts +7 -0
  38. package/dist/components/DashboardBuilder/TileFrame.d.ts +14 -12
  39. package/dist/components/DashboardBuilder/TileMenu.d.ts +11 -3
  40. package/dist/components/DashboardBuilder/annotationText.d.ts +4 -0
  41. package/dist/components/DashboardBuilder/catalog.d.ts +4 -0
  42. package/dist/components/DashboardBuilder/changedTile.d.ts +7 -0
  43. package/dist/components/DashboardBuilder/chartLine.d.ts +33 -0
  44. package/dist/components/DashboardBuilder/controls.d.ts +2 -2
  45. package/dist/components/DashboardBuilder/document.d.ts +42 -26
  46. package/dist/components/DashboardBuilder/documentSession.d.ts +100 -0
  47. package/dist/components/DashboardBuilder/legacyNotebook.d.ts +73 -0
  48. package/dist/components/DashboardBuilder/loadMalloy.d.ts +15 -0
  49. package/dist/components/DashboardBuilder/malloyText.d.ts +45 -5
  50. package/dist/components/DashboardBuilder/malloyTree.d.ts +119 -0
  51. package/dist/components/DashboardBuilder/newDashboard.d.ts +3 -1
  52. package/dist/components/DashboardBuilder/openDraft.d.ts +10 -0
  53. package/dist/components/DashboardBuilder/preview.d.ts +24 -4
  54. package/dist/components/DashboardBuilder/readDocument.d.ts +4 -1
  55. package/dist/components/DashboardBuilder/readForEditor.d.ts +16 -0
  56. package/dist/components/DashboardBuilder/sortable.d.ts +14 -0
  57. package/dist/components/DashboardBuilder/spliceDocument.d.ts +13 -13
  58. package/dist/components/DashboardBuilder/spliceResult.d.ts +11 -0
  59. package/dist/components/DashboardBuilder/tagParse.d.ts +24 -0
  60. package/dist/components/DashboardBuilder/telemetry.d.ts +43 -0
  61. package/dist/components/DashboardBuilder/testing/fixtures.d.ts +3 -1
  62. package/dist/components/DashboardBuilder/testing/inline.d.ts +4 -0
  63. package/dist/components/DashboardBuilder/useBuilderSession.d.ts +89 -0
  64. package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +9 -6
  65. package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +17 -55
  66. package/dist/components/DashboardBuilder/useDocumentEditor.d.ts +105 -0
  67. package/dist/components/DashboardBuilder/useExitGuard.d.ts +19 -0
  68. package/dist/components/DashboardBuilder/useFilterForm.d.ts +3 -3
  69. package/dist/components/DocumentCreate/canRetry.d.ts +6 -0
  70. package/dist/components/DocumentCreate/createDocument.d.ts +58 -0
  71. package/dist/components/DocumentCreate/documentPath.d.ts +10 -0
  72. package/dist/components/DocumentCreate/events.d.ts +10 -0
  73. package/dist/components/DocumentCreate/exportedSources.d.ts +7 -0
  74. package/dist/components/DocumentCreate/guards.d.ts +12 -0
  75. package/dist/components/DocumentCreate/index.d.ts +6 -0
  76. package/dist/components/DocumentCreate/newNotebook.d.ts +9 -0
  77. package/dist/components/DocumentCreate/useDocumentChoices.d.ts +32 -0
  78. package/dist/components/DocumentStorage/DocumentStorage.d.ts +2 -1
  79. package/dist/components/NarrowEditGate.d.ts +8 -0
  80. package/dist/components/Notebook/Notebook.d.ts +1 -1
  81. package/dist/components/Package/NewDocumentDialog.d.ts +33 -0
  82. package/dist/components/Package/Package.d.ts +1 -0
  83. package/dist/components/Package/documentLocation.d.ts +28 -0
  84. package/dist/components/Package/index.d.ts +4 -0
  85. package/dist/components/Package/useDocumentLocation.d.ts +12 -0
  86. package/dist/components/PackageSection.d.ts +2 -2
  87. package/dist/components/RenderedResult/RenderedResult.d.ts +2 -0
  88. package/dist/components/RenderedResult/ResultContainer.d.ts +8 -1
  89. package/dist/components/RenderedResult/ResultPanel.d.ts +3 -1
  90. package/dist/components/RenderedResult/resultSizing.d.ts +9 -1
  91. package/dist/components/ServerProvider.d.ts +2 -1
  92. package/dist/components/UnsavedChangesDialog.d.ts +9 -0
  93. package/dist/components/given/GivensPanel.d.ts +2 -2
  94. package/dist/components/index.d.ts +2 -0
  95. package/dist/hooks/index.d.ts +1 -0
  96. package/dist/hooks/useNarrowScreen.d.ts +4 -0
  97. package/dist/hooks/useQueryResult.d.ts +2 -0
  98. package/dist/hooks/useSettled.d.ts +14 -0
  99. package/dist/index.cjs.js +23 -24
  100. package/dist/index.es.js +9714 -7072
  101. package/dist/text/index.cjs.js +1 -0
  102. package/dist/text/index.d.ts +2 -0
  103. package/dist/text/index.es.js +6 -0
  104. package/dist/text-entry-BJwltZiy.cjs.js +7 -0
  105. package/dist/text-entry-CbbBcZl8.es.js +196 -0
  106. package/dist/text-entry.d.ts +2 -0
  107. package/dist/utils/clock.d.ts +2 -0
  108. package/package.json +10 -1
  109. package/src/builder-entry.ts +35 -0
  110. package/src/components/Dashboard/Dashboard.tsx +27 -278
  111. package/src/components/Dashboard/DashboardGrid.tsx +68 -7
  112. package/src/components/Dashboard/DashboardTile.spec.tsx +24 -0
  113. package/src/components/Dashboard/DashboardTile.tsx +31 -4
  114. package/src/components/Dashboard/DashboardView.spec.tsx +212 -0
  115. package/src/components/Dashboard/DashboardView.tsx +352 -0
  116. package/src/components/Dashboard/RowsDialog.tsx +1 -1
  117. package/src/components/Dashboard/TileCard.tsx +44 -10
  118. package/src/components/Dashboard/TileFilterTag.spec.tsx +73 -0
  119. package/src/components/Dashboard/TileFilterTag.tsx +78 -0
  120. package/src/components/Dashboard/defaultTileSpan.spec.ts +32 -0
  121. package/src/components/Dashboard/index.ts +3 -0
  122. package/src/components/Dashboard/telemetry.ts +16 -5
  123. package/src/components/DashboardBuilder/AddTileDialog.spec.tsx +88 -0
  124. package/src/components/DashboardBuilder/AddTileDialog.tsx +137 -111
  125. package/src/components/DashboardBuilder/BuilderToolbar.tsx +85 -27
  126. package/src/components/DashboardBuilder/ChartPicker.render.spec.tsx +25 -0
  127. package/src/components/DashboardBuilder/ChartPicker.spec.ts +77 -0
  128. package/src/components/DashboardBuilder/ChartPicker.tsx +153 -0
  129. package/src/components/DashboardBuilder/DashboardBuilder.charts.spec.tsx +205 -0
  130. package/src/components/DashboardBuilder/DashboardBuilder.exit.spec.tsx +192 -0
  131. package/src/components/DashboardBuilder/DashboardBuilder.inline.spec.tsx +329 -0
  132. package/src/components/DashboardBuilder/DashboardBuilder.notebook.spec.tsx +363 -0
  133. package/src/components/DashboardBuilder/DashboardBuilder.notice.spec.tsx +194 -0
  134. package/src/components/DashboardBuilder/DashboardBuilder.openDraft.spec.tsx +157 -0
  135. package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +124 -0
  136. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +103 -78
  137. package/src/components/DashboardBuilder/DashboardBuilder.textTiles.spec.tsx +177 -0
  138. package/src/components/DashboardBuilder/DashboardBuilder.tsx +610 -315
  139. package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +58 -8
  140. package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +191 -0
  141. package/src/components/DashboardBuilder/DashboardEditor.filterTag.spec.tsx +162 -0
  142. package/src/components/DashboardBuilder/DashboardEditor.notebook.spec.tsx +316 -0
  143. package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +56 -10
  144. package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +5 -22
  145. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +96 -14
  146. package/src/components/DashboardBuilder/DashboardEditor.tsx +482 -332
  147. package/src/components/DashboardBuilder/DiffDialog.spec.tsx +25 -0
  148. package/src/components/DashboardBuilder/DiffDialog.tsx +5 -24
  149. package/src/components/DashboardBuilder/DrillDialog.tsx +1 -1
  150. package/src/components/DashboardBuilder/FilterDialog.tsx +10 -3
  151. package/src/components/DashboardBuilder/FilterStrip.tsx +26 -4
  152. package/src/components/DashboardBuilder/InlineMarkdown.tsx +184 -0
  153. package/src/components/DashboardBuilder/InlineText.tsx +106 -0
  154. package/src/components/DashboardBuilder/NotebookEditor.tsx +44 -0
  155. package/src/components/DashboardBuilder/SaveNotice.tsx +113 -0
  156. package/src/components/DashboardBuilder/SettingsPopover.spec.tsx +87 -0
  157. package/src/components/DashboardBuilder/SettingsPopover.tsx +225 -67
  158. package/src/components/DashboardBuilder/SourceViewPicker.tsx +122 -0
  159. package/src/components/DashboardBuilder/TextTileBody.tsx +28 -0
  160. package/src/components/DashboardBuilder/TileFrame.tsx +89 -115
  161. package/src/components/DashboardBuilder/TileMenu.tsx +168 -90
  162. package/src/components/DashboardBuilder/annotationText.spec.ts +33 -0
  163. package/src/components/DashboardBuilder/annotationText.ts +17 -0
  164. package/src/components/DashboardBuilder/artifactBlock.spec.ts +248 -0
  165. package/src/components/DashboardBuilder/artifactTagParity.spec.ts +41 -0
  166. package/src/components/DashboardBuilder/catalog.aggregate.spec.ts +49 -0
  167. package/src/components/DashboardBuilder/catalog.spec.ts +2 -0
  168. package/src/components/DashboardBuilder/catalog.ts +61 -21
  169. package/src/components/DashboardBuilder/changedTile.spec.ts +46 -0
  170. package/src/components/DashboardBuilder/changedTile.ts +28 -0
  171. package/src/components/DashboardBuilder/chartLine.spec.ts +180 -0
  172. package/src/components/DashboardBuilder/chartLine.ts +121 -0
  173. package/src/components/DashboardBuilder/controls.spec.ts +21 -10
  174. package/src/components/DashboardBuilder/controls.ts +22 -8
  175. package/src/components/DashboardBuilder/document.ts +53 -5
  176. package/src/components/DashboardBuilder/documentSession.spec.ts +209 -0
  177. package/src/components/DashboardBuilder/documentSession.ts +257 -0
  178. package/src/components/DashboardBuilder/emptyStart.spec.ts +131 -0
  179. package/src/components/DashboardBuilder/invariants.spec.ts +6 -2
  180. package/src/components/DashboardBuilder/legacyNotebook.chart.spec.ts +77 -0
  181. package/src/components/DashboardBuilder/legacyNotebook.convert.spec.ts +630 -0
  182. package/src/components/DashboardBuilder/legacyNotebook.read.spec.ts +338 -0
  183. package/src/components/DashboardBuilder/legacyNotebook.ts +1117 -0
  184. package/src/components/DashboardBuilder/loadMalloy.spec.ts +80 -0
  185. package/src/components/DashboardBuilder/loadMalloy.ts +39 -0
  186. package/src/components/DashboardBuilder/malloyText.spec.ts +48 -0
  187. package/src/components/DashboardBuilder/malloyText.ts +181 -27
  188. package/src/components/DashboardBuilder/malloyTree.ts +155 -7
  189. package/src/components/DashboardBuilder/newDashboard.spec.ts +46 -2
  190. package/src/components/DashboardBuilder/newDashboard.ts +30 -3
  191. package/src/components/DashboardBuilder/openDraft.ts +52 -0
  192. package/src/components/DashboardBuilder/preview.shapes.spec.ts +75 -0
  193. package/src/components/DashboardBuilder/preview.spec.ts +159 -12
  194. package/src/components/DashboardBuilder/preview.ts +83 -9
  195. package/src/components/DashboardBuilder/readDocument.spec.ts +139 -27
  196. package/src/components/DashboardBuilder/readDocument.ts +130 -44
  197. package/src/components/DashboardBuilder/readForEditor.spec.ts +80 -0
  198. package/src/components/DashboardBuilder/readForEditor.ts +47 -0
  199. package/src/components/DashboardBuilder/scannerShapes.spec.ts +14 -13
  200. package/src/components/DashboardBuilder/sortable.spec.ts +65 -0
  201. package/src/components/DashboardBuilder/sortable.tsx +2 -12
  202. package/src/components/DashboardBuilder/spliceDocument.chart.spec.ts +340 -0
  203. package/src/components/DashboardBuilder/spliceDocument.imports.spec.ts +167 -0
  204. package/src/components/DashboardBuilder/spliceDocument.spec.ts +229 -94
  205. package/src/components/DashboardBuilder/spliceDocument.ts +762 -130
  206. package/src/components/DashboardBuilder/spliceResult.ts +15 -0
  207. package/src/components/DashboardBuilder/statementExtent.spec.ts +33 -30
  208. package/src/components/DashboardBuilder/tagParse.spec.ts +149 -0
  209. package/src/components/DashboardBuilder/tagParse.ts +103 -0
  210. package/src/components/DashboardBuilder/telemetry.ts +47 -0
  211. package/src/components/DashboardBuilder/testing/artifactTagParity.json +197 -0
  212. package/src/components/DashboardBuilder/testing/fixtures.ts +16 -1
  213. package/src/components/DashboardBuilder/testing/inline.ts +25 -0
  214. package/src/components/DashboardBuilder/textTiles.spec.ts +718 -0
  215. package/src/components/DashboardBuilder/useBuilderSession.spec.ts +335 -0
  216. package/src/components/DashboardBuilder/useBuilderSession.ts +292 -0
  217. package/src/components/DashboardBuilder/useBuilderShortcuts.overlay.spec.tsx +65 -0
  218. package/src/components/DashboardBuilder/useBuilderShortcuts.spec.tsx +60 -0
  219. package/src/components/DashboardBuilder/useBuilderShortcuts.ts +36 -10
  220. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +16 -13
  221. package/src/components/DashboardBuilder/useDashboardEditor.ts +54 -181
  222. package/src/components/DashboardBuilder/useDocumentEditor.spec.ts +565 -0
  223. package/src/components/DashboardBuilder/useDocumentEditor.ts +399 -0
  224. package/src/components/DashboardBuilder/useExitGuard.spec.ts +159 -0
  225. package/src/components/DashboardBuilder/useExitGuard.ts +89 -0
  226. package/src/components/DashboardBuilder/useFilterForm.existing.spec.tsx +41 -0
  227. package/src/components/DashboardBuilder/useFilterForm.spec.tsx +24 -2
  228. package/src/components/DashboardBuilder/useFilterForm.ts +41 -13
  229. package/src/components/DashboardBuilder/useTileReorder.spec.tsx +28 -5
  230. package/src/components/DashboardBuilder/useTileReorder.ts +5 -7
  231. package/src/components/DocumentCreate/canRetry.spec.ts +32 -0
  232. package/src/components/DocumentCreate/canRetry.ts +19 -0
  233. package/src/components/DocumentCreate/createDocument.spec.ts +310 -0
  234. package/src/components/DocumentCreate/createDocument.ts +159 -0
  235. package/src/components/DocumentCreate/documentPath.ts +40 -0
  236. package/src/components/DocumentCreate/events.ts +15 -0
  237. package/src/components/DocumentCreate/exportedSources.ts +25 -0
  238. package/src/components/DocumentCreate/guards.ts +45 -0
  239. package/src/components/DocumentCreate/index.ts +27 -0
  240. package/src/components/DocumentCreate/newNotebook.spec.ts +156 -0
  241. package/src/components/DocumentCreate/newNotebook.ts +44 -0
  242. package/src/components/DocumentCreate/useDocumentChoices.spec.tsx +138 -0
  243. package/src/components/DocumentCreate/useDocumentChoices.ts +113 -0
  244. package/src/components/DocumentStorage/DocumentStorage.ts +2 -1
  245. package/src/components/Model/ModelExplorer.spec.tsx +2 -2
  246. package/src/components/Model/SourcesExplorer.tsx +2 -4
  247. package/src/components/NarrowEditGate.spec.tsx +73 -0
  248. package/src/components/NarrowEditGate.tsx +29 -0
  249. package/src/components/Notebook/Notebook.layout.spec.tsx +94 -0
  250. package/src/components/Notebook/Notebook.tsx +66 -27
  251. package/src/components/Package/NewDocumentDialog.spec.tsx +749 -0
  252. package/src/components/Package/NewDocumentDialog.tsx +401 -0
  253. package/src/components/Package/Package.artifacts.spec.tsx +190 -0
  254. package/src/components/Package/Package.create.spec.tsx +380 -0
  255. package/src/components/Package/Package.notebooks.spec.tsx +18 -0
  256. package/src/components/Package/Package.tsx +366 -171
  257. package/src/components/Package/documentLocation.spec.ts +81 -0
  258. package/src/components/Package/documentLocation.ts +55 -0
  259. package/src/components/Package/index.ts +13 -0
  260. package/src/components/Package/useDocumentLocation.ts +59 -0
  261. package/src/components/PackageSection.tsx +2 -2
  262. package/src/components/RenderedResult/RenderedResult.tsx +18 -1
  263. package/src/components/RenderedResult/ResultContainer.tsx +44 -11
  264. package/src/components/RenderedResult/ResultPanel.tsx +4 -0
  265. package/src/components/RenderedResult/resultSizing.spec.ts +68 -0
  266. package/src/components/RenderedResult/resultSizing.ts +14 -3
  267. package/src/components/ServerProvider.tsx +2 -1
  268. package/src/components/UnsavedChangesDialog.spec.tsx +70 -0
  269. package/src/components/UnsavedChangesDialog.tsx +49 -0
  270. package/src/components/given/GivensPanel.spec.tsx +6 -6
  271. package/src/components/given/GivensPanel.tsx +3 -3
  272. package/src/components/index.ts +2 -0
  273. package/src/hooks/index.ts +3 -0
  274. package/src/hooks/useNarrowScreen.ts +21 -0
  275. package/src/hooks/useQueryResult.ts +16 -0
  276. package/src/hooks/useSettled.spec.ts +41 -0
  277. package/src/hooks/useSettled.ts +27 -0
  278. package/src/mainEntry.spec.ts +145 -0
  279. package/src/text-entry.ts +12 -0
  280. package/src/textEntry.spec.ts +118 -0
  281. package/src/utils/clock.spec.ts +12 -0
  282. package/src/utils/clock.ts +6 -0
  283. package/vite.config.ts +4 -0
  284. package/dist/Dashboard-ChyylkTD.cjs.js +0 -136
  285. package/dist/RenderedResult-AJPMUkAD.cjs.js +0 -135
  286. package/dist/ServerProvider-CXrOKD6g.cjs.js +0 -1
  287. package/dist/components/DashboardBuilder/useTileResize.d.ts +0 -29
  288. package/dist/components/Package/NewDashboardDialog.d.ts +0 -18
  289. package/src/components/DashboardBuilder/useTileResize.spec.tsx +0 -121
  290. package/src/components/DashboardBuilder/useTileResize.ts +0 -110
  291. package/src/components/Package/NewDashboardDialog.spec.tsx +0 -129
  292. package/src/components/Package/NewDashboardDialog.tsx +0 -265
@@ -0,0 +1,329 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import {
5
+ cleanup,
6
+ fireEvent,
7
+ render,
8
+ screen,
9
+ waitFor,
10
+ within,
11
+ } from "@testing-library/react";
12
+ import { afterEach, describe, expect, it, mock } from "bun:test";
13
+ import { DashboardBuilder } from "./DashboardBuilder";
14
+ import { openDocument } from "./testing/fixtures";
15
+ import { editInline } from "./testing/inline";
16
+ import { TEXT_TILE_PLACEHOLDER } from "./TextTileBody";
17
+
18
+ const SOURCE = `## artifact { title="Storefront" tiles=[intro { kind=text colspan=12 }, "a -> by_cat", "a -> by_brand"] } dashboard { columns=12 }
19
+ import "../data_app.malloy"
20
+
21
+ ##|(markdown) intro
22
+ Read [the docs](https://example.com/docs).
23
+ |##
24
+
25
+ source: a is scoped_orders extend {
26
+ # colspan=6
27
+ # label="By category"
28
+ view: by_cat is by_category
29
+
30
+ # colspan=6
31
+ view: by_brand is by_category
32
+ }
33
+ `;
34
+
35
+ const catalog = {
36
+ sources: [
37
+ {
38
+ name: "scoped_orders",
39
+ modelPath: "data_app.malloy",
40
+ views: [{ name: "sales_by_state" }],
41
+ givens: [],
42
+ fields: [],
43
+ },
44
+ ],
45
+ };
46
+
47
+ const mount = async (
48
+ options: {
49
+ onSave?: (source: string) => void;
50
+ savesTo?: "package" | "browser" | "host";
51
+ saveLabel?: string;
52
+ } = {},
53
+ ) => {
54
+ const document = await openDocument(SOURCE);
55
+ return render(
56
+ <DashboardBuilder
57
+ source={SOURCE}
58
+ document={document}
59
+ catalog={catalog}
60
+ {...(options.onSave ? { onSave: options.onSave } : {})}
61
+ {...(options.savesTo ? { savesTo: options.savesTo } : {})}
62
+ {...(options.saveLabel ? { saveLabel: options.saveLabel } : {})}
63
+ />,
64
+ );
65
+ };
66
+
67
+ const tile = (name: string) => screen.getByLabelText(`Tile ${name}`);
68
+ const button = (name: string) =>
69
+ screen.getByRole("button", { name, hidden: true });
70
+ const undo = () => fireEvent.click(button("Undo"));
71
+
72
+ afterEach(cleanup);
73
+
74
+ describe("click-to-edit text", () => {
75
+ it("opens on a click, commits on Enter, and is one undo step", async () => {
76
+ await mount();
77
+ editInline("By category", "Tile title", "Revenue");
78
+ expect(within(tile("by_cat")).getByText("Revenue")).toBeDefined();
79
+ undo();
80
+ expect(within(tile("by_cat")).getByText("By category")).toBeDefined();
81
+ expect(button("Undo")).toHaveProperty("disabled", true);
82
+ });
83
+
84
+ it("puts the old text back on Escape, with no history entry", async () => {
85
+ await mount();
86
+ editInline("By category", "Tile title", "Discarded", "Escape");
87
+ expect(within(tile("by_cat")).getByText("By category")).toBeDefined();
88
+ expect(screen.queryByLabelText("Tile title")).toBeNull();
89
+ expect(button("Undo")).toHaveProperty("disabled", true);
90
+ });
91
+
92
+ it("commits when focus leaves the field", async () => {
93
+ await mount();
94
+ fireEvent.click(screen.getByText("By category"));
95
+ const field = screen.getByLabelText("Tile title");
96
+ fireEvent.change(field, { target: { value: "Left behind" } });
97
+ fireEvent.blur(field);
98
+ expect(within(tile("by_cat")).getByText("Left behind")).toBeDefined();
99
+ });
100
+
101
+ it("adds no history entry for text that did not change", async () => {
102
+ await mount();
103
+ editInline("By category", "Tile title", "By category");
104
+ expect(button("Undo")).toHaveProperty("disabled", true);
105
+ });
106
+
107
+ it("opens from the keyboard: the display is a tab stop that Enter and Space open", async () => {
108
+ await mount();
109
+ const display = screen.getByText("By category");
110
+ expect(display.tagName).toBe("BUTTON");
111
+ expect(display.tabIndex).toBe(0);
112
+ fireEvent.keyDown(display, { key: "Enter" });
113
+ expect(screen.getByLabelText("Tile title")).toBeDefined();
114
+ fireEvent.keyDown(screen.getByLabelText("Tile title"), {
115
+ key: "Escape",
116
+ });
117
+ fireEvent.keyDown(screen.getByText("By category"), { key: " " });
118
+ expect(screen.getByLabelText("Tile title")).toBeDefined();
119
+ });
120
+
121
+ it("shows a placeholder for a missing subtitle and an emptied title, and removes the tag when emptied", async () => {
122
+ await mount();
123
+ expect(within(tile("by_cat")).getByText("Add a subtitle")).toBeDefined();
124
+ // An unlabelled tile shows the name it falls back to.
125
+ expect(within(tile("by_brand")).getByText("by_brand")).toBeDefined();
126
+ editInline("By category", "Tile title", "");
127
+ expect(within(tile("by_cat")).getByText("by_cat")).toBeDefined();
128
+ });
129
+
130
+ it("edits the page's title and description in place", async () => {
131
+ await mount();
132
+ editInline("Storefront", "Dashboard title", "Storefront, weekly");
133
+ expect(screen.getByText("Storefront, weekly")).toBeDefined();
134
+ fireEvent.click(screen.getByText("Add a description"));
135
+ const field = screen.getByLabelText("Markdown");
136
+ fireEvent.change(field, { target: { value: "What sold." } });
137
+ fireEvent.keyDown(field, { key: "Escape" });
138
+ expect(screen.getByText("What sold.")).toBeDefined();
139
+ undo();
140
+ expect(screen.getByText("Add a description")).toBeDefined();
141
+ undo();
142
+ expect(screen.getByText("Storefront")).toBeDefined();
143
+ });
144
+
145
+ it("has no title or subtitle fields in the tile menu, and none for the page in Settings", async () => {
146
+ await mount();
147
+ fireEvent.click(screen.getByLabelText("Settings for By category"));
148
+ expect(screen.queryByLabelText("Tile title")).toBeNull();
149
+ expect(screen.queryByLabelText("Tile subtitle")).toBeNull();
150
+ expect(button("Drill-through…")).toBeDefined();
151
+ fireEvent.keyDown(button("Remove tile"), { key: "Escape" });
152
+ fireEvent.click(button("Settings"));
153
+ expect(screen.queryByLabelText("Dashboard title")).toBeNull();
154
+ expect(screen.queryByLabelText("Dashboard description")).toBeNull();
155
+ expect(screen.getByLabelText("Grid width")).toBeDefined();
156
+ });
157
+ });
158
+
159
+ describe("click-to-edit markdown in a text tile", () => {
160
+ it("opens on a click and commits on Done, as one undo step", async () => {
161
+ await mount();
162
+ fireEvent.click(within(tile("intro")).getByText(/Read/));
163
+ const field = screen.getByLabelText("Markdown") as HTMLTextAreaElement;
164
+ expect(field.selectionStart).toBe(field.value.length);
165
+ fireEvent.change(field, { target: { value: "# New heading" } });
166
+ fireEvent.click(screen.getByRole("button", { name: "Done" }));
167
+ expect(
168
+ within(tile("intro")).getByRole("heading", { name: "New heading" }),
169
+ ).toBeDefined();
170
+ undo();
171
+ expect(within(tile("intro")).getByText(/Read/)).toBeDefined();
172
+ });
173
+
174
+ it("keeps its editor open on a draft the writer would refuse, and says why", async () => {
175
+ await mount();
176
+ fireEvent.click(within(tile("intro")).getByText(/Read/));
177
+ const field = screen.getByLabelText("Markdown");
178
+ fireEvent.change(field, { target: { value: "a\n|## b" } });
179
+ expect(screen.getByText(/close the text early/)).toBeDefined();
180
+ expect(
181
+ screen.getByRole("button", { name: "Done" }).hasAttribute("disabled"),
182
+ ).toBe(true);
183
+ // Escape is Done, which holds.
184
+ fireEvent.keyDown(field, { key: "Escape" });
185
+ expect(screen.getByLabelText("Markdown")).toBeDefined();
186
+ fireEvent.change(field, { target: { value: "fine" } });
187
+ fireEvent.keyDown(field, { key: "Escape" });
188
+ expect(screen.queryByLabelText("Markdown")).toBeNull();
189
+ expect(within(tile("intro")).getByText("fine")).toBeDefined();
190
+ });
191
+
192
+ it("Cancel drops the draft", async () => {
193
+ await mount();
194
+ fireEvent.click(within(tile("intro")).getByText(/Read/));
195
+ fireEvent.change(screen.getByLabelText("Markdown"), {
196
+ target: { value: "dropped" },
197
+ });
198
+ fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
199
+ expect(within(tile("intro")).queryByText("dropped")).toBeNull();
200
+ expect(button("Undo")).toHaveProperty("disabled", true);
201
+ });
202
+
203
+ it("opens from the keyboard, and leaves a link inert", async () => {
204
+ await mount();
205
+ const display = within(tile("intro")).getByRole("button", {
206
+ name: /Read/,
207
+ });
208
+ expect(display.tabIndex).toBe(0);
209
+ // A link neither navigates nor opens the editor.
210
+ const link = within(tile("intro")).getByRole("link", {
211
+ name: "the docs",
212
+ });
213
+ expect(fireEvent.click(link)).toBe(false);
214
+ expect(screen.queryByLabelText("Markdown")).toBeNull();
215
+ fireEvent.keyDown(display, { key: "Enter" });
216
+ expect(screen.getByLabelText("Markdown")).toBeDefined();
217
+ });
218
+
219
+ it("shows the hint in an empty tile, and the edit survives a save", async () => {
220
+ let written: string | undefined;
221
+ await mount({
222
+ onSave: (source) => {
223
+ written = source;
224
+ },
225
+ });
226
+ fireEvent.click(button("Add tile"));
227
+ fireEvent.click(screen.getByRole("button", { name: "Text" }));
228
+ fireEvent.click(screen.getByRole("button", { name: "Add text" }));
229
+ fireEvent.click(within(tile("text_1")).getByText(TEXT_TILE_PLACEHOLDER));
230
+ const field = screen.getByLabelText("Markdown");
231
+ expect(field.getAttribute("placeholder")).toBe(TEXT_TILE_PLACEHOLDER);
232
+ fireEvent.change(field, { target: { value: "Typed in place" } });
233
+ fireEvent.keyDown(field, { key: "Escape" });
234
+
235
+ fireEvent.click(button("Save changes"));
236
+ await waitFor(() => expect(written).toBeDefined());
237
+ expect(written).toContain("##|(markdown) text_1\nTyped in place\n|##");
238
+ });
239
+ });
240
+
241
+ describe("the save shortcut inside a markdown field", () => {
242
+ it("saves the open draft, not the text before it", async () => {
243
+ let written: string | undefined;
244
+ await mount({
245
+ onSave: (source) => {
246
+ written = source;
247
+ },
248
+ });
249
+ fireEvent.click(
250
+ within(tile("intro")).getByRole("button", { name: /Read/ }),
251
+ );
252
+ const field = screen.getByLabelText("Markdown");
253
+ field.focus();
254
+ fireEvent.change(field, { target: { value: "Drafted, never closed" } });
255
+ fireEvent.keyDown(field, { key: "s", ctrlKey: true, metaKey: true });
256
+ await waitFor(() => expect(written).toBeDefined());
257
+ expect(written).toContain(
258
+ "##|(markdown) intro\nDrafted, never closed\n|##",
259
+ );
260
+ });
261
+ });
262
+
263
+ describe("undo and redo point at the tile they changed", () => {
264
+ it("scrolls to it and lights it briefly, for the buttons and the keyboard", async () => {
265
+ const scrolled = mock((_options?: unknown) => {});
266
+ const original = HTMLElement.prototype.scrollIntoView;
267
+ HTMLElement.prototype.scrollIntoView = scrolled;
268
+ try {
269
+ await mount();
270
+ editInline("By category", "Tile title", "Revenue");
271
+ expect(tile("by_cat").hasAttribute("data-flash")).toBe(false);
272
+ undo();
273
+ expect(tile("by_cat").getAttribute("data-flash")).toBe("true");
274
+ expect(scrolled).toHaveBeenCalledTimes(1);
275
+ expect(tile("by_brand").hasAttribute("data-flash")).toBe(false);
276
+
277
+ fireEvent.click(button("Redo"));
278
+ expect(scrolled).toHaveBeenCalledTimes(2);
279
+ fireEvent.keyDown(window, {
280
+ key: "z",
281
+ ctrlKey: true,
282
+ metaKey: true,
283
+ });
284
+ expect(scrolled).toHaveBeenCalledTimes(3);
285
+ await waitFor(() =>
286
+ expect(tile("by_cat").hasAttribute("data-flash")).toBe(true),
287
+ );
288
+ } finally {
289
+ HTMLElement.prototype.scrollIntoView = original;
290
+ }
291
+ });
292
+
293
+ it("copes with a browser that cannot scroll", async () => {
294
+ await mount();
295
+ editInline("By category", "Tile title", "Revenue");
296
+ undo();
297
+ expect(tile("by_cat").getAttribute("data-flash")).toBe("true");
298
+ });
299
+ });
300
+
301
+ describe("the save target", () => {
302
+ it("is a caption under Save, not only a tooltip", async () => {
303
+ await mount({ onSave: () => {} });
304
+ expect(screen.getByText("Saves to the package file")).toBeDefined();
305
+ });
306
+
307
+ it("is the workspace's own words when it supplies them", async () => {
308
+ await mount({
309
+ onSave: () => {},
310
+ savesTo: "host",
311
+ saveLabel: "Saved to this draft",
312
+ });
313
+ expect(screen.getByText("Saved to this draft")).toBeDefined();
314
+ expect(screen.queryByText(/embedded in/)).toBeNull();
315
+ });
316
+
317
+ it("is a generic line, without the word host, when the workspace says nothing", async () => {
318
+ await mount({ onSave: () => {}, savesTo: "host" });
319
+ expect(
320
+ screen.getByText("Saves to the app this is embedded in"),
321
+ ).toBeDefined();
322
+ expect(screen.queryByText(/host/i)).toBeNull();
323
+ });
324
+
325
+ it("is absent when there is nowhere to save", async () => {
326
+ await mount();
327
+ expect(screen.queryByText("Saves to the package file")).toBeNull();
328
+ });
329
+ });
@@ -0,0 +1,363 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import {
5
+ cleanup,
6
+ fireEvent,
7
+ render,
8
+ screen,
9
+ waitFor,
10
+ } from "@testing-library/react";
11
+ import { afterEach, describe, expect, it, mock } from "bun:test";
12
+ import * as fs from "fs";
13
+ import * as path from "path";
14
+ import { DashboardBuilder } from "./DashboardBuilder";
15
+ import { readForEditor } from "./readForEditor";
16
+ import { openDocument } from "./testing/fixtures";
17
+ import type { BuilderEvent } from "./telemetry";
18
+ import { closeMenu, editInline } from "./testing/inline";
19
+
20
+ const NOTEBOOK = `## artifact { kind=notebook title="Review" tiles=[intro { kind=text }, "a -> by_cat"] }
21
+ import "../data_app.malloy"
22
+
23
+ ##|(markdown) intro
24
+ Hello.
25
+ |##
26
+
27
+ source: a is scoped_orders extend {
28
+ view: by_cat is by_category
29
+ }
30
+ `;
31
+
32
+ const WIDE = NOTEBOOK.replace(
33
+ " view: by_cat",
34
+ " # colspan=6\n view: by_cat",
35
+ );
36
+
37
+ const DASHBOARD = `## artifact { title="Storefront" tiles=["a -> by_cat"] } dashboard { columns=12 }
38
+ import "../data_app.malloy"
39
+
40
+ source: a is scoped_orders extend {
41
+ # colspan=12
42
+ view: by_cat is by_category
43
+ }
44
+ `;
45
+
46
+ const catalog = {
47
+ sources: [
48
+ {
49
+ name: "scoped_orders",
50
+ modelPath: "data_app.malloy",
51
+ views: [{ name: "sales_by_state" }],
52
+ givens: [],
53
+ fields: [],
54
+ },
55
+ ],
56
+ };
57
+
58
+ const REPO = path.resolve(import.meta.dir, "../../../../..");
59
+ const LEGACY = fs
60
+ .readFileSync(
61
+ path.join(REPO, "examples/storefront/notebooks/category-review.malloy"),
62
+ "utf8",
63
+ )
64
+ .replace(/\r\n/g, "\n");
65
+
66
+ const button = (name: string) =>
67
+ screen.getByRole("button", { name, hidden: true });
68
+
69
+ afterEach(cleanup);
70
+
71
+ const mountText = async (
72
+ source: string,
73
+ options: {
74
+ onSave?: (source: string) => void;
75
+ onEvent?: (event: BuilderEvent) => void;
76
+ withCatalog?: boolean;
77
+ } = {},
78
+ ) =>
79
+ render(
80
+ <DashboardBuilder
81
+ source={source}
82
+ document={await openDocument(source)}
83
+ {...(options.withCatalog ? { catalog } : {})}
84
+ {...(options.onSave ? { onSave: options.onSave } : {})}
85
+ {...(options.onEvent ? { onEvent: options.onEvent } : {})}
86
+ />,
87
+ );
88
+
89
+ describe("DashboardBuilder: a notebook is one column", () => {
90
+ it("offers no width: no grid width, no width presets", async () => {
91
+ await mountText(NOTEBOOK);
92
+ fireEvent.click(button("Settings"));
93
+ expect(screen.getByLabelText("Show as")).toBeDefined();
94
+ expect(screen.queryByLabelText("Grid width")).toBeNull();
95
+ fireEvent.keyDown(screen.getByLabelText("Show as"), { key: "Escape" });
96
+ fireEvent.click(screen.getByLabelText("Settings for intro"));
97
+ expect(screen.queryByRole("button", { name: "Width ½" })).toBeNull();
98
+ fireEvent.click(screen.getByLabelText("Settings for by_cat"));
99
+ expect(screen.queryByRole("button", { name: "Width ½" })).toBeNull();
100
+ });
101
+
102
+ it("does not nudge a width with the arrow keys", async () => {
103
+ // A width left in the file by hand is not the builder's to rewrite.
104
+ await mountText(WIDE, { onSave: () => {} });
105
+ fireEvent.click(screen.getByLabelText("Tile by_cat"));
106
+ fireEvent.keyDown(window, { key: "ArrowLeft" });
107
+ fireEvent.keyDown(window, { key: "ArrowRight" });
108
+ expect(button("Saved")).toBeDefined();
109
+ });
110
+
111
+ it("adds a tile without a width, and never writes columns", async () => {
112
+ let written: string | undefined;
113
+ await mountText(NOTEBOOK, {
114
+ withCatalog: true,
115
+ onSave: (source) => {
116
+ written = source;
117
+ },
118
+ });
119
+ fireEvent.click(button("Add tile"));
120
+ expect(screen.queryByLabelText("Tile width")).toBeNull();
121
+ fireEvent.click(screen.getByLabelText("View sales_by_state"));
122
+ fireEvent.click(screen.getByRole("button", { name: "Add tile" }));
123
+ fireEvent.click(button("Save changes"));
124
+ await waitFor(() => expect(written).toBeDefined());
125
+ expect(written).toContain("view: sales_by_state_tile is sales_by_state");
126
+ expect(written).not.toContain("colspan");
127
+ expect(written).not.toContain("columns");
128
+ });
129
+
130
+ it("names the document's own kind in the Add tile dialog", async () => {
131
+ await mountText(NOTEBOOK, { withCatalog: true });
132
+ fireEvent.click(button("Add tile"));
133
+ expect(
134
+ screen.getByText(
135
+ "A tile shows one view of one source this notebook imports.",
136
+ ),
137
+ ).toBeDefined();
138
+ cleanup();
139
+
140
+ await mountText(DASHBOARD, { withCatalog: true });
141
+ fireEvent.click(button("Add tile"));
142
+ expect(
143
+ screen.getByText(
144
+ "A tile shows one view of one source this dashboard imports.",
145
+ ),
146
+ ).toBeDefined();
147
+ });
148
+
149
+ it("inserts a tile between two tiles from the + on the edge between them", async () => {
150
+ let written: string | undefined;
151
+ await mountText(NOTEBOOK, {
152
+ withCatalog: true,
153
+ onSave: (source) => {
154
+ written = source;
155
+ },
156
+ });
157
+ fireEvent.click(screen.getByLabelText("Insert tile after intro"));
158
+ fireEvent.click(screen.getByRole("button", { name: "Text" }));
159
+ fireEvent.click(screen.getByRole("button", { name: "Add text" }));
160
+ fireEvent.click(button("Save changes"));
161
+ await waitFor(() => expect(written).toBeDefined());
162
+ expect(written).toContain(
163
+ 'tiles=[intro { kind=text }, text_1 { kind=text }, "a -> by_cat"]',
164
+ );
165
+ });
166
+
167
+ it("adds a tile at the end from the section-level +", async () => {
168
+ let written: string | undefined;
169
+ await mountText(NOTEBOOK, {
170
+ withCatalog: true,
171
+ onSave: (source) => {
172
+ written = source;
173
+ },
174
+ });
175
+ fireEvent.click(screen.getByLabelText("Insert tile after intro"));
176
+ fireEvent.keyDown(screen.getByRole("dialog"), { key: "Escape" });
177
+ fireEvent.click(screen.getByLabelText("Add tile at the end"));
178
+ fireEvent.click(screen.getByRole("button", { name: "Text" }));
179
+ fireEvent.click(screen.getByRole("button", { name: "Add text" }));
180
+ fireEvent.click(button("Save changes"));
181
+ await waitFor(() => expect(written).toBeDefined());
182
+ expect(written).toContain(
183
+ 'tiles=[intro { kind=text }, "a -> by_cat", text_1 { kind=text }]',
184
+ );
185
+ });
186
+
187
+ it("offers no insert + in a dashboard, where position is a grid cell", async () => {
188
+ await mountText(DASHBOARD, { withCatalog: true });
189
+ expect(screen.queryByLabelText(/^Insert tile after/)).toBeNull();
190
+ expect(screen.queryByLabelText("Add tile at the end")).toBeNull();
191
+ });
192
+
193
+ it("reports notebook events, with the cell count", async () => {
194
+ const onEvent = mock((_event: BuilderEvent) => {});
195
+ await mountText(NOTEBOOK, { onSave: () => {}, onEvent });
196
+ editInline("by_cat", "Tile title", "Categories");
197
+ fireEvent.click(button("Save changes"));
198
+ await waitFor(() => expect(onEvent).toHaveBeenCalledTimes(1));
199
+ expect(onEvent.mock.calls[0][0]).toMatchObject({
200
+ type: "notebook.saved",
201
+ cells: 2,
202
+ structural: false,
203
+ converted: false,
204
+ where: "package",
205
+ });
206
+ });
207
+ });
208
+
209
+ describe("DashboardBuilder: Show as", () => {
210
+ const showAs = (kind: "Dashboard" | "Notebook") => {
211
+ fireEvent.click(button("Settings"));
212
+ fireEvent.click(screen.getByRole("button", { name: kind }));
213
+ fireEvent.keyDown(screen.getByLabelText("Show as"), { key: "Escape" });
214
+ };
215
+
216
+ it("turns a dashboard into a notebook in place, and drops its width", async () => {
217
+ let written: string | undefined;
218
+ await mountText(DASHBOARD, {
219
+ onSave: (source) => {
220
+ written = source;
221
+ },
222
+ });
223
+ fireEvent.click(screen.getByLabelText("Settings for by_cat"));
224
+ expect(screen.getByRole("button", { name: "Width ½" })).toBeDefined();
225
+ closeMenu();
226
+ showAs("Notebook");
227
+ // The menu follows the toggle at once.
228
+ fireEvent.click(screen.getByLabelText("Settings for by_cat"));
229
+ expect(screen.queryByRole("button", { name: "Width ½" })).toBeNull();
230
+ closeMenu();
231
+ fireEvent.click(button("Save changes"));
232
+ await waitFor(() => expect(written).toBeDefined());
233
+ expect(written).toContain("kind=notebook");
234
+ expect(written).not.toContain("columns");
235
+ // Everything else in the file is where it was.
236
+ expect(written).toContain("source: a is scoped_orders extend {");
237
+ });
238
+
239
+ it("turns a notebook back into a dashboard", async () => {
240
+ let written: string | undefined;
241
+ await mountText(NOTEBOOK, {
242
+ onSave: (source) => {
243
+ written = source;
244
+ },
245
+ });
246
+ showAs("Dashboard");
247
+ fireEvent.click(button("Save changes"));
248
+ await waitFor(() => expect(written).toBeDefined());
249
+ expect(written).not.toContain("kind=notebook");
250
+ expect(written).toContain('title="Review"');
251
+ });
252
+ });
253
+
254
+ describe("DashboardBuilder: a notebook in the cell format", () => {
255
+ const open = async (
256
+ options: {
257
+ onSave?: (source: string) => void;
258
+ onExit?: () => void;
259
+ onEvent?: (event: BuilderEvent) => void;
260
+ onDirtyChange?: (dirty: boolean) => void;
261
+ } = {},
262
+ ) => {
263
+ const result = await readForEditor(LEGACY);
264
+ if (result.ok === false) throw new Error(result.reason);
265
+ if (!result.conversion) throw new Error("expected a conversion");
266
+ render(
267
+ <DashboardBuilder
268
+ source={LEGACY}
269
+ document={result.document}
270
+ conversion={result.conversion}
271
+ {...options}
272
+ />,
273
+ );
274
+ return result.conversion;
275
+ };
276
+
277
+ it("opens unsaved, says what Save does, and is not edited", async () => {
278
+ const onDirtyChange = mock((_dirty: boolean) => {});
279
+ await open({ onSave: () => {}, onDirtyChange });
280
+ expect(
281
+ screen.getByText(
282
+ /This notebook is in the cell format\. Saving rewrites it as a layout notebook, and a named query run once becomes that tile's view; Undo save puts it back\./,
283
+ ),
284
+ ).toBeDefined();
285
+ expect(button("Save changes")).toBeDefined();
286
+ // Each tile says why it has no preview yet, beside the view it will run.
287
+ expect(
288
+ screen.getAllByText("Preview appears after you Save"),
289
+ ).toHaveLength(3);
290
+ expect(
291
+ screen.getByText("order_items_tiles → revenue_by_month"),
292
+ ).toBeDefined();
293
+ // No edit has been made, so a host guarding navigation is told so.
294
+ expect(onDirtyChange).toHaveBeenLastCalledWith(false);
295
+ });
296
+
297
+ it("leaves at once when nothing was changed since the conversion", async () => {
298
+ const onExit = mock(() => {});
299
+ await open({ onSave: () => {}, onExit });
300
+ fireEvent.click(button("Close"));
301
+ expect(onExit).toHaveBeenCalledTimes(1);
302
+ expect(screen.queryByRole("button", { name: "Keep editing" })).toBeNull();
303
+ });
304
+
305
+ it("asks before leaving once the converted notebook is edited", async () => {
306
+ const onExit = mock(() => {});
307
+ await open({ onSave: () => {}, onExit });
308
+ editInline("Revenue by month", "Tile title", "Monthly revenue");
309
+ fireEvent.click(button("Close"));
310
+ expect(button("Keep editing")).toBeDefined();
311
+ expect(onExit).not.toHaveBeenCalled();
312
+ });
313
+
314
+ it("saves the conversion, and Undo save writes the cell format back byte for byte", async () => {
315
+ const writes: string[] = [];
316
+ const onEvent = mock((_event: BuilderEvent) => {});
317
+ const conversion = await open({
318
+ onSave: (source) => void writes.push(source),
319
+ onEvent,
320
+ });
321
+ fireEvent.click(button("Save changes"));
322
+ await waitFor(() => expect(writes).toHaveLength(1));
323
+ // Nothing was edited, so the file written is the conversion itself.
324
+ expect(writes[0]).toBe(conversion.to);
325
+ expect(onEvent.mock.calls[0][0]).toMatchObject({
326
+ type: "notebook.saved",
327
+ converted: true,
328
+ });
329
+ expect(
330
+ screen.queryByText(/This notebook is in the cell format/),
331
+ ).toBeNull();
332
+
333
+ fireEvent.click(await screen.findByRole("button", { name: "Undo save" }));
334
+ await waitFor(() => expect(writes).toHaveLength(2));
335
+ expect(writes[1]).toBe(LEGACY);
336
+ // Back to conversion-pending: the banner and Save return.
337
+ expect(
338
+ await screen.findByText(/This notebook is in the cell format/),
339
+ ).toBeDefined();
340
+ expect(button("Save changes")).toBeDefined();
341
+ expect(onEvent.mock.calls.map(([event]) => event.type)).toEqual([
342
+ "notebook.saved",
343
+ "notebook.save_undone",
344
+ ]);
345
+ });
346
+
347
+ it("keeps the edits made before the save through its undo", async () => {
348
+ const writes: string[] = [];
349
+ await open({ onSave: (source) => void writes.push(source) });
350
+ editInline("Revenue by month", "Tile title", "Monthly revenue");
351
+ fireEvent.click(button("Save changes"));
352
+ await waitFor(() => expect(writes).toHaveLength(1));
353
+ expect(writes[0]).toContain('# label="Monthly revenue"');
354
+
355
+ fireEvent.click(await screen.findByRole("button", { name: "Undo save" }));
356
+ await waitFor(() => expect(writes).toHaveLength(2));
357
+ expect(writes[1]).toBe(LEGACY);
358
+ expect(screen.getByLabelText("Tile revenue_by_month")).toBeDefined();
359
+ expect(
360
+ screen.getByLabelText("Settings for Monthly revenue"),
361
+ ).toBeDefined();
362
+ });
363
+ });