@malloy-publisher/sdk 0.9.0 → 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.
- package/dist/{Dashboard-H1kJlDFo.es.js → DashboardTile-BFcxdv7R.es.js} +15918 -17760
- package/dist/DashboardTile-sg8LjUk8.cjs.js +137 -0
- package/dist/RenderedResult-B48wAjM8.cjs.js +141 -0
- package/dist/{RenderedResult-BRgIgxWh.es.js → RenderedResult-CBLHr32C.es.js} +193 -183
- package/dist/{ServerProvider-Boxrv6Ym.es.js → ServerProvider-DCV8BUWD.es.js} +529 -521
- package/dist/ServerProvider-HRqT3w1C.cjs.js +1 -0
- package/dist/builder/index.cjs.js +146 -58
- package/dist/builder/index.es.js +9076 -6479
- package/dist/builder-entry.d.ts +4 -0
- package/dist/client/api.d.ts +82 -48
- package/dist/client/configuration.d.ts +1 -1
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.es.js +84 -82
- package/dist/components/Dashboard/Dashboard.d.ts +8 -15
- package/dist/components/Dashboard/DashboardGrid.d.ts +23 -6
- package/dist/components/Dashboard/DashboardTile.d.ts +10 -1
- package/dist/components/Dashboard/DashboardView.d.ts +36 -0
- package/dist/components/Dashboard/TileCard.d.ts +15 -4
- package/dist/components/Dashboard/TileFilterTag.d.ts +12 -0
- package/dist/components/Dashboard/index.d.ts +3 -0
- package/dist/components/Dashboard/telemetry.d.ts +15 -3
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +8 -1
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +16 -5
- package/dist/components/DashboardBuilder/ChartPicker.d.ts +29 -0
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +48 -21
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +17 -4
- package/dist/components/DashboardBuilder/DiffDialog.d.ts +2 -10
- package/dist/components/DashboardBuilder/FilterDialog.d.ts +2 -2
- package/dist/components/DashboardBuilder/FilterStrip.d.ts +3 -1
- package/dist/components/DashboardBuilder/InlineMarkdown.d.ts +18 -0
- package/dist/components/DashboardBuilder/InlineText.d.ts +19 -0
- package/dist/components/DashboardBuilder/NotebookEditor.d.ts +15 -0
- package/dist/components/DashboardBuilder/SaveNotice.d.ts +27 -0
- package/dist/components/DashboardBuilder/SettingsPopover.d.ts +19 -7
- package/dist/components/DashboardBuilder/SourceViewPicker.d.ts +9 -0
- package/dist/components/DashboardBuilder/TextTileBody.d.ts +7 -0
- package/dist/components/DashboardBuilder/TileFrame.d.ts +14 -12
- package/dist/components/DashboardBuilder/TileMenu.d.ts +11 -3
- package/dist/components/DashboardBuilder/annotationText.d.ts +4 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +4 -0
- package/dist/components/DashboardBuilder/changedTile.d.ts +7 -0
- package/dist/components/DashboardBuilder/chartLine.d.ts +33 -0
- package/dist/components/DashboardBuilder/controls.d.ts +2 -2
- package/dist/components/DashboardBuilder/document.d.ts +42 -26
- package/dist/components/DashboardBuilder/documentSession.d.ts +100 -0
- package/dist/components/DashboardBuilder/legacyNotebook.d.ts +73 -0
- package/dist/components/DashboardBuilder/loadMalloy.d.ts +15 -0
- package/dist/components/DashboardBuilder/malloyText.d.ts +45 -5
- package/dist/components/DashboardBuilder/malloyTree.d.ts +119 -0
- package/dist/components/DashboardBuilder/newDashboard.d.ts +3 -1
- package/dist/components/DashboardBuilder/openDraft.d.ts +10 -0
- package/dist/components/DashboardBuilder/preview.d.ts +24 -4
- package/dist/components/DashboardBuilder/readDocument.d.ts +4 -1
- package/dist/components/DashboardBuilder/readForEditor.d.ts +16 -0
- package/dist/components/DashboardBuilder/sortable.d.ts +14 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +13 -13
- package/dist/components/DashboardBuilder/spliceResult.d.ts +11 -0
- package/dist/components/DashboardBuilder/tagParse.d.ts +24 -0
- package/dist/components/DashboardBuilder/telemetry.d.ts +43 -0
- package/dist/components/DashboardBuilder/testing/fixtures.d.ts +3 -1
- package/dist/components/DashboardBuilder/testing/inline.d.ts +4 -0
- package/dist/components/DashboardBuilder/useBuilderSession.d.ts +89 -0
- package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +9 -6
- package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +17 -55
- package/dist/components/DashboardBuilder/useDocumentEditor.d.ts +105 -0
- package/dist/components/DashboardBuilder/useExitGuard.d.ts +19 -0
- package/dist/components/DashboardBuilder/useFilterForm.d.ts +3 -3
- package/dist/components/DocumentCreate/canRetry.d.ts +6 -0
- package/dist/components/DocumentCreate/createDocument.d.ts +58 -0
- package/dist/components/DocumentCreate/documentPath.d.ts +10 -0
- package/dist/components/DocumentCreate/events.d.ts +10 -0
- package/dist/components/DocumentCreate/exportedSources.d.ts +7 -0
- package/dist/components/DocumentCreate/guards.d.ts +12 -0
- package/dist/components/DocumentCreate/index.d.ts +6 -0
- package/dist/components/DocumentCreate/newNotebook.d.ts +9 -0
- package/dist/components/DocumentCreate/useDocumentChoices.d.ts +32 -0
- package/dist/components/DocumentStorage/DocumentStorage.d.ts +2 -1
- package/dist/components/NarrowEditGate.d.ts +8 -0
- package/dist/components/Notebook/Notebook.d.ts +1 -1
- package/dist/components/Package/NewDocumentDialog.d.ts +33 -0
- package/dist/components/Package/Package.d.ts +1 -0
- package/dist/components/Package/documentLocation.d.ts +28 -0
- package/dist/components/Package/index.d.ts +4 -0
- package/dist/components/Package/useDocumentLocation.d.ts +12 -0
- package/dist/components/PackageSection.d.ts +2 -2
- package/dist/components/RenderedResult/RenderedResult.d.ts +2 -0
- package/dist/components/RenderedResult/ResultContainer.d.ts +8 -1
- package/dist/components/RenderedResult/ResultPanel.d.ts +3 -1
- package/dist/components/RenderedResult/resultSizing.d.ts +9 -1
- package/dist/components/ServerProvider.d.ts +2 -1
- package/dist/components/UnsavedChangesDialog.d.ts +9 -0
- package/dist/components/given/GivensPanel.d.ts +2 -2
- package/dist/components/index.d.ts +2 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useNarrowScreen.d.ts +4 -0
- package/dist/hooks/useQueryResult.d.ts +2 -0
- package/dist/hooks/useSettled.d.ts +14 -0
- package/dist/index.cjs.js +23 -24
- package/dist/index.es.js +9714 -7072
- package/dist/text/index.cjs.js +1 -0
- package/dist/text/index.d.ts +2 -0
- package/dist/text/index.es.js +6 -0
- package/dist/text-entry-BJwltZiy.cjs.js +7 -0
- package/dist/text-entry-CbbBcZl8.es.js +196 -0
- package/dist/text-entry.d.ts +2 -0
- package/dist/utils/clock.d.ts +2 -0
- package/package.json +10 -1
- package/src/builder-entry.ts +35 -0
- package/src/components/Dashboard/Dashboard.tsx +27 -278
- package/src/components/Dashboard/DashboardGrid.tsx +68 -7
- package/src/components/Dashboard/DashboardTile.spec.tsx +24 -0
- package/src/components/Dashboard/DashboardTile.tsx +31 -4
- package/src/components/Dashboard/DashboardView.spec.tsx +212 -0
- package/src/components/Dashboard/DashboardView.tsx +352 -0
- package/src/components/Dashboard/RowsDialog.tsx +1 -1
- package/src/components/Dashboard/TileCard.tsx +44 -10
- package/src/components/Dashboard/TileFilterTag.spec.tsx +73 -0
- package/src/components/Dashboard/TileFilterTag.tsx +78 -0
- package/src/components/Dashboard/defaultTileSpan.spec.ts +32 -0
- package/src/components/Dashboard/index.ts +3 -0
- package/src/components/Dashboard/telemetry.ts +16 -5
- package/src/components/DashboardBuilder/AddTileDialog.spec.tsx +88 -0
- package/src/components/DashboardBuilder/AddTileDialog.tsx +137 -111
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +85 -27
- package/src/components/DashboardBuilder/ChartPicker.render.spec.tsx +25 -0
- package/src/components/DashboardBuilder/ChartPicker.spec.ts +77 -0
- package/src/components/DashboardBuilder/ChartPicker.tsx +153 -0
- package/src/components/DashboardBuilder/DashboardBuilder.charts.spec.tsx +205 -0
- package/src/components/DashboardBuilder/DashboardBuilder.exit.spec.tsx +192 -0
- package/src/components/DashboardBuilder/DashboardBuilder.inline.spec.tsx +329 -0
- package/src/components/DashboardBuilder/DashboardBuilder.notebook.spec.tsx +363 -0
- package/src/components/DashboardBuilder/DashboardBuilder.notice.spec.tsx +194 -0
- package/src/components/DashboardBuilder/DashboardBuilder.openDraft.spec.tsx +157 -0
- package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +124 -0
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +103 -78
- package/src/components/DashboardBuilder/DashboardBuilder.textTiles.spec.tsx +177 -0
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +610 -315
- package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +58 -8
- package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +191 -0
- package/src/components/DashboardBuilder/DashboardEditor.filterTag.spec.tsx +162 -0
- package/src/components/DashboardBuilder/DashboardEditor.notebook.spec.tsx +316 -0
- package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +56 -10
- package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +5 -22
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +96 -14
- package/src/components/DashboardBuilder/DashboardEditor.tsx +482 -332
- package/src/components/DashboardBuilder/DiffDialog.spec.tsx +25 -0
- package/src/components/DashboardBuilder/DiffDialog.tsx +5 -24
- package/src/components/DashboardBuilder/DrillDialog.tsx +1 -1
- package/src/components/DashboardBuilder/FilterDialog.tsx +10 -3
- package/src/components/DashboardBuilder/FilterStrip.tsx +26 -4
- package/src/components/DashboardBuilder/InlineMarkdown.tsx +184 -0
- package/src/components/DashboardBuilder/InlineText.tsx +106 -0
- package/src/components/DashboardBuilder/NotebookEditor.tsx +44 -0
- package/src/components/DashboardBuilder/SaveNotice.tsx +113 -0
- package/src/components/DashboardBuilder/SettingsPopover.spec.tsx +87 -0
- package/src/components/DashboardBuilder/SettingsPopover.tsx +225 -67
- package/src/components/DashboardBuilder/SourceViewPicker.tsx +122 -0
- package/src/components/DashboardBuilder/TextTileBody.tsx +28 -0
- package/src/components/DashboardBuilder/TileFrame.tsx +89 -115
- package/src/components/DashboardBuilder/TileMenu.tsx +168 -90
- package/src/components/DashboardBuilder/annotationText.spec.ts +33 -0
- package/src/components/DashboardBuilder/annotationText.ts +17 -0
- package/src/components/DashboardBuilder/artifactBlock.spec.ts +248 -0
- package/src/components/DashboardBuilder/artifactTagParity.spec.ts +41 -0
- package/src/components/DashboardBuilder/catalog.aggregate.spec.ts +49 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +2 -0
- package/src/components/DashboardBuilder/catalog.ts +61 -21
- package/src/components/DashboardBuilder/changedTile.spec.ts +46 -0
- package/src/components/DashboardBuilder/changedTile.ts +28 -0
- package/src/components/DashboardBuilder/chartLine.spec.ts +180 -0
- package/src/components/DashboardBuilder/chartLine.ts +121 -0
- package/src/components/DashboardBuilder/controls.spec.ts +21 -10
- package/src/components/DashboardBuilder/controls.ts +22 -8
- package/src/components/DashboardBuilder/document.ts +53 -5
- package/src/components/DashboardBuilder/documentSession.spec.ts +209 -0
- package/src/components/DashboardBuilder/documentSession.ts +257 -0
- package/src/components/DashboardBuilder/emptyStart.spec.ts +131 -0
- package/src/components/DashboardBuilder/invariants.spec.ts +6 -2
- package/src/components/DashboardBuilder/legacyNotebook.chart.spec.ts +77 -0
- package/src/components/DashboardBuilder/legacyNotebook.convert.spec.ts +630 -0
- package/src/components/DashboardBuilder/legacyNotebook.read.spec.ts +338 -0
- package/src/components/DashboardBuilder/legacyNotebook.ts +1117 -0
- package/src/components/DashboardBuilder/loadMalloy.spec.ts +80 -0
- package/src/components/DashboardBuilder/loadMalloy.ts +39 -0
- package/src/components/DashboardBuilder/malloyText.spec.ts +48 -0
- package/src/components/DashboardBuilder/malloyText.ts +181 -27
- package/src/components/DashboardBuilder/malloyTree.ts +155 -7
- package/src/components/DashboardBuilder/newDashboard.spec.ts +46 -2
- package/src/components/DashboardBuilder/newDashboard.ts +30 -3
- package/src/components/DashboardBuilder/openDraft.ts +52 -0
- package/src/components/DashboardBuilder/preview.shapes.spec.ts +75 -0
- package/src/components/DashboardBuilder/preview.spec.ts +159 -12
- package/src/components/DashboardBuilder/preview.ts +83 -9
- package/src/components/DashboardBuilder/readDocument.spec.ts +139 -27
- package/src/components/DashboardBuilder/readDocument.ts +130 -44
- package/src/components/DashboardBuilder/readForEditor.spec.ts +80 -0
- package/src/components/DashboardBuilder/readForEditor.ts +47 -0
- package/src/components/DashboardBuilder/scannerShapes.spec.ts +14 -13
- package/src/components/DashboardBuilder/sortable.spec.ts +65 -0
- package/src/components/DashboardBuilder/sortable.tsx +2 -12
- package/src/components/DashboardBuilder/spliceDocument.chart.spec.ts +340 -0
- package/src/components/DashboardBuilder/spliceDocument.imports.spec.ts +167 -0
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +229 -94
- package/src/components/DashboardBuilder/spliceDocument.ts +762 -130
- package/src/components/DashboardBuilder/spliceResult.ts +15 -0
- package/src/components/DashboardBuilder/statementExtent.spec.ts +33 -30
- package/src/components/DashboardBuilder/tagParse.spec.ts +149 -0
- package/src/components/DashboardBuilder/tagParse.ts +103 -0
- package/src/components/DashboardBuilder/telemetry.ts +47 -0
- package/src/components/DashboardBuilder/testing/artifactTagParity.json +197 -0
- package/src/components/DashboardBuilder/testing/fixtures.ts +16 -1
- package/src/components/DashboardBuilder/testing/inline.ts +25 -0
- package/src/components/DashboardBuilder/textTiles.spec.ts +718 -0
- package/src/components/DashboardBuilder/useBuilderSession.spec.ts +335 -0
- package/src/components/DashboardBuilder/useBuilderSession.ts +292 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.overlay.spec.tsx +65 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.spec.tsx +60 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.ts +36 -10
- package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +16 -13
- package/src/components/DashboardBuilder/useDashboardEditor.ts +54 -181
- package/src/components/DashboardBuilder/useDocumentEditor.spec.ts +565 -0
- package/src/components/DashboardBuilder/useDocumentEditor.ts +399 -0
- package/src/components/DashboardBuilder/useExitGuard.spec.ts +159 -0
- package/src/components/DashboardBuilder/useExitGuard.ts +89 -0
- package/src/components/DashboardBuilder/useFilterForm.existing.spec.tsx +41 -0
- package/src/components/DashboardBuilder/useFilterForm.spec.tsx +24 -2
- package/src/components/DashboardBuilder/useFilterForm.ts +41 -13
- package/src/components/DashboardBuilder/useTileReorder.spec.tsx +28 -5
- package/src/components/DashboardBuilder/useTileReorder.ts +5 -7
- package/src/components/DocumentCreate/canRetry.spec.ts +32 -0
- package/src/components/DocumentCreate/canRetry.ts +19 -0
- package/src/components/DocumentCreate/createDocument.spec.ts +310 -0
- package/src/components/DocumentCreate/createDocument.ts +159 -0
- package/src/components/DocumentCreate/documentPath.ts +40 -0
- package/src/components/DocumentCreate/events.ts +15 -0
- package/src/components/DocumentCreate/exportedSources.ts +25 -0
- package/src/components/DocumentCreate/guards.ts +45 -0
- package/src/components/DocumentCreate/index.ts +27 -0
- package/src/components/DocumentCreate/newNotebook.spec.ts +156 -0
- package/src/components/DocumentCreate/newNotebook.ts +44 -0
- package/src/components/DocumentCreate/useDocumentChoices.spec.tsx +138 -0
- package/src/components/DocumentCreate/useDocumentChoices.ts +113 -0
- package/src/components/DocumentStorage/DocumentStorage.ts +2 -1
- package/src/components/Model/ModelExplorer.spec.tsx +2 -2
- package/src/components/Model/SourcesExplorer.tsx +2 -4
- package/src/components/NarrowEditGate.spec.tsx +73 -0
- package/src/components/NarrowEditGate.tsx +29 -0
- package/src/components/Notebook/Notebook.layout.spec.tsx +94 -0
- package/src/components/Notebook/Notebook.tsx +66 -27
- package/src/components/Package/NewDocumentDialog.spec.tsx +749 -0
- package/src/components/Package/NewDocumentDialog.tsx +401 -0
- package/src/components/Package/Package.artifacts.spec.tsx +190 -0
- package/src/components/Package/Package.create.spec.tsx +380 -0
- package/src/components/Package/Package.notebooks.spec.tsx +18 -0
- package/src/components/Package/Package.tsx +366 -171
- package/src/components/Package/documentLocation.spec.ts +81 -0
- package/src/components/Package/documentLocation.ts +55 -0
- package/src/components/Package/index.ts +13 -0
- package/src/components/Package/useDocumentLocation.ts +59 -0
- package/src/components/PackageSection.tsx +2 -2
- package/src/components/RenderedResult/RenderedResult.tsx +18 -1
- package/src/components/RenderedResult/ResultContainer.tsx +44 -11
- package/src/components/RenderedResult/ResultPanel.tsx +4 -0
- package/src/components/RenderedResult/resultSizing.spec.ts +68 -0
- package/src/components/RenderedResult/resultSizing.ts +14 -3
- package/src/components/ServerProvider.tsx +2 -1
- package/src/components/UnsavedChangesDialog.spec.tsx +70 -0
- package/src/components/UnsavedChangesDialog.tsx +49 -0
- package/src/components/given/GivensPanel.spec.tsx +6 -6
- package/src/components/given/GivensPanel.tsx +3 -3
- package/src/components/index.ts +2 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/useNarrowScreen.ts +21 -0
- package/src/hooks/useQueryResult.ts +16 -0
- package/src/hooks/useSettled.spec.ts +41 -0
- package/src/hooks/useSettled.ts +27 -0
- package/src/mainEntry.spec.ts +145 -0
- package/src/text-entry.ts +12 -0
- package/src/textEntry.spec.ts +118 -0
- package/src/utils/clock.spec.ts +12 -0
- package/src/utils/clock.ts +6 -0
- package/vite.config.ts +4 -0
- package/dist/Dashboard-ChyylkTD.cjs.js +0 -136
- package/dist/RenderedResult-AJPMUkAD.cjs.js +0 -135
- package/dist/ServerProvider-CXrOKD6g.cjs.js +0 -1
- package/dist/components/DashboardBuilder/useTileResize.d.ts +0 -29
- package/dist/components/Package/NewDashboardDialog.d.ts +0 -18
- package/src/components/DashboardBuilder/useTileResize.spec.tsx +0 -121
- package/src/components/DashboardBuilder/useTileResize.ts +0 -110
- package/src/components/Package/NewDashboardDialog.spec.tsx +0 -129
- package/src/components/Package/NewDashboardDialog.tsx +0 -265
|
@@ -0,0 +1,316 @@
|
|
|
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 { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
12
|
+
import * as fs from "fs";
|
|
13
|
+
import * as path from "path";
|
|
14
|
+
import {
|
|
15
|
+
clearCache,
|
|
16
|
+
mockServerProvider,
|
|
17
|
+
pending,
|
|
18
|
+
serverWrapper,
|
|
19
|
+
} from "../../../test/serverProvider";
|
|
20
|
+
import { sha256Hex } from "../../utils/sha256";
|
|
21
|
+
import {
|
|
22
|
+
DocumentNotFoundError,
|
|
23
|
+
type DocumentLocator,
|
|
24
|
+
type DocumentStorage,
|
|
25
|
+
type DocumentType,
|
|
26
|
+
type Workspace,
|
|
27
|
+
} from "../DocumentStorage";
|
|
28
|
+
import { DocumentStorageProvider } from "../DocumentStorage/DocumentStorageProvider";
|
|
29
|
+
import type { BuilderEvent } from "./telemetry";
|
|
30
|
+
import { editInline } from "./testing/inline";
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The one editor opened as a notebook: how it reads the file, where it takes
|
|
34
|
+
* the manifest from, and what it does with a notebook in the cell format.
|
|
35
|
+
*/
|
|
36
|
+
const REPO = path.resolve(import.meta.dir, "../../../../..");
|
|
37
|
+
const LEGACY = fs
|
|
38
|
+
.readFileSync(
|
|
39
|
+
path.join(REPO, "examples/storefront/notebooks/category-review.malloy"),
|
|
40
|
+
"utf8",
|
|
41
|
+
)
|
|
42
|
+
.replace(/\r\n/g, "\n");
|
|
43
|
+
|
|
44
|
+
const LAYOUT = `## artifact { kind=notebook title="Tour" tiles=[intro { kind=text }] }
|
|
45
|
+
|
|
46
|
+
##|(markdown) intro
|
|
47
|
+
Hello.
|
|
48
|
+
|##
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
const REFUSED = `## artifact { kind=notebook }
|
|
52
|
+
import { orders } from "../m.malloy"
|
|
53
|
+
|
|
54
|
+
run: orders extend { dimension: z is 1 } -> { select: z }
|
|
55
|
+
`;
|
|
56
|
+
|
|
57
|
+
let served = LAYOUT;
|
|
58
|
+
let servedHash = await sha256Hex(LAYOUT);
|
|
59
|
+
let writes: string[] = [];
|
|
60
|
+
|
|
61
|
+
const getModel = mock(
|
|
62
|
+
async (
|
|
63
|
+
_env: string,
|
|
64
|
+
_pkg: string,
|
|
65
|
+
modelPath: string,
|
|
66
|
+
_versionId?: string,
|
|
67
|
+
_authoring?: boolean,
|
|
68
|
+
) => ({
|
|
69
|
+
data: {
|
|
70
|
+
modelPath,
|
|
71
|
+
sourceText: modelPath.endsWith("tour.malloy") ? served : served,
|
|
72
|
+
givens: [{ name: "FROM_MODEL", type: "string" }],
|
|
73
|
+
},
|
|
74
|
+
}),
|
|
75
|
+
);
|
|
76
|
+
const getNotebook = mock(
|
|
77
|
+
async (_env: string, _pkg: string, modelPath: string) => ({
|
|
78
|
+
data: served.includes("tiles=")
|
|
79
|
+
? {
|
|
80
|
+
dashboard: {
|
|
81
|
+
path: modelPath,
|
|
82
|
+
kind: "notebook",
|
|
83
|
+
givens: [{ name: "FROM_MANIFEST", type: "string" }],
|
|
84
|
+
tiles: [],
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
: {},
|
|
88
|
+
}),
|
|
89
|
+
);
|
|
90
|
+
const getDashboard = mock(() => pending());
|
|
91
|
+
const listModels = mock(async () => ({ data: [] }));
|
|
92
|
+
const executeQueryModel = mock(() => pending());
|
|
93
|
+
const updateModelSource = mock(
|
|
94
|
+
async (
|
|
95
|
+
_env: string,
|
|
96
|
+
_pkg: string,
|
|
97
|
+
modelPath: string,
|
|
98
|
+
body: { source: string; expectedHash?: string },
|
|
99
|
+
) => {
|
|
100
|
+
if (body.expectedHash !== servedHash)
|
|
101
|
+
throw { response: { status: 409, data: { message: "changed" } } };
|
|
102
|
+
served = body.source;
|
|
103
|
+
writes.push(body.source);
|
|
104
|
+
servedHash = `hash-${writes.length}`;
|
|
105
|
+
return { data: { path: modelPath, contentHash: servedHash } };
|
|
106
|
+
},
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const serverContext: {
|
|
110
|
+
mutable: boolean | undefined;
|
|
111
|
+
isLoadingStatus: boolean;
|
|
112
|
+
} = { mutable: true, isLoadingStatus: false };
|
|
113
|
+
mockServerProvider(
|
|
114
|
+
{
|
|
115
|
+
models: { getModel, listModels, executeQueryModel, updateModelSource },
|
|
116
|
+
notebooks: { getNotebook },
|
|
117
|
+
dashboards: {
|
|
118
|
+
getDashboard,
|
|
119
|
+
listDashboards: mock(async () => ({ data: [] })),
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
serverContext,
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const { DashboardEditor } = await import("./DashboardEditor");
|
|
126
|
+
const { NotebookEditor } = await import("./NotebookEditor");
|
|
127
|
+
|
|
128
|
+
const button = (name: string | RegExp) =>
|
|
129
|
+
screen.getByRole("button", { name, hidden: true });
|
|
130
|
+
|
|
131
|
+
const mount = (
|
|
132
|
+
props: Partial<Parameters<typeof DashboardEditor>[0]> & {
|
|
133
|
+
dashboardName?: string;
|
|
134
|
+
} = {},
|
|
135
|
+
onEvent?: (event: BuilderEvent) => void,
|
|
136
|
+
) =>
|
|
137
|
+
render(
|
|
138
|
+
<DashboardEditor
|
|
139
|
+
kind="notebook"
|
|
140
|
+
environmentName="env"
|
|
141
|
+
packageName="pkg"
|
|
142
|
+
dashboardName="tour"
|
|
143
|
+
{...(onEvent ? { onEvent } : {})}
|
|
144
|
+
{...(props as object)}
|
|
145
|
+
/>,
|
|
146
|
+
{ wrapper: serverWrapper },
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
beforeEach(async () => {
|
|
150
|
+
cleanup();
|
|
151
|
+
clearCache();
|
|
152
|
+
localStorage.clear();
|
|
153
|
+
served = LAYOUT;
|
|
154
|
+
servedHash = await sha256Hex(LAYOUT);
|
|
155
|
+
writes = [];
|
|
156
|
+
serverContext.mutable = true;
|
|
157
|
+
getModel.mockClear();
|
|
158
|
+
getNotebook.mockClear();
|
|
159
|
+
getDashboard.mockClear();
|
|
160
|
+
updateModelSource.mockClear();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe("DashboardEditor as a notebook", () => {
|
|
164
|
+
it("reads the file with the authoring flag, and the manifest from the notebook read", async () => {
|
|
165
|
+
const onEvent = mock((_event: BuilderEvent) => {});
|
|
166
|
+
mount({}, onEvent);
|
|
167
|
+
expect(await screen.findByText("Tour")).toBeDefined();
|
|
168
|
+
expect(getModel.mock.calls[0].slice(0, 3)).toEqual([
|
|
169
|
+
"env",
|
|
170
|
+
"pkg",
|
|
171
|
+
"notebooks/tour.malloy",
|
|
172
|
+
]);
|
|
173
|
+
expect(getModel.mock.calls[0][4]).toBe(true);
|
|
174
|
+
await waitFor(() => expect(getNotebook).toHaveBeenCalled());
|
|
175
|
+
expect(getDashboard).not.toHaveBeenCalled();
|
|
176
|
+
expect(onEvent.mock.calls[0][0]).toMatchObject({
|
|
177
|
+
type: "notebook.opened",
|
|
178
|
+
from: "package",
|
|
179
|
+
cells: 1,
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("opens the file where the host says it is, not where its kind would put it", async () => {
|
|
184
|
+
mount({ path: "dashboards/tour.malloy" });
|
|
185
|
+
expect(await screen.findByText("Tour")).toBeDefined();
|
|
186
|
+
expect(getModel.mock.calls[0][2]).toBe("dashboards/tour.malloy");
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("opens the file NotebookEditor is told it is at", async () => {
|
|
190
|
+
render(
|
|
191
|
+
<NotebookEditor
|
|
192
|
+
environmentName="env"
|
|
193
|
+
packageName="pkg"
|
|
194
|
+
notebookName="tour"
|
|
195
|
+
path="dashboards/tour.malloy"
|
|
196
|
+
/>,
|
|
197
|
+
{ wrapper: serverWrapper },
|
|
198
|
+
);
|
|
199
|
+
expect(await screen.findByText("Tour")).toBeDefined();
|
|
200
|
+
expect(getModel.mock.calls[0][2]).toBe("dashboards/tour.malloy");
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("refuses a .malloynb notebook without fetching it", async () => {
|
|
204
|
+
const onEvent = mock((_event: BuilderEvent) => {});
|
|
205
|
+
mount({ dashboardName: "old.malloynb" }, onEvent);
|
|
206
|
+
expect(
|
|
207
|
+
await screen.findByText(/a \.malloynb notebook is read, not edited/),
|
|
208
|
+
).toBeDefined();
|
|
209
|
+
expect(getModel).not.toHaveBeenCalled();
|
|
210
|
+
expect(onEvent.mock.calls[0][0]).toMatchObject({
|
|
211
|
+
type: "notebook.open_refused",
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("offers a notebook in the cell format as a conversion, and Save and Undo save are exact", async () => {
|
|
216
|
+
served = LEGACY;
|
|
217
|
+
servedHash = await sha256Hex(LEGACY);
|
|
218
|
+
const onEvent = mock((_event: BuilderEvent) => {});
|
|
219
|
+
mount({}, onEvent);
|
|
220
|
+
expect(
|
|
221
|
+
await screen.findByText(/This notebook is in the cell format/),
|
|
222
|
+
).toBeDefined();
|
|
223
|
+
expect(screen.getByLabelText("Tile revenue_by_month")).toBeDefined();
|
|
224
|
+
|
|
225
|
+
fireEvent.click(button("Save changes"));
|
|
226
|
+
await waitFor(() => expect(writes).toHaveLength(1));
|
|
227
|
+
expect(writes[0]).toContain("tiles=[\n text_1 { kind=text }");
|
|
228
|
+
expect(writes[0]).toContain("view: revenue_by_month is sales_by_month");
|
|
229
|
+
expect(
|
|
230
|
+
await screen.findByRole("button", { name: "Undo save" }),
|
|
231
|
+
).toBeDefined();
|
|
232
|
+
|
|
233
|
+
fireEvent.click(screen.getByRole("button", { name: "Undo save" }));
|
|
234
|
+
await waitFor(() => expect(writes).toHaveLength(2));
|
|
235
|
+
expect(writes[1]).toBe(LEGACY);
|
|
236
|
+
expect(
|
|
237
|
+
await screen.findByText(/This notebook is in the cell format/),
|
|
238
|
+
).toBeDefined();
|
|
239
|
+
expect(onEvent.mock.calls.map(([event]) => event.type)).toEqual([
|
|
240
|
+
"notebook.opened",
|
|
241
|
+
"notebook.saved",
|
|
242
|
+
"notebook.save_undone",
|
|
243
|
+
]);
|
|
244
|
+
expect(onEvent.mock.calls[1][0]).toMatchObject({ converted: true });
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it("says why a notebook cannot be converted, naming the line", async () => {
|
|
248
|
+
served = REFUSED;
|
|
249
|
+
const onEvent = mock((_event: BuilderEvent) => {});
|
|
250
|
+
mount({}, onEvent);
|
|
251
|
+
const alert = await screen.findByText(/cannot be opened in the builder/);
|
|
252
|
+
expect(alert.textContent).toMatch(/line 4/i);
|
|
253
|
+
expect(
|
|
254
|
+
screen.queryByText(/This notebook is in the cell format/),
|
|
255
|
+
).toBeNull();
|
|
256
|
+
expect(onEvent.mock.calls[0][0]).toMatchObject({
|
|
257
|
+
type: "notebook.open_refused",
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
describe("DashboardEditor as a notebook: the host's record", () => {
|
|
263
|
+
const RECORD: Workspace = {
|
|
264
|
+
name: "Branch",
|
|
265
|
+
writeable: true,
|
|
266
|
+
description: "Saved to the draft branch",
|
|
267
|
+
authoritative: true,
|
|
268
|
+
};
|
|
269
|
+
class Store implements DocumentStorage {
|
|
270
|
+
readonly types: DocumentType[] = [];
|
|
271
|
+
readonly saved = new Map<string, string>();
|
|
272
|
+
constructor(private readonly record: string | undefined) {}
|
|
273
|
+
async listWorkspaces(): Promise<Workspace[]> {
|
|
274
|
+
return [RECORD];
|
|
275
|
+
}
|
|
276
|
+
async listDocuments(): Promise<DocumentLocator[]> {
|
|
277
|
+
return [];
|
|
278
|
+
}
|
|
279
|
+
async getDocument(locator: DocumentLocator): Promise<string> {
|
|
280
|
+
this.types.push(locator.type);
|
|
281
|
+
if (this.record === undefined)
|
|
282
|
+
throw new DocumentNotFoundError(locator.path);
|
|
283
|
+
return this.record;
|
|
284
|
+
}
|
|
285
|
+
async saveDocument(locator: DocumentLocator, content: string) {
|
|
286
|
+
this.saved.set(locator.path, content);
|
|
287
|
+
}
|
|
288
|
+
async deleteDocument(): Promise<void> {}
|
|
289
|
+
async moveDocument(): Promise<void> {}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
it("reads and writes it under the notebook type", async () => {
|
|
293
|
+
const store = new Store(LAYOUT.replace("Hello.", "From the record."));
|
|
294
|
+
render(
|
|
295
|
+
<DocumentStorageProvider documentStorage={store}>
|
|
296
|
+
<DashboardEditor
|
|
297
|
+
kind="notebook"
|
|
298
|
+
environmentName="env"
|
|
299
|
+
packageName="pkg"
|
|
300
|
+
dashboardName="tour"
|
|
301
|
+
/>
|
|
302
|
+
</DocumentStorageProvider>,
|
|
303
|
+
{ wrapper: serverWrapper },
|
|
304
|
+
);
|
|
305
|
+
expect(await screen.findByText("From the record.")).toBeDefined();
|
|
306
|
+
expect(store.types).toEqual(["notebook"]);
|
|
307
|
+
editInline("Tour", "Notebook title", "Tour, again");
|
|
308
|
+
fireEvent.click(button("Save changes"));
|
|
309
|
+
await waitFor(() => expect(store.saved.size).toBe(1));
|
|
310
|
+
expect(store.saved.get("env/pkg/notebooks/tour.malloy")).toContain(
|
|
311
|
+
'title="Tour, again"',
|
|
312
|
+
);
|
|
313
|
+
// The record took the write; the package file was left alone.
|
|
314
|
+
expect(updateModelSource).not.toHaveBeenCalled();
|
|
315
|
+
});
|
|
316
|
+
});
|
|
@@ -8,7 +8,9 @@ import {
|
|
|
8
8
|
mockServerProvider,
|
|
9
9
|
pending,
|
|
10
10
|
serverWrapper,
|
|
11
|
+
TEST_SERVER,
|
|
11
12
|
} from "../../../test/serverProvider";
|
|
13
|
+
import { globalQueryClient } from "../../utils/queryClient";
|
|
12
14
|
import { sha256Hex } from "../../utils/sha256";
|
|
13
15
|
import { BrowserDocumentStorage } from "../DocumentStorage/BrowserDocumentStorage";
|
|
14
16
|
import { DocumentStorageProvider } from "../DocumentStorage/DocumentStorageProvider";
|
|
@@ -26,6 +28,7 @@ source: a is scoped_orders extend {
|
|
|
26
28
|
# label="By category"
|
|
27
29
|
view: by_cat is by_category
|
|
28
30
|
}`;
|
|
31
|
+
import { editInline } from "./testing/inline";
|
|
29
32
|
|
|
30
33
|
const getModel = mock((_env: string, _pkg: string, path: string) =>
|
|
31
34
|
Promise.resolve({
|
|
@@ -110,11 +113,7 @@ describe("DashboardEditor, when the server takes writes", () => {
|
|
|
110
113
|
screen.getByText("Save writes the file into the package."),
|
|
111
114
|
).toBeDefined();
|
|
112
115
|
|
|
113
|
-
|
|
114
|
-
fireEvent.change(screen.getByLabelText("Tile title"), {
|
|
115
|
-
target: { value: "Categories" },
|
|
116
|
-
});
|
|
117
|
-
fireEvent.keyDown(screen.getByLabelText("Tile title"), { key: "Escape" });
|
|
116
|
+
editInline("By category", "Tile title", "Categories");
|
|
118
117
|
fireEvent.click(button("Save changes"));
|
|
119
118
|
|
|
120
119
|
await waitFor(() => expect(updateModelSource).toHaveBeenCalledTimes(1));
|
|
@@ -134,6 +133,26 @@ describe("DashboardEditor, when the server takes writes", () => {
|
|
|
134
133
|
expect(screen.queryByText(/saved in this browser/)).toBeNull();
|
|
135
134
|
});
|
|
136
135
|
|
|
136
|
+
it("Undo save after resuming a draft writes the package file back, not the draft", async () => {
|
|
137
|
+
const draft = PACKAGE_FILE.replace(
|
|
138
|
+
'title="Storefront"',
|
|
139
|
+
'title="Drafted"',
|
|
140
|
+
);
|
|
141
|
+
await new BrowserDocumentStorage().saveDocument(DRAFT, draft);
|
|
142
|
+
mount();
|
|
143
|
+
await screen.findByText("Storefront");
|
|
144
|
+
fireEvent.click(button("Resume"));
|
|
145
|
+
await screen.findByText("Drafted");
|
|
146
|
+
editInline("By category", "Tile title", "Categories");
|
|
147
|
+
fireEvent.click(button("Save changes"));
|
|
148
|
+
await waitFor(() => expect(updateModelSource).toHaveBeenCalledTimes(1));
|
|
149
|
+
fireEvent.click(
|
|
150
|
+
await screen.findByRole("button", { name: "Undo save", hidden: true }),
|
|
151
|
+
);
|
|
152
|
+
await waitFor(() => expect(updateModelSource).toHaveBeenCalledTimes(2));
|
|
153
|
+
expect(updateModelSource.mock.calls[1][3].source).toBe(PACKAGE_FILE);
|
|
154
|
+
});
|
|
155
|
+
|
|
137
156
|
it("keeps the edit and shows the server's reason when the package refuses the write", async () => {
|
|
138
157
|
updateModelSource.mockImplementationOnce(() =>
|
|
139
158
|
Promise.reject({
|
|
@@ -147,11 +166,7 @@ describe("DashboardEditor, when the server takes writes", () => {
|
|
|
147
166
|
);
|
|
148
167
|
mount();
|
|
149
168
|
await screen.findByText("Storefront");
|
|
150
|
-
|
|
151
|
-
fireEvent.change(screen.getByLabelText("Tile title"), {
|
|
152
|
-
target: { value: "Categories" },
|
|
153
|
-
});
|
|
154
|
-
fireEvent.keyDown(screen.getByLabelText("Tile title"), { key: "Escape" });
|
|
169
|
+
editInline("By category", "Tile title", "Categories");
|
|
155
170
|
fireEvent.click(button("Save changes"));
|
|
156
171
|
await waitFor(() =>
|
|
157
172
|
expect(screen.getByRole("alert").textContent).toContain(
|
|
@@ -160,4 +175,35 @@ describe("DashboardEditor, when the server takes writes", () => {
|
|
|
160
175
|
);
|
|
161
176
|
expect(button("Save changes")).toBeDefined();
|
|
162
177
|
});
|
|
178
|
+
|
|
179
|
+
it("drops the cached results of the saved file, which are keyed on query text, not content", async () => {
|
|
180
|
+
const key = (modelPath: string) => [
|
|
181
|
+
"queryResult",
|
|
182
|
+
"env",
|
|
183
|
+
"pkg",
|
|
184
|
+
undefined,
|
|
185
|
+
modelPath,
|
|
186
|
+
undefined,
|
|
187
|
+
"run: a -> by_cat",
|
|
188
|
+
undefined,
|
|
189
|
+
"{}",
|
|
190
|
+
TEST_SERVER,
|
|
191
|
+
];
|
|
192
|
+
globalQueryClient.setQueryData(key("dashboards/overview.malloy"), "old");
|
|
193
|
+
globalQueryClient.setQueryData(key("dashboards/other.malloy"), "other");
|
|
194
|
+
mount();
|
|
195
|
+
await screen.findByText("Storefront");
|
|
196
|
+
editInline("By category", "Tile title", "Categories");
|
|
197
|
+
fireEvent.click(button("Save changes"));
|
|
198
|
+
await waitFor(() =>
|
|
199
|
+
expect(
|
|
200
|
+
globalQueryClient.getQueryState(key("dashboards/overview.malloy"))
|
|
201
|
+
?.isInvalidated,
|
|
202
|
+
).toBe(true),
|
|
203
|
+
);
|
|
204
|
+
expect(
|
|
205
|
+
globalQueryClient.getQueryState(key("dashboards/other.malloy"))
|
|
206
|
+
?.isInvalidated,
|
|
207
|
+
).toBe(false);
|
|
208
|
+
});
|
|
163
209
|
});
|
|
@@ -33,6 +33,7 @@ source: a is scoped_orders extend {
|
|
|
33
33
|
# label="By category"
|
|
34
34
|
view: by_cat is by_category
|
|
35
35
|
}`;
|
|
36
|
+
import { editInline } from "./testing/inline";
|
|
36
37
|
|
|
37
38
|
const getModel = mock(
|
|
38
39
|
(_env: string, _pkg: string, path: string, _versionId?: string) =>
|
|
@@ -212,7 +213,7 @@ describe("versionId", () => {
|
|
|
212
213
|
// screen.
|
|
213
214
|
expect(cacheKeys("dashboard-editor-model")[0]).toContain('"v7"');
|
|
214
215
|
expect(cacheKeys("dashboard-editor-manifest")[0]).toContain('"v7"');
|
|
215
|
-
expect(cacheKeys("
|
|
216
|
+
expect(cacheKeys("dashboards")[0]).toContain('"v7"');
|
|
216
217
|
await waitFor(() =>
|
|
217
218
|
expect(cacheKeys("dashboard-editor-catalog")[0]).toContain('"v7"'),
|
|
218
219
|
);
|
|
@@ -238,13 +239,7 @@ describe("versionId", () => {
|
|
|
238
239
|
serverContext.mutable = true;
|
|
239
240
|
mountByUri();
|
|
240
241
|
await screen.findByText("Storefront");
|
|
241
|
-
|
|
242
|
-
fireEvent.change(screen.getByLabelText("Tile title"), {
|
|
243
|
-
target: { value: "Categories" },
|
|
244
|
-
});
|
|
245
|
-
fireEvent.keyDown(screen.getByLabelText("Tile title"), {
|
|
246
|
-
key: "Escape",
|
|
247
|
-
});
|
|
242
|
+
editInline("By category", "Tile title", "Categories");
|
|
248
243
|
fireEvent.click(button("Save changes"));
|
|
249
244
|
|
|
250
245
|
await waitFor(() => expect(updateModelSource).toHaveBeenCalledTimes(1));
|
|
@@ -266,13 +261,7 @@ describe("versionId", () => {
|
|
|
266
261
|
(call) => call[2] === "dashboards/overview.malloy",
|
|
267
262
|
).length;
|
|
268
263
|
|
|
269
|
-
|
|
270
|
-
fireEvent.change(screen.getByLabelText("Tile title"), {
|
|
271
|
-
target: { value: "Categories" },
|
|
272
|
-
});
|
|
273
|
-
fireEvent.keyDown(screen.getByLabelText("Tile title"), {
|
|
274
|
-
key: "Escape",
|
|
275
|
-
});
|
|
264
|
+
editInline("By category", "Tile title", "Categories");
|
|
276
265
|
fireEvent.click(button("Save changes"));
|
|
277
266
|
await waitFor(() => expect(updateModelSource).toHaveBeenCalledTimes(1));
|
|
278
267
|
|
|
@@ -318,13 +307,7 @@ describe("Save, pinned to a version", () => {
|
|
|
318
307
|
|
|
319
308
|
// Unaffected: a copy kept beside the package never goes through
|
|
320
309
|
// `updateModelSource`, so the version pin has nothing to refuse.
|
|
321
|
-
|
|
322
|
-
fireEvent.change(screen.getByLabelText("Tile title"), {
|
|
323
|
-
target: { value: "Categories" },
|
|
324
|
-
});
|
|
325
|
-
fireEvent.keyDown(screen.getByLabelText("Tile title"), {
|
|
326
|
-
key: "Escape",
|
|
327
|
-
});
|
|
310
|
+
editInline("By category", "Tile title", "Categories");
|
|
328
311
|
fireEvent.click(button("Save changes"));
|
|
329
312
|
await waitFor(() => expect(button("Saved")).toBeDefined());
|
|
330
313
|
});
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
act,
|
|
6
|
+
fireEvent,
|
|
7
|
+
render,
|
|
8
|
+
screen,
|
|
9
|
+
waitFor,
|
|
10
|
+
} from "@testing-library/react";
|
|
5
11
|
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
6
12
|
import {
|
|
7
13
|
clearCache,
|
|
@@ -12,6 +18,7 @@ import {
|
|
|
12
18
|
import { BrowserDocumentStorage } from "../DocumentStorage/BrowserDocumentStorage";
|
|
13
19
|
import { DocumentStorageProvider } from "../DocumentStorage/DocumentStorageProvider";
|
|
14
20
|
import type { DashboardEvent } from "../Dashboard/telemetry";
|
|
21
|
+
import { globalQueryClient } from "../../utils/queryClient";
|
|
15
22
|
|
|
16
23
|
/**
|
|
17
24
|
* The Console's path through the builder, with the server mocked at the
|
|
@@ -26,14 +33,20 @@ source: a is scoped_orders extend {
|
|
|
26
33
|
# label="By category"
|
|
27
34
|
view: by_cat is by_category
|
|
28
35
|
}`;
|
|
36
|
+
import { editInline } from "./testing/inline";
|
|
37
|
+
|
|
38
|
+
let served = PACKAGE_FILE;
|
|
39
|
+
/** Set, and the dashboard's own file fails to fetch: a refetch the server could not answer. */
|
|
40
|
+
let fetchFailure: Error | undefined;
|
|
29
41
|
|
|
30
42
|
const getModel = mock((_env: string, _pkg: string, path: string) =>
|
|
31
|
-
path === "broken.malloy"
|
|
32
|
-
|
|
43
|
+
path === "broken.malloy" ||
|
|
44
|
+
(fetchFailure && path === "dashboards/overview.malloy")
|
|
45
|
+
? Promise.reject(fetchFailure ?? new Error("reloading"))
|
|
33
46
|
: Promise.resolve({
|
|
34
47
|
data:
|
|
35
48
|
path === "dashboards/overview.malloy"
|
|
36
|
-
? { modelPath: path, sourceText:
|
|
49
|
+
? { modelPath: path, sourceText: served }
|
|
37
50
|
: {
|
|
38
51
|
modelPath: path,
|
|
39
52
|
sources: [
|
|
@@ -76,10 +89,17 @@ const executeQueryModel = mock(() => pending());
|
|
|
76
89
|
const listModels = mock(() =>
|
|
77
90
|
Promise.resolve({ data: [{ path: "data_app.malloy" }] }),
|
|
78
91
|
);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
92
|
+
const serverContext: {
|
|
93
|
+
mutable: boolean | undefined;
|
|
94
|
+
isLoadingStatus: boolean;
|
|
95
|
+
} = { mutable: undefined, isLoadingStatus: false };
|
|
96
|
+
mockServerProvider(
|
|
97
|
+
{
|
|
98
|
+
models: { getModel, executeQueryModel, listModels },
|
|
99
|
+
dashboards: { getDashboard, listDashboards },
|
|
100
|
+
},
|
|
101
|
+
serverContext,
|
|
102
|
+
);
|
|
83
103
|
|
|
84
104
|
// Imported after the stub is registered: a static import would hoist above it.
|
|
85
105
|
const { DashboardEditor } = await import("./DashboardEditor");
|
|
@@ -116,6 +136,11 @@ const button = (name: string | RegExp) =>
|
|
|
116
136
|
beforeEach(() => {
|
|
117
137
|
clearCache();
|
|
118
138
|
localStorage.clear();
|
|
139
|
+
served = PACKAGE_FILE;
|
|
140
|
+
fetchFailure = undefined;
|
|
141
|
+
serverContext.mutable = undefined;
|
|
142
|
+
serverContext.isLoadingStatus = false;
|
|
143
|
+
getDashboard.mockClear();
|
|
119
144
|
});
|
|
120
145
|
|
|
121
146
|
describe("DashboardEditor", () => {
|
|
@@ -136,6 +161,67 @@ describe("DashboardEditor", () => {
|
|
|
136
161
|
await screen.findByRole("button", { name: "Add tile", hidden: true });
|
|
137
162
|
});
|
|
138
163
|
|
|
164
|
+
it("opens a dashboard with no tiles without asking for a manifest the server would 404", async () => {
|
|
165
|
+
served = PACKAGE_FILE.replace('tiles=["a -> by_cat"]', "tiles=[]");
|
|
166
|
+
mount();
|
|
167
|
+
expect(
|
|
168
|
+
await screen.findByText(/not served until it has a tile/),
|
|
169
|
+
).toBeDefined();
|
|
170
|
+
expect(
|
|
171
|
+
(
|
|
172
|
+
await screen.findAllByRole("button", {
|
|
173
|
+
name: "Add tile",
|
|
174
|
+
hidden: true,
|
|
175
|
+
})
|
|
176
|
+
).length,
|
|
177
|
+
).toBe(2);
|
|
178
|
+
expect(getDashboard).not.toHaveBeenCalled();
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("keeps the builder and its unsaved edit through a failed refetch", async () => {
|
|
182
|
+
mount();
|
|
183
|
+
await screen.findByText("Storefront");
|
|
184
|
+
editInline("By category", "Tile title", "Categories");
|
|
185
|
+
|
|
186
|
+
fetchFailure = new Error("the server went away");
|
|
187
|
+
await act(async () => {
|
|
188
|
+
await globalQueryClient.refetchQueries({
|
|
189
|
+
queryKey: ["dashboard-editor-model"],
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
expect(
|
|
193
|
+
await screen.findByText(/could not be re-read from the server/),
|
|
194
|
+
).toBeDefined();
|
|
195
|
+
expect(screen.getByLabelText("Tile by_cat")).toBeDefined();
|
|
196
|
+
expect(button("Save changes")).toBeDefined();
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("does not call an undecided server writable or read-only while its status loads", async () => {
|
|
200
|
+
serverContext.isLoadingStatus = true;
|
|
201
|
+
mount();
|
|
202
|
+
expect(
|
|
203
|
+
await screen.findByText("Checking whether this server takes writes."),
|
|
204
|
+
).toBeDefined();
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("says the server did not say whether it takes writes, once status has settled", async () => {
|
|
208
|
+
mount();
|
|
209
|
+
expect(
|
|
210
|
+
await screen.findByText(
|
|
211
|
+
"This server did not say whether it takes writes, so Save is off.",
|
|
212
|
+
),
|
|
213
|
+
).toBeDefined();
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("says why when reading the file throws, rather than loading forever", async () => {
|
|
217
|
+
// A body the reader cannot take apart, so the read rejects instead of refusing.
|
|
218
|
+
served = 42 as unknown as string;
|
|
219
|
+
mount();
|
|
220
|
+
expect(
|
|
221
|
+
await screen.findByText(/cannot be opened in the builder/),
|
|
222
|
+
).toBeDefined();
|
|
223
|
+
});
|
|
224
|
+
|
|
139
225
|
it("keeps the catalog when one published model fails to load", async () => {
|
|
140
226
|
listModels.mockImplementationOnce(() =>
|
|
141
227
|
Promise.resolve({
|
|
@@ -155,11 +241,7 @@ describe("DashboardEditor", () => {
|
|
|
155
241
|
it("saves an edit into the browser and marks it saved", async () => {
|
|
156
242
|
const storage = mount();
|
|
157
243
|
await screen.findByText("Storefront");
|
|
158
|
-
|
|
159
|
-
fireEvent.change(screen.getByLabelText("Tile title"), {
|
|
160
|
-
target: { value: "Categories" },
|
|
161
|
-
});
|
|
162
|
-
fireEvent.keyDown(screen.getByLabelText("Tile title"), { key: "Escape" });
|
|
244
|
+
editInline("By category", "Tile title", "Categories");
|
|
163
245
|
fireEvent.click(button("Save changes"));
|
|
164
246
|
await waitFor(async () =>
|
|
165
247
|
expect(await storage.getDocument(DRAFT)).toContain(
|
|
@@ -212,7 +294,7 @@ describe("DashboardEditor", () => {
|
|
|
212
294
|
from: "package",
|
|
213
295
|
tiles: 1,
|
|
214
296
|
});
|
|
215
|
-
fireEvent.click(button("
|
|
297
|
+
fireEvent.click(button("Close"));
|
|
216
298
|
expect(onExit).toHaveBeenCalledTimes(1);
|
|
217
299
|
});
|
|
218
300
|
});
|