@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,749 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
5
|
+
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
6
|
+
import {
|
|
7
|
+
cacheKeys,
|
|
8
|
+
clearCache,
|
|
9
|
+
mockServerProvider,
|
|
10
|
+
pending,
|
|
11
|
+
serverWrapper,
|
|
12
|
+
TEST_SERVER,
|
|
13
|
+
} from "../../../test/serverProvider";
|
|
14
|
+
import type { CreateTarget } from "../DocumentCreate";
|
|
15
|
+
import {
|
|
16
|
+
DocumentNotFoundError,
|
|
17
|
+
type DocumentLocator,
|
|
18
|
+
type DocumentStorage,
|
|
19
|
+
type Workspace,
|
|
20
|
+
} from "../DocumentStorage/DocumentStorage";
|
|
21
|
+
|
|
22
|
+
const info = (names: string[]) =>
|
|
23
|
+
JSON.stringify({
|
|
24
|
+
entries: names.map((name) => ({ kind: "source", name })),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const MODELS: Record<string, unknown> = {
|
|
28
|
+
"storefront.malloy": {
|
|
29
|
+
modelPath: "storefront.malloy",
|
|
30
|
+
modelInfo: info(["order_items", "products"]),
|
|
31
|
+
sources: [
|
|
32
|
+
{
|
|
33
|
+
name: "order_items",
|
|
34
|
+
views: [{ name: "by_category" }, { name: "by_brand" }],
|
|
35
|
+
},
|
|
36
|
+
{ name: "products", views: [] },
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
"other.malloy": { modelPath: "other.malloy", sources: [] },
|
|
40
|
+
// Imports `order_items` whole-file: it is in `sources` but not exported, so `import { order_items } from "../mid.malloy"` would not compile.
|
|
41
|
+
"mid.malloy": {
|
|
42
|
+
modelPath: "mid.malloy",
|
|
43
|
+
modelInfo: info(["mid_src"]),
|
|
44
|
+
sources: [
|
|
45
|
+
{ name: "order_items", views: [{ name: "by_category" }] },
|
|
46
|
+
{ name: "mid_src", views: [{ name: "overview" }] },
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
const serve = (
|
|
51
|
+
_env: string,
|
|
52
|
+
_pkg: string,
|
|
53
|
+
path: string,
|
|
54
|
+
_versionId?: string,
|
|
55
|
+
): Promise<{ data: unknown }> => Promise.resolve({ data: MODELS[path] });
|
|
56
|
+
const getModel = mock(serve);
|
|
57
|
+
mockServerProvider({ models: { getModel } });
|
|
58
|
+
|
|
59
|
+
const { NewDocumentDialog } = await import("./NewDocumentDialog");
|
|
60
|
+
|
|
61
|
+
type Dialog = Parameters<typeof NewDocumentDialog>[0];
|
|
62
|
+
|
|
63
|
+
const packageTarget = (
|
|
64
|
+
existing: string[] = [],
|
|
65
|
+
write: (path: string, source: string) => Promise<void> = async () => {},
|
|
66
|
+
): CreateTarget => ({ route: "package", existing, write });
|
|
67
|
+
|
|
68
|
+
const mount = (props: Partial<Dialog> = {}) =>
|
|
69
|
+
render(
|
|
70
|
+
<NewDocumentDialog
|
|
71
|
+
open
|
|
72
|
+
kind="dashboard"
|
|
73
|
+
environmentName="env"
|
|
74
|
+
packageName="pkg"
|
|
75
|
+
models={["storefront.malloy", "other.malloy"]}
|
|
76
|
+
target={packageTarget()}
|
|
77
|
+
onClose={() => {}}
|
|
78
|
+
onCreated={() => {}}
|
|
79
|
+
{...props}
|
|
80
|
+
/>,
|
|
81
|
+
{ wrapper: serverWrapper },
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const titleFilled = (value: string, label = "Dashboard title") =>
|
|
85
|
+
waitFor(() =>
|
|
86
|
+
expect(screen.getByLabelText(label)).toHaveProperty("value", value),
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
beforeEach(() => {
|
|
90
|
+
clearCache();
|
|
91
|
+
getModel.mockClear();
|
|
92
|
+
getModel.mockImplementation(serve);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const failing = (status?: number) =>
|
|
96
|
+
Promise.reject(
|
|
97
|
+
Object.assign(
|
|
98
|
+
new Error("Request failed"),
|
|
99
|
+
status === undefined ? {} : { response: { status } },
|
|
100
|
+
),
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const createButton = (name: string | RegExp) =>
|
|
104
|
+
screen.getByRole("button", { name });
|
|
105
|
+
|
|
106
|
+
const isDisabled = (element: HTMLElement) => element.hasAttribute("disabled");
|
|
107
|
+
|
|
108
|
+
describe("NewDocumentDialog", () => {
|
|
109
|
+
it("writes a dashboard with the picked view as its first tile and hands back where it went", async () => {
|
|
110
|
+
const write = mock((_path: string, _source: string) => Promise.resolve());
|
|
111
|
+
const onCreated = mock((_created: unknown) => {});
|
|
112
|
+
const onEvent = mock((_event: unknown) => {});
|
|
113
|
+
mount({ target: packageTarget([], write), onCreated, onEvent });
|
|
114
|
+
await titleFilled("by category");
|
|
115
|
+
|
|
116
|
+
// A source with no views is not on the list, so a pair that cannot be written cannot be picked.
|
|
117
|
+
fireEvent.mouseDown(screen.getByRole("combobox", { name: /First tile/ }));
|
|
118
|
+
expect(
|
|
119
|
+
screen.getAllByRole("option").map((option) => option.textContent),
|
|
120
|
+
).toEqual(["order_items → by_category", "order_items → by_brand"]);
|
|
121
|
+
fireEvent.click(
|
|
122
|
+
screen.getByRole("option", { name: "order_items → by_brand" }),
|
|
123
|
+
);
|
|
124
|
+
fireEvent.change(screen.getByLabelText("Dashboard title"), {
|
|
125
|
+
target: { value: "Sales by Region" },
|
|
126
|
+
});
|
|
127
|
+
expect(
|
|
128
|
+
screen.getByText(/Written as dashboards\/sales-by-region\.malloy/),
|
|
129
|
+
).toBeDefined();
|
|
130
|
+
|
|
131
|
+
fireEvent.click(screen.getByRole("button", { name: "Create dashboard" }));
|
|
132
|
+
await waitFor(() => expect(onCreated).toHaveBeenCalledTimes(1));
|
|
133
|
+
expect(onCreated.mock.calls[0][0]).toEqual({
|
|
134
|
+
kind: "dashboard",
|
|
135
|
+
path: "dashboards/sales-by-region.malloy",
|
|
136
|
+
slug: "sales-by-region",
|
|
137
|
+
});
|
|
138
|
+
const [path, source] = write.mock.calls[0];
|
|
139
|
+
expect(path).toBe("dashboards/sales-by-region.malloy");
|
|
140
|
+
expect(source).toContain('tiles=["order_items_tiles -> by_brand_tile"]');
|
|
141
|
+
expect(source).toContain(
|
|
142
|
+
'import { order_items } from "../storefront.malloy"',
|
|
143
|
+
);
|
|
144
|
+
expect(onEvent.mock.calls).toEqual([
|
|
145
|
+
[{ type: "dashboard.created", where: "package" }],
|
|
146
|
+
]);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("writes a notebook under notebooks/ with its first query", async () => {
|
|
150
|
+
const write = mock((_path: string, _source: string) => Promise.resolve());
|
|
151
|
+
const onCreated = mock((_created: unknown) => {});
|
|
152
|
+
mount({
|
|
153
|
+
kind: "notebook",
|
|
154
|
+
target: packageTarget([], write),
|
|
155
|
+
onCreated,
|
|
156
|
+
});
|
|
157
|
+
await titleFilled("by category", "Notebook title");
|
|
158
|
+
expect(
|
|
159
|
+
screen.getByRole("combobox", { name: /First query/ }),
|
|
160
|
+
).toBeDefined();
|
|
161
|
+
|
|
162
|
+
fireEvent.click(screen.getByRole("button", { name: "Create notebook" }));
|
|
163
|
+
await waitFor(() => expect(onCreated).toHaveBeenCalledTimes(1));
|
|
164
|
+
expect(onCreated.mock.calls[0][0]).toEqual({
|
|
165
|
+
kind: "notebook",
|
|
166
|
+
path: "notebooks/by-category.malloy",
|
|
167
|
+
slug: "by-category",
|
|
168
|
+
});
|
|
169
|
+
const [path, source] = write.mock.calls[0];
|
|
170
|
+
expect(path).toBe("notebooks/by-category.malloy");
|
|
171
|
+
expect(source).toContain("kind=notebook");
|
|
172
|
+
expect(source).toContain("view: by_category_tile is by_category");
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("switches kind in place, keeping the choices already read", async () => {
|
|
176
|
+
mount();
|
|
177
|
+
await titleFilled("by category");
|
|
178
|
+
fireEvent.mouseDown(screen.getByRole("combobox", { name: /Type/ }));
|
|
179
|
+
fireEvent.click(screen.getByRole("option", { name: "Notebook" }));
|
|
180
|
+
expect(
|
|
181
|
+
screen.getByRole("button", { name: "Create notebook" }),
|
|
182
|
+
).toBeDefined();
|
|
183
|
+
expect(screen.getByLabelText("Notebook title")).toBeDefined();
|
|
184
|
+
expect(getModel).toHaveBeenCalledTimes(2);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("takes the next free name when the package already has the title's file", async () => {
|
|
188
|
+
const write = mock((_path: string, _source: string) => Promise.resolve());
|
|
189
|
+
mount({
|
|
190
|
+
target: packageTarget(
|
|
191
|
+
["dashboards/overview.malloy", "dashboards/overview-2.malloy"],
|
|
192
|
+
write,
|
|
193
|
+
),
|
|
194
|
+
});
|
|
195
|
+
await titleFilled("by category");
|
|
196
|
+
fireEvent.change(screen.getByLabelText("Dashboard title"), {
|
|
197
|
+
target: { value: "Overview" },
|
|
198
|
+
});
|
|
199
|
+
expect(
|
|
200
|
+
screen.getByText(/Written as dashboards\/overview-3\.malloy/),
|
|
201
|
+
).toBeDefined();
|
|
202
|
+
fireEvent.click(screen.getByRole("button", { name: "Create dashboard" }));
|
|
203
|
+
await waitFor(() => expect(write).toHaveBeenCalledTimes(1));
|
|
204
|
+
expect(write.mock.calls[0][0]).toBe("dashboards/overview-3.malloy");
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("does not offer a notebook name a dashboard already took, and the reverse", async () => {
|
|
208
|
+
mount({
|
|
209
|
+
kind: "notebook",
|
|
210
|
+
target: packageTarget(["dashboards/by-category.malloy"]),
|
|
211
|
+
});
|
|
212
|
+
await titleFilled("by category", "Notebook title");
|
|
213
|
+
expect(
|
|
214
|
+
screen.getByText(/Written as notebooks\/by-category\.malloy/),
|
|
215
|
+
).toBeDefined();
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("shows what a failed write said and stays open", async () => {
|
|
219
|
+
const onCreated = mock((_created: unknown) => {});
|
|
220
|
+
mount({
|
|
221
|
+
target: packageTarget([], () =>
|
|
222
|
+
Promise.reject(
|
|
223
|
+
Object.assign(new Error("x"), {
|
|
224
|
+
response: { data: { message: "File already exists" } },
|
|
225
|
+
}),
|
|
226
|
+
),
|
|
227
|
+
),
|
|
228
|
+
onCreated,
|
|
229
|
+
});
|
|
230
|
+
await titleFilled("by category");
|
|
231
|
+
fireEvent.click(screen.getByRole("button", { name: "Create dashboard" }));
|
|
232
|
+
expect(await screen.findByText("File already exists")).toBeDefined();
|
|
233
|
+
expect(onCreated).not.toHaveBeenCalled();
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("offers only the sources a model exports, not the ones it imports", async () => {
|
|
237
|
+
mount({ models: ["mid.malloy"] });
|
|
238
|
+
await titleFilled("overview");
|
|
239
|
+
fireEvent.mouseDown(screen.getByRole("combobox", { name: /First tile/ }));
|
|
240
|
+
expect(
|
|
241
|
+
screen.getAllByRole("option").map((option) => option.textContent),
|
|
242
|
+
).toEqual(["mid_src → overview"]);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("offers nothing from a model whose exports are not stated", async () => {
|
|
246
|
+
MODELS["bare.malloy"] = {
|
|
247
|
+
modelPath: "bare.malloy",
|
|
248
|
+
sources: [{ name: "s", views: [{ name: "v" }] }],
|
|
249
|
+
};
|
|
250
|
+
mount({ models: ["bare.malloy"] });
|
|
251
|
+
expect(
|
|
252
|
+
await screen.findByText(/no model in this package declares one yet/),
|
|
253
|
+
).toBeDefined();
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it("says what to do when the package has no models", () => {
|
|
257
|
+
mount({ models: [] });
|
|
258
|
+
expect(screen.getByText(/This package has no models yet/)).toBeDefined();
|
|
259
|
+
expect(getModel).not.toHaveBeenCalled();
|
|
260
|
+
expect(
|
|
261
|
+
screen
|
|
262
|
+
.getByRole("button", {
|
|
263
|
+
name: "Create dashboard: No model view to start from yet",
|
|
264
|
+
})
|
|
265
|
+
.hasAttribute("disabled"),
|
|
266
|
+
).toBe(true);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("says what to do when no model declares a view", async () => {
|
|
270
|
+
mount({ models: ["other.malloy"] });
|
|
271
|
+
expect(
|
|
272
|
+
await screen.findByText(/no model in this package declares one yet/),
|
|
273
|
+
).toBeDefined();
|
|
274
|
+
expect(screen.getByText(/Add a view to a source/)).toBeDefined();
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
describe("requests", () => {
|
|
278
|
+
it("reads nothing until it is opened, then one model each under its own key", async () => {
|
|
279
|
+
const view = mount({ open: false });
|
|
280
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
281
|
+
expect(getModel).not.toHaveBeenCalled();
|
|
282
|
+
|
|
283
|
+
view.rerender(
|
|
284
|
+
<NewDocumentDialog
|
|
285
|
+
open
|
|
286
|
+
kind="dashboard"
|
|
287
|
+
environmentName="env"
|
|
288
|
+
packageName="pkg"
|
|
289
|
+
models={["storefront.malloy", "other.malloy"]}
|
|
290
|
+
target={packageTarget()}
|
|
291
|
+
onClose={() => {}}
|
|
292
|
+
onCreated={() => {}}
|
|
293
|
+
/>,
|
|
294
|
+
);
|
|
295
|
+
await titleFilled("by category");
|
|
296
|
+
expect(getModel).toHaveBeenCalledTimes(2);
|
|
297
|
+
expect(cacheKeys("new-document-model")).toEqual([
|
|
298
|
+
`["new-document-model","env","pkg",null,"storefront.malloy","${TEST_SERVER}"]`,
|
|
299
|
+
`["new-document-model","env","pkg",null,"other.malloy","${TEST_SERVER}"]`,
|
|
300
|
+
]);
|
|
301
|
+
|
|
302
|
+
// Closing and reopening reads the cache, not the server.
|
|
303
|
+
view.rerender(
|
|
304
|
+
<NewDocumentDialog
|
|
305
|
+
open={false}
|
|
306
|
+
kind="dashboard"
|
|
307
|
+
environmentName="env"
|
|
308
|
+
packageName="pkg"
|
|
309
|
+
models={["storefront.malloy", "other.malloy"]}
|
|
310
|
+
target={packageTarget()}
|
|
311
|
+
onClose={() => {}}
|
|
312
|
+
onCreated={() => {}}
|
|
313
|
+
/>,
|
|
314
|
+
);
|
|
315
|
+
view.rerender(
|
|
316
|
+
<NewDocumentDialog
|
|
317
|
+
open
|
|
318
|
+
kind="notebook"
|
|
319
|
+
environmentName="env"
|
|
320
|
+
packageName="pkg"
|
|
321
|
+
models={["storefront.malloy", "other.malloy"]}
|
|
322
|
+
target={packageTarget()}
|
|
323
|
+
onClose={() => {}}
|
|
324
|
+
onCreated={() => {}}
|
|
325
|
+
/>,
|
|
326
|
+
);
|
|
327
|
+
await titleFilled("by category", "Notebook title");
|
|
328
|
+
expect(getModel).toHaveBeenCalledTimes(2);
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
describe("on the storage route", () => {
|
|
333
|
+
const WORKSPACE: Workspace = {
|
|
334
|
+
name: "record",
|
|
335
|
+
writeable: true,
|
|
336
|
+
description: "The record",
|
|
337
|
+
authoritative: true,
|
|
338
|
+
};
|
|
339
|
+
const saved: string[] = [];
|
|
340
|
+
const storage: DocumentStorage = {
|
|
341
|
+
listWorkspaces: async () => [WORKSPACE],
|
|
342
|
+
// A stale listing: it does not know about the file the store has.
|
|
343
|
+
listDocuments: async () => [],
|
|
344
|
+
getDocument: async (locator: DocumentLocator) => {
|
|
345
|
+
if (locator.path === "env/pkg/notebooks/overview.malloy")
|
|
346
|
+
return "someone else's";
|
|
347
|
+
throw new DocumentNotFoundError("absent");
|
|
348
|
+
},
|
|
349
|
+
saveDocument: async (locator: DocumentLocator) => {
|
|
350
|
+
saved.push(locator.path);
|
|
351
|
+
},
|
|
352
|
+
deleteDocument: async () => {},
|
|
353
|
+
moveDocument: async () => {},
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
it("saves into the store under a name the store does not have", async () => {
|
|
357
|
+
saved.length = 0;
|
|
358
|
+
const onCreated = mock((_created: unknown) => {});
|
|
359
|
+
mount({
|
|
360
|
+
kind: "notebook",
|
|
361
|
+
target: {
|
|
362
|
+
route: "storage",
|
|
363
|
+
storage,
|
|
364
|
+
workspace: WORKSPACE,
|
|
365
|
+
environmentName: "env",
|
|
366
|
+
packageName: "pkg",
|
|
367
|
+
},
|
|
368
|
+
onCreated,
|
|
369
|
+
});
|
|
370
|
+
await titleFilled("by category", "Notebook title");
|
|
371
|
+
fireEvent.change(screen.getByLabelText("Notebook title"), {
|
|
372
|
+
target: { value: "Overview" },
|
|
373
|
+
});
|
|
374
|
+
fireEvent.click(
|
|
375
|
+
screen.getByRole("button", { name: "Create notebook" }),
|
|
376
|
+
);
|
|
377
|
+
await waitFor(() => expect(onCreated).toHaveBeenCalledTimes(1));
|
|
378
|
+
expect(saved).toEqual(["env/pkg/notebooks/overview-2.malloy"]);
|
|
379
|
+
expect(onCreated.mock.calls[0][0]).toMatchObject({
|
|
380
|
+
slug: "overview-2",
|
|
381
|
+
locator: { workspace: "record", type: "notebook" },
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
describe("NewDocumentDialog: what a model read is cached under", () => {
|
|
388
|
+
it("reads each model at the package's version, under a key that names the version and the server", async () => {
|
|
389
|
+
mount({ versionId: "v3" });
|
|
390
|
+
await titleFilled("by category");
|
|
391
|
+
expect(getModel.mock.calls[0]).toEqual([
|
|
392
|
+
"env",
|
|
393
|
+
"pkg",
|
|
394
|
+
"storefront.malloy",
|
|
395
|
+
"v3",
|
|
396
|
+
]);
|
|
397
|
+
const [key] = cacheKeys("new-document-model");
|
|
398
|
+
expect(key).toContain('"v3"');
|
|
399
|
+
expect(key).toContain(TEST_SERVER);
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
describe("NewDocumentDialog: a model it could not read", () => {
|
|
404
|
+
it("names it, keeps the rest, and offers a retry that brings its views back", async () => {
|
|
405
|
+
let healthy = false;
|
|
406
|
+
getModel.mockImplementation((env, pkg, path, versionId) =>
|
|
407
|
+
path === "storefront.malloy" && !healthy
|
|
408
|
+
? failing(503)
|
|
409
|
+
: serve(env, pkg, path, versionId),
|
|
410
|
+
);
|
|
411
|
+
mount();
|
|
412
|
+
expect(
|
|
413
|
+
await screen.findByText(
|
|
414
|
+
"Couldn't read storefront.malloy, so its views aren't listed.",
|
|
415
|
+
),
|
|
416
|
+
).toBeDefined();
|
|
417
|
+
expect(
|
|
418
|
+
screen.queryByText(/no model in this package declares/),
|
|
419
|
+
).toBeNull();
|
|
420
|
+
expect(
|
|
421
|
+
isDisabled(
|
|
422
|
+
createButton(
|
|
423
|
+
"Create dashboard: Couldn't read the model views to start from",
|
|
424
|
+
),
|
|
425
|
+
),
|
|
426
|
+
).toBe(true);
|
|
427
|
+
|
|
428
|
+
healthy = true;
|
|
429
|
+
fireEvent.click(screen.getByRole("button", { name: "Retry" }));
|
|
430
|
+
await titleFilled("by category");
|
|
431
|
+
expect(screen.queryByText(/Couldn't read storefront\.malloy/)).toBeNull();
|
|
432
|
+
expect(isDisabled(createButton("Create dashboard"))).toBe(false);
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
it("names every model it could not read", async () => {
|
|
436
|
+
getModel.mockImplementation(() => failing(500));
|
|
437
|
+
mount();
|
|
438
|
+
expect(
|
|
439
|
+
await screen.findByText(
|
|
440
|
+
"Couldn't read storefront.malloy, other.malloy, so their views aren't listed.",
|
|
441
|
+
),
|
|
442
|
+
).toBeDefined();
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
it("lets Create through when another model still offers a view", async () => {
|
|
446
|
+
getModel.mockImplementation((env, pkg, path, versionId) =>
|
|
447
|
+
path === "other.malloy"
|
|
448
|
+
? failing(500)
|
|
449
|
+
: serve(env, pkg, path, versionId),
|
|
450
|
+
);
|
|
451
|
+
mount();
|
|
452
|
+
await titleFilled("by category");
|
|
453
|
+
expect(
|
|
454
|
+
await screen.findByText(
|
|
455
|
+
"Couldn't read other.malloy, so its views aren't listed.",
|
|
456
|
+
),
|
|
457
|
+
).toBeDefined();
|
|
458
|
+
expect(isDisabled(createButton("Create dashboard"))).toBe(false);
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
for (const [status, retry] of [
|
|
462
|
+
[401, false],
|
|
463
|
+
[403, false],
|
|
464
|
+
[404, false],
|
|
465
|
+
[500, true],
|
|
466
|
+
[503, true],
|
|
467
|
+
[undefined, true],
|
|
468
|
+
] as const)
|
|
469
|
+
it(`${retry ? "offers" : "offers no"} Retry after ${status ?? "no response"}`, async () => {
|
|
470
|
+
getModel.mockImplementation(() => failing(status));
|
|
471
|
+
mount({ models: ["storefront.malloy"] });
|
|
472
|
+
await screen.findByText(/Couldn't read storefront\.malloy/);
|
|
473
|
+
expect(screen.queryByRole("button", { name: "Retry" }) !== null).toBe(
|
|
474
|
+
retry,
|
|
475
|
+
);
|
|
476
|
+
});
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
describe("NewDocumentDialog: why Create is off", () => {
|
|
480
|
+
it("while the views load, in its name and its tooltip", async () => {
|
|
481
|
+
getModel.mockImplementation(() => pending());
|
|
482
|
+
mount();
|
|
483
|
+
const button = createButton("Create dashboard: Loading model views");
|
|
484
|
+
expect(isDisabled(button)).toBe(true);
|
|
485
|
+
fireEvent.mouseOver(button.parentElement!);
|
|
486
|
+
expect((await screen.findByRole("tooltip")).textContent).toBe(
|
|
487
|
+
"Loading model views",
|
|
488
|
+
);
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
it("while the host still lists the models, not that the package has none", () => {
|
|
492
|
+
mount({ models: [], modelsLoading: true });
|
|
493
|
+
expect(screen.queryByText(/This package has no models yet/)).toBeNull();
|
|
494
|
+
expect(
|
|
495
|
+
isDisabled(createButton("Create dashboard: Loading model views")),
|
|
496
|
+
).toBe(true);
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
it("when the host could not list the models, with its Retry", () => {
|
|
500
|
+
const onRetryModels = mock(() => {});
|
|
501
|
+
mount({
|
|
502
|
+
models: [],
|
|
503
|
+
modelsError: Object.assign(new Error("x"), {
|
|
504
|
+
response: { status: 502 },
|
|
505
|
+
}),
|
|
506
|
+
onRetryModels,
|
|
507
|
+
});
|
|
508
|
+
expect(screen.queryByText(/This package has no models yet/)).toBeNull();
|
|
509
|
+
expect(
|
|
510
|
+
screen.getByText(/Couldn't read this package's models/),
|
|
511
|
+
).toBeDefined();
|
|
512
|
+
expect(
|
|
513
|
+
isDisabled(
|
|
514
|
+
createButton(
|
|
515
|
+
"Create dashboard: Couldn't read the model views to start from",
|
|
516
|
+
),
|
|
517
|
+
),
|
|
518
|
+
).toBe(true);
|
|
519
|
+
fireEvent.click(screen.getByRole("button", { name: "Retry" }));
|
|
520
|
+
expect(onRetryModels).toHaveBeenCalledTimes(1);
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
it("offers no Retry for a models listing a retry cannot fix", () => {
|
|
524
|
+
mount({
|
|
525
|
+
models: [],
|
|
526
|
+
modelsError: { status: 403 },
|
|
527
|
+
onRetryModels: () => {},
|
|
528
|
+
});
|
|
529
|
+
expect(
|
|
530
|
+
screen.getByText(/Couldn't read this package's models/),
|
|
531
|
+
).toBeDefined();
|
|
532
|
+
expect(screen.queryByRole("button", { name: "Retry" })).toBeNull();
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
it("when every model failed to read", async () => {
|
|
536
|
+
getModel.mockImplementation(() => failing(500));
|
|
537
|
+
mount();
|
|
538
|
+
await screen.findByText(/Couldn't read storefront\.malloy/);
|
|
539
|
+
expect(
|
|
540
|
+
isDisabled(
|
|
541
|
+
createButton(
|
|
542
|
+
"Create dashboard: Couldn't read the model views to start from",
|
|
543
|
+
),
|
|
544
|
+
),
|
|
545
|
+
).toBe(true);
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
it("when no model has a view", async () => {
|
|
549
|
+
mount({ models: ["other.malloy"] });
|
|
550
|
+
await screen.findByText(/no model in this package declares one yet/);
|
|
551
|
+
expect(
|
|
552
|
+
isDisabled(
|
|
553
|
+
createButton("Create dashboard: No model view to start from yet"),
|
|
554
|
+
),
|
|
555
|
+
).toBe(true);
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
it("not for a blank title, whose problem it shows on press", async () => {
|
|
559
|
+
const write = mock((_path: string, _source: string) => Promise.resolve());
|
|
560
|
+
mount({ target: packageTarget([], write) });
|
|
561
|
+
await titleFilled("by category");
|
|
562
|
+
fireEvent.change(screen.getByLabelText("Dashboard title"), {
|
|
563
|
+
target: { value: " " },
|
|
564
|
+
});
|
|
565
|
+
expect(screen.queryByText("A title cannot be empty.")).toBeNull();
|
|
566
|
+
const button = createButton("Create dashboard");
|
|
567
|
+
expect(isDisabled(button)).toBe(false);
|
|
568
|
+
fireEvent.click(button);
|
|
569
|
+
expect(screen.getByText("A title cannot be empty.")).toBeDefined();
|
|
570
|
+
expect(
|
|
571
|
+
screen.getByLabelText("Dashboard title").getAttribute("aria-invalid"),
|
|
572
|
+
).toBe("true");
|
|
573
|
+
expect(write).not.toHaveBeenCalled();
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
it("not for a title that cannot be written, whose problem shows as it is typed", async () => {
|
|
577
|
+
mount({ kind: "notebook" });
|
|
578
|
+
await titleFilled("by category", "Notebook title");
|
|
579
|
+
fireEvent.change(screen.getByLabelText("Notebook title"), {
|
|
580
|
+
target: { value: "a |## b" },
|
|
581
|
+
});
|
|
582
|
+
expect(screen.getByText(/A title cannot contain `\|##`/)).toBeDefined();
|
|
583
|
+
expect(isDisabled(createButton("Create notebook"))).toBe(false);
|
|
584
|
+
});
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
describe("NewDocumentDialog: the picked view", () => {
|
|
588
|
+
const base = MODELS["storefront.malloy"] as Record<string, unknown>;
|
|
589
|
+
const versions: Record<string, unknown> = {
|
|
590
|
+
reordered: {
|
|
591
|
+
...base,
|
|
592
|
+
sources: [
|
|
593
|
+
{
|
|
594
|
+
name: "order_items",
|
|
595
|
+
views: [{ name: "by_brand" }, { name: "by_category" }],
|
|
596
|
+
},
|
|
597
|
+
],
|
|
598
|
+
},
|
|
599
|
+
dropped: {
|
|
600
|
+
...base,
|
|
601
|
+
sources: [{ name: "order_items", views: [{ name: "by_category" }] }],
|
|
602
|
+
},
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
const reread = (view: ReturnType<typeof mount>, versionId: string) =>
|
|
606
|
+
view.rerender(
|
|
607
|
+
<NewDocumentDialog
|
|
608
|
+
open
|
|
609
|
+
kind="dashboard"
|
|
610
|
+
environmentName="env"
|
|
611
|
+
packageName="pkg"
|
|
612
|
+
versionId={versionId}
|
|
613
|
+
models={["storefront.malloy"]}
|
|
614
|
+
target={packageTarget()}
|
|
615
|
+
onClose={() => {}}
|
|
616
|
+
onCreated={() => {}}
|
|
617
|
+
/>,
|
|
618
|
+
);
|
|
619
|
+
|
|
620
|
+
const firstTile = () => screen.getByRole("combobox", { name: /First tile/ });
|
|
621
|
+
|
|
622
|
+
const pickBrand = async () => {
|
|
623
|
+
await titleFilled("by category");
|
|
624
|
+
fireEvent.mouseDown(firstTile());
|
|
625
|
+
fireEvent.click(
|
|
626
|
+
screen.getByRole("option", { name: "order_items → by_brand" }),
|
|
627
|
+
);
|
|
628
|
+
expect(firstTile().textContent).toBe("order_items → by_brand");
|
|
629
|
+
};
|
|
630
|
+
|
|
631
|
+
beforeEach(() => {
|
|
632
|
+
getModel.mockImplementation((env, pkg, path, versionId) =>
|
|
633
|
+
versionId !== undefined && versions[versionId] !== undefined
|
|
634
|
+
? Promise.resolve({ data: versions[versionId] })
|
|
635
|
+
: serve(env, pkg, path, versionId),
|
|
636
|
+
);
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
it("stays picked when the views are read again in another order", async () => {
|
|
640
|
+
const view = mount({ models: ["storefront.malloy"], versionId: "first" });
|
|
641
|
+
await pickBrand();
|
|
642
|
+
reread(view, "reordered");
|
|
643
|
+
await waitFor(() => expect(getModel).toHaveBeenCalledTimes(2));
|
|
644
|
+
await waitFor(() =>
|
|
645
|
+
expect(firstTile().textContent).toBe("order_items → by_brand"),
|
|
646
|
+
);
|
|
647
|
+
expect(isDisabled(createButton("Create dashboard"))).toBe(false);
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
it("is not swapped for another when it leaves the list", async () => {
|
|
651
|
+
const view = mount({ models: ["storefront.malloy"], versionId: "first" });
|
|
652
|
+
await pickBrand();
|
|
653
|
+
reread(view, "dropped");
|
|
654
|
+
expect(
|
|
655
|
+
await screen.findByText(
|
|
656
|
+
"The view you picked is no longer in this model; pick another.",
|
|
657
|
+
),
|
|
658
|
+
).toBeDefined();
|
|
659
|
+
expect(firstTile().textContent).not.toContain("by_category");
|
|
660
|
+
expect(
|
|
661
|
+
isDisabled(
|
|
662
|
+
createButton("Create dashboard: Pick a view to start from"),
|
|
663
|
+
),
|
|
664
|
+
).toBe(true);
|
|
665
|
+
});
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
describe("NewDocumentDialog: while it creates", () => {
|
|
669
|
+
it("says so, and neither Cancel, Escape nor the backdrop closes it", async () => {
|
|
670
|
+
let finish: () => void = () => {};
|
|
671
|
+
const write = mock(
|
|
672
|
+
(_path: string, _source: string) =>
|
|
673
|
+
new Promise<void>((resolve) => {
|
|
674
|
+
finish = resolve;
|
|
675
|
+
}),
|
|
676
|
+
);
|
|
677
|
+
const onClose = mock(() => {});
|
|
678
|
+
const onCreated = mock((_created: unknown) => {});
|
|
679
|
+
mount({ target: packageTarget([], write), onClose, onCreated });
|
|
680
|
+
await titleFilled("by category");
|
|
681
|
+
fireEvent.click(createButton("Create dashboard"));
|
|
682
|
+
|
|
683
|
+
const creating = await screen.findByRole("button", {
|
|
684
|
+
name: "Creating dashboard…",
|
|
685
|
+
});
|
|
686
|
+
expect(isDisabled(creating)).toBe(true);
|
|
687
|
+
expect(isDisabled(screen.getByRole("button", { name: "Cancel" }))).toBe(
|
|
688
|
+
true,
|
|
689
|
+
);
|
|
690
|
+
fireEvent.keyDown(screen.getByRole("dialog"), { key: "Escape" });
|
|
691
|
+
fireEvent.click(document.querySelector(".MuiBackdrop-root")!);
|
|
692
|
+
expect(onClose).not.toHaveBeenCalled();
|
|
693
|
+
|
|
694
|
+
finish();
|
|
695
|
+
await waitFor(() => expect(onCreated).toHaveBeenCalledTimes(1));
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
it("names the notebook kind while it creates one", async () => {
|
|
699
|
+
mount({ kind: "notebook", target: packageTarget([], () => pending()) });
|
|
700
|
+
await titleFilled("by category", "Notebook title");
|
|
701
|
+
fireEvent.click(createButton("Create notebook"));
|
|
702
|
+
expect(
|
|
703
|
+
await screen.findByRole("button", { name: "Creating notebook…" }),
|
|
704
|
+
).toBeDefined();
|
|
705
|
+
});
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
describe("NewDocumentDialog: what the host decides", () => {
|
|
709
|
+
it("closes from Cancel and from Escape", async () => {
|
|
710
|
+
const onClose = mock(() => {});
|
|
711
|
+
mount({ onClose });
|
|
712
|
+
await titleFilled("by category");
|
|
713
|
+
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
|
|
714
|
+
fireEvent.keyDown(screen.getByRole("dialog"), { key: "Escape" });
|
|
715
|
+
expect(onClose).toHaveBeenCalledTimes(2);
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
it("offers no kind to switch to when allowKindChange is false", async () => {
|
|
719
|
+
mount({ kind: "notebook", allowKindChange: false });
|
|
720
|
+
await titleFilled("by category", "Notebook title");
|
|
721
|
+
expect(screen.queryByRole("combobox", { name: /Type/ })).toBeNull();
|
|
722
|
+
expect(createButton("Create notebook")).toBeDefined();
|
|
723
|
+
});
|
|
724
|
+
|
|
725
|
+
it("says where the host saves it, in the host's words", async () => {
|
|
726
|
+
mount({
|
|
727
|
+
target: {
|
|
728
|
+
route: "storage",
|
|
729
|
+
storage: {} as DocumentStorage,
|
|
730
|
+
workspace: {
|
|
731
|
+
name: "w",
|
|
732
|
+
writeable: true,
|
|
733
|
+
description: "",
|
|
734
|
+
authoritative: true,
|
|
735
|
+
},
|
|
736
|
+
environmentName: "env",
|
|
737
|
+
packageName: "pkg",
|
|
738
|
+
existing: [],
|
|
739
|
+
},
|
|
740
|
+
savedAs: "Saved to your workspace, and opened in the builder.",
|
|
741
|
+
});
|
|
742
|
+
await titleFilled("by category");
|
|
743
|
+
expect(
|
|
744
|
+
screen.getByText(
|
|
745
|
+
"Saved to your workspace, and opened in the builder.",
|
|
746
|
+
),
|
|
747
|
+
).toBeDefined();
|
|
748
|
+
});
|
|
749
|
+
});
|