@bevel-software/platform-core-frontend 0.25.2 → 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/__tests__/ToolPage.test.tsx +53 -0
- 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/components/tool-page/ToolPage.tsx +45 -1
- package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
- package/src/modules/library/services/plugins.api.ts +4 -1
- package/src/modules/library/services/tools.api.ts +27 -0
- 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 +65 -81
- 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 +92 -152
- 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__/ExternalAgentAccessPage.test.tsx +4 -4
- 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 +101 -11
- 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 +26 -14
- 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 +22 -5
- 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/shared/mcp/__tests__/connect-snippets.test.ts +2 -2
- package/src/shared/mcp/connect-snippets.ts +8 -5
- package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
- package/src/modules/onboarding/welcome-state.ts +0 -36
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
5
|
+
import { AppRegistryContext, type AppRegistry } from '../../../core/registry';
|
|
6
|
+
import type { EmbedFileView } from '../services/embed.api';
|
|
7
|
+
import { EMBED_EXPIRED } from '../embed-host';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The HTTP surface, stubbed. The error CLASS is hoisted with the rest: the
|
|
11
|
+
* view tells an expired token from any other failure by `status`, so the
|
|
12
|
+
* class the view does `instanceof` against has to be the one the stub
|
|
13
|
+
* throws — and a `vi.mock` factory is hoisted above every declaration in the
|
|
14
|
+
* file, so a class declared below it would not exist yet.
|
|
15
|
+
*/
|
|
16
|
+
const api = vi.hoisted(() => {
|
|
17
|
+
class FakeEmbedApiError extends Error {
|
|
18
|
+
readonly status: number;
|
|
19
|
+
constructor(status: number, message: string) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = 'EmbedApiError';
|
|
22
|
+
this.status = status;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
EmbedApiError: FakeEmbedApiError,
|
|
27
|
+
loadEmbed: vi.fn(),
|
|
28
|
+
lockEmbed: vi.fn(),
|
|
29
|
+
heartbeatEmbed: vi.fn(),
|
|
30
|
+
cancelEmbed: vi.fn(),
|
|
31
|
+
saveEmbed: vi.fn(),
|
|
32
|
+
proposeEmbed: vi.fn(),
|
|
33
|
+
embedRawUrl: vi.fn(
|
|
34
|
+
(token: string, path?: string) => `/api/embed/raw?token=${token}${path ? `&path=${path}` : ''}`,
|
|
35
|
+
),
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
vi.mock('../services/embed.api', () => api);
|
|
39
|
+
const { EmbedApiError: FakeEmbedApiError } = api;
|
|
40
|
+
|
|
41
|
+
import { EmbedView } from '../components/EmbedView';
|
|
42
|
+
|
|
43
|
+
const KB = 'knowledge-base';
|
|
44
|
+
const PAGE = '# Thing\n\nWhat it is.\n';
|
|
45
|
+
|
|
46
|
+
function view(overrides: Partial<EmbedFileView> = {}): EmbedFileView {
|
|
47
|
+
return {
|
|
48
|
+
nodeName: 'Thing',
|
|
49
|
+
repoRelative: 'Data/Thing.md',
|
|
50
|
+
workspacePath: `${KB}/Data/Thing.md`,
|
|
51
|
+
kbDirName: KB,
|
|
52
|
+
branch: 'main',
|
|
53
|
+
appUrl: 'https://hexis.example/workspace/main/knowledge-base/Data/Thing.md',
|
|
54
|
+
content: PAGE,
|
|
55
|
+
contentIsText: true,
|
|
56
|
+
linked: true,
|
|
57
|
+
canRead: true,
|
|
58
|
+
canWrite: true,
|
|
59
|
+
linkUrl: 'https://hexis.example/embed/link?token=tok',
|
|
60
|
+
...overrides,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const EMPTY_REGISTRY = {
|
|
65
|
+
apps: [],
|
|
66
|
+
panes: [],
|
|
67
|
+
topLevelRoutes: [],
|
|
68
|
+
viewerRoutes: [],
|
|
69
|
+
renderers: [],
|
|
70
|
+
banners: [],
|
|
71
|
+
fileViewerPanels: [],
|
|
72
|
+
adminMenuItems: [],
|
|
73
|
+
explorerItems: [],
|
|
74
|
+
folderMenuItems: [],
|
|
75
|
+
settingsNavItems: [],
|
|
76
|
+
} as unknown as AppRegistry;
|
|
77
|
+
|
|
78
|
+
function mount(registry: AppRegistry = EMPTY_REGISTRY) {
|
|
79
|
+
return render(
|
|
80
|
+
<AppRegistryContext.Provider value={registry}>
|
|
81
|
+
<MemoryRouter>
|
|
82
|
+
<EmbedView />
|
|
83
|
+
</MemoryRouter>
|
|
84
|
+
</AppRegistryContext.Provider>,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
beforeEach(() => {
|
|
89
|
+
for (const fn of Object.values(api)) (fn as { mockReset?: () => void }).mockReset?.();
|
|
90
|
+
api.embedRawUrl.mockImplementation(
|
|
91
|
+
(token: string, path?: string) => `/api/embed/raw?token=${token}${path ? `&path=${path}` : ''}`,
|
|
92
|
+
);
|
|
93
|
+
// The lock is let go on the way out too (unmount), so a test that ends
|
|
94
|
+
// mid-edit sees a cancel it never arranged — answered, like the real call.
|
|
95
|
+
api.cancelEmbed.mockResolvedValue(undefined);
|
|
96
|
+
window.history.replaceState({}, '', '/embed?token=tok');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
afterEach(() => {
|
|
100
|
+
// Unmount BEFORE the mocks are restored: the view lets go of a held lock
|
|
101
|
+
// on its way out, and that call must still meet the stubbed API.
|
|
102
|
+
cleanup();
|
|
103
|
+
vi.restoreAllMocks();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('a view with no usable token', () => {
|
|
107
|
+
/**
|
|
108
|
+
* The one state that shows NO content, ever — and it must be reachable
|
|
109
|
+
* without a request, because a view opened with no token at all has
|
|
110
|
+
* nothing to ask.
|
|
111
|
+
*/
|
|
112
|
+
it('says it expired, asks nothing, and shows no content when the token is absent', async () => {
|
|
113
|
+
window.history.replaceState({}, '', '/embed');
|
|
114
|
+
mount();
|
|
115
|
+
expect(await screen.findByText(EMBED_EXPIRED)).toBeTruthy();
|
|
116
|
+
expect(api.loadEmbed).not.toHaveBeenCalled();
|
|
117
|
+
expect(screen.queryByText(/What it is/)).toBeNull();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('says it expired when the token is rejected, and shows no content', async () => {
|
|
121
|
+
api.loadEmbed.mockRejectedValue(new FakeEmbedApiError(401, 'Invalid or expired embed token'));
|
|
122
|
+
mount();
|
|
123
|
+
expect(await screen.findByText(EMBED_EXPIRED)).toBeTruthy();
|
|
124
|
+
expect(screen.queryByText(/What it is/)).toBeNull();
|
|
125
|
+
// Not the Edit control either: there is no page to edit.
|
|
126
|
+
expect(screen.queryByRole('button', { name: 'Edit' })).toBeNull();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('does NOT claim expiry for a failure that is not about the token', async () => {
|
|
130
|
+
api.loadEmbed.mockRejectedValue(new FakeEmbedApiError(500, 'Something went wrong.'));
|
|
131
|
+
mount();
|
|
132
|
+
expect(await screen.findByRole('alert')).toHaveProperty('textContent', 'Something went wrong.');
|
|
133
|
+
expect(screen.queryByText(EMBED_EXPIRED)).toBeNull();
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
describe('a writer', () => {
|
|
138
|
+
it('sees Edit, and saving writes the page', async () => {
|
|
139
|
+
api.loadEmbed.mockResolvedValue(view());
|
|
140
|
+
api.lockEmbed.mockResolvedValue({ acquired: true });
|
|
141
|
+
api.saveEmbed.mockResolvedValue(undefined);
|
|
142
|
+
mount();
|
|
143
|
+
|
|
144
|
+
const edit = await screen.findByRole('button', { name: 'Edit' });
|
|
145
|
+
expect(screen.queryByRole('button', { name: 'Propose changes' })).toBeNull();
|
|
146
|
+
await userEvent.click(edit);
|
|
147
|
+
|
|
148
|
+
await waitFor(() => expect(api.lockEmbed).toHaveBeenCalledWith('tok'));
|
|
149
|
+
const save = await screen.findByRole('button', { name: 'Save' });
|
|
150
|
+
await userEvent.click(save);
|
|
151
|
+
await waitFor(() => expect(api.saveEmbed).toHaveBeenCalledWith('tok', PAGE));
|
|
152
|
+
// A save goes to the default branch; it is never a proposal.
|
|
153
|
+
expect(api.proposeEmbed).not.toHaveBeenCalled();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('says who holds the lock rather than opening an editor', async () => {
|
|
157
|
+
api.loadEmbed.mockResolvedValue(view());
|
|
158
|
+
api.lockEmbed.mockResolvedValue({ acquired: false, holderName: 'Bob' });
|
|
159
|
+
mount();
|
|
160
|
+
await userEvent.click(await screen.findByRole('button', { name: 'Edit' }));
|
|
161
|
+
expect(await screen.findByRole('alert')).toHaveProperty(
|
|
162
|
+
'textContent',
|
|
163
|
+
'Bob is editing this page — try again shortly.',
|
|
164
|
+
);
|
|
165
|
+
expect(screen.queryByRole('button', { name: 'Save' })).toBeNull();
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Hidden is not closed. The lock is let go while the frame is hidden — and
|
|
170
|
+
* taken AGAIN when it comes back, before Save can mean anything. Somebody
|
|
171
|
+
* who took it meanwhile keeps it, and Save is refused.
|
|
172
|
+
*/
|
|
173
|
+
it('takes the lock again after a tab switch, and refuses Save if someone else took it', async () => {
|
|
174
|
+
api.loadEmbed.mockResolvedValue(view());
|
|
175
|
+
api.lockEmbed.mockResolvedValueOnce({ acquired: true });
|
|
176
|
+
api.cancelEmbed.mockResolvedValue(undefined);
|
|
177
|
+
mount();
|
|
178
|
+
await userEvent.click(await screen.findByRole('button', { name: 'Edit' }));
|
|
179
|
+
await screen.findByRole('button', { name: 'Save' });
|
|
180
|
+
|
|
181
|
+
const setVisibility = (state: 'hidden' | 'visible') => {
|
|
182
|
+
Object.defineProperty(document, 'visibilityState', { configurable: true, value: state });
|
|
183
|
+
document.dispatchEvent(new Event('visibilitychange'));
|
|
184
|
+
};
|
|
185
|
+
setVisibility('hidden');
|
|
186
|
+
await waitFor(() => expect(api.cancelEmbed).toHaveBeenCalledWith('tok'));
|
|
187
|
+
api.lockEmbed.mockResolvedValueOnce({ acquired: false, holderName: 'Bob' });
|
|
188
|
+
setVisibility('visible');
|
|
189
|
+
|
|
190
|
+
await waitFor(() => expect(api.lockEmbed).toHaveBeenCalledTimes(2));
|
|
191
|
+
expect(await screen.findByText(/Bob started editing this page/)).toBeTruthy();
|
|
192
|
+
expect((screen.getByRole('button', { name: 'Save' }) as HTMLButtonElement).disabled).toBe(true);
|
|
193
|
+
expect(api.saveEmbed).not.toHaveBeenCalled();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('keeps Save when the lock is taken back cleanly', async () => {
|
|
197
|
+
api.loadEmbed.mockResolvedValue(view());
|
|
198
|
+
api.lockEmbed.mockResolvedValue({ acquired: true });
|
|
199
|
+
api.cancelEmbed.mockResolvedValue(undefined);
|
|
200
|
+
mount();
|
|
201
|
+
await userEvent.click(await screen.findByRole('button', { name: 'Edit' }));
|
|
202
|
+
Object.defineProperty(document, 'visibilityState', { configurable: true, value: 'hidden' });
|
|
203
|
+
document.dispatchEvent(new Event('visibilitychange'));
|
|
204
|
+
Object.defineProperty(document, 'visibilityState', { configurable: true, value: 'visible' });
|
|
205
|
+
document.dispatchEvent(new Event('visibilitychange'));
|
|
206
|
+
await waitFor(() => expect(api.lockEmbed).toHaveBeenCalledTimes(2));
|
|
207
|
+
expect((screen.getByRole('button', { name: 'Save' }) as HTMLButtonElement).disabled).toBe(false);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Write access withdrawn mid-edit: the heartbeat answers 403. The editor
|
|
212
|
+
* stays open with the draft, Save becomes Send proposal, and the reader is
|
|
213
|
+
* told why — never an editor that quietly stopped saving.
|
|
214
|
+
*/
|
|
215
|
+
/** Heartbeats captured instead of scheduled, so a test can fire one. */
|
|
216
|
+
function captureHeartbeats(): Array<() => void> {
|
|
217
|
+
const ticks: Array<() => void> = [];
|
|
218
|
+
const realSetInterval = window.setInterval.bind(window);
|
|
219
|
+
vi.spyOn(window, 'setInterval').mockImplementation(((fn: () => void, ms?: number) => {
|
|
220
|
+
if (ms === 30_000) {
|
|
221
|
+
ticks.push(fn);
|
|
222
|
+
return 0;
|
|
223
|
+
}
|
|
224
|
+
return realSetInterval(fn, ms);
|
|
225
|
+
}) as typeof window.setInterval);
|
|
226
|
+
return ticks;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const EDITED = '# Thing\n\nWhat it is, edited.\n';
|
|
230
|
+
|
|
231
|
+
async function editThenLoseWrite() {
|
|
232
|
+
const ticks = captureHeartbeats();
|
|
233
|
+
api.loadEmbed.mockResolvedValueOnce(view());
|
|
234
|
+
api.lockEmbed.mockResolvedValue({ acquired: true });
|
|
235
|
+
api.cancelEmbed.mockResolvedValue(undefined);
|
|
236
|
+
api.heartbeatEmbed.mockRejectedValue(new FakeEmbedApiError(403, 'Forbidden'));
|
|
237
|
+
api.proposeEmbed.mockResolvedValue({ url: 'https://hexis.example/change-requests/3' });
|
|
238
|
+
mount();
|
|
239
|
+
await userEvent.click(await screen.findByRole('button', { name: 'Edit' }));
|
|
240
|
+
await screen.findByRole('button', { name: 'Save' });
|
|
241
|
+
// The draft differs from the page, so a reload that dropped it would show.
|
|
242
|
+
fireEvent.change(screen.getByRole('textbox'), { target: { value: EDITED } });
|
|
243
|
+
return ticks;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Write access withdrawn mid-edit: the heartbeat answers 403. The editor
|
|
248
|
+
* stays open with the draft, Save becomes Send proposal, and the reader is
|
|
249
|
+
* told why — never an editor that quietly stopped saving.
|
|
250
|
+
*/
|
|
251
|
+
it('turns Save into Send proposal, keeping the draft, when a heartbeat finds write access withdrawn', async () => {
|
|
252
|
+
const ticks = await editThenLoseWrite();
|
|
253
|
+
api.loadEmbed.mockResolvedValueOnce(view({ canWrite: false }));
|
|
254
|
+
ticks.at(-1)!();
|
|
255
|
+
|
|
256
|
+
expect(await screen.findByText(/You can no longer edit this page directly/)).toBeTruthy();
|
|
257
|
+
// A proposal takes no lock, so the edit lock is released straight away.
|
|
258
|
+
expect(api.cancelEmbed).toHaveBeenCalledWith('tok');
|
|
259
|
+
const send = await screen.findByRole('button', { name: 'Send proposal' });
|
|
260
|
+
expect((screen.getByRole('textbox') as HTMLTextAreaElement).value).toBe(EDITED);
|
|
261
|
+
await userEvent.click(send);
|
|
262
|
+
await waitFor(() => expect(api.proposeEmbed).toHaveBeenCalledWith('tok', EDITED));
|
|
263
|
+
expect(api.saveEmbed).not.toHaveBeenCalled();
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* The same 403 when READ access went too. The no-access screen would strand
|
|
268
|
+
* the draft, so the editor stays on it with nothing sendable, and says why;
|
|
269
|
+
* Discard then lands on what the reader may now see.
|
|
270
|
+
*/
|
|
271
|
+
it('keeps the draft on screen but sends nothing when a heartbeat finds read access withdrawn', async () => {
|
|
272
|
+
const ticks = await editThenLoseWrite();
|
|
273
|
+
api.loadEmbed.mockResolvedValue(view({ canRead: false, canWrite: false }));
|
|
274
|
+
ticks.at(-1)!();
|
|
275
|
+
|
|
276
|
+
expect(await screen.findByText(/You no longer have access to this page/)).toBeTruthy();
|
|
277
|
+
expect((screen.getByRole('textbox') as HTMLTextAreaElement).value).toBe(EDITED);
|
|
278
|
+
expect((screen.getByRole('button', { name: 'Save' }) as HTMLButtonElement).disabled).toBe(true);
|
|
279
|
+
// The lock is let go at once, not left to block other writers until TTL.
|
|
280
|
+
expect(api.cancelEmbed).toHaveBeenCalledWith('tok');
|
|
281
|
+
api.cancelEmbed.mockClear();
|
|
282
|
+
|
|
283
|
+
await userEvent.click(screen.getByRole('button', { name: 'Discard' }));
|
|
284
|
+
// And Discard releases again regardless — a no-op if it is already free.
|
|
285
|
+
await waitFor(() => expect(api.cancelEmbed).toHaveBeenCalledWith('tok'));
|
|
286
|
+
expect(await screen.findByText(/You don.t have access to this page/)).toBeTruthy();
|
|
287
|
+
expect(screen.queryByText(/What it is/)).toBeNull();
|
|
288
|
+
expect(api.saveEmbed).not.toHaveBeenCalled();
|
|
289
|
+
expect(api.proposeEmbed).not.toHaveBeenCalled();
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it('releases the lock on Discard', async () => {
|
|
293
|
+
api.loadEmbed.mockResolvedValue(view());
|
|
294
|
+
api.lockEmbed.mockResolvedValue({ acquired: true });
|
|
295
|
+
api.cancelEmbed.mockResolvedValue(undefined);
|
|
296
|
+
mount();
|
|
297
|
+
await userEvent.click(await screen.findByRole('button', { name: 'Edit' }));
|
|
298
|
+
await userEvent.click(await screen.findByRole('button', { name: 'Discard' }));
|
|
299
|
+
await waitFor(() => expect(api.cancelEmbed).toHaveBeenCalledWith('tok'));
|
|
300
|
+
expect(await screen.findByRole('button', { name: 'Edit' })).toBeTruthy();
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
describe('a viewer without write access', () => {
|
|
305
|
+
/**
|
|
306
|
+
* NOT a "no access" notice where a control should be. The enterprise panel
|
|
307
|
+
* this replaced told such a reader they had no edit access and left them a
|
|
308
|
+
* link out; the rule now is that there is always something they can do.
|
|
309
|
+
*/
|
|
310
|
+
it('sees Propose changes, and never a no-access notice', async () => {
|
|
311
|
+
api.loadEmbed.mockResolvedValue(view({ canWrite: false }));
|
|
312
|
+
mount();
|
|
313
|
+
expect(await screen.findByRole('button', { name: 'Propose changes' })).toBeTruthy();
|
|
314
|
+
expect(screen.queryByRole('button', { name: 'Edit' })).toBeNull();
|
|
315
|
+
expect(screen.queryByText(/don't have edit access/i)).toBeNull();
|
|
316
|
+
expect(screen.queryByText(/no access/i)).toBeNull();
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it('sends the proposal, takes no lock, and points at the change request', async () => {
|
|
320
|
+
api.loadEmbed.mockResolvedValue(view({ canWrite: false }));
|
|
321
|
+
api.proposeEmbed.mockResolvedValue({ branch: 'suggestions/a-1/knowledge', number: 7, url: '/change-requests/7' });
|
|
322
|
+
mount();
|
|
323
|
+
await userEvent.click(await screen.findByRole('button', { name: 'Propose changes' }));
|
|
324
|
+
// No round trip to open the editor: a proposal touches nothing on the
|
|
325
|
+
// default branch, so there is no lock to take.
|
|
326
|
+
expect(api.lockEmbed).not.toHaveBeenCalled();
|
|
327
|
+
await userEvent.click(await screen.findByRole('button', { name: 'Send proposal' }));
|
|
328
|
+
await waitFor(() => expect(api.proposeEmbed).toHaveBeenCalledWith('tok', PAGE));
|
|
329
|
+
expect(await screen.findByText(/sent for approval/i)).toBeTruthy();
|
|
330
|
+
expect(screen.getByRole('link', { name: 'Open the change request' })).toBeTruthy();
|
|
331
|
+
// And nothing landed on the default branch.
|
|
332
|
+
expect(api.saveEmbed).not.toHaveBeenCalled();
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
describe('a viewer who cannot read the page, or is not linked', () => {
|
|
337
|
+
it('is sent to sign in, with no content shown', async () => {
|
|
338
|
+
api.loadEmbed.mockResolvedValue(view({ linked: false, canRead: false, content: '' }));
|
|
339
|
+
mount();
|
|
340
|
+
expect(await screen.findByRole('link', { name: 'Link your account' })).toBeTruthy();
|
|
341
|
+
expect(screen.queryByText(/What it is/)).toBeNull();
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it('is told to ask an owner, with no content shown', async () => {
|
|
345
|
+
api.loadEmbed.mockResolvedValue(view({ canRead: false, canWrite: false, content: '' }));
|
|
346
|
+
mount();
|
|
347
|
+
expect(await screen.findByText(/don't have access to this page/i)).toBeTruthy();
|
|
348
|
+
expect(screen.queryByText(/What it is/)).toBeNull();
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
describe('a file with no editing surface', () => {
|
|
353
|
+
/**
|
|
354
|
+
* An image, a PDF, a workbook: the app's file page offers no write action
|
|
355
|
+
* for these either, because there is no text behind the control. Nothing is
|
|
356
|
+
* implied about access.
|
|
357
|
+
*/
|
|
358
|
+
it.each([
|
|
359
|
+
['an image', 'Shots/x.png', false],
|
|
360
|
+
['a PDF', 'Docs/x.pdf', false],
|
|
361
|
+
['a Word document', 'Docs/x.docx', false],
|
|
362
|
+
])('offers no write action for %s', async (_label, repo, contentIsText) => {
|
|
363
|
+
api.loadEmbed.mockResolvedValue(
|
|
364
|
+
view({ repoRelative: repo, workspacePath: `${KB}/${repo}`, content: '', contentIsText }),
|
|
365
|
+
);
|
|
366
|
+
mount();
|
|
367
|
+
await waitFor(() => expect(api.loadEmbed).toHaveBeenCalled());
|
|
368
|
+
await waitFor(() => expect(screen.queryByText('Thing')).toBeTruthy());
|
|
369
|
+
expect(screen.queryByRole('button', { name: 'Edit' })).toBeNull();
|
|
370
|
+
expect(screen.queryByRole('button', { name: 'Propose changes' })).toBeNull();
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
describe('the renderer', () => {
|
|
375
|
+
/**
|
|
376
|
+
* The page is drawn by the APP's renderer for its type, through the same
|
|
377
|
+
* lookup the file page uses — so a renderer a deployment REGISTERS reaches
|
|
378
|
+
* the embed on the day it is added.
|
|
379
|
+
*/
|
|
380
|
+
it('uses a deployment registered override when there is one', async () => {
|
|
381
|
+
api.loadEmbed.mockResolvedValue(
|
|
382
|
+
view({ repoRelative: 'Pages/Report.html', workspacePath: `${KB}/Pages/Report.html`, content: '<p>hi</p>' }),
|
|
383
|
+
);
|
|
384
|
+
const registry = {
|
|
385
|
+
...EMPTY_REGISTRY,
|
|
386
|
+
renderers: [
|
|
387
|
+
{
|
|
388
|
+
extensions: ['.html', '.htm'],
|
|
389
|
+
Component: () => <div data-testid="enterprise-html">the enterprise renderer</div>,
|
|
390
|
+
},
|
|
391
|
+
],
|
|
392
|
+
} as unknown as AppRegistry;
|
|
393
|
+
mount(registry);
|
|
394
|
+
expect(await screen.findByTestId('enterprise-html')).toBeTruthy();
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
it('falls back to the built-in renderer for the type when nothing is registered', async () => {
|
|
398
|
+
api.loadEmbed.mockResolvedValue(view());
|
|
399
|
+
mount();
|
|
400
|
+
// The markdown renderer's read view renders the heading as a heading.
|
|
401
|
+
expect(await screen.findByRole('heading', { name: 'Thing' })).toBeTruthy();
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* End to end for the link rule: the page the embed mounts must hand EVERY
|
|
406
|
+
* outgoing link to the host, never leave one as an anchor the sandbox will
|
|
407
|
+
* follow in place. An external link reaching the reader as
|
|
408
|
+
* `target="_blank"` is the shape that navigated the frame away on a real
|
|
409
|
+
* boot — `target` is ignored without `allow-popups`.
|
|
410
|
+
*/
|
|
411
|
+
it('gives the app renderer the surface link policy, so no link navigates the frame', async () => {
|
|
412
|
+
api.loadEmbed.mockResolvedValue(
|
|
413
|
+
view({ content: '# Thing\n\n[docs](https://example.test/docs) and [other](Other.md)\n' }),
|
|
414
|
+
);
|
|
415
|
+
mount();
|
|
416
|
+
const external = await screen.findByRole('link', { name: 'docs' });
|
|
417
|
+
const internal = screen.getByRole('link', { name: 'other' });
|
|
418
|
+
expect(external.getAttribute('target')).toBeNull();
|
|
419
|
+
expect(internal.getAttribute('target')).toBeNull();
|
|
420
|
+
|
|
421
|
+
// And a click on either is HANDED OVER: the frame's own navigation is
|
|
422
|
+
// prevented, and the host path is what opens it (standalone, as here,
|
|
423
|
+
// that path is a new tab).
|
|
424
|
+
const open = vi.spyOn(window, 'open').mockReturnValue(null);
|
|
425
|
+
expect(fireEvent.click(external)).toBe(false);
|
|
426
|
+
expect(fireEvent.click(internal)).toBe(false);
|
|
427
|
+
expect(open.mock.calls.map((c) => c[0])).toEqual([
|
|
428
|
+
'https://example.test/docs',
|
|
429
|
+
`${window.location.origin}/workspace/main/${KB}/Data/Other.md`,
|
|
430
|
+
]);
|
|
431
|
+
expect(open.mock.calls.every((c) => c[1] === '_blank')).toBe(true);
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* A picture in a markdown page is fetched under the token from the
|
|
436
|
+
* repository root — the renderer hands the surface a WORKSPACE path, and
|
|
437
|
+
* sent as written the server resolved it beside the page a second time
|
|
438
|
+
* (`Data/knowledge-base/Data/shot.png`), so every image 404'd.
|
|
439
|
+
*/
|
|
440
|
+
it('asks for a picture beside the page by its repository path', async () => {
|
|
441
|
+
api.loadEmbed.mockResolvedValue(view({ content: '# Thing\n\n\n' }));
|
|
442
|
+
mount();
|
|
443
|
+
const img = await screen.findByRole('img', { name: 'shot' });
|
|
444
|
+
expect(img.getAttribute('src')).toBe('/api/embed/raw?token=tok&path=/Data/shot.png');
|
|
445
|
+
expect(api.embedRawUrl).toHaveBeenCalledWith('tok', '/Data/shot.png', expect.anything());
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* A heading's copy-link is the page's canonical address plus the heading.
|
|
450
|
+
* A view opened AT a heading carries that heading in its app address; the
|
|
451
|
+
* canonical address drops it, or every copied link would carry two.
|
|
452
|
+
*/
|
|
453
|
+
it('copies a heading link from the page address without the heading the view opened at', async () => {
|
|
454
|
+
const writeText = vi.fn().mockResolvedValue(undefined);
|
|
455
|
+
// A stub `vi.restoreAllMocks` does not know about: removed by hand, so
|
|
456
|
+
// no later test in this file meets a clipboard this one left behind.
|
|
457
|
+
Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true });
|
|
458
|
+
try {
|
|
459
|
+
api.loadEmbed.mockResolvedValue(
|
|
460
|
+
view({
|
|
461
|
+
appUrl: 'https://hexis.example/workspace/main/knowledge-base/Data/Thing.md#what-it-is',
|
|
462
|
+
heading: 'what-it-is',
|
|
463
|
+
}),
|
|
464
|
+
);
|
|
465
|
+
mount();
|
|
466
|
+
const btn = await screen.findByRole('button', { name: /copy link to this heading/i });
|
|
467
|
+
fireEvent.click(btn);
|
|
468
|
+
expect(writeText).toHaveBeenCalledWith('https://hexis.example/workspace/main/knowledge-base/Data/Thing.md#thing');
|
|
469
|
+
} finally {
|
|
470
|
+
Reflect.deleteProperty(navigator, 'clipboard');
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
});
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { configureEmbed, EMBED_HANDOFF_GLOBAL, readEmbedHandoff, resetEmbedConfig } from '../embed-config';
|
|
3
|
+
import { embedRawUrl, loadEmbed, lockEmbed, saveEmbed } from '../services/embed.api';
|
|
4
|
+
import { openThroughHost, resolveToAppUrl } from '../embed-host';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The embed runs on two surfaces — the SPA's `/embed` page and the MCP App
|
|
8
|
+
* view's sandbox — and `embed-config` is the one place that says which. These
|
|
9
|
+
* tests drive the difference through the modules that read it: the API
|
|
10
|
+
* client, the host bridge, and the handoff the view leaves on the window.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const BASE = 'https://hexis.example';
|
|
14
|
+
const KB = { kbDirName: 'knowledge-base', branch: 'main' };
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
resetEmbedConfig();
|
|
18
|
+
vi.unstubAllGlobals();
|
|
19
|
+
vi.restoreAllMocks();
|
|
20
|
+
delete (window as unknown as Record<string, unknown>)[EMBED_HANDOFF_GLOBAL];
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('unconfigured — the SPA /embed page', () => {
|
|
24
|
+
it('addresses the API relative to the page', () => {
|
|
25
|
+
expect(embedRawUrl('tok', '/Data/a.png')).toBe('/api/embed/raw?token=tok&path=%2FData%2Fa.png');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('builds app addresses on the page own origin', () => {
|
|
29
|
+
expect(resolveToAppUrl('/workspace/main/x', '', null)).toBe(`${window.location.origin}/workspace/main/x`);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('handed the deployment address — the MCP App view', () => {
|
|
34
|
+
it('addresses the read routes on the deployment, still without cookies', async () => {
|
|
35
|
+
configureEmbed({ baseUrl: BASE, token: 'tok' });
|
|
36
|
+
const fetchMock = vi.fn(async () => ({ ok: true, json: async () => ({ nodeName: 'Thing' }) }));
|
|
37
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
38
|
+
await loadEmbed('tok');
|
|
39
|
+
expect(fetchMock).toHaveBeenCalledWith(
|
|
40
|
+
`${BASE}/api/embed/load?token=tok`,
|
|
41
|
+
expect.objectContaining({ credentials: 'omit' }),
|
|
42
|
+
);
|
|
43
|
+
expect(embedRawUrl('tok', '/Data/a.png')).toBe(`${BASE}/api/embed/raw?token=tok&path=%2FData%2Fa.png`);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('addresses the write routes on the deployment, still without cookies', async () => {
|
|
47
|
+
configureEmbed({ baseUrl: BASE, token: 'tok' });
|
|
48
|
+
const fetchMock = vi.fn(async () => ({ ok: true, status: 204, json: async () => ({ acquired: true }) }));
|
|
49
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
50
|
+
await lockEmbed('tok');
|
|
51
|
+
await saveEmbed('tok', '# changed');
|
|
52
|
+
expect(fetchMock).toHaveBeenNthCalledWith(
|
|
53
|
+
1,
|
|
54
|
+
`${BASE}/api/embed/lock`,
|
|
55
|
+
expect.objectContaining({ method: 'POST', credentials: 'omit', body: JSON.stringify({ token: 'tok' }) }),
|
|
56
|
+
);
|
|
57
|
+
expect(fetchMock).toHaveBeenNthCalledWith(
|
|
58
|
+
2,
|
|
59
|
+
`${BASE}/api/embed/save`,
|
|
60
|
+
expect.objectContaining({
|
|
61
|
+
method: 'POST',
|
|
62
|
+
credentials: 'omit',
|
|
63
|
+
body: JSON.stringify({ token: 'tok', content: '# changed' }),
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('keeps a path prefix the deployment is served under', async () => {
|
|
69
|
+
configureEmbed({ baseUrl: `${BASE}/hexis`, token: 'tok' });
|
|
70
|
+
expect(embedRawUrl('tok')).toBe(`${BASE}/hexis/api/embed/raw?token=tok`);
|
|
71
|
+
expect(resolveToAppUrl('/workspace/main/x', '', null)).toBe(`${BASE}/hexis/workspace/main/x`);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('builds app addresses on the deployment, not on the sandbox document', () => {
|
|
75
|
+
configureEmbed({ baseUrl: BASE, token: 'tok' });
|
|
76
|
+
expect(resolveToAppUrl('/workspace/main/x', '', null)).toBe(`${BASE}/workspace/main/x`);
|
|
77
|
+
expect(resolveToAppUrl('Other.md#goal', 'knowledge-base/Data/Thing.md', KB)).toBe(
|
|
78
|
+
`${BASE}/workspace/main/knowledge-base/Data/Other.md#goal`,
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('opens a link through the host, and nowhere else', () => {
|
|
83
|
+
const openLink = vi.fn();
|
|
84
|
+
configureEmbed({ baseUrl: BASE, token: 'tok', openLink });
|
|
85
|
+
const windowOpen = vi.spyOn(window, 'open').mockImplementation(() => null);
|
|
86
|
+
openThroughHost('Other.md', 'knowledge-base/Data/Thing.md', KB);
|
|
87
|
+
expect(openLink).toHaveBeenCalledWith(`${BASE}/workspace/main/knowledge-base/Data/Other.md`);
|
|
88
|
+
expect(windowOpen).not.toHaveBeenCalled();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('refuses to hand the host a destination the link grammar refuses', () => {
|
|
92
|
+
const openLink = vi.fn();
|
|
93
|
+
configureEmbed({ baseUrl: BASE, token: 'tok', openLink });
|
|
94
|
+
openThroughHost('javascript:alert(1)', 'knowledge-base/Data/Thing.md', KB);
|
|
95
|
+
expect(openLink).not.toHaveBeenCalled();
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe('the handoff the view leaves on the window', () => {
|
|
100
|
+
const set = (value: unknown) => {
|
|
101
|
+
(window as unknown as Record<string, unknown>)[EMBED_HANDOFF_GLOBAL] = value;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
it('is absent when the bundle was not loaded by the view', () => {
|
|
105
|
+
expect(readEmbedHandoff()).toBeNull();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('is read with its address kept to origin and path, and the open-link kept', () => {
|
|
109
|
+
const openLink = () => undefined;
|
|
110
|
+
set({ baseUrl: `${BASE}/?x=1#y`, token: 'tok', openLink });
|
|
111
|
+
expect(readEmbedHandoff()).toEqual({ baseUrl: BASE, token: 'tok', openLink });
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('keeps the path prefix a deployment is served under', () => {
|
|
115
|
+
set({ baseUrl: `${BASE}/hexis/`, token: 'tok' });
|
|
116
|
+
expect(readEmbedHandoff()).toEqual({ baseUrl: `${BASE}/hexis`, token: 'tok' });
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it.each([
|
|
120
|
+
['no token', { baseUrl: BASE, token: '' }],
|
|
121
|
+
['a non-http address', { baseUrl: 'javascript:alert(1)', token: 'tok' }],
|
|
122
|
+
['a relative address', { baseUrl: '/api', token: 'tok' }],
|
|
123
|
+
['not an object', 'https://hexis.example'],
|
|
124
|
+
])('is refused with %s', (_label, value) => {
|
|
125
|
+
set(value);
|
|
126
|
+
expect(readEmbedHandoff()).toBeNull();
|
|
127
|
+
});
|
|
128
|
+
});
|