@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
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
NO_SHARED_HISTORY_RECOVERY_PROMPT,
|
|
8
8
|
} from '../error-messages';
|
|
9
9
|
|
|
10
|
-
describe('friendlyGitError
|
|
10
|
+
describe('friendlyGitError: translates raw backend git messages', () => {
|
|
11
11
|
// The legacy "direct push to protected branch is not allowed" case is
|
|
12
12
|
// retired with the access-at-lock-acquisition refactor: writing to the
|
|
13
13
|
// official versions is allowed wherever the user has path-level access.
|
|
@@ -19,7 +19,7 @@ describe('friendlyGitError — translates raw backend git messages', () => {
|
|
|
19
19
|
'Branch "target-company-state" is protected — opening a PR from a protected branch is not allowed.',
|
|
20
20
|
);
|
|
21
21
|
expect(friendlyGitError(err)).toBe(
|
|
22
|
-
'You can\'t propose changes from "target-company-state"
|
|
22
|
+
'You can\'t propose changes from "target-company-state": open the change request from a draft instead.',
|
|
23
23
|
);
|
|
24
24
|
});
|
|
25
25
|
|
|
@@ -32,7 +32,7 @@ describe('friendlyGitError — translates raw backend git messages', () => {
|
|
|
32
32
|
'Branch "target-company-state" is protected — creating a protected branch is not allowed.',
|
|
33
33
|
);
|
|
34
34
|
expect(friendlyGitError(err)).toBe(
|
|
35
|
-
'The name "target-company-state" is reserved
|
|
35
|
+
'The name "target-company-state" is reserved: it\'s an official version.',
|
|
36
36
|
);
|
|
37
37
|
});
|
|
38
38
|
|
|
@@ -82,7 +82,7 @@ describe('friendlyGitError — translates raw backend git messages', () => {
|
|
|
82
82
|
});
|
|
83
83
|
});
|
|
84
84
|
|
|
85
|
-
describe('parseGitError
|
|
85
|
+
describe('parseGitError: structured form for actionable UIs', () => {
|
|
86
86
|
it('returns kind="plain" for arbitrary errors', () => {
|
|
87
87
|
const info = parseGitError(new Error('oops'));
|
|
88
88
|
expect(info).toEqual({ kind: 'plain', message: 'oops' });
|
|
@@ -23,7 +23,7 @@ export const NO_SHARED_HISTORY_RECOVERY_PROMPT = (head: string, base: string): s
|
|
|
23
23
|
`My draft "${head}" can't be proposed because it doesn't share history with "${base}".`,
|
|
24
24
|
'It was likely started from an unrelated point or outside the app.',
|
|
25
25
|
'Please investigate which protected branch it should have been forked from,',
|
|
26
|
-
'then either recreate the draft on top of that branch or rebase it onto the right starting point
|
|
26
|
+
'then either recreate the draft on top of that branch or rebase it onto the right starting point:',
|
|
27
27
|
"whichever preserves my edits. Then I'll share the changes again.",
|
|
28
28
|
].join(' ');
|
|
29
29
|
};
|
|
@@ -76,7 +76,7 @@ export function parseGitError(err: unknown): GitErrorInfo {
|
|
|
76
76
|
function friendlyNoSharedHistoryMessage(base: string): string {
|
|
77
77
|
const baseName = protectedBranchDisplayName(base) ?? base;
|
|
78
78
|
return (
|
|
79
|
-
`This draft doesn't share history with the ${baseName}
|
|
79
|
+
`This draft doesn't share history with the ${baseName}. It was likely started ` +
|
|
80
80
|
`from an unrelated point or outside the app. The assistant can investigate and ` +
|
|
81
81
|
`move your edits onto the right starting point so you can share them.`
|
|
82
82
|
);
|
|
@@ -131,11 +131,11 @@ export function friendlyGitError(err: unknown): string {
|
|
|
131
131
|
const [, branch, action] = protectedMatch;
|
|
132
132
|
switch (action) {
|
|
133
133
|
case 'creating a protected branch':
|
|
134
|
-
return `The name "${branch}" is reserved
|
|
134
|
+
return `The name "${branch}" is reserved: it's an official version.`;
|
|
135
135
|
case 'deleting a protected branch':
|
|
136
136
|
return `"${branch}" is an official version and can't be deleted.`;
|
|
137
137
|
case 'opening a PR from a protected branch':
|
|
138
|
-
return `You can't propose changes from "${branch}"
|
|
138
|
+
return `You can't propose changes from "${branch}": open the change request from a draft instead.`;
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
|
|
@@ -155,7 +155,7 @@ export function friendlyGitError(err: unknown): string {
|
|
|
155
155
|
// nonsense, so route that case to a dedicated message that names the
|
|
156
156
|
// real recovery path (contact a repo admin to broaden access).
|
|
157
157
|
if (eligible === 'none') {
|
|
158
|
-
return `You don't have permission to edit "${path}". Nobody currently has edit permission for this file
|
|
158
|
+
return `You don't have permission to edit "${path}". Nobody currently has edit permission for this file. Contact a repo admin to grant access or broaden the rules for this folder.`;
|
|
159
159
|
}
|
|
160
160
|
return `You don't have permission to edit "${path}". Editing is restricted to ${eligible}. Ask one of them to make the change, or to broaden access for this folder.`;
|
|
161
161
|
}
|
|
@@ -194,7 +194,7 @@ export function friendlyGitError(err: unknown): string {
|
|
|
194
194
|
return 'Keep the change request title to 256 characters or less.';
|
|
195
195
|
}
|
|
196
196
|
if (raw === 'PR head and base must differ') {
|
|
197
|
-
return "Your draft and the version you're proposing into are the same
|
|
197
|
+
return "Your draft and the version you're proposing into are the same. Nothing to request.";
|
|
198
198
|
}
|
|
199
199
|
if (raw.startsWith('Could not resolve a base branch for')) {
|
|
200
200
|
return "Couldn't tell which official version this draft was started from. Share the draft first, then try again.";
|
|
@@ -213,7 +213,7 @@ export function friendlyGitError(err: unknown): string {
|
|
|
213
213
|
// Cancel-change-request mappings. The backend throws CancelStateError /
|
|
214
214
|
// CancelAuthError with these literal messages; treat them as equality keys.
|
|
215
215
|
if (raw === 'This change request was already applied.') {
|
|
216
|
-
return "This change request was already applied
|
|
216
|
+
return "This change request was already applied. There's nothing to cancel.";
|
|
217
217
|
}
|
|
218
218
|
if (raw === 'This change request is already cancelled.') {
|
|
219
219
|
return "This change request was already cancelled.";
|
|
@@ -110,17 +110,6 @@ export async function fetchForkBase(
|
|
|
110
110
|
return data.base;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
export async function revert(
|
|
114
|
-
workspaceId: string,
|
|
115
|
-
sha: string,
|
|
116
|
-
): Promise<CommitAttribution> {
|
|
117
|
-
return handleApiResponse(
|
|
118
|
-
await authFetch(`/api/workspace/${workspaceId}/workflow/changes/${encodeURIComponent(sha)}/revert`, {
|
|
119
|
-
method: 'POST',
|
|
120
|
-
}),
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
113
|
export async function fetchFileHistory(
|
|
125
114
|
workspaceId: string,
|
|
126
115
|
path: string,
|
|
@@ -145,6 +134,23 @@ export async function fetchFileDiff(
|
|
|
145
134
|
return data.diff;
|
|
146
135
|
}
|
|
147
136
|
|
|
137
|
+
/**
|
|
138
|
+
* Full file contents on both sides of one commit (`sha^` vs `sha`). Null on a
|
|
139
|
+
* side means the file is absent there (added / deleted at this commit). Used
|
|
140
|
+
* by the history panel to render markdown diffs; `fetchFileDiff` keeps
|
|
141
|
+
* serving the raw patch for other file types.
|
|
142
|
+
*/
|
|
143
|
+
export async function fetchFileAtChange(
|
|
144
|
+
workspaceId: string,
|
|
145
|
+
path: string,
|
|
146
|
+
sha: string,
|
|
147
|
+
): Promise<{ baseline: string | null; current: string | null }> {
|
|
148
|
+
const q = new URLSearchParams({ path, sha });
|
|
149
|
+
return handleApiResponse(
|
|
150
|
+
await authFetch(`/api/workspace/${workspaceId}/workflow/file-at-change?${q.toString()}`),
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
148
154
|
export async function fetchFileComparison(
|
|
149
155
|
workspaceId: string,
|
|
150
156
|
path: string,
|
|
@@ -97,7 +97,7 @@ export function buildResolveApplyConflictsPrompt(input: {
|
|
|
97
97
|
return [
|
|
98
98
|
`I tried to apply change request #${changeRequestNumber} into \`${base}\` and the two sides have differences that couldn't be reconciled automatically.${pathBlurb}`,
|
|
99
99
|
'',
|
|
100
|
-
"Please look at each affected file, decide what the merged version should look like for the process to remain consistent, and apply your resolution to the change request's source branch. Then retry applying the change request. If you genuinely can't tell which version should win on a particular file, ask me about that specific case in plain language
|
|
100
|
+
"Please look at each affected file, decide what the merged version should look like for the process to remain consistent, and apply your resolution to the change request's source branch. Then retry applying the change request. If you genuinely can't tell which version should win on a particular file, ask me about that specific case in plain language. But resolve everything you can on your own first.",
|
|
101
101
|
].join('\n');
|
|
102
102
|
}
|
|
103
103
|
|
|
@@ -127,7 +127,7 @@ export function buildResolveRefreshConflictsPrompt(input: {
|
|
|
127
127
|
return [
|
|
128
128
|
`I tried to bring the latest \`${base}\` into change request #${changeRequestNumber} (so the diff reflects what would actually apply now) and the two sides have differences that couldn't be reconciled automatically.${pathBlurb}`,
|
|
129
129
|
'',
|
|
130
|
-
"Please decide the merged version for each affected file so the change request stays coherent with the latest target, apply your resolution to the change request's source branch, then refresh again. If you can't tell which version should win on a particular file, ask me about that one case in plain language
|
|
130
|
+
"Please decide the merged version for each affected file so the change request stays coherent with the latest target, apply your resolution to the change request's source branch, then refresh again. If you can't tell which version should win on a particular file, ask me about that one case in plain language. But resolve everything you can on your own first.",
|
|
131
131
|
].join('\n');
|
|
132
132
|
}
|
|
133
133
|
|
|
@@ -53,9 +53,18 @@ export interface GitContextValue {
|
|
|
53
53
|
* `branch` is itself protected / can't be resolved.
|
|
54
54
|
*/
|
|
55
55
|
fetchForkBase(branch: string): Promise<string | null>;
|
|
56
|
-
revert(sha: string): Promise<CommitAttribution>;
|
|
57
56
|
fetchFileHistory(path: string, limit?: number): Promise<CommitAttribution[]>;
|
|
58
57
|
fetchFileDiff(path: string, sha: string): Promise<string>;
|
|
58
|
+
/**
|
|
59
|
+
* Full before/after contents of `path` at one commit (`sha^` vs `sha`);
|
|
60
|
+
* null on a side means the file is absent there. The history panel uses
|
|
61
|
+
* this to render markdown changes as a red/green rendered-markdown diff
|
|
62
|
+
* instead of the raw patch `fetchFileDiff` returns.
|
|
63
|
+
*/
|
|
64
|
+
fetchFileAtChange(
|
|
65
|
+
path: string,
|
|
66
|
+
sha: string,
|
|
67
|
+
): Promise<{ baseline: string | null; current: string | null }>;
|
|
59
68
|
/**
|
|
60
69
|
* Unified diff of `path` between two branches. Read-only; nothing is
|
|
61
70
|
* checked out or written. `fromBranch` and `toBranch` must be names from
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { act, fireEvent, render, screen } from '@testing-library/react';
|
|
2
|
+
import { beforeEach, describe, expect, it } from 'vitest';
|
|
3
|
+
import {
|
|
4
|
+
SIDEBAR_DRAWER_MAX_WIDTH,
|
|
5
|
+
SIDEBAR_DRAWER_WIDTH,
|
|
6
|
+
SidebarFrame,
|
|
7
|
+
} from '../components/SidebarFrame';
|
|
8
|
+
import {
|
|
9
|
+
SIDEBAR_DEFAULT_WIDTH,
|
|
10
|
+
setSidebarCollapsed,
|
|
11
|
+
setSidebarNarrow,
|
|
12
|
+
setSidebarWidth,
|
|
13
|
+
useSidebar,
|
|
14
|
+
} from '../state/sidebar';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Cross the narrow breakpoint. happy-dom answers `matchMedia` out of
|
|
18
|
+
* `innerWidth`, so moving the viewport is how a test reaches the drawer
|
|
19
|
+
* layout — there is no CSS engine here to do it for us.
|
|
20
|
+
*/
|
|
21
|
+
function setViewportWidth(width: number): void {
|
|
22
|
+
const testWindow = window as typeof window & {
|
|
23
|
+
happyDOM: { setInnerWidth(value: number): void };
|
|
24
|
+
};
|
|
25
|
+
testWindow.happyDOM.setInnerWidth(width);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Mount a frame and hand back the `<aside>` — what most assertions here are about. */
|
|
29
|
+
function renderFrame(): HTMLElement {
|
|
30
|
+
const { container } = render(
|
|
31
|
+
<SidebarFrame label="Library groups">
|
|
32
|
+
<button type="button">Engineering</button>
|
|
33
|
+
</SidebarFrame>,
|
|
34
|
+
);
|
|
35
|
+
return container.querySelector('aside') as HTMLElement;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The same mount, keeping the whole render result. The backdrop is a SIBLING
|
|
40
|
+
* of the aside rather than a child, so a test that needs it cannot get there
|
|
41
|
+
* from the element `renderFrame` returns.
|
|
42
|
+
*/
|
|
43
|
+
function renderFrameWithContainer() {
|
|
44
|
+
return render(
|
|
45
|
+
<SidebarFrame label="Library groups">
|
|
46
|
+
<button type="button">Engineering</button>
|
|
47
|
+
</SidebarFrame>,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
setViewportWidth(1400);
|
|
53
|
+
// The sidebar store is module state, so the breakpoint it last settled on
|
|
54
|
+
// outlives the component. Reset it with the rest, or a test that mounts at
|
|
55
|
+
// phone width inherits "already narrow" from its predecessor and the frame
|
|
56
|
+
// treats the mount as a no-op instead of a crossing.
|
|
57
|
+
setSidebarNarrow(false);
|
|
58
|
+
setSidebarCollapsed(false);
|
|
59
|
+
setSidebarWidth(SIDEBAR_DEFAULT_WIDTH);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('SidebarFrame: narrow viewport', () => {
|
|
63
|
+
it('starts collapsed and genuinely removes the sidebar from interaction', () => {
|
|
64
|
+
setViewportWidth(375);
|
|
65
|
+
const aside = renderFrame();
|
|
66
|
+
|
|
67
|
+
expect(aside).toHaveStyle({ width: '0px' });
|
|
68
|
+
expect(aside).toHaveAttribute('inert');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('starts expanded at its stored width on a wide viewport', () => {
|
|
72
|
+
setSidebarWidth(320);
|
|
73
|
+
const aside = renderFrame();
|
|
74
|
+
|
|
75
|
+
expect(aside).toHaveStyle({ width: '320px' });
|
|
76
|
+
expect(aside).not.toHaveAttribute('inert');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it.each([
|
|
80
|
+
[900, '0px', true],
|
|
81
|
+
[901, `${SIDEBAR_DEFAULT_WIDTH}px`, false],
|
|
82
|
+
])('switches the sidebar at the exact %ipx boundary', (width, expectedWidth, inert) => {
|
|
83
|
+
setViewportWidth(width);
|
|
84
|
+
const aside = renderFrame();
|
|
85
|
+
|
|
86
|
+
expect(aside).toHaveStyle({ width: expectedWidth });
|
|
87
|
+
expect(aside.hasAttribute('inert')).toBe(inert);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('collapses when the viewport crosses from wide to narrow', () => {
|
|
91
|
+
const aside = renderFrame();
|
|
92
|
+
|
|
93
|
+
act(() => setViewportWidth(375));
|
|
94
|
+
|
|
95
|
+
expect(aside).toHaveStyle({ width: '0px' });
|
|
96
|
+
expect(aside).toHaveAttribute('inert');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('reopens when the viewport crosses from narrow to wide', () => {
|
|
100
|
+
setViewportWidth(375);
|
|
101
|
+
const aside = renderFrame();
|
|
102
|
+
|
|
103
|
+
act(() => {
|
|
104
|
+
// happy-dom initializes each MediaQueryList listener's transition state
|
|
105
|
+
// on its first resize event; browsers already retain the initial match.
|
|
106
|
+
window.dispatchEvent(new Event('resize'));
|
|
107
|
+
setViewportWidth(1400);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
expect(aside).toHaveStyle({ width: `${SIDEBAR_DEFAULT_WIDTH}px` });
|
|
111
|
+
expect(aside).not.toHaveAttribute('inert');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('keeps a manual narrow-screen open until another breakpoint transition', () => {
|
|
115
|
+
setViewportWidth(375);
|
|
116
|
+
const aside = renderFrame();
|
|
117
|
+
|
|
118
|
+
act(() => setSidebarCollapsed(false));
|
|
119
|
+
act(() => setSidebarWidth(260));
|
|
120
|
+
|
|
121
|
+
expect(aside.style.width).toBe(SIDEBAR_DRAWER_WIDTH);
|
|
122
|
+
expect(aside.style.maxWidth).toBe(SIDEBAR_DRAWER_MAX_WIDTH);
|
|
123
|
+
expect(aside).not.toHaveAttribute('inert');
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it.each(['File explorer', 'Library groups'])(
|
|
127
|
+
'opens %s as the same modal drawer over a backdrop',
|
|
128
|
+
(label) => {
|
|
129
|
+
setViewportWidth(375);
|
|
130
|
+
const { container } = render(
|
|
131
|
+
<SidebarFrame label={label}>
|
|
132
|
+
<button type="button">First destination</button>
|
|
133
|
+
<button type="button">Last destination</button>
|
|
134
|
+
</SidebarFrame>,
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
act(() => setSidebarCollapsed(false));
|
|
138
|
+
|
|
139
|
+
const drawer = screen.getByRole('dialog', { name: label });
|
|
140
|
+
expect(drawer).toHaveClass('fixed', 'z-50');
|
|
141
|
+
expect(drawer.style.width).toBe(SIDEBAR_DRAWER_WIDTH);
|
|
142
|
+
expect(drawer.style.maxWidth).toBe(SIDEBAR_DRAWER_MAX_WIDTH);
|
|
143
|
+
expect(container.querySelector('[data-sidebar-backdrop]')).toBeInTheDocument();
|
|
144
|
+
expect(screen.queryByRole('separator', { name: /resize/i })).toBeNull();
|
|
145
|
+
expect(screen.getByRole('button', { name: 'First destination' })).toHaveFocus();
|
|
146
|
+
},
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
it('closes the drawer from its backdrop', () => {
|
|
150
|
+
setViewportWidth(375);
|
|
151
|
+
const { container } = renderFrameWithContainer();
|
|
152
|
+
act(() => setSidebarCollapsed(false));
|
|
153
|
+
|
|
154
|
+
fireEvent.click(container.querySelector('[data-sidebar-backdrop]')!);
|
|
155
|
+
|
|
156
|
+
expect(container.querySelector('aside')).toHaveAttribute('inert');
|
|
157
|
+
expect(container.querySelector('[data-sidebar-backdrop]')).toBeNull();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('closes the drawer with Escape', () => {
|
|
161
|
+
setViewportWidth(375);
|
|
162
|
+
const aside = renderFrame();
|
|
163
|
+
act(() => setSidebarCollapsed(false));
|
|
164
|
+
|
|
165
|
+
fireEvent.keyDown(document, { key: 'Escape' });
|
|
166
|
+
|
|
167
|
+
expect(aside).toHaveAttribute('inert');
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* The invariant the store's paired write exists to hold, watched from a
|
|
172
|
+
* subscriber across every snapshot the frame's mount and two crossings
|
|
173
|
+
* produce. A snapshot saying "narrow" while the nav is still showing is a
|
|
174
|
+
* drawer nobody opened: it paints over the page for a frame, and its focus
|
|
175
|
+
* trap fires on the way past. So the two facts have to land together.
|
|
176
|
+
*
|
|
177
|
+
* Only mount and crossings are probed — once the user reopens the nav by
|
|
178
|
+
* hand at phone width, narrow-and-showing is exactly the drawer, not a
|
|
179
|
+
* glitch.
|
|
180
|
+
*/
|
|
181
|
+
it('never publishes a narrow breakpoint with a still-showing sidebar', () => {
|
|
182
|
+
const seen: Array<{ narrow: boolean; collapsed: boolean }> = [];
|
|
183
|
+
/** Records every sidebar snapshot it is rendered for, in order. */
|
|
184
|
+
function Probe() {
|
|
185
|
+
const { narrow, collapsed } = useSidebar();
|
|
186
|
+
seen.push({ narrow, collapsed });
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
setViewportWidth(375);
|
|
191
|
+
render(
|
|
192
|
+
<>
|
|
193
|
+
<Probe />
|
|
194
|
+
<SidebarFrame label="Library groups">
|
|
195
|
+
<button type="button">Engineering</button>
|
|
196
|
+
</SidebarFrame>
|
|
197
|
+
</>,
|
|
198
|
+
);
|
|
199
|
+
act(() => setViewportWidth(1400));
|
|
200
|
+
act(() => setViewportWidth(375));
|
|
201
|
+
|
|
202
|
+
expect(seen.length).toBeGreaterThan(1);
|
|
203
|
+
expect(seen.filter((s) => s.narrow && !s.collapsed)).toEqual([]);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('keeps the existing wide behavior when matchMedia is unavailable', () => {
|
|
207
|
+
const originalMatchMedia = window.matchMedia;
|
|
208
|
+
Object.defineProperty(window, 'matchMedia', {
|
|
209
|
+
configurable: true,
|
|
210
|
+
value: undefined,
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
try {
|
|
214
|
+
const aside = renderFrame();
|
|
215
|
+
expect(aside).toHaveStyle({ width: `${SIDEBAR_DEFAULT_WIDTH}px` });
|
|
216
|
+
expect(aside).not.toHaveAttribute('inert');
|
|
217
|
+
} finally {
|
|
218
|
+
Object.defineProperty(window, 'matchMedia', {
|
|
219
|
+
configurable: true,
|
|
220
|
+
value: originalMatchMedia,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
});
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { act, render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import { SidebarToggle } from '../components/SidebarToggle';
|
|
4
|
+
import { SIDEBAR_DOM_ID, SidebarFrame } from '../components/SidebarFrame';
|
|
5
|
+
import {
|
|
6
|
+
SIDEBAR_DEFAULT_WIDTH,
|
|
7
|
+
SIDEBAR_MAX_WIDTH,
|
|
8
|
+
SIDEBAR_MIN_WIDTH,
|
|
9
|
+
setSidebarCollapsed,
|
|
10
|
+
setSidebarWidth,
|
|
11
|
+
toggleSidebar,
|
|
12
|
+
} from '../state/sidebar';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Hiding the nav, and sizing it. Two halves, tested where each one lives: the
|
|
16
|
+
* button says what it will do next, and the frame goes genuinely away rather
|
|
17
|
+
* than merely narrow.
|
|
18
|
+
*
|
|
19
|
+
* The button is only ever found by its accessible name here — that name IS the
|
|
20
|
+
* feature for anyone not looking at the screen, and the glyph is `aria-hidden`
|
|
21
|
+
* precisely so the name is the only thing carrying it.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
setSidebarCollapsed(false);
|
|
26
|
+
setSidebarWidth(SIDEBAR_DEFAULT_WIDTH);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
function frame() {
|
|
30
|
+
const { container } = render(
|
|
31
|
+
<SidebarFrame label="Library groups">
|
|
32
|
+
<button type="button">Engineering</button>
|
|
33
|
+
</SidebarFrame>,
|
|
34
|
+
);
|
|
35
|
+
return container.querySelector(`#${SIDEBAR_DOM_ID}`) as HTMLElement;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe('SidebarToggle', () => {
|
|
39
|
+
it('offers to hide the sidebar while it is showing', () => {
|
|
40
|
+
render(<SidebarToggle collapsed={false} onToggle={vi.fn()} />);
|
|
41
|
+
const button = screen.getByRole('button', { name: 'Hide sidebar' });
|
|
42
|
+
expect(button).toHaveAttribute('aria-expanded', 'true');
|
|
43
|
+
expect(button).toHaveAttribute('aria-controls', SIDEBAR_DOM_ID);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('offers to show it again once hidden', () => {
|
|
47
|
+
render(<SidebarToggle collapsed onToggle={vi.fn()} />);
|
|
48
|
+
const button = screen.getByRole('button', { name: 'Show sidebar' });
|
|
49
|
+
expect(button).toHaveAttribute('aria-expanded', 'false');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('reports the click and keeps no state of its own', () => {
|
|
53
|
+
const onToggle = vi.fn();
|
|
54
|
+
const { rerender } = render(<SidebarToggle collapsed={false} onToggle={onToggle} />);
|
|
55
|
+
fireEvent.click(screen.getByRole('button', { name: 'Hide sidebar' }));
|
|
56
|
+
expect(onToggle).toHaveBeenCalledTimes(1);
|
|
57
|
+
|
|
58
|
+
// The label follows the prop, not the click: the store owns the state.
|
|
59
|
+
expect(screen.getByRole('button', { name: 'Hide sidebar' })).toBeInTheDocument();
|
|
60
|
+
rerender(<SidebarToggle collapsed onToggle={onToggle} />);
|
|
61
|
+
expect(screen.getByRole('button', { name: 'Show sidebar' })).toBeInTheDocument();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('draws one glyph, and hides it from the accessible name', () => {
|
|
65
|
+
const { container } = render(<SidebarToggle collapsed={false} onToggle={vi.fn()} />);
|
|
66
|
+
const svg = container.querySelector('svg')!;
|
|
67
|
+
expect(svg).toHaveAttribute('aria-hidden', 'true');
|
|
68
|
+
// The panel outline plus its filled left rail — the shape of the thing it
|
|
69
|
+
// toggles, which is why there is a `path` and not just a `rect`.
|
|
70
|
+
expect(container.querySelectorAll('svg rect')).toHaveLength(1);
|
|
71
|
+
expect(container.querySelectorAll('svg path')).toHaveLength(1);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('SidebarFrame: collapsed', () => {
|
|
76
|
+
it('stays reachable while showing', () => {
|
|
77
|
+
const aside = frame();
|
|
78
|
+
expect(aside).not.toHaveAttribute('inert');
|
|
79
|
+
expect(screen.getByRole('button', { name: 'Engineering' })).toBeInTheDocument();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('goes inert when hidden, so tab order does not walk into a nav nobody can see', () => {
|
|
83
|
+
setSidebarCollapsed(true);
|
|
84
|
+
expect(frame()).toHaveAttribute('inert');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* A gesture is performed; a fact is not. Hiding the nav yourself earns the
|
|
89
|
+
* 240ms slide, but the welcome page hiding it for the length of a greeting
|
|
90
|
+
* must not animate — a sidebar that moves on its own reads as a glitch on
|
|
91
|
+
* the way in and as the nav opening itself on the way out.
|
|
92
|
+
*/
|
|
93
|
+
it('animates a change you made', () => {
|
|
94
|
+
act(() => setSidebarCollapsed(true));
|
|
95
|
+
expect(frame().className).toContain('transition-[width]');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('does not animate one nobody asked for', () => {
|
|
99
|
+
act(() => setSidebarCollapsed(true, true));
|
|
100
|
+
expect(frame().className).toContain('transition-none');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// The flag must not outlive the change that set it, or the toolbar button
|
|
104
|
+
// would silently stop animating for the rest of the session.
|
|
105
|
+
it('goes back to animating as soon as somebody uses the button', () => {
|
|
106
|
+
act(() => setSidebarCollapsed(true, true));
|
|
107
|
+
act(() => toggleSidebar());
|
|
108
|
+
expect(frame().className).toContain('transition-[width]');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// A handle you can drag while the thing it sizes is at zero width would be
|
|
112
|
+
// sizing something invisible (proto:98).
|
|
113
|
+
it('withdraws the drag handle while hidden', () => {
|
|
114
|
+
render(
|
|
115
|
+
<SidebarFrame label="Library groups">
|
|
116
|
+
<span>x</span>
|
|
117
|
+
</SidebarFrame>,
|
|
118
|
+
);
|
|
119
|
+
expect(screen.getByRole('separator', { name: /resize/i })).toBeInTheDocument();
|
|
120
|
+
act(() => setSidebarCollapsed(true));
|
|
121
|
+
expect(screen.queryByRole('separator', { name: /resize/i })).toBeNull();
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe('SidebarFrame: resize', () => {
|
|
126
|
+
function grip() {
|
|
127
|
+
render(
|
|
128
|
+
<SidebarFrame label="Library groups">
|
|
129
|
+
<span>x</span>
|
|
130
|
+
</SidebarFrame>,
|
|
131
|
+
);
|
|
132
|
+
return screen.getByRole('separator', { name: /resize/i });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// A separator you can only drag is a control half the people cannot use.
|
|
136
|
+
it('resizes from the keyboard, in both directions', () => {
|
|
137
|
+
const separator = grip();
|
|
138
|
+
fireEvent.keyDown(separator, { key: 'ArrowRight' });
|
|
139
|
+
expect(separator).toHaveAttribute('aria-valuenow', String(SIDEBAR_DEFAULT_WIDTH + 8));
|
|
140
|
+
fireEvent.keyDown(separator, { key: 'ArrowLeft' });
|
|
141
|
+
expect(separator).toHaveAttribute('aria-valuenow', String(SIDEBAR_DEFAULT_WIDTH));
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('takes a bigger step with shift held', () => {
|
|
145
|
+
const separator = grip();
|
|
146
|
+
fireEvent.keyDown(separator, { key: 'ArrowRight', shiftKey: true });
|
|
147
|
+
expect(separator).toHaveAttribute('aria-valuenow', String(SIDEBAR_DEFAULT_WIDTH + 32));
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('goes back to the default on Home, and on a double-click', () => {
|
|
151
|
+
const separator = grip();
|
|
152
|
+
fireEvent.keyDown(separator, { key: 'ArrowRight', shiftKey: true });
|
|
153
|
+
fireEvent.keyDown(separator, { key: 'Home' });
|
|
154
|
+
expect(separator).toHaveAttribute('aria-valuenow', String(SIDEBAR_DEFAULT_WIDTH));
|
|
155
|
+
|
|
156
|
+
fireEvent.keyDown(separator, { key: 'ArrowLeft', shiftKey: true });
|
|
157
|
+
fireEvent.doubleClick(separator);
|
|
158
|
+
expect(separator).toHaveAttribute('aria-valuenow', String(SIDEBAR_DEFAULT_WIDTH));
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// Clamped rather than free: below the minimum the names stop being readable,
|
|
162
|
+
// and above the maximum the nav competes with the document for the page.
|
|
163
|
+
it('stops at the ends of the range', () => {
|
|
164
|
+
const separator = grip();
|
|
165
|
+
for (let i = 0; i < 40; i += 1) {
|
|
166
|
+
fireEvent.keyDown(separator, { key: 'ArrowLeft', shiftKey: true });
|
|
167
|
+
}
|
|
168
|
+
expect(separator).toHaveAttribute('aria-valuenow', String(SIDEBAR_MIN_WIDTH));
|
|
169
|
+
for (let i = 0; i < 40; i += 1) {
|
|
170
|
+
fireEvent.keyDown(separator, { key: 'ArrowRight', shiftKey: true });
|
|
171
|
+
}
|
|
172
|
+
expect(separator).toHaveAttribute('aria-valuenow', String(SIDEBAR_MAX_WIDTH));
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* The lock a drag puts on the whole document, and getting it back off.
|
|
178
|
+
*
|
|
179
|
+
* `cursor` and `user-select` go on `document.body` — outside React's tree, so
|
|
180
|
+
* nothing unmounts them for us. Collapsing takes the separator away mid-drag
|
|
181
|
+
* and the `pointerup` that would have ended the drag never arrives, which is
|
|
182
|
+
* how the lock used to outlive the drag that set it and leave the entire app
|
|
183
|
+
* un-selectable under a resize cursor with no way back.
|
|
184
|
+
*/
|
|
185
|
+
describe('SidebarFrame: drag cleanup', () => {
|
|
186
|
+
beforeEach(() => {
|
|
187
|
+
document.body.style.cursor = '';
|
|
188
|
+
document.body.style.userSelect = '';
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
function startDrag() {
|
|
192
|
+
const { unmount } = render(
|
|
193
|
+
<SidebarFrame label="Library groups">
|
|
194
|
+
<span>x</span>
|
|
195
|
+
</SidebarFrame>,
|
|
196
|
+
);
|
|
197
|
+
const separator = screen.getByRole('separator', { name: /resize/i });
|
|
198
|
+
// The frame captures the pointer so a drag survives an iframe in the main
|
|
199
|
+
// column; happy-dom has no implementation to capture with.
|
|
200
|
+
separator.setPointerCapture = () => {};
|
|
201
|
+
fireEvent.pointerDown(separator, { button: 0, pointerId: 1 });
|
|
202
|
+
return { separator, unmount };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const locked = () =>
|
|
206
|
+
document.body.style.cursor === 'col-resize' && document.body.style.userSelect === 'none';
|
|
207
|
+
|
|
208
|
+
it('locks the document while the drag is live, and lets go on pointerup', () => {
|
|
209
|
+
const { separator } = startDrag();
|
|
210
|
+
expect(locked()).toBe(true);
|
|
211
|
+
fireEvent.pointerUp(separator, { pointerId: 1 });
|
|
212
|
+
expect(locked()).toBe(false);
|
|
213
|
+
expect(document.body.style.cursor).toBe('');
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('lets go when a collapse takes the separator away mid-drag', () => {
|
|
217
|
+
startDrag();
|
|
218
|
+
expect(locked()).toBe(true);
|
|
219
|
+
act(() => setSidebarCollapsed(true));
|
|
220
|
+
expect(locked()).toBe(false);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
// The other half of the same bug: ending a drag by collapsing has to FORGET
|
|
224
|
+
// it too, or the sidebar coming back re-applies a lock nobody asked for.
|
|
225
|
+
it('does not re-lock the document when the sidebar comes back', () => {
|
|
226
|
+
startDrag();
|
|
227
|
+
act(() => setSidebarCollapsed(true));
|
|
228
|
+
act(() => setSidebarCollapsed(false));
|
|
229
|
+
expect(locked()).toBe(false);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// The third way out, and the one with nothing else to fall back on: a route
|
|
233
|
+
// change takes the whole frame away mid-drag. No pointerup, no collapse, and
|
|
234
|
+
// `document.body` is not React's to tidy — only the cleanup gets it back.
|
|
235
|
+
it('lets go when the frame unmounts mid-drag', () => {
|
|
236
|
+
const { unmount } = startDrag();
|
|
237
|
+
expect(locked()).toBe(true);
|
|
238
|
+
unmount();
|
|
239
|
+
expect(locked()).toBe(false);
|
|
240
|
+
expect(document.body.style.cursor).toBe('');
|
|
241
|
+
});
|
|
242
|
+
});
|