@bevel-software/platform-core-frontend 0.26.0 → 0.28.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.
Files changed (206) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +87 -25
  3. package/src/core/ProductName.tsx +49 -0
  4. package/src/core/__tests__/ProductName.test.tsx +46 -0
  5. package/src/core/__tests__/ShellRoutes.test.tsx +22 -0
  6. package/src/core/__tests__/core-contributions.test.ts +16 -0
  7. package/src/core/core-contributions.ts +17 -0
  8. package/src/core/maker-url.ts +30 -0
  9. package/src/core/registry.ts +78 -1
  10. package/src/index.css +23 -5
  11. package/src/index.ts +5 -0
  12. package/src/lib/__tests__/latest-request.test.ts +48 -0
  13. package/src/lib/latest-request.ts +45 -0
  14. package/src/modules/access/__tests__/ManageAccessDialog.no-sso-invite.test.tsx +222 -0
  15. package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +1 -1
  16. package/src/modules/access/api.ts +19 -3
  17. package/src/modules/access/components/ManageAccessDialog.tsx +61 -8
  18. package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +16 -1
  19. package/src/modules/admin/__tests__/RolesCorruptedBanner.test.tsx +70 -0
  20. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +284 -39
  21. package/src/modules/admin/components/AdminRolesPage.tsx +13 -14
  22. package/src/modules/admin/components/RolesCorruptedBanner.tsx +9 -4
  23. package/src/modules/admin/components/UserAccountsPage.tsx +91 -107
  24. package/src/modules/admin/services/roles.api.ts +14 -1
  25. package/src/modules/auth/__tests__/LoginScreen.test.tsx +80 -5
  26. package/src/modules/auth/__tests__/sso-strict-probe.test.ts +66 -0
  27. package/src/modules/auth/components/LoginScreen.tsx +101 -73
  28. package/src/modules/auth/services/account.api.ts +59 -3
  29. package/src/modules/auth/services/sso.ts +30 -10
  30. package/src/modules/auth/state/use-sign-in-methods.ts +41 -0
  31. package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +176 -0
  32. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +68 -0
  33. package/src/modules/change-requests/__tests__/ChangeRequestLink.test.tsx +182 -0
  34. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +1 -1
  35. package/src/modules/change-requests/__tests__/readFileOnBranch.test.ts +79 -0
  36. package/src/modules/change-requests/components/ChangeBox.tsx +6 -1
  37. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +45 -15
  38. package/src/modules/change-requests/components/ChangeRequestLink.tsx +151 -0
  39. package/src/modules/change-requests/components/CrFileTree.tsx +2 -1
  40. package/src/modules/change-requests/components/FileChangeBoxes.tsx +4 -2
  41. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +6 -3
  42. package/src/modules/change-requests/services/change-requests.api.ts +15 -2
  43. package/src/modules/change-requests/utils/readFailure.ts +22 -0
  44. package/src/modules/embed/__tests__/EmbedLinkPage.test.tsx +74 -0
  45. package/src/modules/embed/__tests__/EmbedView.test.tsx +473 -0
  46. package/src/modules/embed/__tests__/embed-config.test.ts +128 -0
  47. package/src/modules/embed/__tests__/embed-host.test.ts +111 -0
  48. package/src/modules/embed/__tests__/mcp-app-view.test.ts +295 -0
  49. package/src/modules/embed/__tests__/mount.test.tsx +157 -0
  50. package/src/modules/embed/components/EmbedLinkPage.tsx +109 -0
  51. package/src/modules/embed/components/EmbedView.tsx +545 -0
  52. package/src/modules/embed/embed-config.ts +132 -0
  53. package/src/modules/embed/embed-host.ts +120 -0
  54. package/src/modules/embed/mount.tsx +80 -0
  55. package/src/modules/embed/services/embed-token.ts +22 -0
  56. package/src/modules/embed/services/embed.api.ts +158 -0
  57. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +202 -4
  58. package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +59 -1
  59. package/src/modules/git/__tests__/PullNeededBanner.test.tsx +39 -22
  60. package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +7 -2
  61. package/src/modules/git/branch-delete-menu-item.tsx +24 -0
  62. package/src/modules/git/components/BranchSwitcher.tsx +29 -5
  63. package/src/modules/git/components/GitSyncFailedBanner.tsx +53 -15
  64. package/src/modules/git/components/HistoryVersionPreview.tsx +5 -3
  65. package/src/modules/git/components/PullNeededBanner.tsx +15 -49
  66. package/src/modules/git/hooks/useAutoPullUpdates.ts +9 -5
  67. package/src/modules/git/index.ts +15 -0
  68. package/src/modules/git/services/__tests__/error-messages.test.ts +67 -0
  69. package/src/modules/git/services/__tests__/pull-failure.test.ts +36 -0
  70. package/src/modules/git/services/error-messages.ts +58 -1
  71. package/src/modules/git/services/pull-failure.ts +68 -0
  72. package/src/modules/git/state/branch-delete-confirm.ts +46 -0
  73. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +1 -0
  74. package/src/modules/layout/__tests__/breakpoints.test.ts +7 -1
  75. package/src/modules/layout/breakpoints.ts +8 -0
  76. package/src/modules/library/__tests__/PluginExtras.test.tsx +9 -9
  77. package/src/modules/library/__tests__/PluginPage.test.tsx +8 -1
  78. package/src/modules/library/__tests__/SkillsTree.test.tsx +13 -4
  79. package/src/modules/library/components/LibraryPage.tsx +22 -0
  80. package/src/modules/library/components/PluginExtras.tsx +23 -6
  81. package/src/modules/library/components/PluginPage.tsx +6 -1
  82. package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
  83. package/src/modules/library/services/plugins.api.ts +4 -1
  84. package/src/modules/library/state/plugins-revision.ts +28 -0
  85. package/src/modules/onboarding/__tests__/InviteButton.test.tsx +214 -0
  86. package/src/modules/onboarding/__tests__/agent-connection-api.test.ts +55 -0
  87. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +87 -82
  88. package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +164 -0
  89. package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1458 -0
  90. package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +811 -0
  91. package/src/modules/onboarding/__tests__/invite-emails.test.ts +247 -0
  92. package/src/modules/onboarding/__tests__/onboarding.test.tsx +226 -193
  93. package/src/modules/onboarding/__tests__/starter-pack-card.test.tsx +136 -0
  94. package/src/modules/onboarding/components/CreatorWelcomePage.tsx +7 -11
  95. package/src/modules/onboarding/components/EmailChipsInput.tsx +138 -0
  96. package/src/modules/onboarding/components/GetStartedColumn.tsx +670 -0
  97. package/src/modules/onboarding/components/InviteButton.tsx +139 -0
  98. package/src/modules/onboarding/components/InviteDialog.tsx +741 -0
  99. package/src/modules/onboarding/components/RootLanding.tsx +8 -24
  100. package/src/modules/onboarding/components/StarterPackCard.tsx +98 -0
  101. package/src/modules/onboarding/components/WelcomePage.tsx +65 -154
  102. package/src/modules/onboarding/first-page-prompt.ts +123 -0
  103. package/src/modules/onboarding/invite-emails.ts +313 -0
  104. package/src/modules/onboarding/services/agent-connection.api.ts +53 -0
  105. package/src/modules/onboarding/services/starter-packs.api.ts +83 -0
  106. package/src/modules/onboarding/state/agent-connection.ts +167 -0
  107. package/src/modules/onboarding/state/invite-dialog.context.ts +35 -0
  108. package/src/modules/onboarding/state/invite-dialog.tsx +39 -0
  109. package/src/modules/onboarding/state/onboarding.ts +133 -59
  110. package/src/modules/onboarding/state/starter-packs.ts +169 -0
  111. package/src/modules/settings/settings-nav-items.tsx +8 -3
  112. package/src/modules/setup/__tests__/setup.first-run-storage.test.tsx +389 -0
  113. package/src/modules/setup/__tests__/setup.github.test.tsx +5 -5
  114. package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +1 -1
  115. package/src/modules/setup/__tests__/setup.repository-change.test.tsx +1 -1
  116. package/src/modules/setup/__tests__/setup.repository.test.tsx +21 -21
  117. package/src/modules/setup/__tests__/setup.test.tsx +56 -15
  118. package/src/modules/setup/__tests__/useConnectionProbe.test.tsx +123 -0
  119. package/src/modules/setup/components/FirstRunStorage.tsx +560 -0
  120. package/src/modules/setup/components/SetupGate.tsx +46 -1
  121. package/src/modules/setup/components/SetupScreen.tsx +81 -84
  122. package/src/modules/setup/hooks/useConnectionProbe.ts +93 -0
  123. package/src/modules/setup/services/setup.api.ts +3 -3
  124. package/src/modules/setup/utils/suggested-branch.ts +27 -0
  125. package/src/modules/toolbar/commands/__tests__/actions.test.tsx +210 -0
  126. package/src/modules/toolbar/commands/actions.tsx +330 -0
  127. package/src/modules/toolbar/commands/command-menu.ts +44 -0
  128. package/src/modules/toolbar/commands/useCommandActions.ts +71 -0
  129. package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
  130. package/src/modules/toolbar/components/AppSwitcher.tsx +125 -22
  131. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
  132. package/src/modules/toolbar/components/ProfileMenu.tsx +9 -4
  133. package/src/modules/toolbar/components/SearchPalette.tsx +540 -0
  134. package/src/modules/toolbar/components/Toolbar.tsx +10 -0
  135. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +230 -52
  136. package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
  137. package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +864 -0
  138. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +57 -2
  139. package/src/modules/toolbar/search/__tests__/rank.test.ts +93 -0
  140. package/src/modules/toolbar/search/__tests__/sources.test.ts +131 -0
  141. package/src/modules/toolbar/search/rank.ts +111 -0
  142. package/src/modules/toolbar/search/sources.ts +169 -0
  143. package/src/modules/workflow/hooks/useFileLock.ts +10 -7
  144. package/src/modules/workflow/services/__tests__/lock.api.test.ts +41 -0
  145. package/src/modules/workflow/services/lock.api.ts +17 -2
  146. package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +49 -1
  147. package/src/modules/workspace/components/EditorTabs.tsx +39 -15
  148. package/src/modules/workspace/components/FileExplorer.tsx +39 -6
  149. package/src/modules/workspace/components/FilePaneCard.tsx +6 -2
  150. package/src/modules/workspace/components/FileRoute.tsx +12 -7
  151. package/src/modules/workspace/components/FileViewer.tsx +271 -74
  152. package/src/modules/workspace/components/KbPageHeader.tsx +13 -6
  153. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +88 -21
  154. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +92 -4
  155. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +23 -3
  156. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +330 -6
  157. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +17 -2
  158. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -16
  159. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +6 -0
  160. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +23 -21
  161. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +13 -29
  162. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +9 -2
  163. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +8 -0
  164. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +14 -19
  165. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +11 -17
  166. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +35 -7
  167. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -17
  168. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.links.test.tsx +73 -0
  169. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.scaffold.test.tsx +64 -0
  170. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.surface.test.tsx +82 -0
  171. package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +99 -0
  172. package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +129 -35
  173. package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +149 -0
  174. package/src/modules/workspace/components/renderers/__tests__/kbMarkdownLinkPolicy.test.tsx +100 -0
  175. package/src/modules/workspace/components/renderers/htmlSandbox.ts +76 -20
  176. package/src/modules/workspace/components/renderers/index.ts +26 -0
  177. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +51 -1
  178. package/src/modules/workspace/components/renderers/rendererRawRead.ts +53 -0
  179. package/src/modules/workspace/components/renderers/rendererSurface.ts +109 -0
  180. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +8 -2
  181. package/src/modules/workspace/hooks/__tests__/useCreatePage.test.ts +137 -0
  182. package/src/modules/workspace/hooks/__tests__/useKnowledgeWriteTarget.test.ts +302 -0
  183. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +126 -21
  184. package/src/modules/workspace/hooks/useCreatePage.ts +206 -0
  185. package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +238 -0
  186. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +24 -7
  187. package/src/modules/workspace/hooks/useWorkspaceState.ts +42 -8
  188. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +10 -0
  189. package/src/modules/workspace/routing/__tests__/md-links-parity.test.tsx +113 -0
  190. package/src/modules/workspace/routing/kb-routes.ts +66 -12
  191. package/src/modules/workspace/state/editable-page.ts +42 -0
  192. package/src/modules/workspace/state/workspace.context.ts +13 -4
  193. package/src/modules/workspace/utils/__tests__/display-file-name.test.ts +60 -0
  194. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +75 -0
  195. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +16 -0
  196. package/src/modules/workspace/utils/display-file-name.ts +102 -0
  197. package/src/modules/workspace/utils/fileTree.ts +49 -14
  198. package/src/modules/workspace/utils/treeConfirm.ts +15 -0
  199. package/src/shared/__tests__/no-builtin-confirm.test.ts +102 -0
  200. package/src/shared/components/ConfirmProvider.tsx +156 -0
  201. package/src/shared/components/Dialog.tsx +7 -0
  202. package/src/shared/components/__tests__/ConfirmProvider.test.tsx +198 -0
  203. package/src/shared/components/confirm-context.ts +94 -0
  204. package/src/shared/components/index.ts +3 -0
  205. package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
  206. package/src/modules/onboarding/welcome-state.ts +0 -36
