@bevel-software/platform-core-frontend 0.32.0 → 0.34.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 +1 -1
- package/src/lib/__tests__/api.test.ts +28 -1
- package/src/lib/api.ts +4 -2
- package/src/modules/access/__tests__/ManageAccessDialog.add-row-picking.test.tsx +53 -1
- package/src/modules/access/api.ts +4 -5
- package/src/modules/access/components/ManageAccessDialog.tsx +11 -12
- package/src/modules/access/hooks/useAccessRequests.ts +1 -1
- package/src/modules/access/hooks/useFileAccess.ts +1 -1
- package/src/modules/access/index.ts +11 -0
- package/src/modules/access/requests.api.ts +1 -1
- package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +51 -0
- package/src/modules/admin/components/AddMemberInput.tsx +1 -1
- package/src/modules/admin/components/DirectoryGroupsPage.tsx +42 -5
- package/src/modules/admin/components/UserAccountsPage.tsx +3 -3
- package/src/modules/admin/index.ts +7 -0
- package/src/modules/admin/services/groups.api.ts +11 -1
- package/src/modules/admin/state/admin.context.tsx +1 -1
- package/src/modules/agents/__tests__/useConnectAsChoice.test.ts +56 -0
- package/src/modules/agents/components/ConnectAsChoice.tsx +81 -0
- package/src/modules/agents/connect-as.ts +15 -0
- package/src/modules/agents/index.ts +5 -0
- package/src/modules/agents/services/agent-choices.api.ts +39 -0
- package/src/modules/agents/useConnectAsChoice.ts +66 -0
- package/src/modules/audit/__tests__/AuditLogPage.test.tsx +13 -0
- package/src/modules/audit/components/AuditEventsPanel.tsx +1 -1
- package/src/modules/audit/components/AuditLogPage.tsx +11 -2
- package/src/modules/audit/services/audit.api.ts +5 -0
- package/src/modules/auth/__tests__/AccountPage.test.tsx +21 -0
- package/src/modules/auth/__tests__/account.api.test.ts +69 -0
- package/src/modules/auth/components/AccountPage.tsx +8 -2
- package/src/modules/auth/index.ts +12 -0
- package/src/modules/auth/services/account.api.ts +18 -2
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.access-rules.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.binary.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.edit.test.tsx +166 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.initial-file.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.moved.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +0 -2
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +0 -1
- package/src/modules/change-requests/components/BranchFilePreview.tsx +4 -12
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +138 -30
- package/src/modules/change-requests/components/ChangeRequestLink.tsx +2 -3
- package/src/modules/change-requests/components/CrFileTree.tsx +1 -1
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +2 -3
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +3 -5
- package/src/modules/change-requests/hooks/useCrFileDiffs.ts +1 -1
- package/src/modules/change-requests/index.ts +14 -0
- package/src/modules/change-requests/services/change-requests.api.ts +2 -2
- package/src/modules/change-requests/services/denied-file.api.ts +2 -2
- package/src/modules/change-requests/services/propose.api.ts +3 -4
- package/src/modules/change-requests/utils/diff.ts +1 -1
- package/src/modules/change-requests/utils/readFailure.ts +1 -1
- package/src/modules/embed/__tests__/EmbedView.test.tsx +19 -2
- package/src/modules/embed/components/EmbedLinkPage.tsx +1 -2
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +0 -14
- package/src/modules/git/__tests__/git.api.test.ts +2 -2
- package/src/modules/git/components/BranchSwitcher.tsx +3 -4
- package/src/modules/git/components/FileHistoryPanel.tsx +2 -2
- package/src/modules/git/components/GitSyncFailedBanner.tsx +2 -4
- package/src/modules/git/components/HistoryVersionPreview.tsx +4 -15
- package/src/modules/git/components/PullNeededBanner.tsx +1 -1
- package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +1 -1
- package/src/modules/git/hooks/useAutoPullUpdates.ts +1 -1
- package/src/modules/git/index.ts +11 -0
- package/src/modules/layout/components/MobileChatLayout.tsx +1 -1
- package/src/modules/layout/index.ts +9 -0
- package/src/modules/library/__tests__/SkillPage.test.tsx +268 -24
- package/src/modules/library/__tests__/propose-change.test.ts +75 -0
- package/src/modules/library/components/AddToPluginDialog.tsx +1 -1
- package/src/modules/library/components/ChangeRequestDock.tsx +1 -1
- package/src/modules/library/components/LibraryLayout.tsx +2 -2
- package/src/modules/library/components/LibraryPage.tsx +3 -3
- package/src/modules/library/components/ManagedPluginRequests.tsx +1 -1
- package/src/modules/library/components/NewSkillPanel.tsx +2 -2
- package/src/modules/library/components/PersonalAddDialog.tsx +1 -1
- package/src/modules/library/components/PersonalPluginPage.tsx +1 -1
- package/src/modules/library/components/PluginExtras.tsx +1 -4
- package/src/modules/library/components/PluginPage.tsx +1 -1
- package/src/modules/library/components/PluginRows.tsx +1 -1
- package/src/modules/library/components/SkillsTree.tsx +1 -4
- package/src/modules/library/components/plugin-page-parts.tsx +1 -1
- package/src/modules/library/components/skill-page/SkillFilePane.tsx +74 -14
- package/src/modules/library/components/skill-page/SkillPage.tsx +80 -47
- package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +2 -4
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +2 -2
- package/src/modules/library/hooks/useJoinRequests.ts +1 -1
- package/src/modules/library/hooks/useLibraryData.ts +3 -3
- package/src/modules/library/hooks/useToolPage.ts +1 -1
- package/src/modules/library/hooks/useToolSource.ts +1 -1
- package/src/modules/library/index.ts +12 -0
- package/src/modules/library/routes/LibraryRoutes.tsx +1 -1
- package/src/modules/library/routes/WorkspaceItemRoute.tsx +1 -3
- package/src/modules/library/routes/library-paths.ts +1 -1
- package/src/modules/library/services/library.api.ts +10 -8
- package/src/modules/library/services/plugins.api.ts +1 -1
- package/src/modules/library/services/teams.api.ts +1 -1
- package/src/modules/library/utils/status.ts +2 -2
- package/src/modules/onboarding/components/ConnectAgentPill.tsx +1 -1
- package/src/modules/onboarding/components/CreatorWelcomePage.tsx +2 -3
- package/src/modules/onboarding/components/GetStartedColumn.tsx +6 -13
- package/src/modules/onboarding/components/InviteButton.tsx +2 -2
- package/src/modules/onboarding/components/InviteDialog.tsx +4 -6
- package/src/modules/onboarding/components/RootLanding.tsx +2 -2
- package/src/modules/onboarding/components/StarterPackCard.tsx +1 -1
- package/src/modules/onboarding/components/WelcomePage.tsx +2 -5
- package/src/modules/onboarding/index.ts +10 -0
- package/src/modules/onboarding/paths.ts +1 -1
- package/src/modules/onboarding/state/agent-connection.ts +2 -2
- package/src/modules/onboarding/state/onboarding.ts +1 -1
- package/src/modules/onboarding/state/starter-packs.ts +1 -1
- package/src/modules/pr/components/OpenChangeRequestDialog.tsx +1 -1
- package/src/modules/pr/index.ts +14 -0
- package/src/modules/pr/services/pr-approvals.api.ts +1 -1
- package/src/modules/pr/services/pr-cancel.api.ts +1 -1
- package/src/modules/pr/services/pr-detail.api.ts +2 -2
- package/src/modules/pr/services/pr-edit.api.ts +22 -0
- package/src/modules/pr/services/pr-merge.api.ts +1 -1
- package/src/modules/pr/services/pr-open.api.ts +1 -1
- package/src/modules/review/components/DiffViewer.tsx +1 -1
- package/src/modules/review/components/MarkdownDiffViewer.tsx +24 -3
- package/src/modules/review/components/ReviewPanel.tsx +10 -5
- package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +31 -0
- package/src/modules/review/state/ReviewProvider.tsx +2 -2
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +79 -16
- package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +112 -2
- package/src/modules/secrets-vault/index.ts +6 -0
- package/src/modules/secrets-vault/services/connect.api.ts +20 -5
- package/src/modules/settings/components/DeploymentPage.tsx +2 -2
- package/src/modules/settings/components/SettingsLayout.tsx +2 -2
- package/src/modules/settings/index.ts +8 -0
- package/src/modules/setup/components/FirstRunStorage.tsx +1 -1
- package/src/modules/setup/index.ts +6 -0
- package/src/modules/toolbar/commands/actions.tsx +3 -3
- package/src/modules/toolbar/commands/useCommandActions.ts +5 -9
- package/src/modules/toolbar/components/AgentInstructionsCard.tsx +2 -2
- package/src/modules/toolbar/components/AppSwitcher.tsx +1 -2
- package/src/modules/toolbar/components/CoworkSetupSteps.tsx +1 -1
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +39 -5
- package/src/modules/toolbar/components/ProfileMenu.tsx +3 -3
- package/src/modules/toolbar/components/SearchPalette.tsx +4 -8
- package/src/modules/toolbar/components/Toolbar.tsx +2 -5
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +91 -2
- package/src/modules/toolbar/index.ts +6 -0
- package/src/modules/toolbar/search/sources.ts +4 -7
- package/src/modules/toolbar/services/agent-instructions.api.ts +1 -1
- package/src/modules/toolbar/services/external-api-keys.api.ts +5 -2
- package/src/modules/tools/ToolsExplorerPage.tsx +217 -18
- package/src/modules/tools/__tests__/ToolsExplorerPage.read-only.test.tsx +220 -0
- package/src/modules/tools/tool-hints.api.ts +44 -0
- package/src/modules/workflow/index.ts +7 -0
- package/src/modules/workflow/state/ChangeRequestStaleBinder.tsx +1 -0
- package/src/modules/workflow/state/EventBusFocusBinder.tsx +1 -1
- package/src/modules/workspace/components/FileExplorer.tsx +35 -8
- package/src/modules/workspace/components/FilePaneCard.tsx +37 -12
- package/src/modules/workspace/components/FileRoute.tsx +10 -3
- package/src/modules/workspace/components/FileViewer.tsx +169 -25
- package/src/modules/workspace/components/FullScreenView.tsx +93 -0
- package/src/modules/workspace/components/KbFileRail.tsx +1 -1
- package/src/modules/workspace/components/KbPageHeader.tsx +9 -0
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +163 -0
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +11 -0
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +487 -3
- package/src/modules/workspace/components/readingCarry.ts +59 -0
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +74 -180
- package/src/modules/workspace/components/renderers/KbAppLink.tsx +56 -0
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +30 -10
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +37 -40
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +1 -1
- package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.links.test.tsx +185 -0
- package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.tools.test.tsx +168 -42
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.sectionReclick.test.tsx +88 -0
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +199 -29
- package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +57 -7
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +122 -4
- package/src/modules/workspace/components/renderers/__tests__/htmlToolBridge.test.ts +235 -1
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +29 -4
- package/src/modules/workspace/components/renderers/__tests__/liveDataReferencePage.test.ts +397 -0
- package/src/modules/workspace/components/renderers/__tests__/pageToolsHarness.ts +79 -0
- package/src/modules/workspace/components/renderers/__tests__/useHtmlToolBridge.test.tsx +316 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +123 -28
- package/src/modules/workspace/components/renderers/htmlToolBridge.ts +215 -25
- package/src/modules/workspace/components/renderers/index.ts +10 -0
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +35 -28
- package/src/modules/workspace/components/renderers/scrollToHeading.ts +35 -0
- package/src/modules/workspace/components/renderers/useHtmlToolBridge.tsx +253 -0
- package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +6 -0
- package/src/modules/workspace/hooks/useFullScreenView.ts +52 -0
- package/src/modules/workspace/hooks/useImageRevision.ts +1 -1
- package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +1 -1
- package/src/modules/workspace/hooks/useLastCommit.ts +1 -1
- package/src/modules/workspace/hooks/useLinksOut.ts +12 -6
- package/src/modules/workspace/hooks/useWorkspaceState.ts +4 -4
- package/src/modules/workspace/index.ts +50 -2
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +262 -25
- package/src/modules/workspace/routing/kb-routes.ts +222 -54
- package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +0 -1
- package/src/modules/workspace/state/open-change-requests.tsx +1 -1
- package/src/modules/workspace/utils/fileTree.ts +1 -1
- package/src/modules/workspace/utils/frameEscape.ts +15 -0
- package/src/modules/workspace/utils/treeConfirm.ts +1 -1
- package/src/shared/theme/measure.ts +7 -0
- package/src/modules/pr/services/pr-comments.api.ts +0 -45
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect, vi } from 'vitest';
|
|
2
2
|
import { render, screen, waitFor, fireEvent } from '@testing-library/react';
|
|
3
3
|
import userEvent from '@testing-library/user-event';
|
|
4
|
-
import { MemoryRouter } from 'react-router-dom';
|
|
4
|
+
import { MemoryRouter, useLocation } from 'react-router-dom';
|
|
5
5
|
import { WorkspaceContext, type WorkspaceContextValue } from '../../../state/workspace.context';
|
|
6
6
|
import { makeWorkspaceFixture } from '../../../__tests__/testFixtures';
|
|
7
7
|
import { GitContext, type GitContextValue } from '../../../../git/state/git.context';
|
|
@@ -16,6 +16,17 @@ vi.mock('react-router-dom', async (importActual) => ({
|
|
|
16
16
|
useNavigate: () => navigateMock,
|
|
17
17
|
}));
|
|
18
18
|
|
|
19
|
+
/** The router's location, as text — what a link inside the file must not change. */
|
|
20
|
+
function LocationProbe() {
|
|
21
|
+
const location = useLocation();
|
|
22
|
+
return <output data-testid="location">{location.pathname + location.search + location.hash}</output>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** `window.open` answering with a tab, as a browser does when it opens one. */
|
|
26
|
+
function stubWindowOpen() {
|
|
27
|
+
return vi.spyOn(window, 'open').mockImplementation(() => ({ opener: window }) as unknown as Window);
|
|
28
|
+
}
|
|
29
|
+
|
|
19
30
|
function makeGit(): GitContextValue {
|
|
20
31
|
return {
|
|
21
32
|
status: { branch: 'alice/draft', hasUpstream: true, unmergedFromUpstream: false },
|
|
@@ -195,71 +206,230 @@ describe('MarkdownRenderer', () => {
|
|
|
195
206
|
|
|
196
207
|
// --- Link rendering in preview (readOnly) mode ---
|
|
197
208
|
|
|
198
|
-
|
|
209
|
+
// `at` is the address this tab is on — a file page, or the same page in
|
|
210
|
+
// full screen. The probe shows the router's location, which a link inside
|
|
211
|
+
// the file must leave as it was.
|
|
212
|
+
function renderPreview(content: string, filePath: string, at = `/workspace/alice%2Fdraft/${filePath}`) {
|
|
199
213
|
return render(
|
|
200
|
-
<MemoryRouter>
|
|
214
|
+
<MemoryRouter initialEntries={[at]}>
|
|
201
215
|
<WorkspaceContext.Provider value={makeWorkspace()}>
|
|
202
216
|
<GitContext.Provider value={makeGit()}>
|
|
203
217
|
<MarkdownRenderer content={content} filePath={filePath} onSave={async () => {}} readOnly />
|
|
218
|
+
<LocationProbe />
|
|
204
219
|
</GitContext.Provider>
|
|
205
220
|
</WorkspaceContext.Provider>
|
|
206
221
|
</MemoryRouter>,
|
|
207
222
|
);
|
|
208
223
|
}
|
|
209
224
|
|
|
210
|
-
|
|
225
|
+
/**
|
|
226
|
+
* A link inside the file opened `url` in a new tab, and this tab went
|
|
227
|
+
* nowhere. The anchor names the same address with `target="_blank"`, so a
|
|
228
|
+
* middle-click or the context menu opens what the click opened.
|
|
229
|
+
*/
|
|
230
|
+
async function expectOpensInNewTab(name: string, url: string) {
|
|
211
231
|
navigateMock.mockClear();
|
|
212
|
-
const
|
|
232
|
+
const open = stubWindowOpen();
|
|
233
|
+
const before = screen.getByTestId('location').textContent;
|
|
234
|
+
const link = screen.getByRole('link', { name });
|
|
235
|
+
expect(link).toHaveAttribute('href', url);
|
|
236
|
+
expect(link).toHaveAttribute('target', '_blank');
|
|
237
|
+
expect(link).toHaveAttribute('rel', 'noopener');
|
|
238
|
+
await userEvent.setup().click(link);
|
|
239
|
+
expect(open).toHaveBeenCalledWith(url, '_blank');
|
|
240
|
+
expect(navigateMock).not.toHaveBeenCalled();
|
|
241
|
+
expect(screen.getByTestId('location').textContent).toBe(before);
|
|
242
|
+
open.mockRestore();
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
it('opens a nodeType frontmatter link in a new tab', async () => {
|
|
213
246
|
renderPreview(
|
|
214
247
|
'---\nnodeType: "[Process](../NodeTypes/Process.md)"\n---\n\n# Body',
|
|
215
248
|
'Knowledge/Sub/Foo.md',
|
|
216
249
|
);
|
|
217
|
-
|
|
218
|
-
await user.click(link);
|
|
219
|
-
expect(navigateMock).toHaveBeenCalledWith('/workspace/alice%2Fdraft/Knowledge/NodeTypes/Process.md');
|
|
250
|
+
await expectOpensInNewTab('Process', '/workspace/alice%2Fdraft/Knowledge/NodeTypes/Process.md');
|
|
220
251
|
});
|
|
221
252
|
|
|
222
|
-
it('
|
|
223
|
-
navigateMock.mockClear();
|
|
224
|
-
const user = userEvent.setup();
|
|
253
|
+
it('opens a bare body link whose path contains spaces in a new tab', async () => {
|
|
225
254
|
renderPreview('[Open](Some File.md)', 'Knowledge/Foo.md');
|
|
226
|
-
|
|
227
|
-
await user.click(link);
|
|
228
|
-
expect(navigateMock).toHaveBeenCalledWith('/workspace/alice%2Fdraft/Knowledge/Some%20File.md');
|
|
255
|
+
await expectOpensInNewTab('Open', '/workspace/alice%2Fdraft/Knowledge/Some%20File.md');
|
|
229
256
|
});
|
|
230
257
|
|
|
231
|
-
it('
|
|
232
|
-
navigateMock.mockClear();
|
|
233
|
-
const user = userEvent.setup();
|
|
258
|
+
it('opens an angle-bracketed body link with spaces in a new tab', async () => {
|
|
234
259
|
renderPreview('[Open](<Some File.md>)', 'Knowledge/Foo.md');
|
|
235
|
-
|
|
236
|
-
await user.click(link);
|
|
237
|
-
expect(navigateMock).toHaveBeenCalledWith('/workspace/alice%2Fdraft/Knowledge/Some%20File.md');
|
|
260
|
+
await expectOpensInNewTab('Open', '/workspace/alice%2Fdraft/Knowledge/Some%20File.md');
|
|
238
261
|
});
|
|
239
262
|
|
|
240
263
|
// The link a paste wraps a Copy path in: root-anchored, so it opens the same
|
|
241
264
|
// file however deep the linking page sits.
|
|
242
265
|
it('opens a pasted root-anchored link from a file in a different folder', async () => {
|
|
243
|
-
navigateMock.mockClear();
|
|
244
|
-
const user = userEvent.setup();
|
|
245
266
|
renderPreview(
|
|
246
267
|
'[subfile](</knowledge-base/KnowledgeBase/File Type examples/subfile.md>)',
|
|
247
268
|
'knowledge-base/KnowledgeBase/Other/Deep/parent.md',
|
|
248
269
|
);
|
|
249
|
-
await
|
|
250
|
-
|
|
270
|
+
await expectOpensInNewTab(
|
|
271
|
+
'subfile',
|
|
251
272
|
'/workspace/alice%2Fdraft/knowledge-base/KnowledgeBase/File%20Type%20examples/subfile.md',
|
|
252
273
|
);
|
|
253
274
|
});
|
|
254
275
|
|
|
255
276
|
it('keeps the branch of an absolute citation URL instead of resolving it against the file', async () => {
|
|
256
|
-
navigateMock.mockClear();
|
|
257
|
-
const user = userEvent.setup();
|
|
258
277
|
renderPreview('[Cited](/workspace/target-company-state/knowledge-base/GTM/Bundle.md#status)', 'Knowledge/Foo.md');
|
|
259
|
-
await
|
|
260
|
-
|
|
261
|
-
|
|
278
|
+
await expectOpensInNewTab('Cited', '/workspace/target-company-state/knowledge-base/GTM/Bundle.md#status');
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
// Once the hook resolves targets, a workspace link that is not a `.md` is
|
|
282
|
+
// the app's too: left to the browser it was a relative URL that replaced
|
|
283
|
+
// the page being read.
|
|
284
|
+
it('opens a link to an HTML page of the workspace in a new tab', async () => {
|
|
285
|
+
renderPreview('[Board](../Dashboards/Board.html)', 'Knowledge/Foo.md');
|
|
286
|
+
await expectOpensInNewTab('Board', '/workspace/alice%2Fdraft/Dashboards/Board.html');
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
// A scheme is what makes a link external, not a name that starts `http`:
|
|
290
|
+
// judged by prefix, this page of the workspace was left to the browser as a
|
|
291
|
+
// relative URL that replaced the page being read.
|
|
292
|
+
it('opens a relative link to a file whose name starts with http in a new tab', async () => {
|
|
293
|
+
renderPreview('[Notes](http-notes.md)', 'Knowledge/Foo.md');
|
|
294
|
+
await expectOpensInNewTab('Notes', '/workspace/alice%2Fdraft/Knowledge/http-notes.md');
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it('opens an id-link in a new tab at the node URL, heading kept', async () => {
|
|
298
|
+
renderPreview('[Plan](plan-node#goal)', 'Knowledge/Foo.md');
|
|
299
|
+
await expectOpensInNewTab('Plan', '/workspace/alice%2Fdraft/plan-node#goal');
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
// Full screen is this tab's view, asked for by its query. The new tab gets
|
|
303
|
+
// the target's plain address, and this one keeps `?fullscreen=1`.
|
|
304
|
+
it('in full screen, opens the plain address in a new tab and stays full screen', async () => {
|
|
305
|
+
renderPreview('[Open](Other.md)', 'Knowledge/Foo.md', '/workspace/alice%2Fdraft/Knowledge/Foo.md?fullscreen=1');
|
|
306
|
+
expect(screen.getByTestId('location')).toHaveTextContent('?fullscreen=1');
|
|
307
|
+
await expectOpensInNewTab('Open', '/workspace/alice%2Fdraft/Knowledge/Other.md');
|
|
308
|
+
expect(screen.getByTestId('location')).toHaveTextContent('?fullscreen=1');
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it('in full screen, opens an id-link in a new tab at the plain node URL', async () => {
|
|
312
|
+
renderPreview('[Plan](plan-node)', 'Knowledge/Foo.md', '/workspace/alice%2Fdraft/foo-node?fullscreen=1');
|
|
313
|
+
await expectOpensInNewTab('Plan', '/workspace/alice%2Fdraft/plan-node');
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// A section link is the browser's: a plain fragment anchor, no new tab.
|
|
317
|
+
it('leaves a same-file anchor to scroll in place', async () => {
|
|
318
|
+
renderPreview('[Goal](#goal)', 'Knowledge/Foo.md');
|
|
319
|
+
const open = stubWindowOpen();
|
|
320
|
+
const link = screen.getByRole('link', { name: 'Goal' });
|
|
321
|
+
expect(link).toHaveAttribute('href', '#goal');
|
|
322
|
+
expect(link).not.toHaveAttribute('target');
|
|
323
|
+
await userEvent.setup().click(link);
|
|
324
|
+
expect(open).not.toHaveBeenCalled();
|
|
325
|
+
open.mockRestore();
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// The same section written as a path to this file: this tab moves by its
|
|
329
|
+
// fragment only, on its own address and query — full screen stays.
|
|
330
|
+
it('scrolls a link to a section of this file in place, keeping the address and query', async () => {
|
|
331
|
+
navigateMock.mockClear();
|
|
332
|
+
renderPreview('[Goal](Foo.md#goal)', 'Knowledge/Foo.md', '/workspace/alice%2Fdraft/foo-node?fullscreen=1');
|
|
333
|
+
const open = stubWindowOpen();
|
|
334
|
+
const link = screen.getByRole('link', { name: 'Goal' });
|
|
335
|
+
expect(link).toHaveAttribute('href', '/workspace/alice%2Fdraft/foo-node?fullscreen=1#goal');
|
|
336
|
+
expect(link).not.toHaveAttribute('target');
|
|
337
|
+
await userEvent.setup().click(link);
|
|
338
|
+
expect(navigateMock).toHaveBeenCalledWith('/workspace/alice%2Fdraft/foo-node?fullscreen=1#goal');
|
|
339
|
+
expect(open).not.toHaveBeenCalled();
|
|
340
|
+
open.mockRestore();
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
// ...and on that address the page scrolls the heading the fragment names
|
|
344
|
+
// into view: the other half of "a section link scrolls in place".
|
|
345
|
+
it('scrolls the heading a section address names into view, in full screen too', async () => {
|
|
346
|
+
const original = Element.prototype.scrollIntoView;
|
|
347
|
+
const scrolled: string[] = [];
|
|
348
|
+
Element.prototype.scrollIntoView = function (this: Element) {
|
|
349
|
+
scrolled.push(this.id);
|
|
350
|
+
};
|
|
351
|
+
try {
|
|
352
|
+
renderPreview('# Intro\n\n## Goal\n\nText', 'Knowledge/Foo.md', '/workspace/alice%2Fdraft/foo-node?fullscreen=1#goal');
|
|
353
|
+
await waitFor(() => expect(scrolled).toEqual(['goal']));
|
|
354
|
+
expect(screen.getByTestId('location').textContent).toBe('/workspace/alice%2Fdraft/foo-node?fullscreen=1#goal');
|
|
355
|
+
} finally {
|
|
356
|
+
Element.prototype.scrollIntoView = original;
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
// Ctrl/⌘/Shift-click on a new-tab link is the browser's to answer, as for
|
|
361
|
+
// any `target="_blank"` anchor: the app neither cancels it nor opens a tab.
|
|
362
|
+
it('leaves a modifier-click on a link to the browser', () => {
|
|
363
|
+
renderPreview('[Open](Other.md)', 'Knowledge/Foo.md');
|
|
364
|
+
const open = stubWindowOpen();
|
|
365
|
+
const link = screen.getByRole('link', { name: 'Open' });
|
|
366
|
+
// Read once the app's handlers have all had the click, then cancelled so
|
|
367
|
+
// the test DOM does not go and fetch the link itself.
|
|
368
|
+
const leftToBrowser: boolean[] = [];
|
|
369
|
+
const after = (e: Event) => {
|
|
370
|
+
leftToBrowser.push(!e.defaultPrevented);
|
|
371
|
+
e.preventDefault();
|
|
372
|
+
};
|
|
373
|
+
window.addEventListener('click', after);
|
|
374
|
+
for (const modifier of [{ ctrlKey: true }, { metaKey: true }, { shiftKey: true }]) {
|
|
375
|
+
link.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, ...modifier }));
|
|
376
|
+
}
|
|
377
|
+
window.removeEventListener('click', after);
|
|
378
|
+
expect(leftToBrowser).toEqual([true, true, true]);
|
|
379
|
+
expect(open).not.toHaveBeenCalled();
|
|
380
|
+
open.mockRestore();
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// A section link carries this tab's own address too, so a Ctrl-click or a
|
|
384
|
+
// middle-click on it is the browser's: it opens that section where the
|
|
385
|
+
// reader asked, and this tab does not move.
|
|
386
|
+
it('leaves a modified or middle click on a section link to the browser', () => {
|
|
387
|
+
navigateMock.mockClear();
|
|
388
|
+
renderPreview('[Goal](Foo.md#goal)', 'Knowledge/Foo.md', '/workspace/alice%2Fdraft/foo-node?fullscreen=1');
|
|
389
|
+
const open = stubWindowOpen();
|
|
390
|
+
const link = screen.getByRole('link', { name: 'Goal' });
|
|
391
|
+
const leftToBrowser: boolean[] = [];
|
|
392
|
+
const after = (e: Event) => {
|
|
393
|
+
leftToBrowser.push(!e.defaultPrevented);
|
|
394
|
+
e.preventDefault();
|
|
395
|
+
};
|
|
396
|
+
window.addEventListener('click', after);
|
|
397
|
+
for (const init of [{ ctrlKey: true }, { metaKey: true }, { shiftKey: true }, { button: 1 }]) {
|
|
398
|
+
link.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, ...init }));
|
|
399
|
+
}
|
|
400
|
+
window.removeEventListener('click', after);
|
|
401
|
+
expect(leftToBrowser).toEqual([true, true, true, true]);
|
|
402
|
+
expect(navigateMock).not.toHaveBeenCalled();
|
|
403
|
+
expect(open).not.toHaveBeenCalled();
|
|
404
|
+
open.mockRestore();
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
// The node on screen is known by its id, not read off the address: a tab
|
|
408
|
+
// still on the file's PATH URL (not canonicalized yet, or a library frame
|
|
409
|
+
// that never canonicalizes) keeps an id-link to this node in place.
|
|
410
|
+
it('scrolls an id-link to the node on screen in place while the tab is on its path URL', async () => {
|
|
411
|
+
navigateMock.mockClear();
|
|
412
|
+
const filePath = 'Knowledge/OnPath.md';
|
|
413
|
+
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) =>
|
|
414
|
+
String(input).includes('/resolve-path?')
|
|
415
|
+
? new Response(JSON.stringify({ id: 'on-path-node' }), { status: 200 })
|
|
416
|
+
: new Response('', { status: 404 }),
|
|
262
417
|
);
|
|
418
|
+
try {
|
|
419
|
+
renderPreview('[Goal](on-path-node#goal) [Plan](plan-node)', filePath, `/workspace/alice%2Fdraft/${filePath}?fullscreen=1`);
|
|
420
|
+
const here = `/workspace/alice%2Fdraft/${filePath}?fullscreen=1#goal`;
|
|
421
|
+
await waitFor(() => expect(screen.getByRole('link', { name: 'Goal' })).toHaveAttribute('href', here));
|
|
422
|
+
expect(screen.getByRole('link', { name: 'Goal' })).not.toHaveAttribute('target');
|
|
423
|
+
const open = stubWindowOpen();
|
|
424
|
+
await userEvent.setup().click(screen.getByRole('link', { name: 'Goal' }));
|
|
425
|
+
expect(navigateMock).toHaveBeenCalledWith(here);
|
|
426
|
+
expect(open).not.toHaveBeenCalled();
|
|
427
|
+
open.mockRestore();
|
|
428
|
+
// Another node is still another tab.
|
|
429
|
+
await expectOpensInNewTab('Plan', '/workspace/alice%2Fdraft/plan-node');
|
|
430
|
+
} finally {
|
|
431
|
+
fetchSpy.mockRestore();
|
|
432
|
+
}
|
|
263
433
|
});
|
|
264
434
|
|
|
265
435
|
// --- Images in preview mode ---
|
|
@@ -16,9 +16,22 @@ export interface BridgeRun {
|
|
|
16
16
|
* was cancelled. `alreadyPrevented` is a click a handler of the page's own
|
|
17
17
|
* cancelled before it bubbled up to the bridge. `noAnchor` is a click on
|
|
18
18
|
* something that is not inside an `<a>` at all — a button, a div — which
|
|
19
|
-
* the bridge must leave alone.
|
|
19
|
+
* the bridge must leave alone. `ctrlKey`/`metaKey`/`shiftKey`/`altKey`
|
|
20
|
+
* are the keys held; `button` 1 is the middle button, which a browser
|
|
21
|
+
* dispatches as an `auxclick` (never a `click`), and so does this.
|
|
20
22
|
*/
|
|
21
|
-
click: (
|
|
23
|
+
click: (
|
|
24
|
+
href: string,
|
|
25
|
+
opts?: {
|
|
26
|
+
alreadyPrevented?: boolean;
|
|
27
|
+
noAnchor?: boolean;
|
|
28
|
+
ctrlKey?: boolean;
|
|
29
|
+
metaKey?: boolean;
|
|
30
|
+
shiftKey?: boolean;
|
|
31
|
+
altKey?: boolean;
|
|
32
|
+
button?: number;
|
|
33
|
+
},
|
|
34
|
+
) => { prevented: boolean };
|
|
22
35
|
/** `window.bevel` as the page's own scripts see it. */
|
|
23
36
|
bevel: Record<string, unknown>;
|
|
24
37
|
/** Messages posted to the parent. */
|
|
@@ -35,6 +48,14 @@ export interface BridgeRun {
|
|
|
35
48
|
* Answers once the frame's handlers and the promises they settle have run.
|
|
36
49
|
*/
|
|
37
50
|
deliver: (data: unknown, opts?: { fromParent?: boolean }) => Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Press `key` with focus inside the frame, as it reaches the window.
|
|
53
|
+
* `alreadyPrevented` is one a handler of the page's cancelled before the
|
|
54
|
+
* bridge's; `preventedAfter` one a handler the page added later cancelled
|
|
55
|
+
* after it, in the same dispatch. Answers once the dispatch is over and the
|
|
56
|
+
* task the bridge leaves behind has run.
|
|
57
|
+
*/
|
|
58
|
+
press: (key: string, opts?: { alreadyPrevented?: boolean; preventedAfter?: boolean }) => Promise<void>;
|
|
38
59
|
}
|
|
39
60
|
|
|
40
61
|
/**
|
|
@@ -44,15 +65,26 @@ export interface BridgeRun {
|
|
|
44
65
|
*/
|
|
45
66
|
export function runBridge(
|
|
46
67
|
page: { ids?: string[]; names?: string[]; namedControls?: string[] } = {},
|
|
47
|
-
opts: { toolBridge?: boolean } = {},
|
|
68
|
+
opts: { toolBridge?: boolean | { documentId: string; tools?: boolean } } = {},
|
|
48
69
|
): BridgeRun {
|
|
49
70
|
// No lib sources: a vm script cannot parse an `export`. The bridge is
|
|
50
71
|
// appended after the lib either way.
|
|
51
72
|
const out = buildSandboxedHtml({ title: 't', libModuleSources: [], bodyHtml: '', toolBridge: opts.toolBridge });
|
|
52
73
|
const scriptBody = out.match(/<script type="module">([\s\S]*?)<\/script>/)![1];
|
|
53
74
|
|
|
54
|
-
type ClickEvent = {
|
|
75
|
+
type ClickEvent = {
|
|
76
|
+
type: string;
|
|
77
|
+
button: number;
|
|
78
|
+
ctrlKey: boolean;
|
|
79
|
+
metaKey: boolean;
|
|
80
|
+
shiftKey: boolean;
|
|
81
|
+
altKey: boolean;
|
|
82
|
+
target: { closest: () => unknown };
|
|
83
|
+
defaultPrevented: boolean;
|
|
84
|
+
preventDefault: () => void;
|
|
85
|
+
};
|
|
55
86
|
const handlers: ((e: ClickEvent) => void)[] = [];
|
|
87
|
+
const auxHandlers: ((e: ClickEvent) => void)[] = [];
|
|
56
88
|
const posted: unknown[] = [];
|
|
57
89
|
const scrolled: string[] = [];
|
|
58
90
|
const scrolledTags: string[] = [];
|
|
@@ -68,6 +100,7 @@ export function runBridge(
|
|
|
68
100
|
const names = new Set(page.names ?? []);
|
|
69
101
|
const controls = new Set(page.namedControls ?? []);
|
|
70
102
|
const messageHandlers: ((e: { source: unknown; data: unknown }) => void)[] = [];
|
|
103
|
+
const keyHandlers: ((e: { key: string; defaultPrevented: boolean }) => void)[] = [];
|
|
71
104
|
const parent = { postMessage: (msg: unknown) => posted.push(msg) };
|
|
72
105
|
// The frame's request timers, cleared when the test ends: a call a test
|
|
73
106
|
// leaves unanswered must not keep the worker alive for the runtime's
|
|
@@ -79,8 +112,10 @@ export function runBridge(
|
|
|
79
112
|
});
|
|
80
113
|
const ctx: Record<string, unknown> = {
|
|
81
114
|
// The frame's window: the tool bridge listens on it for the parent's answers.
|
|
82
|
-
addEventListener: (type: string, fn: (e:
|
|
83
|
-
|
|
115
|
+
addEventListener: (type: string, fn: (e: never) => void) => {
|
|
116
|
+
// One window, two event shapes: the type names which this listener takes.
|
|
117
|
+
if (type === 'message') messageHandlers.push(fn as (e: { source: unknown; data: unknown }) => void);
|
|
118
|
+
if (type === 'keydown') keyHandlers.push(fn as (e: { key: string; defaultPrevented: boolean }) => void);
|
|
84
119
|
},
|
|
85
120
|
setTimeout: (fn: () => void, ms?: number) => {
|
|
86
121
|
const t = setTimeout(() => {
|
|
@@ -97,6 +132,7 @@ export function runBridge(
|
|
|
97
132
|
document: {
|
|
98
133
|
addEventListener: (type: string, fn: (e: ClickEvent) => void) => {
|
|
99
134
|
if (type === 'click') handlers.push(fn);
|
|
135
|
+
if (type === 'auxclick') auxHandlers.push(fn);
|
|
100
136
|
},
|
|
101
137
|
getElementById: (id: string) => (ids.has(id) ? element(id) : null),
|
|
102
138
|
// In document order a control comes first here, so a fallback that
|
|
@@ -119,7 +155,15 @@ export function runBridge(
|
|
|
119
155
|
click: (href: string, opts = {}) => {
|
|
120
156
|
let prevented = opts.alreadyPrevented ?? false;
|
|
121
157
|
const anchor = opts.noAnchor ? null : { getAttribute: () => href };
|
|
122
|
-
|
|
158
|
+
const button = opts.button ?? 0;
|
|
159
|
+
const type = button === 0 ? 'click' : 'auxclick';
|
|
160
|
+
for (const fn of type === 'click' ? handlers : auxHandlers) fn({
|
|
161
|
+
type,
|
|
162
|
+
button,
|
|
163
|
+
ctrlKey: opts.ctrlKey ?? false,
|
|
164
|
+
metaKey: opts.metaKey ?? false,
|
|
165
|
+
shiftKey: opts.shiftKey ?? false,
|
|
166
|
+
altKey: opts.altKey ?? false,
|
|
123
167
|
target: { closest: () => anchor },
|
|
124
168
|
defaultPrevented: prevented,
|
|
125
169
|
preventDefault: () => (prevented = true),
|
|
@@ -136,5 +180,11 @@ export function runBridge(
|
|
|
136
180
|
for (const fn of messageHandlers) fn({ source, data });
|
|
137
181
|
await new Promise((r) => setTimeout(r, 0));
|
|
138
182
|
},
|
|
183
|
+
press: async (key, pressOpts = {}) => {
|
|
184
|
+
const event = { key, defaultPrevented: pressOpts.alreadyPrevented ?? false };
|
|
185
|
+
for (const fn of keyHandlers) fn(event);
|
|
186
|
+
if (pressOpts.preventedAfter) event.defaultPrevented = true;
|
|
187
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
188
|
+
},
|
|
139
189
|
};
|
|
140
190
|
}
|
|
@@ -424,6 +424,33 @@ describe('buildSandboxedHtml', () => {
|
|
|
424
424
|
expect(out).toContain('jumpTo(href)');
|
|
425
425
|
});
|
|
426
426
|
|
|
427
|
+
// A key pressed inside the frame never reaches the app, so the app's
|
|
428
|
+
// Escape (a card's close, leaving full screen) would go deaf once the
|
|
429
|
+
// reader clicked into the page. The frame hands the parent an Escape the
|
|
430
|
+
// page did not use, and nothing else.
|
|
431
|
+
it('hands the parent an Escape the page left alone, and no other key', async () => {
|
|
432
|
+
const bridge = runBridge();
|
|
433
|
+
await bridge.press('Escape');
|
|
434
|
+
await bridge.press('a');
|
|
435
|
+
await bridge.press('Enter');
|
|
436
|
+
expect(bridge.posted).toEqual([{ type: 'bevel.key', key: 'Escape' }]);
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it('keeps an Escape the page cancelled to the page', async () => {
|
|
440
|
+
const bridge = runBridge();
|
|
441
|
+
await bridge.press('Escape', { alreadyPrevented: true });
|
|
442
|
+
expect(bridge.posted).toEqual([]);
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
// A handler the page adds after the bridge ran comes after the bridge's in
|
|
446
|
+
// the same phase; the page's word on the key is final only once the
|
|
447
|
+
// dispatch is over, so that is when the bridge reads it.
|
|
448
|
+
it('keeps an Escape to the page when a handler of its own cancels it after the bridge\'s', async () => {
|
|
449
|
+
const bridge = runBridge();
|
|
450
|
+
await bridge.press('Escape', { preventedAfter: true });
|
|
451
|
+
expect(bridge.posted).toEqual([]);
|
|
452
|
+
});
|
|
453
|
+
|
|
427
454
|
it('injects no height reporter: the frame tells its parent where a link goes, never how tall it is', () => {
|
|
428
455
|
// The frame's height is the reader's (`frameResizeHandle.ts`), never
|
|
429
456
|
// read off the page: a page laid out in the frame and measured there
|
|
@@ -455,6 +482,51 @@ describe('buildSandboxedHtml', () => {
|
|
|
455
482
|
expect(bridge.scrolled).toEqual(['goal']);
|
|
456
483
|
});
|
|
457
484
|
|
|
485
|
+
/**
|
|
486
|
+
* A click the reader asked a new tab of. The frame's sandbox has no
|
|
487
|
+
* allow-popups, so the browser cannot open one from inside it: the bridge
|
|
488
|
+
* cancels the click and asks the parent, saying so (`newTab: true`), for
|
|
489
|
+
* every destination, a fragment of this page included. A plain click and
|
|
490
|
+
* an Alt click are followed as before.
|
|
491
|
+
*/
|
|
492
|
+
describe('a modified or middle click asks the parent for a new tab', () => {
|
|
493
|
+
it('posts newTab for Ctrl, Cmd, Shift and the middle button, to another file and to a section of this page', () => {
|
|
494
|
+
const bridge = runBridge({ ids: ['totals'] });
|
|
495
|
+
expect(bridge.click('Board.html', { ctrlKey: true })).toEqual({ prevented: true });
|
|
496
|
+
expect(bridge.click('Board.html#q3', { metaKey: true })).toEqual({ prevented: true });
|
|
497
|
+
expect(bridge.click(' https://example.com/docs ', { shiftKey: true })).toEqual({ prevented: true });
|
|
498
|
+
expect(bridge.click('#totals', { button: 1 })).toEqual({ prevented: true });
|
|
499
|
+
expect(bridge.posted).toEqual([
|
|
500
|
+
{ type: 'bevel.navigate', href: 'Board.html', newTab: true },
|
|
501
|
+
{ type: 'bevel.navigate', href: 'Board.html#q3', newTab: true },
|
|
502
|
+
{ type: 'bevel.navigate', href: 'https://example.com/docs', newTab: true },
|
|
503
|
+
{ type: 'bevel.navigate', href: '#totals', newTab: true },
|
|
504
|
+
]);
|
|
505
|
+
// A section asked for in a new tab does not scroll this one.
|
|
506
|
+
expect(bridge.scrolled).toEqual([]);
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
it('follows a plain or an Alt click as before, and leaves the right button alone', () => {
|
|
510
|
+
const bridge = runBridge({ ids: ['totals'] });
|
|
511
|
+
bridge.click('Board.html');
|
|
512
|
+
bridge.click('Board.html', { altKey: true });
|
|
513
|
+
bridge.click('#totals');
|
|
514
|
+
expect(bridge.click('Board.html', { button: 2 })).toEqual({ prevented: false });
|
|
515
|
+
expect(bridge.posted).toEqual([
|
|
516
|
+
{ type: 'bevel.navigate', href: 'Board.html' },
|
|
517
|
+
{ type: 'bevel.navigate', href: 'Board.html' },
|
|
518
|
+
]);
|
|
519
|
+
expect(bridge.scrolled).toEqual(['totals']);
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
it('leaves a modified click the page already cancelled to the page', () => {
|
|
523
|
+
const bridge = runBridge();
|
|
524
|
+
bridge.click('Board.html', { ctrlKey: true, alreadyPrevented: true });
|
|
525
|
+
bridge.click('Board.html', { button: 1, alreadyPrevented: true });
|
|
526
|
+
expect(bridge.posted).toEqual([]);
|
|
527
|
+
});
|
|
528
|
+
});
|
|
529
|
+
|
|
458
530
|
/**
|
|
459
531
|
* A bare fragment is an in-page jump by either route. Left to the browser, a
|
|
460
532
|
* `srcdoc` frame resolves `#totals` against the APP's URL and navigates
|
|
@@ -565,6 +637,20 @@ describe('buildSandboxedHtml', () => {
|
|
|
565
637
|
]);
|
|
566
638
|
expect(bridge.scrolled).toEqual([]);
|
|
567
639
|
});
|
|
640
|
+
|
|
641
|
+
it('a fragment the parent hands back (a link to this page by its own name) scrolls as a bare one does', async () => {
|
|
642
|
+
const bridge = runBridge({ ids: ['q3'] });
|
|
643
|
+
await bridge.deliver({ type: 'bevel.jump', hash: '#q3' });
|
|
644
|
+
expect(bridge.scrolled).toEqual(['q3']);
|
|
645
|
+
expect(bridge.posted).toEqual([]);
|
|
646
|
+
});
|
|
647
|
+
|
|
648
|
+
it('takes a jump from the parent only: a message from anywhere else scrolls nothing', async () => {
|
|
649
|
+
const bridge = runBridge({ ids: ['q3'] });
|
|
650
|
+
await bridge.deliver({ type: 'bevel.jump', hash: '#q3' }, { fromParent: false });
|
|
651
|
+
await bridge.deliver({ type: 'bevel.jump', hash: 'q3' });
|
|
652
|
+
expect(bridge.scrolled).toEqual([]);
|
|
653
|
+
});
|
|
568
654
|
});
|
|
569
655
|
|
|
570
656
|
it('embeds the body HTML verbatim (sanitization happens upstream)', () => {
|
|
@@ -600,25 +686,57 @@ describe('buildSandboxedHtml', () => {
|
|
|
600
686
|
});
|
|
601
687
|
|
|
602
688
|
describe('window.bevel.tools in the frame', () => {
|
|
603
|
-
type Tools = Record<'searchTools' | 'toolsInfo' | 'callTool' | 'callToolChain', (...a: unknown[]) => Promise<unknown>>;
|
|
689
|
+
type Tools = Record<'searchTools' | 'toolsInfo' | 'callTool' | 'callToolChain' | 'uploadFile', (...a: unknown[]) => Promise<unknown>>;
|
|
604
690
|
const toolsOf = (bridge: ReturnType<typeof runBridge>) => bridge.bevel.tools as Tools | null;
|
|
605
691
|
|
|
606
|
-
it('has the
|
|
692
|
+
it('has the five functions where the app answers tools, each posting a call with a request id', async () => {
|
|
607
693
|
const bridge = runBridge({}, { toolBridge: true });
|
|
608
694
|
const tools = toolsOf(bridge)!;
|
|
609
|
-
expect(Object.keys(tools).sort()).toEqual(['callTool', 'callToolChain', 'searchTools', 'toolsInfo']);
|
|
695
|
+
expect(Object.keys(tools).sort()).toEqual(['callTool', 'callToolChain', 'searchTools', 'toolsInfo', 'uploadFile']);
|
|
610
696
|
void tools.searchTools('change request');
|
|
611
697
|
void tools.toolsInfo(['read_file']);
|
|
612
698
|
void tools.callTool('read_file', { body: { path: 'a.md' } });
|
|
613
699
|
void tools.callToolChain('return 1');
|
|
700
|
+
const file = new Blob(['a,b\n']);
|
|
701
|
+
void tools.uploadFile(file, { name: 'Budget.csv', branch: 'main', destination: 'Data', mode: 'overwrite', all: true });
|
|
614
702
|
const posted = bridge.posted as Array<{ type: string; requestId: string; fn: string; args: unknown[] }>;
|
|
615
703
|
expect(posted.map((m) => [m.type, m.fn, m.args])).toEqual([
|
|
616
704
|
['bevel.tool.call', 'searchTools', ['change request']],
|
|
617
705
|
['bevel.tool.call', 'toolsInfo', [['read_file']]],
|
|
618
706
|
['bevel.tool.call', 'callTool', ['read_file', { body: { path: 'a.md' } }]],
|
|
619
707
|
['bevel.tool.call', 'callToolChain', ['return 1']],
|
|
708
|
+
// The file itself, for the parent to clone; of the options, only the four it reads.
|
|
709
|
+
['bevel.tool.call', 'uploadFile', [file, { name: 'Budget.csv', branch: 'main', destination: 'Data', mode: 'overwrite' }]],
|
|
710
|
+
]);
|
|
711
|
+
expect((posted[4]!.args as unknown[])[0]).toBe(file);
|
|
712
|
+
expect(new Set(posted.map((m) => m.requestId)).size).toBe(5);
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
it('stamps every message with the identity the app built the document with, and none without one', async () => {
|
|
716
|
+
// The real runtime, given the identity the app minted for this document:
|
|
717
|
+
// tool calls and requireTools alike carry it, so the app can tell this
|
|
718
|
+
// document's messages from a replaced document's. Built with `true`, the
|
|
719
|
+
// runtime posts no identity; built with `tools: false`, the document has
|
|
720
|
+
// no tools but still asks `requireTools` as itself.
|
|
721
|
+
const named = runBridge({}, { toolBridge: { documentId: 'doc-abc' } });
|
|
722
|
+
void toolsOf(named)!.callTool('read_file', { body: { path: 'a.md' } });
|
|
723
|
+
void (named.bevel.requireTools as () => Promise<boolean>)();
|
|
724
|
+
expect((named.posted as Array<Record<string, unknown>>).map((m) => [m.type, m.documentId])).toEqual([
|
|
725
|
+
['bevel.tool.call', 'doc-abc'],
|
|
726
|
+
['bevel.tools.require', 'doc-abc'],
|
|
727
|
+
]);
|
|
728
|
+
|
|
729
|
+
const anonymous = runBridge({}, { toolBridge: true });
|
|
730
|
+
void toolsOf(anonymous)!.callTool('read_file', {});
|
|
731
|
+
void (anonymous.bevel.requireTools as () => Promise<boolean>)();
|
|
732
|
+
expect((anonymous.posted as Array<Record<string, unknown>>).every((m) => !('documentId' in m))).toBe(true);
|
|
733
|
+
|
|
734
|
+
const toolless = runBridge({}, { toolBridge: { documentId: 'doc-xyz', tools: false } });
|
|
735
|
+
expect(toolsOf(toolless)).toBeNull();
|
|
736
|
+
void (toolless.bevel.requireTools as () => Promise<boolean>)();
|
|
737
|
+
expect((toolless.posted as Array<Record<string, unknown>>).map((m) => [m.type, m.documentId])).toEqual([
|
|
738
|
+
['bevel.tools.require', 'doc-xyz'],
|
|
620
739
|
]);
|
|
621
|
-
expect(new Set(posted.map((m) => m.requestId)).size).toBe(4);
|
|
622
740
|
});
|
|
623
741
|
|
|
624
742
|
it("resolves with the parent's answer and rejects with its error and code, matched by request id", async () => {
|