@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,19 +1,36 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach, type MockInstance } from 'vitest';
|
|
2
2
|
import { renderHook } from '@testing-library/react';
|
|
3
3
|
import { GitContext, type GitContextValue } from '../../../git/state/git.context';
|
|
4
4
|
import { WorkspaceContext } from '../../state/workspace.context';
|
|
5
5
|
import { makeWorkspaceFixture } from '../../__tests__/testFixtures';
|
|
6
|
-
import { useFileNav, resolveKbHref } from '../kb-routes';
|
|
6
|
+
import { useFileNav, useNodeIdNav, resolveKbHref } from '../kb-routes';
|
|
7
7
|
|
|
8
8
|
// Capture what openFile navigates to, and stand in for the URL it reads the
|
|
9
9
|
// branch out of.
|
|
10
10
|
const navigateMock = vi.hoisted(() => vi.fn());
|
|
11
|
-
const routerMock = vi.hoisted(() => ({ pathname: '/' }));
|
|
11
|
+
const routerMock = vi.hoisted(() => ({ pathname: '/', search: '' }));
|
|
12
12
|
vi.mock('react-router-dom', () => ({
|
|
13
13
|
useNavigate: () => navigateMock,
|
|
14
|
-
useLocation: () => ({ pathname: routerMock.pathname, search:
|
|
14
|
+
useLocation: () => ({ pathname: routerMock.pathname, search: routerMock.search, hash: '', state: null, key: 'k' }),
|
|
15
15
|
}));
|
|
16
16
|
|
|
17
|
+
// `window.open` answering with a tab, as a browser does when it opens one.
|
|
18
|
+
// A link inside a file opens its target there and never navigates this tab.
|
|
19
|
+
let openMock: MockInstance<typeof window.open>;
|
|
20
|
+
let openedTab: { opener: unknown };
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
navigateMock.mockClear();
|
|
23
|
+
routerMock.search = '';
|
|
24
|
+
openedTab = { opener: window };
|
|
25
|
+
openMock = vi.spyOn(window, 'open').mockImplementation(() => openedTab as unknown as Window);
|
|
26
|
+
});
|
|
27
|
+
afterEach(() => openMock.mockRestore());
|
|
28
|
+
|
|
29
|
+
function expectNewTab(url: string) {
|
|
30
|
+
expect(openMock).toHaveBeenCalledWith(url, '_blank');
|
|
31
|
+
expect(navigateMock).not.toHaveBeenCalled();
|
|
32
|
+
}
|
|
33
|
+
|
|
17
34
|
function gitOnBranch(branch: string): GitContextValue {
|
|
18
35
|
return {
|
|
19
36
|
status: { branch, hasUpstream: true, unmergedFromUpstream: false },
|
|
@@ -42,8 +59,10 @@ function renderNav(
|
|
|
42
59
|
branch: string,
|
|
43
60
|
kbDirName: string | null = 'knowledge-base',
|
|
44
61
|
pathname = '/',
|
|
62
|
+
search = '',
|
|
45
63
|
) {
|
|
46
64
|
routerMock.pathname = pathname;
|
|
65
|
+
routerMock.search = search;
|
|
47
66
|
return renderHook(() => useFileNav(), {
|
|
48
67
|
wrapper: ({ children }) => (
|
|
49
68
|
<GitContext.Provider value={gitOnBranch(branch)}>
|
|
@@ -121,11 +140,12 @@ describe('useFileNav.openFile', () => {
|
|
|
121
140
|
);
|
|
122
141
|
});
|
|
123
142
|
|
|
124
|
-
|
|
125
|
-
|
|
143
|
+
// A page's "Open in the platform", asked for from inside the page: a new
|
|
144
|
+
// tab, which carries no router state, so the ask rides in the address.
|
|
145
|
+
it('opens a page on its FILE PAGE in a new tab, by an address that asks for it', () => {
|
|
126
146
|
const { result } = renderNav('main');
|
|
127
147
|
result.current.openFilePage('knowledge-base/Skills/qa-bridge/view.html');
|
|
128
|
-
|
|
148
|
+
expectNewTab('/workspace/main/knowledge-base/Skills/qa-bridge/view.html?as=file');
|
|
129
149
|
});
|
|
130
150
|
|
|
131
151
|
it('opens a tree path verbatim even when a folder inside it is named like the kbDirName', () => {
|
|
@@ -292,7 +312,7 @@ describe('useFileNav.openLink', () => {
|
|
|
292
312
|
navigateMock.mockClear();
|
|
293
313
|
const { result } = renderNav('alice/draft');
|
|
294
314
|
result.current.openLink('Some%20File.md#goal', 'knowledge-base/Knowledge/Foo.md');
|
|
295
|
-
|
|
315
|
+
expectNewTab(
|
|
296
316
|
'/workspace/alice%2Fdraft/knowledge-base/Knowledge/Some%20File.md#goal',
|
|
297
317
|
);
|
|
298
318
|
});
|
|
@@ -305,7 +325,23 @@ describe('useFileNav.openLink', () => {
|
|
|
305
325
|
'/workspace/target-company-state/knowledge-base/x.md',
|
|
306
326
|
'knowledge-base/Knowledge/Foo.md',
|
|
307
327
|
);
|
|
308
|
-
|
|
328
|
+
expectNewTab('/workspace/target-company-state/knowledge-base/x.md');
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
// A new tab the reader asked for (a modified or middle click a host had to
|
|
332
|
+
// relay): every in-app destination opens in one at its plain address, a
|
|
333
|
+
// section of this file included, and `onSection` does not scroll this tab.
|
|
334
|
+
it('opens every in-app destination in a new tab when the reader asked for one', () => {
|
|
335
|
+
navigateMock.mockClear();
|
|
336
|
+
const { result } = renderNav('alice/draft');
|
|
337
|
+
const onSection = vi.fn();
|
|
338
|
+
result.current.openLink('#goal', 'knowledge-base/Knowledge/Foo.md', { newTab: true, onSection });
|
|
339
|
+
expectNewTab('/workspace/alice%2Fdraft/knowledge-base/Knowledge/Foo.md#goal');
|
|
340
|
+
openMock.mockClear();
|
|
341
|
+
result.current.openLink('Other.md', 'knowledge-base/Knowledge/Foo.md', { newTab: true, homeBranch: 'main', onSection });
|
|
342
|
+
expectNewTab('/workspace/main/knowledge-base/Knowledge/Other.md');
|
|
343
|
+
expect(onSection).not.toHaveBeenCalled();
|
|
344
|
+
expect(navigateMock).not.toHaveBeenCalled();
|
|
309
345
|
});
|
|
310
346
|
|
|
311
347
|
// Every caller reaches `openLink` by CANCELLING the browser's navigation
|
|
@@ -359,7 +395,7 @@ describe('useFileNav.openLink', () => {
|
|
|
359
395
|
navigateMock.mockClear();
|
|
360
396
|
const { result } = renderNav('alice/draft');
|
|
361
397
|
result.current.openLink('Board.html', 'knowledge-base/Dashboards/a.html');
|
|
362
|
-
|
|
398
|
+
expectNewTab(
|
|
363
399
|
'/workspace/alice%2Fdraft/knowledge-base/Dashboards/Board.html',
|
|
364
400
|
);
|
|
365
401
|
});
|
|
@@ -368,7 +404,7 @@ describe('useFileNav.openLink', () => {
|
|
|
368
404
|
navigateMock.mockClear();
|
|
369
405
|
const { result } = renderNav('alice/draft');
|
|
370
406
|
result.current.openLink('../Reports/Q3.html#totals', 'knowledge-base/Dashboards/a.html');
|
|
371
|
-
|
|
407
|
+
expectNewTab(
|
|
372
408
|
'/workspace/alice%2Fdraft/knowledge-base/Reports/Q3.html#totals',
|
|
373
409
|
);
|
|
374
410
|
});
|
|
@@ -381,7 +417,7 @@ describe('useFileNav.openLink', () => {
|
|
|
381
417
|
navigateMock.mockClear();
|
|
382
418
|
const { result } = renderNav('alice/draft');
|
|
383
419
|
result.current.openLink('Missing.html', 'knowledge-base/Dashboards/a.html');
|
|
384
|
-
|
|
420
|
+
expectNewTab(
|
|
385
421
|
'/workspace/alice%2Fdraft/knowledge-base/Dashboards/Missing.html',
|
|
386
422
|
);
|
|
387
423
|
});
|
|
@@ -393,7 +429,7 @@ describe('useFileNav.openLink', () => {
|
|
|
393
429
|
navigateMock.mockClear();
|
|
394
430
|
const { result } = renderNav('alice/draft');
|
|
395
431
|
result.current.openLink('\n Board.html\n ', 'knowledge-base/Dashboards/a.html');
|
|
396
|
-
|
|
432
|
+
expectNewTab(
|
|
397
433
|
'/workspace/alice%2Fdraft/knowledge-base/Dashboards/Board.html',
|
|
398
434
|
);
|
|
399
435
|
});
|
|
@@ -405,18 +441,16 @@ describe('useFileNav.openLink', () => {
|
|
|
405
441
|
' /workspace/bob%2Fmain/knowledge-base/Reports/Q3.html#totals ',
|
|
406
442
|
'knowledge-base/Dashboards/a.html',
|
|
407
443
|
);
|
|
408
|
-
|
|
444
|
+
expectNewTab(
|
|
409
445
|
'/workspace/bob%2Fmain/knowledge-base/Reports/Q3.html#totals',
|
|
410
446
|
);
|
|
411
447
|
});
|
|
412
448
|
|
|
413
449
|
it('keeps a padded same-document anchor on the file it sits in', () => {
|
|
414
|
-
|
|
415
|
-
const { result } = renderNav('alice/draft');
|
|
450
|
+
const { result } = renderNav('alice/draft', 'knowledge-base', '/workspace/alice%2Fdraft/knowledge-base/Dashboards/a.html');
|
|
416
451
|
result.current.openLink(' #goal ', 'knowledge-base/Dashboards/a.html');
|
|
417
|
-
expect(navigateMock).toHaveBeenCalledWith(
|
|
418
|
-
|
|
419
|
-
);
|
|
452
|
+
expect(navigateMock).toHaveBeenCalledWith('/workspace/alice%2Fdraft/knowledge-base/Dashboards/a.html#goal');
|
|
453
|
+
expect(openMock).not.toHaveBeenCalled();
|
|
420
454
|
});
|
|
421
455
|
|
|
422
456
|
// `window.open` would strip the padding itself, but the address handed over
|
|
@@ -433,12 +467,99 @@ describe('useFileNav.openLink', () => {
|
|
|
433
467
|
|
|
434
468
|
// A section link is a scroll, not a navigation to somewhere else.
|
|
435
469
|
it('keeps a same-document anchor on the file it sits in', () => {
|
|
436
|
-
|
|
437
|
-
const { result } = renderNav('alice/draft');
|
|
470
|
+
const { result } = renderNav('alice/draft', 'knowledge-base', '/workspace/alice%2Fdraft/knowledge-base/Knowledge/Foo.md');
|
|
438
471
|
result.current.openLink('#overview', 'knowledge-base/Knowledge/Foo.md');
|
|
439
|
-
expect(navigateMock).toHaveBeenCalledWith(
|
|
440
|
-
|
|
441
|
-
|
|
472
|
+
expect(navigateMock).toHaveBeenCalledWith('/workspace/alice%2Fdraft/knowledge-base/Knowledge/Foo.md#overview');
|
|
473
|
+
expect(openMock).not.toHaveBeenCalled();
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
// The section link moves this tab by its fragment ONLY: a node shown at its
|
|
477
|
+
// id URL stays there, and full screen (`?fullscreen=1`) stays on.
|
|
478
|
+
it('scrolls a section link in place on this tab\'s own address, query kept', () => {
|
|
479
|
+
const { result } = renderNav('alice/draft', 'knowledge-base', '/workspace/alice%2Fdraft/foo-node', '?fullscreen=1');
|
|
480
|
+
result.current.openLink('Foo.md#overview', 'knowledge-base/Knowledge/Foo.md');
|
|
481
|
+
expect(navigateMock).toHaveBeenCalledWith('/workspace/alice%2Fdraft/foo-node?fullscreen=1#overview');
|
|
482
|
+
expect(openMock).not.toHaveBeenCalled();
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
// The same file on ANOTHER branch is another file.
|
|
486
|
+
it('opens the same path on another branch in a new tab', () => {
|
|
487
|
+
const { result } = renderNav('alice/draft', 'knowledge-base', '/workspace/alice%2Fdraft/knowledge-base/Knowledge/Foo.md');
|
|
488
|
+
result.current.openLink('/workspace/main/knowledge-base/Knowledge/Foo.md#overview', 'knowledge-base/Knowledge/Foo.md');
|
|
489
|
+
expectNewTab('/workspace/main/knowledge-base/Knowledge/Foo.md#overview');
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
it('in full screen, opens another file at its plain address and leaves this tab alone', () => {
|
|
493
|
+
const { result } = renderNav('alice/draft', 'knowledge-base', '/workspace/alice%2Fdraft/knowledge-base/Dashboards/a.html', '?fullscreen=1');
|
|
494
|
+
result.current.openLink('../Knowledge/Plan.md', 'knowledge-base/Dashboards/a.html');
|
|
495
|
+
expectNewTab('/workspace/alice%2Fdraft/knowledge-base/Knowledge/Plan.md');
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
// The new tab is the app's own page, opened without `noopener` only so a
|
|
499
|
+
// refusal can be told from a success; the opener is cut the same moment.
|
|
500
|
+
it('severs the new tab\'s opener', () => {
|
|
501
|
+
const { result } = renderNav('alice/draft');
|
|
502
|
+
result.current.openLink('Board.html', 'knowledge-base/Dashboards/a.html');
|
|
503
|
+
expect(openedTab.opener).toBeNull();
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
it('reports a tab the browser refused to open, rather than swallowing the click', () => {
|
|
507
|
+
openMock.mockImplementation(() => null);
|
|
508
|
+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
509
|
+
const { result } = renderNav('alice/draft');
|
|
510
|
+
result.current.openLink('Board.html', 'knowledge-base/Dashboards/a.html');
|
|
511
|
+
expect(warn).toHaveBeenCalledWith(expect.stringContaining('/workspace/alice%2Fdraft/knowledge-base/Dashboards/Board.html'));
|
|
512
|
+
expect(navigateMock).not.toHaveBeenCalled();
|
|
513
|
+
warn.mockRestore();
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
// What an anchor carries is what the click opens.
|
|
517
|
+
it('answers linkTarget with the address and the tab openLink uses', () => {
|
|
518
|
+
const { result } = renderNav('alice/draft', 'knowledge-base', '/workspace/alice%2Fdraft/knowledge-base/Knowledge/Foo.md');
|
|
519
|
+
expect(result.current.linkTarget('Other.md', 'knowledge-base/Knowledge/Foo.md')).toEqual({
|
|
520
|
+
href: '/workspace/alice%2Fdraft/knowledge-base/Knowledge/Other.md',
|
|
521
|
+
newTab: true,
|
|
522
|
+
});
|
|
523
|
+
expect(result.current.linkTarget('#a', 'knowledge-base/Knowledge/Foo.md')).toEqual({
|
|
524
|
+
href: '/workspace/alice%2Fdraft/knowledge-base/Knowledge/Foo.md#a',
|
|
525
|
+
newTab: false,
|
|
526
|
+
});
|
|
527
|
+
expect(result.current.linkTarget('https://example.com', 'knowledge-base/Knowledge/Foo.md')).toBeNull();
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
// The skill page reads its files from the default branch whatever is
|
|
531
|
+
// checked out: told so, a relative link opens there, and a link to the
|
|
532
|
+
// file itself is still a section of this tab.
|
|
533
|
+
it('resolves a relative link on the home branch it is told the file was read from', () => {
|
|
534
|
+
const { result } = renderNav('alice/draft', 'knowledge-base', '/skills-and-tools/skills/newsletter');
|
|
535
|
+
const base = 'knowledge-base/Skills/newsletter/SKILL.md';
|
|
536
|
+
expect(result.current.linkTarget('ref.md', base, 'main')).toEqual({
|
|
537
|
+
href: '/workspace/main/knowledge-base/Skills/newsletter/ref.md',
|
|
538
|
+
newTab: true,
|
|
539
|
+
});
|
|
540
|
+
expect(result.current.linkTarget('SKILL.md#steps', base, 'main')).toEqual({
|
|
541
|
+
href: '/skills-and-tools/skills/newsletter#steps',
|
|
542
|
+
newTab: false,
|
|
543
|
+
});
|
|
544
|
+
result.current.openLink('ref.md', base, { homeBranch: 'main' });
|
|
545
|
+
expectNewTab('/workspace/main/knowledge-base/Skills/newsletter/ref.md');
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
// A host whose address does not scroll to a fragment (an HTML page's frame,
|
|
549
|
+
// the skill page) takes a section link itself: handed the fragment, while
|
|
550
|
+
// this tab stays where it is. Another file still opens a new tab.
|
|
551
|
+
it('hands a section link to the host that scrolls it, and moves nothing', () => {
|
|
552
|
+
navigateMock.mockClear();
|
|
553
|
+
const { result } = renderNav('main', 'knowledge-base', '/workspace/main/knowledge-base/Dashboards/Roadmap.html');
|
|
554
|
+
const base = 'knowledge-base/Dashboards/Roadmap.html';
|
|
555
|
+
const onSection = vi.fn();
|
|
556
|
+
result.current.openLink('Roadmap.html#q3', base, { onSection });
|
|
557
|
+
result.current.openLink('/workspace/main/knowledge-base/Dashboards/Roadmap.html#q4', base, { onSection });
|
|
558
|
+
expect(onSection.mock.calls).toEqual([['#q3'], ['#q4']]);
|
|
559
|
+
expect(navigateMock).not.toHaveBeenCalled();
|
|
560
|
+
result.current.openLink('Board.html#q3', base, { onSection });
|
|
561
|
+
expect(onSection).toHaveBeenCalledTimes(2);
|
|
562
|
+
expectNewTab('/workspace/main/knowledge-base/Dashboards/Board.html#q3');
|
|
442
563
|
});
|
|
443
564
|
});
|
|
444
565
|
|
|
@@ -482,7 +603,7 @@ describe('useFileNav: which branch a click lands on', () => {
|
|
|
482
603
|
'/workspace/target-company-state/knowledge-base/Knowledge/Old.md',
|
|
483
604
|
);
|
|
484
605
|
result.current.openLink('./New.md', 'knowledge-base/Knowledge/Old.md');
|
|
485
|
-
|
|
606
|
+
expectNewTab(
|
|
486
607
|
'/workspace/target-company-state/knowledge-base/Knowledge/New.md',
|
|
487
608
|
);
|
|
488
609
|
});
|
|
@@ -494,3 +615,119 @@ describe('useFileNav: which branch a click lands on', () => {
|
|
|
494
615
|
expect(navigateMock).toHaveBeenCalledWith('/workspace/alice%2Fdraft/Knowledge/New.md');
|
|
495
616
|
});
|
|
496
617
|
});
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* An id-link is a link inside a file too. The new tab gets the node's id URL
|
|
621
|
+
* and resolves it there (its route answers not-found for an id the reader
|
|
622
|
+
* cannot see), so the tab opens inside the click rather than after a round
|
|
623
|
+
* trip, at the address a middle-click on the same anchor would open.
|
|
624
|
+
*/
|
|
625
|
+
describe('useNodeIdNav', () => {
|
|
626
|
+
function renderNodeNav(pathname: string, search = '') {
|
|
627
|
+
routerMock.pathname = pathname;
|
|
628
|
+
routerMock.search = search;
|
|
629
|
+
return renderHook(() => useNodeIdNav(), {
|
|
630
|
+
wrapper: ({ children }) => (
|
|
631
|
+
<GitContext.Provider value={gitOnBranch('alice/draft')}>
|
|
632
|
+
<WorkspaceContext.Provider value={makeWorkspaceFixture({ kbDirName: 'knowledge-base' })}>
|
|
633
|
+
{children}
|
|
634
|
+
</WorkspaceContext.Provider>
|
|
635
|
+
</GitContext.Provider>
|
|
636
|
+
),
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
it('opens another node in a new tab at its id URL, heading kept', () => {
|
|
641
|
+
const { result } = renderNodeNav('/workspace/alice%2Fdraft/knowledge-base/Knowledge/Foo.md');
|
|
642
|
+
result.current.openNodeId('plan-node#goal');
|
|
643
|
+
expectNewTab('/workspace/alice%2Fdraft/plan-node#goal');
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
it('in full screen, opens the plain id URL and leaves this tab alone', () => {
|
|
647
|
+
const { result } = renderNodeNav('/workspace/alice%2Fdraft/foo-node', '?fullscreen=1');
|
|
648
|
+
result.current.openNodeId('plan-node');
|
|
649
|
+
expectNewTab('/workspace/alice%2Fdraft/plan-node');
|
|
650
|
+
});
|
|
651
|
+
|
|
652
|
+
it('scrolls a link to the node on screen in place, address and query kept', () => {
|
|
653
|
+
const { result } = renderNodeNav('/workspace/alice%2Fdraft/foo-node', '?fullscreen=1');
|
|
654
|
+
result.current.openNodeId('foo-node#goal');
|
|
655
|
+
expect(navigateMock).toHaveBeenCalledWith('/workspace/alice%2Fdraft/foo-node?fullscreen=1#goal');
|
|
656
|
+
expect(openMock).not.toHaveBeenCalled();
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
// The node on screen told by its id: a tab still on the file's path URL —
|
|
660
|
+
// canonicalizing, or a `FileRoute` that never canonicalizes — keeps a link
|
|
661
|
+
// to it in place; any other id is still a new tab.
|
|
662
|
+
it('scrolls a link to the node on screen in place on its path URL when told its id', () => {
|
|
663
|
+
const path = '/workspace/alice%2Fdraft/knowledge-base/Knowledge/Foo.md';
|
|
664
|
+
const { result } = renderNodeNav(path, '?fullscreen=1');
|
|
665
|
+
expect(result.current.nodeIdTarget('foo-node#goal', 'foo-node')).toEqual({
|
|
666
|
+
href: `${path}?fullscreen=1#goal`,
|
|
667
|
+
newTab: false,
|
|
668
|
+
});
|
|
669
|
+
result.current.openNodeId('foo-node#goal', 'foo-node');
|
|
670
|
+
expect(navigateMock).toHaveBeenCalledWith(`${path}?fullscreen=1#goal`);
|
|
671
|
+
expect(openMock).not.toHaveBeenCalled();
|
|
672
|
+
navigateMock.mockClear();
|
|
673
|
+
result.current.openNodeId('plan-node', 'foo-node');
|
|
674
|
+
expectNewTab('/workspace/alice%2Fdraft/plan-node');
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
// A host whose address has no heading scroll (the skill page) is handed
|
|
678
|
+
// the fragment of a link to its own node and scrolls itself; the tab does
|
|
679
|
+
// not move. A link to any other node still opens a new tab.
|
|
680
|
+
it('hands a link to the node on screen to onSection, and moves nothing', () => {
|
|
681
|
+
const { result } = renderNodeNav('/skills-and-tools/skills/newsletter');
|
|
682
|
+
const onSection = vi.fn();
|
|
683
|
+
result.current.openNodeId('newsletter#steps', 'newsletter', { onSection });
|
|
684
|
+
expect(onSection).toHaveBeenCalledWith('#steps');
|
|
685
|
+
expect(navigateMock).not.toHaveBeenCalled();
|
|
686
|
+
expect(openMock).not.toHaveBeenCalled();
|
|
687
|
+
result.current.openNodeId('plan-node#goal', 'newsletter', { onSection });
|
|
688
|
+
expect(onSection).toHaveBeenCalledTimes(1);
|
|
689
|
+
expectNewTab('/workspace/alice%2Fdraft/plan-node#goal');
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
// A host that read its file from another branch than this tab's (the skill
|
|
693
|
+
// page reads the default branch while a draft is checked out) names it,
|
|
694
|
+
// and the id resolves there — on the click and on the anchor alike.
|
|
695
|
+
it('opens an id on the branch its file was read from when told one', () => {
|
|
696
|
+
const { result } = renderNodeNav('/skills-and-tools/skills/newsletter');
|
|
697
|
+
expect(result.current.nodeIdTarget('plan-node#goal', null, 'main')).toEqual({
|
|
698
|
+
href: '/workspace/main/plan-node#goal',
|
|
699
|
+
newTab: true,
|
|
700
|
+
});
|
|
701
|
+
result.current.openNodeId('plan-node#goal', null, { homeBranch: 'main' });
|
|
702
|
+
expectNewTab('/workspace/main/plan-node#goal');
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
it('answers nodeIdTarget with the same address', () => {
|
|
706
|
+
const { result } = renderNodeNav('/workspace/alice%2Fdraft/foo-node');
|
|
707
|
+
expect(result.current.nodeIdTarget('plan-node#goal')).toEqual({
|
|
708
|
+
href: '/workspace/alice%2Fdraft/plan-node#goal',
|
|
709
|
+
newTab: true,
|
|
710
|
+
});
|
|
711
|
+
});
|
|
712
|
+
});
|
|
713
|
+
|
|
714
|
+
/**
|
|
715
|
+
* The app's own navigation is not a link inside a file: the tree, the tabs,
|
|
716
|
+
* search and the library open in place, through `openFile` and
|
|
717
|
+
* `openWorkspacePath`, in full screen or not.
|
|
718
|
+
*/
|
|
719
|
+
describe('useFileNav: the app\'s own navigation stays in this tab', () => {
|
|
720
|
+
it('opens a tree path in place', () => {
|
|
721
|
+
const { result } = renderNav('alice/draft', 'knowledge-base', '/workspace/alice%2Fdraft/knowledge-base/Knowledge/Old.md', '?fullscreen=1');
|
|
722
|
+
result.current.openWorkspacePath('knowledge-base/Knowledge/New.md');
|
|
723
|
+
expect(navigateMock).toHaveBeenCalledWith('/workspace/alice%2Fdraft/knowledge-base/Knowledge/New.md');
|
|
724
|
+
expect(openMock).not.toHaveBeenCalled();
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
it('opens a tab\'s file in place', () => {
|
|
728
|
+
const { result } = renderNav('alice/draft', 'knowledge-base', '/workspace/alice%2Fdraft/knowledge-base/Knowledge/Old.md');
|
|
729
|
+
result.current.openFile('knowledge-base/Knowledge/New.md');
|
|
730
|
+
expect(navigateMock).toHaveBeenCalledWith('/workspace/alice%2Fdraft/knowledge-base/Knowledge/New.md');
|
|
731
|
+
expect(openMock).not.toHaveBeenCalled();
|
|
732
|
+
});
|
|
733
|
+
});
|