@bevel-software/platform-core-frontend 0.4.0 → 0.5.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 +5 -3
- package/src/core/CoreAppShell.tsx +195 -56
- package/src/core/__tests__/AppChrome.test.tsx +125 -0
- package/src/core/__tests__/ShellRoutes.test.tsx +130 -95
- package/src/core/__tests__/bootstrap.test.ts +63 -0
- package/src/core/bootstrap.ts +73 -0
- package/src/core/events.ts +12 -0
- package/src/core/registry.ts +58 -9
- package/src/index.css +100 -11
- package/src/index.ts +24 -23
- package/src/lib/utils.ts +114 -138
- package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +281 -0
- package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +166 -1
- package/src/modules/access/api.ts +49 -0
- package/src/modules/access/components/ManageAccessDialog.tsx +786 -481
- package/src/modules/access/hooks/useFileAccess.ts +1 -1
- package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +86 -0
- package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +172 -156
- package/src/modules/admin/__tests__/admin.unread.test.tsx +61 -0
- package/src/modules/admin/components/AdminRolesPage.tsx +44 -38
- package/src/modules/admin/components/RolesCorruptedBanner.tsx +11 -10
- package/src/modules/admin/components/UserAccountsPage.tsx +361 -353
- package/src/modules/admin/state/admin.context.tsx +15 -6
- package/src/modules/auth/components/AccountPage.tsx +11 -11
- package/src/modules/auth/components/LoginScreen.tsx +12 -12
- package/src/modules/auth/services/sso.ts +47 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +277 -0
- package/src/modules/change-requests/__tests__/author.test.ts +48 -0
- package/src/modules/change-requests/__tests__/conflict.test.ts +73 -0
- package/src/modules/change-requests/__tests__/diff.test.ts +134 -0
- package/src/modules/change-requests/__tests__/propose.test.ts +93 -0
- package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +72 -0
- package/src/modules/change-requests/change-requests.css +22 -0
- package/src/modules/change-requests/components/ChangeBox.tsx +277 -0
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +713 -0
- package/src/modules/change-requests/components/ConflictHelp.tsx +47 -0
- package/src/modules/change-requests/components/CrFileTree.tsx +398 -0
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +168 -0
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +236 -0
- package/src/modules/change-requests/hooks/useCrFileDiffs.ts +79 -0
- package/src/modules/change-requests/hooks/useFileOnBranch.ts +80 -0
- package/src/modules/change-requests/services/change-requests.api.ts +45 -0
- package/src/modules/change-requests/services/propose.api.ts +162 -0
- package/src/modules/change-requests/utils/author.ts +47 -0
- package/src/modules/change-requests/utils/conflict.ts +38 -0
- package/src/modules/change-requests/utils/diff.ts +80 -0
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +27 -18
- package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +36 -83
- package/src/modules/git/__tests__/PullNeededBanner.test.tsx +5 -5
- package/src/modules/git/__tests__/PullRequestsForMe.test.tsx +147 -0
- package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +2 -8
- package/src/modules/git/components/BranchSwitcher.tsx +68 -31
- package/src/modules/git/components/DiffView.tsx +4 -4
- package/src/modules/git/components/FileComparisonPanel.tsx +20 -20
- package/src/modules/git/components/FileHistoryPanel.tsx +71 -107
- package/src/modules/git/components/PullNeededBanner.tsx +6 -13
- package/src/modules/git/components/PullRequestsForMe.tsx +71 -36
- package/src/modules/git/components/UnifiedDiffView.tsx +4 -4
- package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +2 -2
- package/src/modules/git/hooks/useGitState.ts +15 -14
- package/src/modules/git/services/__tests__/error-messages.test.ts +4 -4
- package/src/modules/git/services/error-messages.ts +7 -7
- package/src/modules/git/services/git.api.ts +17 -11
- package/src/modules/git/services/pr-prompts.ts +2 -2
- package/src/modules/git/state/git.context.ts +10 -1
- package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +224 -0
- package/src/modules/layout/__tests__/SidebarToggle.test.tsx +242 -0
- package/src/modules/layout/__tests__/breakpoints.test.ts +56 -0
- package/src/modules/layout/breakpoints.ts +6 -0
- package/src/modules/layout/components/AppLayout.tsx +17 -5
- package/src/modules/layout/components/DemoBanner.tsx +10 -1
- package/src/modules/layout/components/MaintenanceOverlay.tsx +104 -104
- package/src/modules/layout/components/MobileChatLayout.tsx +31 -26
- package/src/modules/layout/components/ResizableThreePaneLayout.tsx +59 -24
- package/src/modules/layout/components/SidebarFrame.tsx +317 -0
- package/src/modules/layout/components/SidebarToggle.tsx +86 -0
- package/src/modules/layout/components/SlideOverlay.tsx +1 -1
- package/src/modules/layout/components/__tests__/MobileChatLayout.test.tsx +40 -2
- package/src/modules/layout/components/__tests__/ResizableThreePaneLayout.test.tsx +19 -3
- package/src/modules/layout/state/sidebar.ts +200 -0
- package/src/modules/library/__tests__/AddToGroupDialog.test.tsx +313 -0
- package/src/modules/library/__tests__/ChangeRequestDock.test.tsx +84 -0
- package/src/modules/library/__tests__/GroupJoinRequests.test.tsx +178 -0
- package/src/modules/library/__tests__/GroupPage.test.tsx +479 -0
- package/src/modules/library/__tests__/GroupsIndexPage.test.tsx +283 -0
- package/src/modules/library/__tests__/GroupsSidebar.contextmenu.test.tsx +175 -0
- package/src/modules/library/__tests__/GroupsSidebar.locked.test.tsx +96 -0
- package/src/modules/library/__tests__/GroupsSidebar.test.tsx +142 -0
- package/src/modules/library/__tests__/GroupsSidebarMenu.test.tsx +142 -0
- package/src/modules/library/__tests__/LibraryCard.test.tsx +149 -0
- package/src/modules/library/__tests__/LibraryRoutes.test.tsx +378 -0
- package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +347 -0
- package/src/modules/library/__tests__/LockedGroupView.test.tsx +203 -0
- package/src/modules/library/__tests__/NewGroupDialog.test.tsx +114 -0
- package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +177 -0
- package/src/modules/library/__tests__/SkillPage.test.tsx +1063 -0
- package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +259 -0
- package/src/modules/library/__tests__/ToolLogo.test.tsx +63 -0
- package/src/modules/library/__tests__/ToolPage.test.tsx +315 -0
- package/src/modules/library/__tests__/ToolSharePanel.test.tsx +36 -0
- package/src/modules/library/__tests__/ToolVarRow.test.tsx +260 -0
- package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +197 -0
- package/src/modules/library/__tests__/auth-harness.tsx +37 -0
- package/src/modules/library/__tests__/oauth-fragment.test.ts +48 -0
- package/src/modules/library/__tests__/status.test.ts +210 -117
- package/src/modules/library/__tests__/useSkillDetail.test.tsx +102 -0
- package/src/modules/library/__tests__/useToolPage.test.tsx +146 -0
- package/src/modules/library/components/AccessRequestsBanner.tsx +101 -0
- package/src/modules/library/components/AddToGroupDialog.tsx +115 -0
- package/src/modules/library/components/ChangeRequestDock.tsx +71 -47
- package/src/modules/library/components/DeleteGroupDialog.tsx +87 -0
- package/src/modules/library/components/GroupIndexRow.tsx +63 -0
- package/src/modules/library/components/GroupJoinRequests.tsx +56 -0
- package/src/modules/library/components/GroupPage.tsx +373 -0
- package/src/modules/library/components/GroupsIndexPage.tsx +222 -0
- package/src/modules/library/components/GroupsSidebar.tsx +338 -0
- package/src/modules/library/components/GroupsSidebarMenu.tsx +160 -0
- package/src/modules/library/components/LibraryCard.tsx +153 -132
- package/src/modules/library/components/LibraryLayout.tsx +344 -0
- package/src/modules/library/components/LibraryPage.tsx +138 -254
- package/src/modules/library/components/LockGlyph.tsx +31 -0
- package/src/modules/library/components/LockedGroupView.tsx +159 -0
- package/src/modules/library/components/ManagedGroupRequests.tsx +70 -0
- package/src/modules/library/components/NewGroupDialog.tsx +112 -0
- package/src/modules/library/components/NewSkillPanel.tsx +151 -0
- package/src/modules/library/components/PageActions.tsx +156 -0
- package/src/modules/library/components/PendingSkillReview.tsx +63 -0
- package/src/modules/library/components/PersonalAddDialog.tsx +88 -0
- package/src/modules/library/components/PersonalGroupPage.tsx +125 -0
- package/src/modules/library/components/StatusDot.tsx +25 -0
- package/src/modules/library/components/ToolLogo.tsx +171 -0
- package/src/modules/library/components/group-page-parts.tsx +419 -0
- package/src/modules/library/components/skill-page/SkillFileEditor.tsx +134 -0
- package/src/modules/library/components/skill-page/SkillFilePane.tsx +117 -0
- package/src/modules/library/components/skill-page/SkillFileTabs.tsx +112 -0
- package/src/modules/library/components/skill-page/SkillPage.tsx +673 -0
- package/src/modules/library/components/skill-page/tab-ids.ts +33 -0
- package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +175 -0
- package/src/modules/library/components/tool-page/ToolPage.tsx +228 -0
- package/src/modules/library/components/tool-page/ToolSharePanel.tsx +45 -0
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +289 -0
- package/src/modules/library/hooks/useJoinRequests.ts +114 -0
- package/src/modules/library/hooks/useLibraryData.ts +134 -119
- package/src/modules/library/hooks/useSkillDetail.ts +119 -74
- package/src/modules/library/hooks/useToolPage.ts +145 -0
- package/src/modules/library/library.css +108 -320
- package/src/modules/library/routes/LibraryRoutes.tsx +134 -0
- package/src/modules/library/routes/WorkspaceItemRoute.tsx +74 -0
- package/src/modules/library/routes/library-paths.ts +191 -0
- package/src/modules/library/services/groups.api.ts +189 -0
- package/src/modules/library/services/library.api.ts +291 -164
- package/src/modules/library/services/tools.api.ts +60 -0
- package/src/modules/library/state/library-context.ts +22 -0
- package/src/modules/library/state/library-data.tsx +223 -0
- package/src/modules/library/state/toast.context.ts +32 -0
- package/src/modules/library/state/toast.tsx +84 -42
- package/src/modules/library/utils/clipboard.ts +33 -0
- package/src/modules/library/utils/group-summary.ts +68 -0
- package/src/modules/library/utils/names.ts +30 -0
- package/src/modules/library/utils/navigate-external.ts +15 -0
- package/src/modules/library/utils/oauth-fragment.ts +32 -0
- package/src/modules/library/utils/personal-group.ts +36 -0
- package/src/modules/library/utils/status.ts +199 -116
- package/src/modules/library/utils/toast-duration.ts +16 -0
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +533 -0
- package/src/modules/onboarding/agent-clients.ts +48 -0
- package/src/modules/onboarding/components/ConnectAgentPill.tsx +133 -0
- package/src/modules/onboarding/components/RootLanding.tsx +54 -0
- package/src/modules/onboarding/components/WelcomePage.tsx +364 -0
- package/src/modules/onboarding/paths.ts +9 -0
- package/src/modules/onboarding/state/onboarding.ts +191 -0
- package/src/modules/pr/components/OpenChangeRequestDialog.tsx +10 -10
- package/src/modules/pr/services/pr-approvals.api.ts +19 -0
- package/src/modules/pr/services/pr-cancel.api.ts +11 -0
- package/src/modules/review/components/BinaryChangePlaceholder.tsx +3 -3
- package/src/modules/review/components/DiffViewer.tsx +4 -4
- package/src/modules/review/components/MarkdownDiffViewer.tsx +84 -26
- package/src/modules/review/components/ReviewFileRow.tsx +10 -10
- package/src/modules/review/components/ReviewPanel.tsx +49 -17
- package/src/modules/review/components/ReviewPanelSurface.tsx +1 -1
- package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +122 -0
- package/src/modules/review/hooks/__tests__/useReviewState.test.ts +1 -1
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +273 -171
- package/src/modules/secrets-vault/components/SecretsPage.tsx +313 -276
- package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +109 -92
- package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +82 -51
- package/src/modules/secrets-vault/services/connect.api.ts +24 -3
- package/src/modules/settings/components/DeploymentPage.tsx +90 -0
- package/src/modules/settings/components/SettingsLayout.tsx +135 -0
- package/src/modules/settings/components/SettingsNav.tsx +114 -0
- package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +110 -0
- package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +249 -0
- package/src/modules/settings/settings-nav-items.tsx +166 -0
- package/src/modules/setup/__tests__/setup.test.tsx +540 -0
- package/src/modules/setup/components/SetupGate.tsx +67 -0
- package/src/modules/setup/components/SetupScreen.tsx +573 -0
- package/src/modules/setup/services/setup.api.ts +106 -0
- package/src/modules/setup/utils/git-host.ts +34 -0
- package/src/modules/toolbar/components/AppSwitcher.tsx +131 -108
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +548 -548
- package/src/modules/toolbar/components/ProfileMenu.tsx +294 -0
- package/src/modules/toolbar/components/Toolbar.tsx +56 -54
- package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +176 -122
- package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +252 -77
- package/src/modules/tools/ToolsExplorerPage.tsx +45 -40
- package/src/modules/workspace/__tests__/design-system-parity.test.ts +133 -0
- package/src/modules/workspace/__tests__/testFixtures.ts +2 -0
- package/src/modules/workspace/components/EditorTabs.tsx +82 -50
- package/src/modules/workspace/components/FileExplorer.tsx +1292 -1068
- package/src/modules/workspace/components/FilePaneCard.tsx +53 -0
- package/src/modules/workspace/components/FileRoute.tsx +89 -84
- package/src/modules/workspace/components/FileViewer.tsx +1312 -906
- package/src/modules/workspace/components/KbDocumentShell.tsx +138 -0
- package/src/modules/workspace/components/KbFileRail.tsx +128 -0
- package/src/modules/workspace/components/KbPageHeader.tsx +390 -0
- package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +87 -3
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +293 -39
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +1 -16
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +462 -44
- package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +84 -0
- package/src/modules/workspace/components/__tests__/KbFileRail.test.tsx +83 -0
- package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +192 -0
- package/src/modules/workspace/components/renderers/CopyAnchorButton.tsx +64 -0
- package/src/modules/workspace/components/renderers/CsvRenderer.tsx +8 -8
- package/src/modules/workspace/components/renderers/DocxRenderer.tsx +18 -9
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +14 -14
- package/src/modules/workspace/components/renderers/ImageRenderer.tsx +2 -2
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +31 -165
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +18 -5
- package/src/modules/workspace/components/renderers/MermaidDiagram.tsx +27 -10
- package/src/modules/workspace/components/renderers/PdfRenderer.tsx +2 -2
- package/src/modules/workspace/components/renderers/TextRenderer.tsx +11 -5
- package/src/modules/workspace/components/renderers/ToolForm.tsx +24 -24
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +27 -27
- package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -11
- package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +66 -0
- package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +17 -1
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +1 -1
- package/src/modules/workspace/components/renderers/__tests__/MermaidDiagram.test.tsx +58 -0
- package/src/modules/workspace/components/renderers/__tests__/lazyRenderer.test.tsx +68 -0
- package/src/modules/workspace/components/renderers/__tests__/rendererLayout.test.ts +64 -0
- package/src/modules/workspace/components/renderers/__tests__/sanitizeDocxHtml.test.ts +0 -0
- package/src/modules/workspace/components/renderers/chunk-boundary.tsx +71 -0
- package/src/modules/workspace/components/renderers/index.ts +78 -2
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +241 -0
- package/src/modules/workspace/components/renderers/lazyRenderer.tsx +59 -0
- package/src/modules/workspace/components/renderers/sanitizeDocxHtml.ts +91 -0
- package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +59 -0
- package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +237 -0
- package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +185 -0
- package/src/modules/workspace/hooks/useAutoGrowTextarea.ts +30 -0
- package/src/modules/workspace/hooks/useLastCommit.ts +66 -0
- package/src/modules/workspace/hooks/useLinksOut.ts +56 -0
- package/src/modules/workspace/hooks/useOpenChangeRequests.ts +20 -0
- package/src/modules/workspace/hooks/useWorkspaceState.ts +123 -14
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +1 -1
- package/src/modules/workspace/services/workspace.api.ts +9 -2
- package/src/modules/workspace/state/open-change-requests.context.ts +35 -0
- package/src/modules/workspace/state/open-change-requests.tsx +185 -0
- package/src/modules/workspace/state/workspace.context.ts +9 -0
- package/src/modules/workspace/utils/__tests__/diff.test.ts +87 -0
- package/src/modules/workspace/utils/diff.ts +130 -53
- package/src/modules/workspace/utils/fileTree.ts +182 -179
- package/src/modules/workspace/workspace.css +28 -0
- package/src/shared/components/Badge.tsx +62 -0
- package/src/shared/components/Banner.tsx +58 -0
- package/src/shared/components/Button.tsx +90 -0
- package/src/shared/components/Dialog.tsx +6 -6
- package/src/shared/components/Field.tsx +45 -0
- package/src/shared/components/IconButton.tsx +74 -0
- package/src/shared/components/ListRow.tsx +96 -0
- package/src/shared/components/Menu.tsx +88 -0
- package/src/shared/components/PageShell.tsx +54 -51
- package/src/shared/components/Surface.tsx +86 -0
- package/src/shared/components/__tests__/primitives.test.tsx +333 -0
- package/src/shared/components/index.ts +48 -0
- package/src/shared/components/useDismissableMenu.ts +71 -0
- package/src/shared/theme/__tests__/accent-contrast.test.ts +84 -0
- package/src/shared/theme/index.css +12 -0
- package/src/shared/theme/measure.ts +64 -0
- package/src/shared/theme/shadows.css +34 -0
- package/src/shared/theme/tokens.css +193 -0
- package/src/test-setup.ts +9 -0
- package/src/modules/access/components/AccessRestrictedBanner.tsx +0 -31
- package/src/modules/access/components/NodeOwnersBanner.tsx +0 -30
- package/src/modules/git/__tests__/ProtectedBranchBanner.test.tsx +0 -82
- package/src/modules/git/components/ProtectedBranchBanner.tsx +0 -42
- package/src/modules/library/__tests__/DetailDialog.test.tsx +0 -200
- package/src/modules/library/__tests__/diff.test.ts +0 -62
- package/src/modules/library/__tests__/loadout.test.tsx +0 -72
- package/src/modules/library/components/CompareView.tsx +0 -357
- package/src/modules/library/components/DetailDialog.tsx +0 -566
- package/src/modules/library/components/GearIcon.tsx +0 -12
- package/src/modules/library/components/LoadoutSidebar.tsx +0 -156
- package/src/modules/library/components/StatusGem.tsx +0 -21
- package/src/modules/library/components/SuggestChange.tsx +0 -171
- package/src/modules/library/components/particles.ts +0 -50
- package/src/modules/library/state/loadout.tsx +0 -129
- package/src/modules/library/utils/diff.ts +0 -102
- package/src/modules/pr/__tests__/PrApprovalBadge.test.tsx +0 -93
- package/src/modules/pr/__tests__/PrCancelButton.test.tsx +0 -158
- package/src/modules/pr/__tests__/PrCancelConfirmDialog.test.tsx +0 -44
- package/src/modules/pr/__tests__/PrMergeButton.test.tsx +0 -360
- package/src/modules/pr/__tests__/bucketize-comments.test.ts +0 -85
- package/src/modules/pr/__tests__/parsePatch.test.ts +0 -104
- package/src/modules/pr/__tests__/usePrViewerState.test.ts +0 -72
- package/src/modules/pr/components/PrApprovalBadge.tsx +0 -80
- package/src/modules/pr/components/PrCancelButton.tsx +0 -99
- package/src/modules/pr/components/PrCancelConfirmDialog.tsx +0 -119
- package/src/modules/pr/components/PrCommentComposer.tsx +0 -92
- package/src/modules/pr/components/PrCommentThread.tsx +0 -168
- package/src/modules/pr/components/PrCommentsPanel.tsx +0 -143
- package/src/modules/pr/components/PrDiffPane.tsx +0 -425
- package/src/modules/pr/components/PrFileRow.tsx +0 -164
- package/src/modules/pr/components/PrFilesList.tsx +0 -53
- package/src/modules/pr/components/PrHeader.tsx +0 -45
- package/src/modules/pr/components/PrHeaderOverflowMenu.tsx +0 -58
- package/src/modules/pr/components/PrMergeButton.tsx +0 -268
- package/src/modules/pr/components/PrMergeConfirmDialog.tsx +0 -112
- package/src/modules/pr/components/PrRefreshFromTargetButton.tsx +0 -110
- package/src/modules/pr/components/PrViewer.tsx +0 -364
- package/src/modules/pr/hooks/usePrViewerState.ts +0 -150
- package/src/modules/pr/state/pr-viewer.context.ts +0 -34
- package/src/modules/pr/utils/bucketize-comments.ts +0 -55
- package/src/modules/pr/utils/parsePatch.ts +0 -57
- package/src/modules/toolbar/components/AdminMenu.tsx +0 -271
|
@@ -136,7 +136,7 @@ export function useFileAccess(
|
|
|
136
136
|
|
|
137
137
|
/**
|
|
138
138
|
* Render-helper for the "you don't have permission to edit this file" copy.
|
|
139
|
-
* Used
|
|
139
|
+
* Used as a tooltip on disabled save
|
|
140
140
|
* buttons.
|
|
141
141
|
*/
|
|
142
142
|
export function formatEligible(eligible: AccessEligible): string {
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { AdminRolesPage } from '../components/AdminRolesPage';
|
|
5
|
+
import { AdminContext } from '../state/admin.context';
|
|
6
|
+
import { fetchRoles, type RoleRosterEntry } from '../services/roles.api';
|
|
7
|
+
import { suggestPrincipals } from '../../access/api';
|
|
8
|
+
|
|
9
|
+
vi.mock('../services/roles.api', async (importOriginal) => {
|
|
10
|
+
const actual = await importOriginal<typeof import('../services/roles.api')>();
|
|
11
|
+
return {
|
|
12
|
+
...actual,
|
|
13
|
+
fetchRoles: vi.fn(),
|
|
14
|
+
addMember: vi.fn(),
|
|
15
|
+
removeMember: vi.fn(),
|
|
16
|
+
createRole: vi.fn(),
|
|
17
|
+
deleteRole: vi.fn(),
|
|
18
|
+
renameRole: vi.fn(),
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
vi.mock('../../access/api', async (importOriginal) => {
|
|
22
|
+
const actual = await importOriginal<typeof import('../../access/api')>();
|
|
23
|
+
return { ...actual, suggestPrincipals: vi.fn() };
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const ENGINEERING: RoleRosterEntry = {
|
|
27
|
+
canonical: 'engineering',
|
|
28
|
+
displayName: 'Engineering',
|
|
29
|
+
members: [],
|
|
30
|
+
isAdmin: false,
|
|
31
|
+
referencedBy: [],
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function renderPage() {
|
|
35
|
+
return render(
|
|
36
|
+
<AdminContext.Provider
|
|
37
|
+
value={{
|
|
38
|
+
isAdmin: true,
|
|
39
|
+
unreadCount: 0,
|
|
40
|
+
lastSeen: null,
|
|
41
|
+
markSeen: () => {},
|
|
42
|
+
refresh: () => {},
|
|
43
|
+
rolesConfigCorrupted: false,
|
|
44
|
+
rolesConfigErrors: [],
|
|
45
|
+
runRolesRecovery: async () => {},
|
|
46
|
+
}}
|
|
47
|
+
>
|
|
48
|
+
<AdminRolesPage />
|
|
49
|
+
</AdminContext.Provider>,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
vi.mocked(fetchRoles).mockReset().mockResolvedValue([ENGINEERING]);
|
|
55
|
+
vi.mocked(suggestPrincipals)
|
|
56
|
+
.mockReset()
|
|
57
|
+
.mockResolvedValue({
|
|
58
|
+
groups: [],
|
|
59
|
+
people: [{ name: 'Alice', email: 'alice@example.com' }],
|
|
60
|
+
peopleWithheld: false,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('AdminRolesPage: add-member autocomplete', () => {
|
|
65
|
+
it('caps the suggestion list at its wrapper so it cannot overflow the card', async () => {
|
|
66
|
+
const user = userEvent.setup();
|
|
67
|
+
renderPage();
|
|
68
|
+
|
|
69
|
+
const input = await screen.findByRole('textbox', { name: 'Member email' });
|
|
70
|
+
await user.type(input, 'al');
|
|
71
|
+
|
|
72
|
+
// The suggest fetch is debounced 200ms; wait for the list to materialise.
|
|
73
|
+
const alice = await screen.findByText(
|
|
74
|
+
'alice@example.com',
|
|
75
|
+
undefined,
|
|
76
|
+
{ timeout: 2000 },
|
|
77
|
+
);
|
|
78
|
+
const list = alice.closest('ul')!;
|
|
79
|
+
|
|
80
|
+
// The wrapper is `flex-1 min-w-0 max-w-[16rem]` and can shrink below
|
|
81
|
+
// 16rem; the list forces `sm:w-72` (18rem) at the sm breakpoint. Without
|
|
82
|
+
// `max-w-full` the absolutely-positioned list escapes the shrinking
|
|
83
|
+
// wrapper and runs past the card border on narrow viewports.
|
|
84
|
+
expect(list.className).toContain('max-w-full');
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -1,156 +1,172 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
import { render, screen, waitFor, within } from '@testing-library/react';
|
|
3
|
-
import userEvent from '@testing-library/user-event';
|
|
4
|
-
import { UserAccountsPage } from '../components/UserAccountsPage';
|
|
5
|
-
import { AdminContext } from '../state/admin.context';
|
|
6
|
-
import { AuthContext, type AuthContextValue } from '../../auth/state/auth.context';
|
|
7
|
-
import {
|
|
8
|
-
createAccount,
|
|
9
|
-
deleteAccount,
|
|
10
|
-
listAccounts,
|
|
11
|
-
} from '../../auth/services/account.api';
|
|
12
|
-
|
|
13
|
-
vi.mock('../../auth/services/account.api', () => ({
|
|
14
|
-
createAccount: vi.fn(),
|
|
15
|
-
deleteAccount: vi.fn(),
|
|
16
|
-
listAccounts: vi.fn(),
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
|
-
const ME = { id: 'admin-1', email: 'admin@example.com', name: 'Admin' };
|
|
20
|
-
const ALICE = {
|
|
21
|
-
id: 'u-alice',
|
|
22
|
-
email: 'alice@example.com',
|
|
23
|
-
name: 'Alice',
|
|
24
|
-
hasPassword: false,
|
|
25
|
-
createdAt: '2026-01-01T00:00:00Z',
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
function renderPage(opts: { isAdmin?: boolean } = {}) {
|
|
29
|
-
const auth: AuthContextValue = {
|
|
30
|
-
user: ME,
|
|
31
|
-
token: 't',
|
|
32
|
-
isLoading: false,
|
|
33
|
-
login: vi.fn(async () => {}),
|
|
34
|
-
logout: vi.fn(),
|
|
35
|
-
};
|
|
36
|
-
return render(
|
|
37
|
-
<AuthContext.Provider value={auth}>
|
|
38
|
-
<AdminContext.Provider
|
|
39
|
-
value={{
|
|
40
|
-
isAdmin: opts.isAdmin ?? true,
|
|
41
|
-
unreadCount: 0,
|
|
42
|
-
lastSeen: null,
|
|
43
|
-
markSeen: () => {},
|
|
44
|
-
refresh: () => {},
|
|
45
|
-
rolesConfigCorrupted: false,
|
|
46
|
-
rolesConfigErrors: [],
|
|
47
|
-
runRolesRecovery: async () => {},
|
|
48
|
-
}}
|
|
49
|
-
>
|
|
50
|
-
<UserAccountsPage />
|
|
51
|
-
</AdminContext.Provider>
|
|
52
|
-
</AuthContext.Provider>,
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
beforeEach(() => {
|
|
57
|
-
vi.mocked(listAccounts)
|
|
58
|
-
.mockReset()
|
|
59
|
-
.mockResolvedValue([
|
|
60
|
-
{ ...ME, hasPassword: true, createdAt: '2026-01-01T00:00:00Z' },
|
|
61
|
-
ALICE,
|
|
62
|
-
]);
|
|
63
|
-
vi.mocked(deleteAccount).mockReset().mockResolvedValue(undefined);
|
|
64
|
-
vi.mocked(createAccount).mockReset().mockResolvedValue(undefined);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('UserAccountsPage', () => {
|
|
68
|
-
it('shows the admins-only state (and never loads) for non-admins', () => {
|
|
69
|
-
renderPage({ isAdmin: false });
|
|
70
|
-
expect(screen.getByText(/Admins only/)).toBeInTheDocument();
|
|
71
|
-
expect(listAccounts).not.toHaveBeenCalled();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('lists accounts with sign-in method; own row offers no actions', async () => {
|
|
75
|
-
renderPage();
|
|
76
|
-
await waitFor(() => expect(screen.getByText('Alice')).toBeInTheDocument());
|
|
77
|
-
expect(screen.getByText(/Single sign-on only/)).toBeInTheDocument();
|
|
78
|
-
expect(
|
|
79
|
-
screen.getByRole('button', { name: 'Set password for alice@example.com' }),
|
|
80
|
-
).toBeInTheDocument();
|
|
81
|
-
expect(
|
|
82
|
-
screen.getByRole('button', { name: 'Delete account alice@example.com' }),
|
|
83
|
-
).toBeInTheDocument();
|
|
84
|
-
expect(
|
|
85
|
-
screen.queryByRole('button', { name: 'Set password for admin@example.com' }),
|
|
86
|
-
).not.toBeInTheDocument();
|
|
87
|
-
expect(
|
|
88
|
-
screen.queryByRole('button', { name: 'Delete account admin@example.com' }),
|
|
89
|
-
).not.toBeInTheDocument();
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('sets a password for a user WITHOUT touching their name', async () => {
|
|
93
|
-
renderPage();
|
|
94
|
-
await waitFor(() => screen.getByText('Alice'));
|
|
95
|
-
await userEvent.click(screen.getByRole('button', { name: 'Set password for alice@example.com' }));
|
|
96
|
-
const dialog = within(screen.getByRole('dialog'));
|
|
97
|
-
// Empty password → the confirm button stays disabled; nothing is sent.
|
|
98
|
-
expect(dialog.getByRole('button', { name: 'Set password' })).toBeDisabled();
|
|
99
|
-
await userEvent.type(dialog.getByLabelText('New password'), 'fresh-password-1');
|
|
100
|
-
await userEvent.click(dialog.getByRole('button', { name: 'Set password' }));
|
|
101
|
-
await waitFor(() =>
|
|
102
|
-
expect(createAccount).toHaveBeenCalledWith('alice@example.com', '', 'fresh-password-1'),
|
|
103
|
-
);
|
|
104
|
-
expect(await screen.findByRole('status')).toHaveTextContent(
|
|
105
|
-
'Password set for alice@example.com',
|
|
106
|
-
);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('deletes an account after confirmation', async () => {
|
|
110
|
-
renderPage();
|
|
111
|
-
await waitFor(() => screen.getByText('Alice'));
|
|
112
|
-
await userEvent.click(screen.getByRole('button', { name: 'Delete account alice@example.com' }));
|
|
113
|
-
const dialog = within(screen.getByRole('dialog'));
|
|
114
|
-
await userEvent.click(dialog.getByRole('button', { name: 'Delete account' }));
|
|
115
|
-
await waitFor(() => expect(deleteAccount).toHaveBeenCalledWith('u-alice'));
|
|
116
|
-
// List reloaded after the delete.
|
|
117
|
-
expect(listAccounts).toHaveBeenCalledTimes(2);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('a failed delete closes the dialog, surfaces the error, and does not reload', async () => {
|
|
121
|
-
vi.mocked(deleteAccount).mockRejectedValueOnce(new Error('Failed to erase user'));
|
|
122
|
-
renderPage();
|
|
123
|
-
await waitFor(() => screen.getByText('Alice'));
|
|
124
|
-
await userEvent.click(screen.getByRole('button', { name: 'Delete account alice@example.com' }));
|
|
125
|
-
const dialog = within(screen.getByRole('dialog'));
|
|
126
|
-
await userEvent.click(dialog.getByRole('button', { name: 'Delete account' }));
|
|
127
|
-
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
|
|
128
|
-
|
|
129
|
-
expect(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
await
|
|
139
|
-
await
|
|
140
|
-
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { render, screen, waitFor, within } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { UserAccountsPage } from '../components/UserAccountsPage';
|
|
5
|
+
import { AdminContext } from '../state/admin.context';
|
|
6
|
+
import { AuthContext, type AuthContextValue } from '../../auth/state/auth.context';
|
|
7
|
+
import {
|
|
8
|
+
createAccount,
|
|
9
|
+
deleteAccount,
|
|
10
|
+
listAccounts,
|
|
11
|
+
} from '../../auth/services/account.api';
|
|
12
|
+
|
|
13
|
+
vi.mock('../../auth/services/account.api', () => ({
|
|
14
|
+
createAccount: vi.fn(),
|
|
15
|
+
deleteAccount: vi.fn(),
|
|
16
|
+
listAccounts: vi.fn(),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
const ME = { id: 'admin-1', email: 'admin@example.com', name: 'Admin' };
|
|
20
|
+
const ALICE = {
|
|
21
|
+
id: 'u-alice',
|
|
22
|
+
email: 'alice@example.com',
|
|
23
|
+
name: 'Alice',
|
|
24
|
+
hasPassword: false,
|
|
25
|
+
createdAt: '2026-01-01T00:00:00Z',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function renderPage(opts: { isAdmin?: boolean } = {}) {
|
|
29
|
+
const auth: AuthContextValue = {
|
|
30
|
+
user: ME,
|
|
31
|
+
token: 't',
|
|
32
|
+
isLoading: false,
|
|
33
|
+
login: vi.fn(async () => {}),
|
|
34
|
+
logout: vi.fn(),
|
|
35
|
+
};
|
|
36
|
+
return render(
|
|
37
|
+
<AuthContext.Provider value={auth}>
|
|
38
|
+
<AdminContext.Provider
|
|
39
|
+
value={{
|
|
40
|
+
isAdmin: opts.isAdmin ?? true,
|
|
41
|
+
unreadCount: 0,
|
|
42
|
+
lastSeen: null,
|
|
43
|
+
markSeen: () => {},
|
|
44
|
+
refresh: () => {},
|
|
45
|
+
rolesConfigCorrupted: false,
|
|
46
|
+
rolesConfigErrors: [],
|
|
47
|
+
runRolesRecovery: async () => {},
|
|
48
|
+
}}
|
|
49
|
+
>
|
|
50
|
+
<UserAccountsPage />
|
|
51
|
+
</AdminContext.Provider>
|
|
52
|
+
</AuthContext.Provider>,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
vi.mocked(listAccounts)
|
|
58
|
+
.mockReset()
|
|
59
|
+
.mockResolvedValue([
|
|
60
|
+
{ ...ME, hasPassword: true, createdAt: '2026-01-01T00:00:00Z' },
|
|
61
|
+
ALICE,
|
|
62
|
+
]);
|
|
63
|
+
vi.mocked(deleteAccount).mockReset().mockResolvedValue(undefined);
|
|
64
|
+
vi.mocked(createAccount).mockReset().mockResolvedValue(undefined);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('UserAccountsPage', () => {
|
|
68
|
+
it('shows the admins-only state (and never loads) for non-admins', () => {
|
|
69
|
+
renderPage({ isAdmin: false });
|
|
70
|
+
expect(screen.getByText(/Admins only/)).toBeInTheDocument();
|
|
71
|
+
expect(listAccounts).not.toHaveBeenCalled();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('lists accounts with sign-in method; own row offers no actions', async () => {
|
|
75
|
+
renderPage();
|
|
76
|
+
await waitFor(() => expect(screen.getByText('Alice')).toBeInTheDocument());
|
|
77
|
+
expect(screen.getByText(/Single sign-on only/)).toBeInTheDocument();
|
|
78
|
+
expect(
|
|
79
|
+
screen.getByRole('button', { name: 'Set password for alice@example.com' }),
|
|
80
|
+
).toBeInTheDocument();
|
|
81
|
+
expect(
|
|
82
|
+
screen.getByRole('button', { name: 'Delete account alice@example.com' }),
|
|
83
|
+
).toBeInTheDocument();
|
|
84
|
+
expect(
|
|
85
|
+
screen.queryByRole('button', { name: 'Set password for admin@example.com' }),
|
|
86
|
+
).not.toBeInTheDocument();
|
|
87
|
+
expect(
|
|
88
|
+
screen.queryByRole('button', { name: 'Delete account admin@example.com' }),
|
|
89
|
+
).not.toBeInTheDocument();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('sets a password for a user WITHOUT touching their name', async () => {
|
|
93
|
+
renderPage();
|
|
94
|
+
await waitFor(() => screen.getByText('Alice'));
|
|
95
|
+
await userEvent.click(screen.getByRole('button', { name: 'Set password for alice@example.com' }));
|
|
96
|
+
const dialog = within(screen.getByRole('dialog'));
|
|
97
|
+
// Empty password → the confirm button stays disabled; nothing is sent.
|
|
98
|
+
expect(dialog.getByRole('button', { name: 'Set password' })).toBeDisabled();
|
|
99
|
+
await userEvent.type(dialog.getByLabelText('New password'), 'fresh-password-1');
|
|
100
|
+
await userEvent.click(dialog.getByRole('button', { name: 'Set password' }));
|
|
101
|
+
await waitFor(() =>
|
|
102
|
+
expect(createAccount).toHaveBeenCalledWith('alice@example.com', '', 'fresh-password-1'),
|
|
103
|
+
);
|
|
104
|
+
expect(await screen.findByRole('status')).toHaveTextContent(
|
|
105
|
+
'Password set for alice@example.com',
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('deletes an account after confirmation', async () => {
|
|
110
|
+
renderPage();
|
|
111
|
+
await waitFor(() => screen.getByText('Alice'));
|
|
112
|
+
await userEvent.click(screen.getByRole('button', { name: 'Delete account alice@example.com' }));
|
|
113
|
+
const dialog = within(screen.getByRole('dialog'));
|
|
114
|
+
await userEvent.click(dialog.getByRole('button', { name: 'Delete account' }));
|
|
115
|
+
await waitFor(() => expect(deleteAccount).toHaveBeenCalledWith('u-alice'));
|
|
116
|
+
// List reloaded after the delete.
|
|
117
|
+
expect(listAccounts).toHaveBeenCalledTimes(2);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('a failed delete closes the dialog, surfaces the error, and does not reload', async () => {
|
|
121
|
+
vi.mocked(deleteAccount).mockRejectedValueOnce(new Error('Failed to erase user'));
|
|
122
|
+
renderPage();
|
|
123
|
+
await waitFor(() => screen.getByText('Alice'));
|
|
124
|
+
await userEvent.click(screen.getByRole('button', { name: 'Delete account alice@example.com' }));
|
|
125
|
+
const dialog = within(screen.getByRole('dialog'));
|
|
126
|
+
await userEvent.click(dialog.getByRole('button', { name: 'Delete account' }));
|
|
127
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
|
|
128
|
+
// Announced, not merely coloured — same guarantee the load failure gets.
|
|
129
|
+
expect(screen.getByRole('alert')).toHaveTextContent('Failed to erase user');
|
|
130
|
+
// And the rows survive: keeping what was already fetched is the half of
|
|
131
|
+
// the old `[]` coercion that was worth keeping, so it is pinned here.
|
|
132
|
+
expect(screen.getByText('Alice')).toBeInTheDocument();
|
|
133
|
+
expect(listAccounts).toHaveBeenCalledTimes(1);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('adds a new account and refreshes the list', async () => {
|
|
137
|
+
renderPage();
|
|
138
|
+
await waitFor(() => screen.getByText('Alice'));
|
|
139
|
+
await userEvent.type(screen.getByLabelText('Email'), 'bob@example.com');
|
|
140
|
+
await userEvent.type(screen.getByLabelText(/Name/), 'Bob');
|
|
141
|
+
await userEvent.type(screen.getByLabelText('Password'), 'bobs-password-1');
|
|
142
|
+
await userEvent.click(screen.getByRole('button', { name: 'Add account' }));
|
|
143
|
+
await waitFor(() =>
|
|
144
|
+
expect(createAccount).toHaveBeenCalledWith('bob@example.com', 'Bob', 'bobs-password-1'),
|
|
145
|
+
);
|
|
146
|
+
expect(listAccounts).toHaveBeenCalledTimes(2);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('surfaces an add failure inline', async () => {
|
|
150
|
+
vi.mocked(createAccount).mockRejectedValueOnce(
|
|
151
|
+
new Error('Password must be at least 8 characters'),
|
|
152
|
+
);
|
|
153
|
+
renderPage();
|
|
154
|
+
await waitFor(() => screen.getByText('Alice'));
|
|
155
|
+
await userEvent.type(screen.getByLabelText('Email'), 'bob@example.com');
|
|
156
|
+
await userEvent.type(screen.getByLabelText('Password'), 'short');
|
|
157
|
+
await userEvent.click(screen.getByRole('button', { name: 'Add account' }));
|
|
158
|
+
expect(await screen.findByRole('alert')).toHaveTextContent('at least 8 characters');
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// "We could not ask" is not "there is nobody". The failure used to store an
|
|
162
|
+
// empty list, so an admin whose backend was unreachable read "No user
|
|
163
|
+
// accounts." — a deployment they would have had every reason to believe.
|
|
164
|
+
it('a failed FIRST load reports the failure rather than an empty deployment', async () => {
|
|
165
|
+
vi.mocked(listAccounts).mockReset().mockRejectedValue(new Error('Backend unreachable'));
|
|
166
|
+
renderPage();
|
|
167
|
+
expect(await screen.findByRole('alert')).toHaveTextContent('Backend unreachable');
|
|
168
|
+
expect(screen.queryByText('No user accounts.')).not.toBeInTheDocument();
|
|
169
|
+
// ...and no "Loading…" left sitting beside the banner forever, either.
|
|
170
|
+
expect(screen.queryByText('Loading…')).not.toBeInTheDocument();
|
|
171
|
+
});
|
|
172
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
3
|
+
import { AdminProvider, useAdmin } from '../state/admin.context';
|
|
4
|
+
import { AuthContext, type AuthContextValue } from '../../auth/state/auth.context';
|
|
5
|
+
import { AppRegistryContext, makeRegistry } from '../../../core/registry';
|
|
6
|
+
|
|
7
|
+
vi.mock('../services/admin.api', () => ({
|
|
8
|
+
fetchAdminAccess: vi.fn().mockResolvedValue({ isAdmin: true, rolesConfig: { ok: true } }),
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
const auth = {
|
|
12
|
+
user: { id: 'u1', email: 'root@example.com', name: 'Root' },
|
|
13
|
+
token: 't',
|
|
14
|
+
isLoading: false,
|
|
15
|
+
login: async () => {},
|
|
16
|
+
logout: () => {},
|
|
17
|
+
} as AuthContextValue;
|
|
18
|
+
|
|
19
|
+
function Badge() {
|
|
20
|
+
return <span data-testid="count">{useAdmin().unreadCount}</span>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function renderWith(registry: ReturnType<typeof makeRegistry>) {
|
|
24
|
+
return render(
|
|
25
|
+
<AuthContext.Provider value={auth}>
|
|
26
|
+
<AppRegistryContext.Provider value={registry}>
|
|
27
|
+
<AdminProvider>
|
|
28
|
+
<Badge />
|
|
29
|
+
</AdminProvider>
|
|
30
|
+
</AppRegistryContext.Provider>
|
|
31
|
+
</AuthContext.Provider>,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let fetchSpy: ReturnType<typeof vi.fn>;
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
fetchSpy = vi.fn().mockResolvedValue({ ok: true, json: async () => ({ count: 0 }) });
|
|
38
|
+
vi.stubGlobal('fetch', fetchSpy);
|
|
39
|
+
});
|
|
40
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The badge counts an ENTERPRISE inbox. Core polled its endpoint every thirty
|
|
44
|
+
* seconds anyway — a guaranteed 404 on every core deployment, forever, filling
|
|
45
|
+
* the console of the one screen an operator opens when something is wrong.
|
|
46
|
+
*/
|
|
47
|
+
describe('AdminProvider: the unread badge', () => {
|
|
48
|
+
it('makes no request at all when nothing is counting', async () => {
|
|
49
|
+
renderWith(makeRegistry({}));
|
|
50
|
+
await waitFor(() => expect(screen.getByTestId('count')).toHaveTextContent('0'));
|
|
51
|
+
const asked = fetchSpy.mock.calls.some((call) => String(call[0]).includes('unread-count'));
|
|
52
|
+
expect(asked).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('uses the counter an overlay registers', async () => {
|
|
56
|
+
const adminUnreadCount = vi.fn().mockResolvedValue(7);
|
|
57
|
+
renderWith(makeRegistry({ adminUnreadCount }));
|
|
58
|
+
await waitFor(() => expect(screen.getByTestId('count')).toHaveTextContent('7'));
|
|
59
|
+
expect(adminUnreadCount).toHaveBeenCalled();
|
|
60
|
+
});
|
|
61
|
+
});
|