@bevel-software/platform-core-frontend 0.26.0 → 0.27.0
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/package.json +2 -2
- package/src/core/CoreAppShell.tsx +87 -25
- package/src/core/ProductName.tsx +49 -0
- package/src/core/__tests__/ShellRoutes.test.tsx +22 -0
- package/src/core/__tests__/core-contributions.test.ts +16 -0
- package/src/core/core-contributions.ts +17 -0
- package/src/core/registry.ts +51 -1
- package/src/index.css +23 -5
- package/src/index.ts +5 -0
- package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +1 -1
- package/src/modules/access/components/ManageAccessDialog.tsx +1 -1
- package/src/modules/admin/__tests__/RolesCorruptedBanner.test.tsx +70 -0
- package/src/modules/admin/components/RolesCorruptedBanner.tsx +9 -4
- package/src/modules/auth/components/LoginScreen.tsx +4 -1
- package/src/modules/auth/services/account.api.ts +28 -1
- package/src/modules/auth/services/sso.ts +1 -2
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +176 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +68 -0
- package/src/modules/change-requests/__tests__/ChangeRequestLink.test.tsx +182 -0
- package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +1 -1
- package/src/modules/change-requests/__tests__/readFileOnBranch.test.ts +79 -0
- package/src/modules/change-requests/components/ChangeBox.tsx +6 -1
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +45 -15
- package/src/modules/change-requests/components/ChangeRequestLink.tsx +151 -0
- package/src/modules/change-requests/components/CrFileTree.tsx +2 -1
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +4 -2
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +6 -3
- package/src/modules/change-requests/services/change-requests.api.ts +15 -2
- package/src/modules/change-requests/utils/readFailure.ts +22 -0
- package/src/modules/embed/__tests__/EmbedLinkPage.test.tsx +74 -0
- package/src/modules/embed/__tests__/EmbedView.test.tsx +473 -0
- package/src/modules/embed/__tests__/embed-config.test.ts +128 -0
- package/src/modules/embed/__tests__/embed-host.test.ts +111 -0
- package/src/modules/embed/__tests__/mcp-app-view.test.ts +295 -0
- package/src/modules/embed/__tests__/mount.test.tsx +157 -0
- package/src/modules/embed/components/EmbedLinkPage.tsx +109 -0
- package/src/modules/embed/components/EmbedView.tsx +545 -0
- package/src/modules/embed/embed-config.ts +132 -0
- package/src/modules/embed/embed-host.ts +120 -0
- package/src/modules/embed/mount.tsx +80 -0
- package/src/modules/embed/services/embed-token.ts +22 -0
- package/src/modules/embed/services/embed.api.ts +158 -0
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +202 -4
- package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +59 -1
- package/src/modules/git/__tests__/PullNeededBanner.test.tsx +39 -22
- package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +7 -2
- package/src/modules/git/branch-delete-menu-item.tsx +24 -0
- package/src/modules/git/components/BranchSwitcher.tsx +29 -5
- package/src/modules/git/components/GitSyncFailedBanner.tsx +53 -15
- package/src/modules/git/components/HistoryVersionPreview.tsx +5 -3
- package/src/modules/git/components/PullNeededBanner.tsx +15 -49
- package/src/modules/git/hooks/useAutoPullUpdates.ts +9 -5
- package/src/modules/git/index.ts +15 -0
- package/src/modules/git/services/__tests__/error-messages.test.ts +67 -0
- package/src/modules/git/services/__tests__/pull-failure.test.ts +36 -0
- package/src/modules/git/services/error-messages.ts +58 -1
- package/src/modules/git/services/pull-failure.ts +68 -0
- package/src/modules/git/state/branch-delete-confirm.ts +46 -0
- package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +1 -0
- package/src/modules/layout/__tests__/breakpoints.test.ts +7 -1
- package/src/modules/layout/breakpoints.ts +8 -0
- package/src/modules/library/__tests__/PluginExtras.test.tsx +9 -9
- package/src/modules/library/__tests__/PluginPage.test.tsx +8 -1
- package/src/modules/library/__tests__/SkillsTree.test.tsx +13 -4
- package/src/modules/library/components/LibraryPage.tsx +22 -0
- package/src/modules/library/components/PluginExtras.tsx +23 -6
- package/src/modules/library/components/PluginPage.tsx +6 -1
- package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
- package/src/modules/library/services/plugins.api.ts +4 -1
- package/src/modules/library/state/plugins-revision.ts +28 -0
- package/src/modules/onboarding/__tests__/agent-connection-api.test.ts +55 -0
- package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +87 -82
- package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +109 -0
- package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1001 -0
- package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +392 -0
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +226 -193
- package/src/modules/onboarding/__tests__/starter-pack-card.test.tsx +136 -0
- package/src/modules/onboarding/components/CreatorWelcomePage.tsx +7 -11
- package/src/modules/onboarding/components/EmailChipsInput.tsx +138 -0
- package/src/modules/onboarding/components/GetStartedColumn.tsx +651 -0
- package/src/modules/onboarding/components/InviteButton.tsx +35 -0
- package/src/modules/onboarding/components/InviteDialog.tsx +424 -0
- package/src/modules/onboarding/components/RootLanding.tsx +8 -24
- package/src/modules/onboarding/components/StarterPackCard.tsx +98 -0
- package/src/modules/onboarding/components/WelcomePage.tsx +65 -154
- package/src/modules/onboarding/first-page-prompt.ts +89 -0
- package/src/modules/onboarding/invite-emails.ts +175 -0
- package/src/modules/onboarding/services/agent-connection.api.ts +53 -0
- package/src/modules/onboarding/services/starter-packs.api.ts +83 -0
- package/src/modules/onboarding/state/agent-connection.ts +167 -0
- package/src/modules/onboarding/state/invite-dialog.context.ts +32 -0
- package/src/modules/onboarding/state/invite-dialog.tsx +31 -0
- package/src/modules/onboarding/state/onboarding.ts +133 -59
- package/src/modules/onboarding/state/starter-packs.ts +169 -0
- package/src/modules/settings/settings-nav-items.tsx +8 -3
- package/src/modules/setup/__tests__/setup.first-run-storage.test.tsx +389 -0
- package/src/modules/setup/__tests__/setup.github.test.tsx +5 -5
- package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +1 -1
- package/src/modules/setup/__tests__/setup.repository-change.test.tsx +1 -1
- package/src/modules/setup/__tests__/setup.repository.test.tsx +21 -21
- package/src/modules/setup/__tests__/setup.test.tsx +56 -15
- package/src/modules/setup/__tests__/useConnectionProbe.test.tsx +123 -0
- package/src/modules/setup/components/FirstRunStorage.tsx +560 -0
- package/src/modules/setup/components/SetupGate.tsx +46 -1
- package/src/modules/setup/components/SetupScreen.tsx +81 -84
- package/src/modules/setup/hooks/useConnectionProbe.ts +93 -0
- package/src/modules/setup/services/setup.api.ts +3 -3
- package/src/modules/setup/utils/suggested-branch.ts +27 -0
- package/src/modules/toolbar/commands/__tests__/actions.test.tsx +210 -0
- package/src/modules/toolbar/commands/actions.tsx +324 -0
- package/src/modules/toolbar/commands/command-menu.ts +44 -0
- package/src/modules/toolbar/commands/useCommandActions.ts +69 -0
- package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
- package/src/modules/toolbar/components/AppSwitcher.tsx +106 -22
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
- package/src/modules/toolbar/components/ProfileMenu.tsx +9 -4
- package/src/modules/toolbar/components/SearchPalette.tsx +540 -0
- package/src/modules/toolbar/components/Toolbar.tsx +10 -0
- package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +187 -54
- package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
- package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +832 -0
- package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +57 -2
- package/src/modules/toolbar/search/__tests__/rank.test.ts +93 -0
- package/src/modules/toolbar/search/__tests__/sources.test.ts +131 -0
- package/src/modules/toolbar/search/rank.ts +111 -0
- package/src/modules/toolbar/search/sources.ts +169 -0
- package/src/modules/workflow/hooks/useFileLock.ts +10 -7
- package/src/modules/workflow/services/__tests__/lock.api.test.ts +41 -0
- package/src/modules/workflow/services/lock.api.ts +17 -2
- package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +49 -1
- package/src/modules/workspace/components/EditorTabs.tsx +39 -15
- package/src/modules/workspace/components/FileExplorer.tsx +39 -6
- package/src/modules/workspace/components/FilePaneCard.tsx +6 -2
- package/src/modules/workspace/components/FileRoute.tsx +12 -7
- package/src/modules/workspace/components/FileViewer.tsx +271 -74
- package/src/modules/workspace/components/KbPageHeader.tsx +13 -6
- package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +88 -21
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +92 -4
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +23 -3
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +330 -6
- package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +17 -2
- package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -16
- package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +6 -0
- package/src/modules/workspace/components/renderers/EmailRenderer.tsx +23 -21
- package/src/modules/workspace/components/renderers/ImageRenderer.tsx +13 -29
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +9 -2
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +8 -0
- package/src/modules/workspace/components/renderers/PdfRenderer.tsx +14 -19
- package/src/modules/workspace/components/renderers/PptxRenderer.tsx +11 -17
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +35 -7
- package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -17
- package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.links.test.tsx +73 -0
- package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.scaffold.test.tsx +64 -0
- package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.surface.test.tsx +82 -0
- package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +99 -0
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +129 -35
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +149 -0
- package/src/modules/workspace/components/renderers/__tests__/kbMarkdownLinkPolicy.test.tsx +100 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +76 -20
- package/src/modules/workspace/components/renderers/index.ts +26 -0
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +51 -1
- package/src/modules/workspace/components/renderers/rendererRawRead.ts +53 -0
- package/src/modules/workspace/components/renderers/rendererSurface.ts +109 -0
- package/src/modules/workspace/components/renderers/rendererWorkspace.ts +8 -2
- package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +126 -21
- package/src/modules/workspace/hooks/useCreatePage.ts +116 -0
- package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +24 -7
- package/src/modules/workspace/hooks/useWorkspaceState.ts +42 -8
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +10 -0
- package/src/modules/workspace/routing/__tests__/md-links-parity.test.tsx +113 -0
- package/src/modules/workspace/routing/kb-routes.ts +66 -12
- package/src/modules/workspace/state/editable-page.ts +42 -0
- package/src/modules/workspace/state/workspace.context.ts +13 -4
- package/src/modules/workspace/utils/__tests__/display-file-name.test.ts +60 -0
- package/src/modules/workspace/utils/__tests__/fileTree.test.ts +75 -0
- package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +16 -0
- package/src/modules/workspace/utils/display-file-name.ts +102 -0
- package/src/modules/workspace/utils/fileTree.ts +49 -14
- package/src/modules/workspace/utils/treeConfirm.ts +15 -0
- package/src/shared/__tests__/no-builtin-confirm.test.ts +102 -0
- package/src/shared/components/ConfirmProvider.tsx +156 -0
- package/src/shared/components/Dialog.tsx +7 -0
- package/src/shared/components/__tests__/ConfirmProvider.test.tsx +198 -0
- package/src/shared/components/confirm-context.ts +94 -0
- package/src/shared/components/index.ts +3 -0
- package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
- package/src/modules/onboarding/welcome-state.ts +0 -36
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { kbFileUrl, resolveKbHref } from '../workspace/routing/kb-routes';
|
|
2
|
+
import { isOpenableExternalHref, normalizeHref } from '../../shared/markdown/hrefs';
|
|
3
|
+
import { embedBaseUrl, embedOpenLink } from './embed-config';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* What an expired, missing or rejected embed token shows. One sentence, no
|
|
7
|
+
* content, and the one thing the reader can act on: ask again.
|
|
8
|
+
*
|
|
9
|
+
* Exported because it is the acceptance criterion in words — the tests assert
|
|
10
|
+
* on this exact text, and the view must have no second way to say it.
|
|
11
|
+
*/
|
|
12
|
+
export const EMBED_EXPIRED =
|
|
13
|
+
'This view has expired. Ask the agent to open the page again.';
|
|
14
|
+
|
|
15
|
+
/** The message the embed page sends its host to have a link opened. */
|
|
16
|
+
export const EMBED_OPEN_MESSAGE = 'bevel-embed-open';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The host's origin, from the referrer — used as the explicit `postMessage`
|
|
20
|
+
* target so nothing is broadcast to `'*'` when we know better.
|
|
21
|
+
*
|
|
22
|
+
* Null when the referrer is stripped or blocked, which is the common case in
|
|
23
|
+
* a sandboxed iframe; the relay then falls back to `'*'`. That is acceptable
|
|
24
|
+
* and not a leak: the payload is a URL to open, the host re-validates it
|
|
25
|
+
* before acting, and the alternative is a dead link.
|
|
26
|
+
*/
|
|
27
|
+
function hostOrigin(): string | null {
|
|
28
|
+
try {
|
|
29
|
+
return new URL(document.referrer).origin;
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Open a destination OUT of the embed — always in a new tab, never in this
|
|
37
|
+
* frame.
|
|
38
|
+
*
|
|
39
|
+
* Inside a host's sandbox `window.open` and `target=_blank` are blocked (no
|
|
40
|
+
* `allow-popups`), so the embed asks the host to open it. Running inside the
|
|
41
|
+
* MCP App view's own document, the view lent it the extension's
|
|
42
|
+
* `ui/open-link` (see `embed-config`); framed by an Atlassian panel, it posts
|
|
43
|
+
* to the parent, which answers with Forge's `router.open`. Standalone — a
|
|
44
|
+
* developer opening `/embed?token=…` directly — falls back to `window.open`.
|
|
45
|
+
*
|
|
46
|
+
* `href` is resolved first, against `basePath` (the file the link sits in)
|
|
47
|
+
* and with `kb`'s naming, so a relative knowledge-base link becomes the app's
|
|
48
|
+
* own absolute address rather than a path only the embed could interpret. An
|
|
49
|
+
* external address is handed over as written.
|
|
50
|
+
*
|
|
51
|
+
* The embed NEVER navigates itself: it is one page deep by decision, and a
|
|
52
|
+
* token is minted for one file — navigating would show a page nothing
|
|
53
|
+
* authorised inside a frame the reader has no way back out of.
|
|
54
|
+
*/
|
|
55
|
+
export function openThroughHost(
|
|
56
|
+
href: string,
|
|
57
|
+
basePath: string,
|
|
58
|
+
kb: { kbDirName: string; branch: string } | null,
|
|
59
|
+
): void {
|
|
60
|
+
const url = resolveToAppUrl(href, basePath, kb);
|
|
61
|
+
if (url === null) return;
|
|
62
|
+
const lent = embedOpenLink();
|
|
63
|
+
if (lent) {
|
|
64
|
+
lent(url);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (window.parent !== window) {
|
|
68
|
+
window.parent.postMessage({ type: EMBED_OPEN_MESSAGE, url }, hostOrigin() ?? '*');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
window.open(url, '_blank', 'noopener,noreferrer');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* `href` as an absolute address a host can open: a knowledge-base link
|
|
76
|
+
* becomes this deployment's `/workspace/<branch>/<path>` URL, an external one
|
|
77
|
+
* is passed through, and anything the link grammar refuses is null.
|
|
78
|
+
*
|
|
79
|
+
* Exported for direct testing — the resolution is the part with rules, and
|
|
80
|
+
* `postMessage` is not testable without a host.
|
|
81
|
+
*/
|
|
82
|
+
export function resolveToAppUrl(
|
|
83
|
+
href: string,
|
|
84
|
+
basePath: string,
|
|
85
|
+
kb: { kbDirName: string; branch: string } | null,
|
|
86
|
+
): string | null {
|
|
87
|
+
if (!kb) {
|
|
88
|
+
// An address the embed built itself — the account-link page, a change
|
|
89
|
+
// request, the app's own page — not one read out of a knowledge-base
|
|
90
|
+
// page. A root-relative path is this deployment's; anything absolute
|
|
91
|
+
// still has to pass the scheme allowlist below, for the same reason.
|
|
92
|
+
const url = normalizeHref(href);
|
|
93
|
+
if (url.startsWith('/') && !url.startsWith('//')) return `${embedBaseUrl()}${url}`;
|
|
94
|
+
// A protocol-relative `//host/path` names another origin without saying
|
|
95
|
+
// so; the embed never builds one, so it is refused rather than relayed.
|
|
96
|
+
return !url.startsWith('//') && isOpenableExternalHref(url) ? url : null;
|
|
97
|
+
}
|
|
98
|
+
const target = resolveKbHref(href, { basePath, kbDirName: kb.kbDirName });
|
|
99
|
+
if (target === null) return null;
|
|
100
|
+
/**
|
|
101
|
+
* An external destination goes to the host — but only one from the SCHEME
|
|
102
|
+
* ALLOWLIST, and in its normalised spelling.
|
|
103
|
+
*
|
|
104
|
+
* This is load-bearing rather than belt-and-braces. The embed asks its host
|
|
105
|
+
* to open whatever it hands over, and a host obliges: `javascript:alert(1)`
|
|
106
|
+
* is a destination the link grammar happily calls "external", and relaying
|
|
107
|
+
* it would be asking the host to run it. The app's own link handler
|
|
108
|
+
* (`openExternalHref`) applies exactly this allowlist for exactly this
|
|
109
|
+
* reason; the embed's has to apply it too, because the embed's links come
|
|
110
|
+
* from a knowledge-base page an agent may have written.
|
|
111
|
+
*/
|
|
112
|
+
if (target.kind === 'external') {
|
|
113
|
+
return isOpenableExternalHref(href) ? normalizeHref(href) : null;
|
|
114
|
+
}
|
|
115
|
+
if (target.kind !== 'workspace') return null;
|
|
116
|
+
// A link that named its own branch keeps it; everything else opens on the
|
|
117
|
+
// branch the embed rendered, which is the default branch.
|
|
118
|
+
const branch = target.branch ?? kb.branch;
|
|
119
|
+
return `${embedBaseUrl()}${kbFileUrl(branch, target.path)}${target.hash}`;
|
|
120
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { StrictMode } from 'react';
|
|
2
|
+
import { createRoot, type Root } from 'react-dom/client';
|
|
3
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
4
|
+
import { AppRegistryContext, type AppRegistry } from '../../core/registry';
|
|
5
|
+
import { configureEmbed, resetEmbedConfig, type EmbedHandoff } from './embed-config';
|
|
6
|
+
import { EmbedView } from './components/EmbedView';
|
|
7
|
+
import { ConfirmProvider } from '../../shared/components';
|
|
8
|
+
|
|
9
|
+
export interface MountEmbedOptions extends EmbedHandoff {
|
|
10
|
+
/**
|
|
11
|
+
* The deployment's registry — the same one its `CoreAppShell` is mounted
|
|
12
|
+
* with — so a renderer the deployment registered (the enterprise `.html`
|
|
13
|
+
* renderer) draws the page here exactly as on the file page.
|
|
14
|
+
*/
|
|
15
|
+
registry: AppRegistry;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface EmbedMount {
|
|
19
|
+
/** Take the embed down and hand the runtime back to the page's own answers. */
|
|
20
|
+
unmount(): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The one embed this document holds. The runtime the embed reads (see
|
|
25
|
+
* `embed-config`) is per document, not per root, so there is one mount at a
|
|
26
|
+
* time: a second `mountEmbed` takes the first down before it configures,
|
|
27
|
+
* rather than leaving two views that read one token.
|
|
28
|
+
*/
|
|
29
|
+
let active: EmbedMount | null = null;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Mount the embed OUTSIDE the app: into a document that is not one of the
|
|
33
|
+
* deployment's pages, with the token and the deployment's address handed in
|
|
34
|
+
* rather than read from the page's URL.
|
|
35
|
+
*
|
|
36
|
+
* This is what the MCP App view calls after loading the deployment's embed
|
|
37
|
+
* bundle into the chat host's sandbox. It cannot frame the deployment's
|
|
38
|
+
* `/embed` page there (Claude pins the sandbox's `frame-src` to `'self'`), so
|
|
39
|
+
* the app's renderers run in the sandbox document itself — the same
|
|
40
|
+
* `EmbedView`, under the same registry, with every address prefixed by the
|
|
41
|
+
* deployment's address and every link handed to the host's `ui/open-link`.
|
|
42
|
+
*
|
|
43
|
+
* The router is in memory: the view never navigates, and the sandbox's own
|
|
44
|
+
* address is not one the app's routes should read.
|
|
45
|
+
*/
|
|
46
|
+
export function mountEmbed(root: HTMLElement, options: MountEmbedOptions): EmbedMount {
|
|
47
|
+
active?.unmount();
|
|
48
|
+
configureEmbed({
|
|
49
|
+
baseUrl: options.baseUrl,
|
|
50
|
+
token: options.token,
|
|
51
|
+
openLink: options.openLink ?? null,
|
|
52
|
+
});
|
|
53
|
+
const reactRoot: Root = createRoot(root);
|
|
54
|
+
reactRoot.render(
|
|
55
|
+
<StrictMode>
|
|
56
|
+
<AppRegistryContext.Provider value={options.registry}>
|
|
57
|
+
<MemoryRouter>
|
|
58
|
+
{/* A link in an embedded email still asks before it opens — and a
|
|
59
|
+
host's sandbox may refuse the browser's own dialog outright. */}
|
|
60
|
+
<ConfirmProvider>
|
|
61
|
+
<EmbedView />
|
|
62
|
+
</ConfirmProvider>
|
|
63
|
+
</MemoryRouter>
|
|
64
|
+
</AppRegistryContext.Provider>
|
|
65
|
+
</StrictMode>,
|
|
66
|
+
);
|
|
67
|
+
const mount: EmbedMount = {
|
|
68
|
+
unmount() {
|
|
69
|
+
reactRoot.unmount();
|
|
70
|
+
// Only the mount that owns the runtime gives it back: a handle that
|
|
71
|
+
// was already replaced must not reset what its successor configured.
|
|
72
|
+
if (active === mount) {
|
|
73
|
+
active = null;
|
|
74
|
+
resetEmbedConfig();
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
active = mount;
|
|
79
|
+
return mount;
|
|
80
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The outside account the token names, read from its payload for DISPLAY
|
|
3
|
+
* only — the server verifies the signature when the link is posted, and
|
|
4
|
+
* nothing here trusts what it decodes. Null when the token is not a JWT this
|
|
5
|
+
* page can read.
|
|
6
|
+
*/
|
|
7
|
+
export function outsideAccountOf(token: string): string | null {
|
|
8
|
+
try {
|
|
9
|
+
const payload = token.split('.')[1];
|
|
10
|
+
if (!payload) return null;
|
|
11
|
+
// The payload is UTF-8: `atob` alone would hand an account name with a
|
|
12
|
+
// non-ASCII character to the page as mojibake.
|
|
13
|
+
const bytes = Uint8Array.from(atob(payload.replace(/-/g, '+').replace(/_/g, '/')), (c) => c.charCodeAt(0));
|
|
14
|
+
const claims = JSON.parse(new TextDecoder().decode(bytes)) as { kind?: unknown; sub?: unknown; accountId?: unknown };
|
|
15
|
+
if (claims.kind === 'atlassian' && typeof claims.sub === 'string') return claims.sub;
|
|
16
|
+
// A token from the release before the subject was generalised names the
|
|
17
|
+
// account as `accountId`; the server still accepts it for its lifetime.
|
|
18
|
+
return typeof claims.accountId === 'string' && claims.accountId ? claims.accountId : null;
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { embedApiBase } from '../embed-config';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The embed page's HTTP surface.
|
|
5
|
+
*
|
|
6
|
+
* Deliberately NOT `authFetch`: there is no session here, and there must not
|
|
7
|
+
* be one. The embed page is framed by any host, so a cookie that travelled
|
|
8
|
+
* into that frame would let a hostile page read and write as whoever happened
|
|
9
|
+
* to be signed in. Every call below carries the embed token and nothing else,
|
|
10
|
+
* and every route refuses a request without one.
|
|
11
|
+
*
|
|
12
|
+
* Every token route is addressed through {@link embedApiBase}: relative in
|
|
13
|
+
* the app, and the deployment's origin when the embed runs inside a chat
|
|
14
|
+
* host's sandbox — a different origin, which is why the server answers these
|
|
15
|
+
* routes to any origin (they carry no cookie to protect).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** What the embed page renders, as `GET /api/embed/load` answers it. */
|
|
19
|
+
export interface EmbedFileView {
|
|
20
|
+
nodeName: string;
|
|
21
|
+
repoRelative: string;
|
|
22
|
+
/** Workspace-relative path (`<kbDir>/<repoRelative>`) — what the app's renderers take. */
|
|
23
|
+
workspacePath: string;
|
|
24
|
+
kbDirName: string;
|
|
25
|
+
branch: string;
|
|
26
|
+
/** The file's address in the app, absolute. */
|
|
27
|
+
appUrl: string;
|
|
28
|
+
/** The heading the view should open at, when the agent named one. */
|
|
29
|
+
heading?: string;
|
|
30
|
+
content: string;
|
|
31
|
+
/** False for a file whose renderer fetches its own bytes (an image, a PDF). */
|
|
32
|
+
contentIsText: boolean;
|
|
33
|
+
linked: boolean;
|
|
34
|
+
canRead: boolean;
|
|
35
|
+
canWrite: boolean;
|
|
36
|
+
linkUrl: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface EmbedLockResult {
|
|
40
|
+
acquired: boolean;
|
|
41
|
+
holderName?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface EmbedProposalResult {
|
|
45
|
+
branch: string;
|
|
46
|
+
number?: number;
|
|
47
|
+
url?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A refusal from an embed route, with its status — so the page can tell an
|
|
52
|
+
* expired token (401, show the expired sentence) from a lock somebody else
|
|
53
|
+
* holds (403/409, say who) from a real failure.
|
|
54
|
+
*/
|
|
55
|
+
export class EmbedApiError extends Error {
|
|
56
|
+
readonly status: number;
|
|
57
|
+
constructor(status: number, message: string) {
|
|
58
|
+
super(message);
|
|
59
|
+
this.name = 'EmbedApiError';
|
|
60
|
+
this.status = status;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function failure(res: Response): Promise<EmbedApiError> {
|
|
65
|
+
let message = `HTTP ${res.status}`;
|
|
66
|
+
try {
|
|
67
|
+
const body = (await res.json()) as { error?: unknown } | null;
|
|
68
|
+
if (typeof body?.error === 'string' && body.error) message = body.error;
|
|
69
|
+
} catch {
|
|
70
|
+
/* not JSON — the status is the whole of what we know */
|
|
71
|
+
}
|
|
72
|
+
return new EmbedApiError(res.status, message);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The token-only routes are called WITHOUT the browser's cookies. The server
|
|
77
|
+
* refuses a session on them anyway; omitting it here keeps a same-origin
|
|
78
|
+
* session from riding along at all, so the boundary does not rest on the
|
|
79
|
+
* server alone. (The account-link call below is the one that needs it.)
|
|
80
|
+
*/
|
|
81
|
+
const TOKEN_ONLY: RequestInit = { credentials: 'omit' };
|
|
82
|
+
|
|
83
|
+
async function post(path: string, body: Record<string, unknown>): Promise<Response> {
|
|
84
|
+
const res = await fetch(`${embedApiBase()}${path}`, {
|
|
85
|
+
...TOKEN_ONLY,
|
|
86
|
+
method: 'POST',
|
|
87
|
+
headers: { 'content-type': 'application/json' },
|
|
88
|
+
body: JSON.stringify(body),
|
|
89
|
+
});
|
|
90
|
+
if (!res.ok) throw await failure(res);
|
|
91
|
+
return res;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export async function loadEmbed(token: string): Promise<EmbedFileView> {
|
|
95
|
+
const res = await fetch(`${embedApiBase()}/api/embed/load?token=${encodeURIComponent(token)}`, TOKEN_ONLY);
|
|
96
|
+
if (!res.ok) throw await failure(res);
|
|
97
|
+
return (await res.json()) as EmbedFileView;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The URL that serves a file's bytes under this token — what the app's
|
|
102
|
+
* byte-reading renderers put in an `<img src>` or fetch themselves.
|
|
103
|
+
*
|
|
104
|
+
* `path` is omitted for the embedded file itself and given for one beside it
|
|
105
|
+
* (a picture a markdown page shows): `/<repo-relative>` from the repository
|
|
106
|
+
* root, or a path relative to the embedded file. The server re-checks the
|
|
107
|
+
* viewer's read access on whatever it resolves to.
|
|
108
|
+
*/
|
|
109
|
+
export function embedRawUrl(
|
|
110
|
+
token: string,
|
|
111
|
+
path?: string,
|
|
112
|
+
options: { version?: number } = {},
|
|
113
|
+
): string {
|
|
114
|
+
let url = `${embedApiBase()}/api/embed/raw?token=${encodeURIComponent(token)}`;
|
|
115
|
+
if (path) url += `&path=${encodeURIComponent(path)}`;
|
|
116
|
+
// A cache key, so a replaced picture reaches an open view. Absent or 0 adds
|
|
117
|
+
// nothing, keeping the URL stable and browser-cacheable.
|
|
118
|
+
if (options.version) url += `&v=${options.version}`;
|
|
119
|
+
return url;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export async function lockEmbed(token: string): Promise<EmbedLockResult> {
|
|
123
|
+
const res = await post('/api/embed/lock', { token });
|
|
124
|
+
return (await res.json()) as EmbedLockResult;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export async function heartbeatEmbed(token: string): Promise<void> {
|
|
128
|
+
await post('/api/embed/heartbeat', { token });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export async function cancelEmbed(token: string): Promise<void> {
|
|
132
|
+
await post('/api/embed/cancel', { token });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export async function saveEmbed(token: string, content: string): Promise<void> {
|
|
136
|
+
await post('/api/embed/save', { token, content });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export async function proposeEmbed(token: string, content: string): Promise<EmbedProposalResult> {
|
|
140
|
+
const res = await post('/api/embed/propose', { token, content });
|
|
141
|
+
return (await res.json()) as EmbedProposalResult;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Link the token's outside account to the signed-in user (the link page). */
|
|
145
|
+
export async function linkEmbedAccount(token: string, bearer: string | null): Promise<void> {
|
|
146
|
+
// Addressed like every other embed route, so a deployment served under a
|
|
147
|
+
// path prefix keeps it; the session cookie rides along because this one
|
|
148
|
+
// call acts AS the signed-in user (see the link page).
|
|
149
|
+
const res = await fetch(`${embedApiBase()}/api/embed/link`, {
|
|
150
|
+
method: 'POST',
|
|
151
|
+
headers: {
|
|
152
|
+
'content-type': 'application/json',
|
|
153
|
+
...(bearer ? { Authorization: `Bearer ${bearer}` } : {}),
|
|
154
|
+
},
|
|
155
|
+
body: JSON.stringify({ token }),
|
|
156
|
+
});
|
|
157
|
+
if (!res.ok) throw await failure(res);
|
|
158
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach, type MockInstance } from 'vitest';
|
|
2
|
+
import { render, screen, fireEvent, waitFor, within } from '@testing-library/react';
|
|
3
3
|
import { MemoryRouter } from 'react-router-dom';
|
|
4
4
|
import type {
|
|
5
5
|
BranchInfo,
|
|
@@ -21,6 +21,8 @@ vi.mock('../../access/api', () => ({
|
|
|
21
21
|
import { fetchFileAccess } from '../../access/api';
|
|
22
22
|
|
|
23
23
|
import { BranchSwitcher } from '../components/BranchSwitcher';
|
|
24
|
+
import { ConfirmProvider } from '../../../shared/components';
|
|
25
|
+
import { askBeforeBranchDelete } from '../state/branch-delete-confirm';
|
|
24
26
|
import { GitContext, type GitContextValue } from '../state/git.context';
|
|
25
27
|
import { ReviewContext, type ReviewContextValue } from '../../review/state/review.context';
|
|
26
28
|
import { AuthContext, type AuthContextValue } from '../../auth/state/auth.context';
|
|
@@ -93,10 +95,11 @@ const workspace = {
|
|
|
93
95
|
openFilePath: null,
|
|
94
96
|
} as unknown as WorkspaceContextValue;
|
|
95
97
|
|
|
96
|
-
function renderSwitcher(git: GitContextValue = makeGit()) {
|
|
98
|
+
function renderSwitcher(git: GitContextValue = makeGit(), authValue: AuthContextValue = auth) {
|
|
97
99
|
return render(
|
|
98
100
|
<MemoryRouter>
|
|
99
|
-
<
|
|
101
|
+
<ConfirmProvider>
|
|
102
|
+
<AuthContext.Provider value={authValue}>
|
|
100
103
|
<WorkspaceContext.Provider value={workspace}>
|
|
101
104
|
<GitContext.Provider value={git}>
|
|
102
105
|
<ReviewContext.Provider value={makeReview()}>
|
|
@@ -105,6 +108,7 @@ function renderSwitcher(git: GitContextValue = makeGit()) {
|
|
|
105
108
|
</GitContext.Provider>
|
|
106
109
|
</WorkspaceContext.Provider>
|
|
107
110
|
</AuthContext.Provider>
|
|
111
|
+
</ConfirmProvider>
|
|
108
112
|
</MemoryRouter>,
|
|
109
113
|
);
|
|
110
114
|
}
|
|
@@ -354,3 +358,197 @@ describe('BranchSwitcher: admin-can-delete affordance', () => {
|
|
|
354
358
|
expect(screen.queryByLabelText(/^Delete /)).toBeNull();
|
|
355
359
|
});
|
|
356
360
|
});
|
|
361
|
+
|
|
362
|
+
// Deleting a shared branch asks in the app's OWN dialog. The browser's
|
|
363
|
+
// built-in confirm could be silenced by the browser ("prevent this page from
|
|
364
|
+
// creating additional dialogs"), after which every delete answered "no"
|
|
365
|
+
// without showing anything. "Don't ask again" skips the question, per person,
|
|
366
|
+
// in this browser, until turned back on from the profile menu.
|
|
367
|
+
describe('BranchSwitcher: deleting a shared branch asks in the app', () => {
|
|
368
|
+
const SKIP_KEY = 'hexis.skipBranchDeleteConfirm:alice@example.com';
|
|
369
|
+
const shared = (name: string): BranchInfo => ({
|
|
370
|
+
name,
|
|
371
|
+
isProtected: false,
|
|
372
|
+
ahead: 0,
|
|
373
|
+
behind: 0,
|
|
374
|
+
hasRemote: true,
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
let confirmSpy: MockInstance<Window['confirm']>;
|
|
378
|
+
beforeEach(() => {
|
|
379
|
+
localStorage.clear();
|
|
380
|
+
vi.mocked(fetchFileAccess).mockResolvedValue({
|
|
381
|
+
canRead: true,
|
|
382
|
+
canWrite: false,
|
|
383
|
+
canDownload: false,
|
|
384
|
+
canOwner: false,
|
|
385
|
+
eligible: { roles: [], users: [] },
|
|
386
|
+
readers: { restricted: false, roles: [], users: [] },
|
|
387
|
+
owners: { roles: [], users: [] },
|
|
388
|
+
downloaders: { roles: [], users: [] },
|
|
389
|
+
sources: {},
|
|
390
|
+
});
|
|
391
|
+
// The browser's dialogs suppressed, as in the report: a built-in confirm
|
|
392
|
+
// that answers "no" without asking. It must never be consulted.
|
|
393
|
+
confirmSpy = vi.spyOn(window, 'confirm').mockReturnValue(false);
|
|
394
|
+
});
|
|
395
|
+
afterEach(() => {
|
|
396
|
+
expect(confirmSpy).not.toHaveBeenCalled();
|
|
397
|
+
vi.restoreAllMocks();
|
|
398
|
+
localStorage.clear();
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
function setup(
|
|
402
|
+
branches: BranchInfo[] = [shared('alice/draft-one'), shared('alice/draft-two')],
|
|
403
|
+
deleteBranch = vi.fn(async () => {}),
|
|
404
|
+
authValue: AuthContextValue = auth,
|
|
405
|
+
) {
|
|
406
|
+
const git = makeGit({ status: makeStatus({ branch: 'alice/elsewhere' }), branches, deleteBranch });
|
|
407
|
+
const view = renderSwitcher(git, authValue);
|
|
408
|
+
fireEvent.click(screen.getByTitle('Your active shared draft'));
|
|
409
|
+
return { deleteBranch, view };
|
|
410
|
+
}
|
|
411
|
+
const clickDelete = (name: string) =>
|
|
412
|
+
fireEvent.click(screen.getByLabelText(`Delete shared draft "${name}": removes it for everyone`));
|
|
413
|
+
|
|
414
|
+
it('names the branch, says it goes for everyone, and offers Cancel, Delete and "Don\'t ask again"', async () => {
|
|
415
|
+
setup();
|
|
416
|
+
clickDelete('alice/draft-one');
|
|
417
|
+
const dialog = await screen.findByRole('dialog');
|
|
418
|
+
expect(dialog.textContent).toContain(
|
|
419
|
+
'Delete shared draft "alice/draft-one"? This removes it from the remote for everyone.',
|
|
420
|
+
);
|
|
421
|
+
expect(within(dialog).getByRole('button', { name: 'Cancel' })).toBeInTheDocument();
|
|
422
|
+
expect(within(dialog).getByRole('button', { name: 'Delete' })).toBeInTheDocument();
|
|
423
|
+
expect(within(dialog).getByRole('checkbox', { name: "Don't ask again" })).not.toBeChecked();
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
it('Cancel keeps the branch', async () => {
|
|
427
|
+
const { deleteBranch } = setup();
|
|
428
|
+
clickDelete('alice/draft-one');
|
|
429
|
+
fireEvent.click(within(await screen.findByRole('dialog')).getByRole('button', { name: 'Cancel' }));
|
|
430
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
|
431
|
+
expect(deleteBranch).not.toHaveBeenCalled();
|
|
432
|
+
// The list is still open behind it.
|
|
433
|
+
expect(screen.getByText('alice/draft-one')).toBeInTheDocument();
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
it('Escape and the close button count as Cancel', async () => {
|
|
437
|
+
const { deleteBranch } = setup();
|
|
438
|
+
clickDelete('alice/draft-one');
|
|
439
|
+
await screen.findByRole('dialog');
|
|
440
|
+
fireEvent.keyDown(document, { key: 'Escape' });
|
|
441
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
|
442
|
+
clickDelete('alice/draft-one');
|
|
443
|
+
fireEvent.click(within(await screen.findByRole('dialog')).getByRole('button', { name: 'Close' }));
|
|
444
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
|
445
|
+
expect(deleteBranch).not.toHaveBeenCalled();
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
it('Delete deletes the branch, and the next delete asks again', async () => {
|
|
449
|
+
const { deleteBranch } = setup();
|
|
450
|
+
clickDelete('alice/draft-one');
|
|
451
|
+
fireEvent.click(within(await screen.findByRole('dialog')).getByRole('button', { name: 'Delete' }));
|
|
452
|
+
await waitFor(() => expect(deleteBranch).toHaveBeenCalledWith('alice/draft-one'));
|
|
453
|
+
expect(localStorage.getItem(SKIP_KEY)).toBeNull();
|
|
454
|
+
clickDelete('alice/draft-two');
|
|
455
|
+
expect(await screen.findByRole('dialog')).toBeInTheDocument();
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
it('"Don\'t ask again" deletes, then later deletes go ahead without the dialog, after a reload too', async () => {
|
|
459
|
+
const { deleteBranch, view } = setup();
|
|
460
|
+
clickDelete('alice/draft-one');
|
|
461
|
+
const dialog = await screen.findByRole('dialog');
|
|
462
|
+
fireEvent.click(within(dialog).getByRole('checkbox', { name: "Don't ask again" }));
|
|
463
|
+
fireEvent.click(within(dialog).getByRole('button', { name: 'Delete' }));
|
|
464
|
+
await waitFor(() => expect(deleteBranch).toHaveBeenCalledWith('alice/draft-one'));
|
|
465
|
+
expect(localStorage.getItem(SKIP_KEY)).toBe('1');
|
|
466
|
+
|
|
467
|
+
clickDelete('alice/draft-two');
|
|
468
|
+
await waitFor(() => expect(deleteBranch).toHaveBeenCalledWith('alice/draft-two'));
|
|
469
|
+
expect(screen.queryByRole('dialog')).toBeNull();
|
|
470
|
+
|
|
471
|
+
// A reload: everything remounts; only the browser's storage remains.
|
|
472
|
+
view.unmount();
|
|
473
|
+
const again = setup([shared('alice/draft-three')]);
|
|
474
|
+
clickDelete('alice/draft-three');
|
|
475
|
+
await waitFor(() => expect(again.deleteBranch).toHaveBeenCalledWith('alice/draft-three'));
|
|
476
|
+
expect(screen.queryByRole('dialog')).toBeNull();
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
it('turned back on (what the profile menu does), the next delete asks again', async () => {
|
|
480
|
+
localStorage.setItem(SKIP_KEY, '1');
|
|
481
|
+
const { deleteBranch } = setup();
|
|
482
|
+
clickDelete('alice/draft-one');
|
|
483
|
+
await waitFor(() => expect(deleteBranch).toHaveBeenCalledWith('alice/draft-one'));
|
|
484
|
+
expect(screen.queryByRole('dialog')).toBeNull();
|
|
485
|
+
|
|
486
|
+
askBeforeBranchDelete('Alice@Example.com');
|
|
487
|
+
expect(localStorage.getItem(SKIP_KEY)).toBeNull();
|
|
488
|
+
clickDelete('alice/draft-two');
|
|
489
|
+
fireEvent.click(within(await screen.findByRole('dialog')).getByRole('button', { name: 'Delete' }));
|
|
490
|
+
await waitFor(() => expect(deleteBranch).toHaveBeenCalledWith('alice/draft-two'));
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
it('a "Don\'t ask again" ticked and then cancelled stores nothing', async () => {
|
|
494
|
+
const { deleteBranch } = setup();
|
|
495
|
+
clickDelete('alice/draft-one');
|
|
496
|
+
const dialog = await screen.findByRole('dialog');
|
|
497
|
+
fireEvent.click(within(dialog).getByRole('checkbox', { name: "Don't ask again" }));
|
|
498
|
+
fireEvent.click(within(dialog).getByRole('button', { name: 'Cancel' }));
|
|
499
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
|
500
|
+
expect(deleteBranch).not.toHaveBeenCalled();
|
|
501
|
+
expect(localStorage.getItem(SKIP_KEY)).toBeNull();
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
it('is per person: someone else signing in on the same browser is still asked', async () => {
|
|
505
|
+
localStorage.setItem(SKIP_KEY, '1');
|
|
506
|
+
const bob = {
|
|
507
|
+
...auth,
|
|
508
|
+
user: { id: 'u2', email: 'bob@example.com', name: 'Bob' },
|
|
509
|
+
} as unknown as AuthContextValue;
|
|
510
|
+
const { deleteBranch } = setup([shared('bob/draft')], undefined, bob);
|
|
511
|
+
clickDelete('bob/draft');
|
|
512
|
+
fireEvent.click(within(await screen.findByRole('dialog')).getByRole('button', { name: 'Delete' }));
|
|
513
|
+
await waitFor(() => expect(deleteBranch).toHaveBeenCalledWith('bob/draft'));
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
it('asks every time when the browser cannot store the choice, and a ticked box still deletes', async () => {
|
|
517
|
+
// What a browser in strict privacy mode does: touching storage throws.
|
|
518
|
+
vi.spyOn(window, 'localStorage', 'get').mockImplementation(() => {
|
|
519
|
+
throw new DOMException('The operation is insecure.', 'SecurityError');
|
|
520
|
+
});
|
|
521
|
+
const { deleteBranch } = setup();
|
|
522
|
+
clickDelete('alice/draft-one');
|
|
523
|
+
let dialog = await screen.findByRole('dialog');
|
|
524
|
+
fireEvent.click(within(dialog).getByRole('checkbox', { name: "Don't ask again" }));
|
|
525
|
+
fireEvent.click(within(dialog).getByRole('button', { name: 'Delete' }));
|
|
526
|
+
await waitFor(() => expect(deleteBranch).toHaveBeenCalledWith('alice/draft-one'));
|
|
527
|
+
|
|
528
|
+
clickDelete('alice/draft-two');
|
|
529
|
+
dialog = await screen.findByRole('dialog');
|
|
530
|
+
expect(deleteBranch).toHaveBeenCalledTimes(1);
|
|
531
|
+
fireEvent.click(within(dialog).getByRole('button', { name: 'Delete' }));
|
|
532
|
+
await waitFor(() => expect(deleteBranch).toHaveBeenCalledWith('alice/draft-two'));
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
it('deletes a branch with no shared copy without a question', async () => {
|
|
536
|
+
const { deleteBranch } = setup([{ ...shared('bob/merged'), hasRemote: false }]);
|
|
537
|
+
fireEvent.click(screen.getByLabelText('Delete this draft (no longer shared)'));
|
|
538
|
+
await waitFor(() => expect(deleteBranch).toHaveBeenCalledWith('bob/merged'));
|
|
539
|
+
expect(screen.queryByRole('dialog')).toBeNull();
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
it('shows a failed deletion in the branch list after Delete', async () => {
|
|
543
|
+
const deleteBranch = vi.fn(async () => {
|
|
544
|
+
throw new Error('Could not delete the branch');
|
|
545
|
+
});
|
|
546
|
+
setup(undefined, deleteBranch);
|
|
547
|
+
clickDelete('alice/draft-one');
|
|
548
|
+
fireEvent.click(within(await screen.findByRole('dialog')).getByRole('button', { name: 'Delete' }));
|
|
549
|
+
// The list stayed open through the dialog's clicks, so its error shows.
|
|
550
|
+
const alert = await screen.findByRole('alert');
|
|
551
|
+
expect(alert.textContent).toMatch(/delete/i);
|
|
552
|
+
expect(screen.getByText('alice/draft-one')).toBeInTheDocument();
|
|
553
|
+
});
|
|
554
|
+
});
|