@@ -1,9 +1,14 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { render, screen, within } from '@testing-library/react';
1
+ import { describe, it, expect, beforeEach } from 'vitest';
2
+ import { fireEvent, render, screen, within } from '@testing-library/react';
3
3
  import userEvent from '@testing-library/user-event';
4
4
  import { MemoryRouter, useLocation } from 'react-router-dom';
5
5
  import { AppSwitcher } from '../AppSwitcher';
6
- import { ActiveAppIdContext, AppRegistryContext, makeRegistry } from '../../../../core/registry';
6
+ import {
7
+ ActiveAppIdContext,
8
+ AppRegistryContext,
9
+ makeRegistry,
10
+ type AppDef,
11
+ } from '../../../../core/registry';
7
12
 
8
13
  /** Exposes the router's current pathname so navigation can be asserted. */
9
14
  function LocationProbe() {
@@ -11,41 +16,69 @@ function LocationProbe() {
11
16
  return <div data-testid="pathname">{location.pathname}</div>;
12
17
  }
13
18
 
14
- function renderSwitcher(opts?: { path?: string; extraApps?: boolean; shellActiveId?: string }) {
15
- // The switcher reads apps from the registry — in the app the shell merges
16
- // the core apps in (see CoreAppShell CORE_APPS); the harness mirrors that.
17
- const coreLikeApps = [
18
- {
19
- id: 'knowledge',
20
- label: 'Knowledge',
21
- path: '/workspace',
22
- description: 'Browse and edit your knowledge base',
23
- order: 10,
24
- element: <div />,
25
- },
26
- {
27
- id: 'skills-tools',
28
- label: 'Skills & Tools',
29
- path: '/skills-and-tools',
30
- description: 'What your assistant can do, and what it connects to',
31
- order: 20,
32
- element: <div />,
33
- },
34
- ];
19
+ /**
20
+ * Move the viewport. happy-dom answers `matchMedia` out of `innerWidth`, so
21
+ * this is how a test crosses the toolbar's compact breakpoint.
22
+ */
23
+ function setViewportWidth(width: number): void {
24
+ const testWindow = window as typeof window & {
25
+ happyDOM: { setInnerWidth(value: number): void };
26
+ };
27
+ testWindow.happyDOM.setInnerWidth(width);
28
+ }
29
+
30
+ // The switcher reads apps from the registry — in the app the shell merges
31
+ // the core apps in (see CoreAppShell CORE_APPS); the harness mirrors that.
32
+ const coreLikeApps: AppDef[] = [
33
+ {
34
+ id: 'knowledge',
35
+ label: 'Knowledge',
36
+ path: '/workspace',
37
+ description: 'Browse and edit your knowledge base',
38
+ order: 10,
39
+ element: <div />,
40
+ },
41
+ {
42
+ id: 'skills-tools',
43
+ label: 'Skills & Tools',
44
+ path: '/skills-and-tools',
45
+ description: 'What your assistant can do, and what it connects to',
46
+ order: 20,
47
+ element: <div />,
48
+ },
49
+ ];
50
+
51
+ const assistantApp: AppDef = {
52
+ id: 'assistant',
53
+ label: 'Assistant',
54
+ path: '/assistant',
55
+ description: 'Chat with your knowledge base',
56
+ order: 30,
57
+ element: <div />,
58
+ };
59
+
60
+ const insightsApp: AppDef = {
61
+ id: 'insights',
62
+ label: 'Insights',
63
+ path: '/insights',
64
+ order: 40,
65
+ element: <div />,
66
+ };
67
+
68
+ function renderSwitcher(opts?: {
69
+ path?: string;
70
+ /** Registry apps past the two core ones. */
71
+ extraApps?: AppDef[];
72
+ shellActiveId?: string;
73
+ /** Where the maker's name leads, as a distribution sets it. */
74
+ makerLink?: string;
75
+ /** What the menu's entry for that place says, as a distribution sets it. */
76
+ makerLinkLabel?: string;
77
+ }) {
35
78
  const registry = makeRegistry({
36
- apps: opts?.extraApps
37
- ? [
38
- ...coreLikeApps,
39
- {
40
- id: 'assistant',
41
- label: 'Assistant',
42
- path: '/assistant',
43
- description: 'Chat with your knowledge base',
44
- order: 30,
45
- element: <div />,
46
- },
47
- ]
48
- : coreLikeApps,
79
+ apps: [...coreLikeApps, ...(opts?.extraApps ?? [])],
80
+ ...(opts?.makerLink !== undefined ? { makerLink: opts.makerLink } : {}),
81
+ ...(opts?.makerLinkLabel !== undefined ? { makerLinkLabel: opts.makerLinkLabel } : {}),
49
82
  });
50
83
  const tree = (
51
84
  <MemoryRouter initialEntries={[opts?.path ?? '/']}>
@@ -64,22 +97,163 @@ function renderSwitcher(opts?: { path?: string; extraApps?: boolean; shellActive
64
97
  );
65
98
  }
66
99
 
67
- describe('AppSwitcher', () => {
100
+ beforeEach(() => {
101
+ setViewportWidth(1400);
102
+ });
103
+
104
+ describe('AppSwitcher as a segmented toggle (few apps, wide toolbar)', () => {
105
+ const nav = () => screen.getByRole('navigation', { name: 'Apps' });
106
+
107
+ it('shows the brand as text and both core apps side by side, with no menu', () => {
108
+ renderSwitcher({ path: '/workspace' });
109
+ expect(screen.getByText(/^Hexis by/).closest('button')).toBeNull();
110
+ const links = within(nav()).getAllByRole('link');
111
+ expect(links.map((l) => l.textContent)).toEqual(['Knowledge', 'Skills & Tools']);
112
+ expect(screen.queryByRole('button', { name: 'Switch app' })).not.toBeInTheDocument();
113
+ });
114
+
115
+ it('marks the app matching the current location as current', () => {
116
+ renderSwitcher({ path: '/workspace/main/Skills' });
117
+ expect(within(nav()).getByRole('link', { name: 'Knowledge' })).toHaveAttribute(
118
+ 'aria-current',
119
+ 'page',
120
+ );
121
+ expect(within(nav()).getByRole('link', { name: 'Skills & Tools' })).not.toHaveAttribute(
122
+ 'aria-current',
123
+ );
124
+ });
125
+
126
+ // See the menu's equivalent below: a skill page at its canonical
127
+ // /workspace URL CLAIMS Skills & Tools, and the toggle follows the claim.
128
+ it('honours a shell-provided active app over the URL prefix', () => {
129
+ renderSwitcher({
130
+ path: '/workspace/main/knowledge-base/Plugins/Sales/create-sales-deck/SKILL.md',
131
+ shellActiveId: 'skills-tools',
132
+ });
133
+ expect(within(nav()).getByRole('link', { name: 'Skills & Tools' })).toHaveAttribute(
134
+ 'aria-current',
135
+ 'page',
136
+ );
137
+ expect(within(nav()).getByRole('link', { name: 'Knowledge' })).not.toHaveAttribute(
138
+ 'aria-current',
139
+ );
140
+ });
141
+
142
+ it('marks no app as current on a standalone settings page', () => {
143
+ renderSwitcher({ path: '/secrets' });
144
+ for (const link of within(nav()).getAllByRole('link')) {
145
+ expect(link).not.toHaveAttribute('aria-current');
146
+ }
147
+ });
148
+
149
+ it('navigates to the chosen app and moves the current mark with it', async () => {
150
+ renderSwitcher({ path: '/workspace' });
151
+ await userEvent.click(within(nav()).getByRole('link', { name: 'Skills & Tools' }));
152
+ expect(screen.getByTestId('pathname')).toHaveTextContent('/skills-and-tools');
153
+ expect(within(nav()).getByRole('link', { name: 'Skills & Tools' })).toHaveAttribute(
154
+ 'aria-current',
155
+ 'page',
156
+ );
157
+ });
158
+
159
+ it('stays put when the current app is clicked from a deep link inside it', async () => {
160
+ renderSwitcher({ path: '/workspace/main/Skills' });
161
+ await userEvent.click(within(nav()).getByRole('link', { name: 'Knowledge' }));
162
+ expect(screen.getByTestId('pathname')).toHaveTextContent('/workspace/main/Skills');
163
+ });
164
+
165
+ it('leaves a modified or middle click on the current app to the browser, for a new tab', () => {
166
+ renderSwitcher({ path: '/workspace/main/Skills' });
167
+ const link = within(nav()).getByRole('link', { name: 'Knowledge' });
168
+ // `fireEvent` answers whether the default action survived: false means cancelled.
169
+ expect(fireEvent.click(link)).toBe(false);
170
+ expect(fireEvent.click(link, { ctrlKey: true })).toBe(true);
171
+ expect(fireEvent.click(link, { metaKey: true })).toBe(true);
172
+ expect(fireEvent.click(link, { shiftKey: true })).toBe(true);
173
+ expect(fireEvent.click(link, { button: 1 })).toBe(true);
174
+ expect(screen.getByTestId('pathname')).toHaveTextContent('/workspace/main/Skills');
175
+ });
176
+
177
+ it('still fits a third, registry-contributed app', () => {
178
+ renderSwitcher({ extraApps: [assistantApp] });
179
+ expect(within(nav()).getAllByRole('link').map((l) => l.textContent)).toEqual([
180
+ 'Knowledge',
181
+ 'Skills & Tools',
182
+ 'Assistant',
183
+ ]);
184
+ });
185
+
186
+ it('falls back to the menu with four apps', () => {
187
+ renderSwitcher({ extraApps: [assistantApp, insightsApp] });
188
+ expect(screen.queryByRole('navigation', { name: 'Apps' })).not.toBeInTheDocument();
189
+ expect(screen.getByRole('button', { name: 'Switch app' })).toBeInTheDocument();
190
+ });
191
+
192
+ it('falls back to the menu on a compact toolbar', () => {
193
+ setViewportWidth(600);
194
+ renderSwitcher({ path: '/workspace' });
195
+ expect(screen.queryByRole('navigation', { name: 'Apps' })).not.toBeInTheDocument();
196
+ expect(screen.getByRole('button', { name: 'Switch app' })).toHaveTextContent('Knowledge');
197
+ });
198
+
199
+ // The trigger holds the name as text, since a link cannot sit inside a
200
+ // button, so the menu carries the link: without it a page in the app on a
201
+ // phone would have no way to where the registry sends the maker's name,
202
+ // which for the hosted cloud is its Impressum.
203
+ it("links the maker's name at the foot of the compact menu, where the registry says", async () => {
204
+ setViewportWidth(600);
205
+ renderSwitcher({ path: '/workspace', makerLink: '/impressum' });
206
+ await userEvent.click(screen.getByRole('button', { name: 'Switch app' }));
207
+ const link = within(screen.getByRole('menu')).getByRole('menuitem', { name: 'Hexis by Bevel' });
208
+ expect(link).toHaveAttribute('href', '/impressum');
209
+ expect(link).toHaveAttribute('target', '_blank');
210
+ });
211
+
212
+ // The hosted cloud's Impressum must be recognisable as one from a page in
213
+ // the app, not only behind the maker's name.
214
+ it("names the maker's link in the compact menu as the registry says", async () => {
215
+ setViewportWidth(600);
216
+ renderSwitcher({ path: '/workspace', makerLink: '/impressum', makerLinkLabel: 'Impressum' });
217
+ await userEvent.click(screen.getByRole('button', { name: 'Switch app' }));
218
+ const link = within(screen.getByRole('menu')).getByRole('menuitem', { name: 'Impressum' });
219
+ expect(link).toHaveAttribute('href', '/impressum');
220
+ expect(within(screen.getByRole('menu')).queryByRole('menuitem', { name: 'Hexis by Bevel' })).toBeNull();
221
+ });
222
+
223
+ it("names it after the product when the registry's label is blank, as when it is absent", async () => {
224
+ setViewportWidth(600);
225
+ renderSwitcher({ path: '/workspace', makerLink: '/impressum', makerLinkLabel: ' ' });
226
+ await userEvent.click(screen.getByRole('button', { name: 'Switch app' }));
227
+ expect(within(screen.getByRole('menu')).getByRole('menuitem', { name: 'Hexis by Bevel' })).toHaveAttribute(
228
+ 'href',
229
+ '/impressum',
230
+ );
231
+ });
232
+ });
233
+
234
+ /**
235
+ * The menu is what more than three apps get, so these run against a
236
+ * four-app registry; the compact case is covered by the fallback test above.
237
+ */
238
+ describe('AppSwitcher as a menu (more than three apps)', () => {
239
+ const renderMenu = (opts?: { path?: string; shellActiveId?: string }) =>
240
+ renderSwitcher({ ...opts, extraApps: [assistantApp, insightsApp] });
241
+
68
242
  it('renders the brand as the trigger and no menu until clicked', () => {
69
- renderSwitcher();
70
- expect(screen.getByText('Bevel')).toBeInTheDocument();
243
+ renderMenu();
244
+ expect(screen.getByText('Hexis by Bevel')).toBeInTheDocument();
71
245
  expect(screen.queryByRole('menu')).not.toBeInTheDocument();
72
246
  });
73
247
 
74
248
  it('names the current app next to the brand', () => {
75
- renderSwitcher({ path: '/skills-and-tools' });
249
+ renderMenu({ path: '/skills-and-tools' });
76
250
  const trigger = screen.getByRole('button', { name: 'Switch app' });
77
251
  expect(trigger).toHaveTextContent('Bevel');
78
252
  expect(trigger).toHaveTextContent('Skills & Tools');
79
253
  });
80
254
 
81
255
  it('names the current app on a deep link inside it', () => {
82
- renderSwitcher({ path: '/workspace/main/Skills' });
256
+ renderMenu({ path: '/workspace/main/Skills' });
83
257
  expect(screen.getByRole('button', { name: 'Switch app' })).toHaveTextContent(
84
258
  'Knowledge',
85
259
  );
@@ -92,7 +266,7 @@ describe('AppSwitcher', () => {
92
266
  * name the surface on screen, not the app that owns the URL prefix.
93
267
  */
94
268
  it('honours a shell-provided active app over the URL prefix', () => {
95
- renderSwitcher({
269
+ renderMenu({
96
270
  path: '/workspace/main/knowledge-base/Plugins/Sales/create-sales-deck/SKILL.md',
97
271
  shellActiveId: 'skills-tools',
98
272
  });
@@ -102,7 +276,7 @@ describe('AppSwitcher', () => {
102
276
  });
103
277
 
104
278
  it('shows the brand alone where no app is active', () => {
105
- renderSwitcher({ path: '/secrets' });
279
+ renderMenu({ path: '/secrets' });
106
280
  const trigger = screen.getByRole('button', { name: 'Switch app' });
107
281
  expect(trigger).toHaveTextContent('Bevel');
108
282
  expect(trigger).not.toHaveTextContent('Knowledge');
@@ -110,7 +284,7 @@ describe('AppSwitcher', () => {
110
284
  });
111
285
 
112
286
  it('updates the named app after switching', async () => {
113
- renderSwitcher({ path: '/workspace' });
287
+ renderMenu({ path: '/workspace' });
114
288
  await userEvent.click(screen.getByRole('button', { name: 'Switch app' }));
115
289
  await userEvent.click(screen.getByRole('menuitem', { name: /Skills & Tools/ }));
116
290
  expect(screen.getByRole('button', { name: 'Switch app' })).toHaveTextContent(
@@ -119,7 +293,7 @@ describe('AppSwitcher', () => {
119
293
  });
120
294
 
121
295
  it('opens the Apps list with the two core apps', async () => {
122
- renderSwitcher();
296
+ renderMenu();
123
297
  await userEvent.click(screen.getByRole('button', { name: 'Switch app' }));
124
298
  const menu = screen.getByRole('menu');
125
299
  expect(within(menu).getByText('Apps')).toBeInTheDocument();
@@ -128,38 +302,42 @@ describe('AppSwitcher', () => {
128
302
  });
129
303
 
130
304
  it('appends registry-contributed apps after the core ones', async () => {
131
- renderSwitcher({ extraApps: true });
305
+ renderMenu();
132
306
  await userEvent.click(screen.getByRole('button', { name: 'Switch app' }));
133
307
  const items = screen.getAllByRole('menuitem');
134
308
  expect(items.map((i) => i.textContent)).toEqual([
135
309
  expect.stringContaining('Knowledge'),
136
310
  expect.stringContaining('Skills & Tools'),
137
311
  expect.stringContaining('Assistant'),
312
+ expect.stringContaining('Insights'),
313
+ // Then the maker's link, to the maker's site unless the registry says otherwise.
314
+ 'Hexis by Bevel',
138
315
  ]);
316
+ expect(items.at(-1)).toHaveAttribute('href', 'https://bevel.software');
139
317
  });
140
318
 
141
319
  it('marks the app matching the current location as current', async () => {
142
- renderSwitcher({ path: '/skills-and-tools' });
320
+ renderMenu({ path: '/skills-and-tools' });
143
321
  await userEvent.click(screen.getByRole('button', { name: 'Switch app' }));
144
322
  const current = screen.getByLabelText('Current app');
145
323
  expect(current.closest('[role="menuitem"]')).toHaveTextContent('Skills & Tools');
146
324
  });
147
325
 
148
326
  it('marks Knowledge as current on a KB deep link', async () => {
149
- renderSwitcher({ path: '/workspace/main/Skills' });
327
+ renderMenu({ path: '/workspace/main/Skills' });
150
328
  await userEvent.click(screen.getByRole('button', { name: 'Switch app' }));
151
329
  const current = screen.getByLabelText('Current app');
152
330
  expect(current.closest('[role="menuitem"]')).toHaveTextContent('Knowledge');
153
331
  });
154
332
 
155
333
  it('marks no app as current on a standalone settings page', async () => {
156
- renderSwitcher({ path: '/secrets' });
334
+ renderMenu({ path: '/secrets' });
157
335
  await userEvent.click(screen.getByRole('button', { name: 'Switch app' }));
158
336
  expect(screen.queryByLabelText('Current app')).not.toBeInTheDocument();
159
337
  });
160
338
 
161
339
  it('navigates to the selected app and closes the menu', async () => {
162
- renderSwitcher();
340
+ renderMenu();
163
341
  await userEvent.click(screen.getByRole('button', { name: 'Switch app' }));
164
342
  await userEvent.click(screen.getByRole('menuitem', { name: /Skills & Tools/ }));
165
343
  expect(screen.getByTestId('pathname')).toHaveTextContent('/skills-and-tools');
@@ -167,7 +345,7 @@ describe('AppSwitcher', () => {
167
345
  });
168
346
 
169
347
  it('closes on Escape without navigating', async () => {
170
- renderSwitcher();
348
+ renderMenu();
171
349
  await userEvent.click(screen.getByRole('button', { name: 'Switch app' }));
172
350
  await userEvent.keyboard('{Escape}');
173
351
  expect(screen.queryByRole('menu')).not.toBeInTheDocument();
@@ -0,0 +1,64 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { render, screen, within } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import { MemoryRouter } from 'react-router-dom';
5
+ import { AuthContext, type AuthContextValue } from '../../../auth/state/auth.context';
6
+ import { AdminContext } from '../../../admin/state/admin.context';
7
+ import type { AdminMenuItem } from '../../../../core/registry';
8
+ import { ProfileMenu } from '../ProfileMenu';
9
+
10
+ // Every admin row hidden from this person — not reachable with today's core
11
+ // rows, which are always shown, so the sections are stubbed here.
12
+ const hidden = (id: string, label: string): AdminMenuItem => ({
13
+ id,
14
+ section: 'admin',
15
+ label,
16
+ path: `/${id}`,
17
+ isShown: () => false,
18
+ });
19
+
20
+ vi.mock('../../../settings/settings-nav-items', () => ({
21
+ useMenuSections: () => ({
22
+ defaultItems: [{ id: 'account', label: 'Account', path: '/account' }],
23
+ adminItems: [hidden('hidden-a', 'Hidden A'), hidden('hidden-b', 'Hidden B')],
24
+ }),
25
+ }));
26
+
27
+ const auth: AuthContextValue = {
28
+ user: { id: 'user-1', email: 'user@example.com', name: 'Test User', avatarUrl: '' },
29
+ token: 'token',
30
+ isLoading: false,
31
+ login: async () => {},
32
+ logout: () => {},
33
+ };
34
+
35
+ describe('ProfileMenu', () => {
36
+ it('draws no Admin only section when every admin row is hidden', async () => {
37
+ render(
38
+ <MemoryRouter>
39
+ <AuthContext.Provider value={auth}>
40
+ <AdminContext.Provider
41
+ value={{
42
+ isAdmin: true,
43
+ unreadCount: 0,
44
+ lastSeen: null,
45
+ markSeen: () => {},
46
+ refresh: () => {},
47
+ rolesConfigCorrupted: false,
48
+ rolesConfigErrors: [],
49
+ runRolesRecovery: async () => {},
50
+ }}
51
+ >
52
+ <ProfileMenu />
53
+ </AdminContext.Provider>
54
+ </AuthContext.Provider>
55
+ </MemoryRouter>,
56
+ );
57
+ await userEvent.click(screen.getByRole('button', { name: 'Test User' }));
58
+ const panel = screen.getByRole('group', { name: 'You and your settings' });
59
+ expect(within(panel).getByRole('button', { name: 'Account' })).toBeInTheDocument();
60
+ expect(within(panel).queryByText('Admin only')).toBeNull();
61
+ expect(within(panel).queryByRole('group')).toBeNull();
62
+ expect(within(panel).queryByRole('button', { name: /Hidden/ })).toBeNull();
63
+ });
64
+ });