@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
2
|
-
import { render, screen, waitFor, act } from '@testing-library/react';
|
|
2
|
+
import { render, screen, waitFor, act, within } from '@testing-library/react';
|
|
3
3
|
import userEvent from '@testing-library/user-event';
|
|
4
4
|
import { MemoryRouter } from 'react-router-dom';
|
|
5
5
|
import { useEffect, useState } from 'react';
|
|
@@ -61,6 +61,63 @@ vi.mock('../../../workflow/services/lock.api', () => ({
|
|
|
61
61
|
},
|
|
62
62
|
}));
|
|
63
63
|
|
|
64
|
+
// The propose flow's one side effect that leaves the page: the network call
|
|
65
|
+
// that commits to the suggestions branch and opens the change request. The
|
|
66
|
+
// spy is the assertion surface; the branch-name helper stays real.
|
|
67
|
+
const proposeMock = vi.hoisted(() =>
|
|
68
|
+
vi.fn(async () => ({ branch: 'suggestions/reader-u9/knowledge' })),
|
|
69
|
+
);
|
|
70
|
+
vi.mock('../../../change-requests/services/propose.api', async (importOriginal) => {
|
|
71
|
+
const actual =
|
|
72
|
+
await importOriginal<typeof import('../../../change-requests/services/propose.api')>();
|
|
73
|
+
return { ...actual, proposeKnowledgeChange: proposeMock };
|
|
74
|
+
});
|
|
75
|
+
// Entering propose mode checks for the caller's open proposal and reads the
|
|
76
|
+
// file's proposed version; the change boxes read the default-branch raw for
|
|
77
|
+
// their diffs — all stubbed so tests decide what is in flight.
|
|
78
|
+
const myCrsMock = vi.hoisted(() => vi.fn(async (): Promise<unknown[]> => []));
|
|
79
|
+
const readBranchMock = vi.hoisted(() => vi.fn(async () => ''));
|
|
80
|
+
vi.mock('../../../change-requests/services/change-requests.api', () => ({
|
|
81
|
+
listOpenChangeRequests: vi.fn(async () => []),
|
|
82
|
+
listMyChangeRequests: myCrsMock,
|
|
83
|
+
readFileOnBranch: readBranchMock,
|
|
84
|
+
}));
|
|
85
|
+
|
|
86
|
+
// The access sheet is a 1200-line dialog with its own suite and its own
|
|
87
|
+
// endpoints. Here it only has to prove WHICH entry the page handed it — a file
|
|
88
|
+
// and its parent folder are the two share scopes, and picking the wrong one is
|
|
89
|
+
// the only mistake this wiring can make.
|
|
90
|
+
vi.mock('../../../access/components/ManageAccessDialog', () => ({
|
|
91
|
+
ManageAccessDialog: ({ entry }: { entry: { relativePath: string; type: string } }) => (
|
|
92
|
+
<div role="dialog" aria-label={`Manage access: ${entry.type} ${entry.relativePath}`} />
|
|
93
|
+
),
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
// Wrap `useFileLock` rather than replacing it: every other case in this file
|
|
97
|
+
// depends on the real acquire/release lifecycle. The wrapper only observes
|
|
98
|
+
// `recordActivity`, which has no other visible effect (it resets a timer), so
|
|
99
|
+
// there is no way to assert the scroll→lock wiring without a spy on it.
|
|
100
|
+
const lockActivity = vi.hoisted(() => ({ recordActivity: vi.fn() }));
|
|
101
|
+
vi.mock('../../../workflow/hooks/useFileLock', async (importOriginal) => {
|
|
102
|
+
const actual = await importOriginal<typeof import('../../../workflow/hooks/useFileLock')>();
|
|
103
|
+
const { useCallback } = await import('react');
|
|
104
|
+
return {
|
|
105
|
+
...actual,
|
|
106
|
+
useFileLock: (args: Parameters<typeof actual.useFileLock>[0]) => {
|
|
107
|
+
const real = actual.useFileLock(args);
|
|
108
|
+
const realRecord = real.recordActivity;
|
|
109
|
+
// Stable identity: FileViewer's scroll effect lists `recordActivity` in
|
|
110
|
+
// its deps, and a fresh function each render would re-bind the listener
|
|
111
|
+
// on every render — changing exactly the behaviour under test.
|
|
112
|
+
const recordActivity = useCallback(() => {
|
|
113
|
+
lockActivity.recordActivity();
|
|
114
|
+
realRecord();
|
|
115
|
+
}, [realRecord]);
|
|
116
|
+
return { ...real, recordActivity };
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
|
|
64
121
|
import { FileViewer } from '../FileViewer';
|
|
65
122
|
// The lock API is mocked above; import the mocked fns so individual tests can
|
|
66
123
|
// override the acquire outcome (e.g. a 403 on enter-edit).
|
|
@@ -69,7 +126,7 @@ import { WorkspaceContext, type WorkspaceContextValue } from '../../state/worksp
|
|
|
69
126
|
import { GitContext, type GitContextValue } from '../../../git/state/git.context';
|
|
70
127
|
import { ReviewContext, type ReviewContextValue } from '../../../review/state/review.context';
|
|
71
128
|
import { AuthContext, type AuthContextValue } from '../../../auth/state/auth.context';
|
|
72
|
-
import {
|
|
129
|
+
import { OpenChangeRequestsContext } from '../../state/open-change-requests.context';
|
|
73
130
|
|
|
74
131
|
let injectPendingFromTest: ((value?: string) => void) | null = null;
|
|
75
132
|
|
|
@@ -81,6 +138,16 @@ function makeStatus(branch = 'alice/draft'): WorkingTreeStatus {
|
|
|
81
138
|
};
|
|
82
139
|
}
|
|
83
140
|
|
|
141
|
+
const fetchFileHistoryMock = vi.fn(async () => [
|
|
142
|
+
{
|
|
143
|
+
sha: 'abc1234',
|
|
144
|
+
authorName: 'Ali Raza',
|
|
145
|
+
authorEmail: 'ali@example.com',
|
|
146
|
+
subject: 'Tighten the wording',
|
|
147
|
+
committedAt: new Date(Date.now() - 3 * 24 * 3600 * 1000).toISOString(),
|
|
148
|
+
},
|
|
149
|
+
]);
|
|
150
|
+
|
|
84
151
|
function makeGit(status: WorkingTreeStatus): GitContextValue {
|
|
85
152
|
const branches: BranchInfo[] = [];
|
|
86
153
|
return {
|
|
@@ -94,15 +161,9 @@ function makeGit(status: WorkingTreeStatus): GitContextValue {
|
|
|
94
161
|
deleteBranch: async () => {},
|
|
95
162
|
pull: async () => {},
|
|
96
163
|
fetchForkBase: async () => null,
|
|
97
|
-
|
|
98
|
-
sha: 'abc',
|
|
99
|
-
authorName: 'n',
|
|
100
|
-
authorEmail: 'e',
|
|
101
|
-
subject: 's',
|
|
102
|
-
committedAt: '2026-04-20T00:00:00.000Z',
|
|
103
|
-
}),
|
|
104
|
-
fetchFileHistory: async () => [],
|
|
164
|
+
fetchFileHistory: fetchFileHistoryMock,
|
|
105
165
|
fetchFileDiff: async () => '',
|
|
166
|
+
fetchFileAtChange: async () => ({ baseline: null, current: null }),
|
|
106
167
|
fetchFileComparison: async () => '',
|
|
107
168
|
};
|
|
108
169
|
}
|
|
@@ -114,6 +175,9 @@ function ViewerHarness({
|
|
|
114
175
|
filePath = 'knowledge-base/Knowledge/Foo.md',
|
|
115
176
|
kbDirName = 'knowledge-base',
|
|
116
177
|
addTab,
|
|
178
|
+
changeRequests = [],
|
|
179
|
+
authUser = null,
|
|
180
|
+
captureTyped = false,
|
|
117
181
|
}: {
|
|
118
182
|
initialContent?: string;
|
|
119
183
|
pendingValue?: string;
|
|
@@ -121,8 +185,19 @@ function ViewerHarness({
|
|
|
121
185
|
filePath?: string;
|
|
122
186
|
kbDirName?: string | null;
|
|
123
187
|
addTab?: WorkspaceContextValue['addTab'];
|
|
188
|
+
/** Open change requests touching `filePath`. */
|
|
189
|
+
changeRequests?: { number: number; title: string; who: string }[];
|
|
190
|
+
/** The signed-in user — the propose flow needs one to author the request. */
|
|
191
|
+
authUser?: AuthContextValue['user'];
|
|
192
|
+
/**
|
|
193
|
+
* Route `setActiveTabContent` into `openFileContent` (savedContent stays
|
|
194
|
+
* put), the way the real workspace state does. Opt-in so the many existing
|
|
195
|
+
* tests keep the historical no-op.
|
|
196
|
+
*/
|
|
197
|
+
captureTyped?: boolean;
|
|
124
198
|
}) {
|
|
125
199
|
const [openFileContent, setOpenFileContent] = useState(initialContent);
|
|
200
|
+
const [savedContent, setSavedContent] = useState(initialContent);
|
|
126
201
|
const [pendingFileContent, setPendingFileContent] = useState<string | null>(null);
|
|
127
202
|
|
|
128
203
|
useEffect(() => {
|
|
@@ -134,10 +209,11 @@ function ViewerHarness({
|
|
|
134
209
|
};
|
|
135
210
|
}, [pendingValue]);
|
|
136
211
|
|
|
212
|
+
const effectiveSaved = captureTyped ? savedContent : openFileContent;
|
|
137
213
|
const tab = {
|
|
138
214
|
path: filePath,
|
|
139
215
|
content: openFileContent,
|
|
140
|
-
savedContent:
|
|
216
|
+
savedContent: effectiveSaved,
|
|
141
217
|
isDirty: false,
|
|
142
218
|
pendingFileContent,
|
|
143
219
|
};
|
|
@@ -150,11 +226,13 @@ function ViewerHarness({
|
|
|
150
226
|
dirtyTabFilenames: [],
|
|
151
227
|
openFilePath: filePath,
|
|
152
228
|
openFileContent,
|
|
153
|
-
openFileSavedContent:
|
|
229
|
+
openFileSavedContent: effectiveSaved,
|
|
154
230
|
hasUnsavedFileChanges: false,
|
|
155
231
|
pendingFileContent,
|
|
156
|
-
setActiveTabContent: () => {},
|
|
232
|
+
setActiveTabContent: captureTyped ? (v: string) => setOpenFileContent(v) : () => {},
|
|
157
233
|
uploadError: null,
|
|
234
|
+
uploadNotice: null,
|
|
235
|
+
clearUploadNotice: () => {},
|
|
158
236
|
isUploading: false,
|
|
159
237
|
uploadProgress: null,
|
|
160
238
|
pendingUploads: new Map(),
|
|
@@ -178,6 +256,7 @@ function ViewerHarness({
|
|
|
178
256
|
moveEntry: async () => {},
|
|
179
257
|
saveFile: async (_relativePath: string, content: string) => {
|
|
180
258
|
setOpenFileContent(content);
|
|
259
|
+
setSavedContent(content);
|
|
181
260
|
},
|
|
182
261
|
reloadTabFromDisk: async () => {},
|
|
183
262
|
setPendingContent: (content: string) => {
|
|
@@ -207,37 +286,42 @@ function ViewerHarness({
|
|
|
207
286
|
clearError: () => {},
|
|
208
287
|
};
|
|
209
288
|
const auth: AuthContextValue = {
|
|
210
|
-
user:
|
|
211
|
-
token: null,
|
|
289
|
+
user: authUser,
|
|
290
|
+
token: authUser ? 't' : null,
|
|
212
291
|
isLoading: false,
|
|
213
292
|
login: async () => {},
|
|
214
293
|
logout: () => {},
|
|
215
294
|
};
|
|
216
|
-
const prViewer: PrViewerContextValue = {
|
|
217
|
-
openPrNumber: null,
|
|
218
|
-
detail: null,
|
|
219
|
-
notFound: false,
|
|
220
|
-
selectedPath: null,
|
|
221
|
-
isLoading: false,
|
|
222
|
-
lastError: null,
|
|
223
|
-
openPr: () => {},
|
|
224
|
-
closeViewer: () => {},
|
|
225
|
-
selectPath: () => {},
|
|
226
|
-
refresh: async () => {},
|
|
227
|
-
};
|
|
228
|
-
|
|
229
295
|
return (
|
|
230
296
|
<MemoryRouter>
|
|
231
297
|
<AuthContext.Provider value={auth}>
|
|
232
298
|
<WorkspaceContext.Provider value={workspace}>
|
|
233
299
|
<GitContext.Provider value={makeGit(makeStatus(branch))}>
|
|
234
300
|
<ReviewContext.Provider value={review}>
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
301
|
+
<OpenChangeRequestsContext.Provider
|
|
302
|
+
value={{
|
|
303
|
+
paths: new Set(changeRequests.length ? [filePath] : []),
|
|
304
|
+
minePaths: new Map(),
|
|
305
|
+
mineNumbers: new Set<number>(),
|
|
306
|
+
forPath: (p) =>
|
|
307
|
+
p === filePath
|
|
308
|
+
? (changeRequests.map((c) => ({
|
|
309
|
+
number: c.number,
|
|
310
|
+
title: c.title,
|
|
311
|
+
appAuthor: { name: c.who },
|
|
312
|
+
author: { login: 'bevel-bot' },
|
|
313
|
+
branch: `suggestions/${c.who.toLowerCase().replace(/\s+/g, '-')}/knowledge`,
|
|
314
|
+
createdAt: new Date().toISOString(),
|
|
315
|
+
touchedNodePaths: ['Knowledge/Foo.md'],
|
|
316
|
+
})) as never)
|
|
317
|
+
: [],
|
|
318
|
+
}}
|
|
319
|
+
>
|
|
320
|
+
<button type="button" onClick={() => setPendingFileContent(pendingValue)}>
|
|
321
|
+
Inject pending
|
|
322
|
+
</button>
|
|
323
|
+
<FileViewer />
|
|
324
|
+
</OpenChangeRequestsContext.Provider>
|
|
241
325
|
</ReviewContext.Provider>
|
|
242
326
|
</GitContext.Provider>
|
|
243
327
|
</WorkspaceContext.Provider>
|
|
@@ -354,16 +438,20 @@ describe('FileViewer', () => {
|
|
|
354
438
|
// never exist, and the access-denied view lives at the route level. See
|
|
355
439
|
// FileRoute.test.tsx's file-denied cases.)
|
|
356
440
|
|
|
357
|
-
it('
|
|
358
|
-
// Write access is
|
|
359
|
-
//
|
|
360
|
-
//
|
|
441
|
+
it('keeps editing enabled on a protected branch and shows no canonical-state banner', () => {
|
|
442
|
+
// Write access is governed by roles.yaml + access.md and enforced by the
|
|
443
|
+
// backend at commit time — the editor is not disabled based on branch
|
|
444
|
+
// name. The informational strip that used to explain the protected branch
|
|
445
|
+
// is gone; nothing narrates the branch to the reader here anymore.
|
|
361
446
|
render(<ViewerHarness initialContent="official" branch="current-company-state" />);
|
|
362
|
-
|
|
363
|
-
|
|
447
|
+
// `toBeEnabled`, not `toBeInTheDocument`: the header disables Edit when
|
|
448
|
+
// someone else holds the lock, so presence alone would pass on a branch
|
|
449
|
+
// that had gone read-only — the opposite of what this test claims.
|
|
450
|
+
expect(screen.getByRole('button', { name: 'Edit' })).toBeEnabled();
|
|
451
|
+
expect(screen.queryByText(/current company state/i)).not.toBeInTheDocument();
|
|
364
452
|
});
|
|
365
453
|
|
|
366
|
-
it('goes read-only
|
|
454
|
+
it('goes read-only, WITHOUT a permission banner, when canWrite is false on a protected branch', async () => {
|
|
367
455
|
// The access gate only fires on protected branches — drafts are
|
|
368
456
|
// free-for-all and never reach the API, so reproducing the read-only
|
|
369
457
|
// state requires a protected branch.
|
|
@@ -374,11 +462,14 @@ describe('FileViewer', () => {
|
|
|
374
462
|
owners: EMPTY_ELIGIBLE,
|
|
375
463
|
};
|
|
376
464
|
render(<ViewerHarness initialContent="official" branch="target-company-state" />);
|
|
465
|
+
// Read-only means the Edit affordance withdraws…
|
|
377
466
|
await waitFor(() => {
|
|
378
|
-
expect(screen.
|
|
467
|
+
expect(screen.queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument();
|
|
379
468
|
});
|
|
380
|
-
|
|
381
|
-
|
|
469
|
+
// …and that is ALL it means on screen: no "you don't have permission"
|
|
470
|
+
// stripe — for a reader the restriction is not news, and the propose
|
|
471
|
+
// affordance says what they CAN do instead.
|
|
472
|
+
expect(screen.queryByText(/You don't have permission to edit/i)).not.toBeInTheDocument();
|
|
382
473
|
});
|
|
383
474
|
|
|
384
475
|
// Drafts are free-for-all: even if the backend would deny at PR-merge
|
|
@@ -489,4 +580,331 @@ describe('FileViewer', () => {
|
|
|
489
580
|
// And we did NOT flip into edit mode — no editable textbox appeared.
|
|
490
581
|
expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
|
|
491
582
|
});
|
|
583
|
+
|
|
584
|
+
// WP1 regression. The document column moved: the viewer pane used to be
|
|
585
|
+
// `overflow-hidden` with a per-renderer scroller, and `editorContainerRef`
|
|
586
|
+
// sat on that pane. It now sits on `KbDocumentShell`, which is what actually
|
|
587
|
+
// scrolls. Scroll events do NOT bubble, so if the ref ever lands on a
|
|
588
|
+
// wrapper nested inside the scroller the capture listener stops firing,
|
|
589
|
+
// nothing type-errors, and a reader's lock silently auto-releases after two
|
|
590
|
+
// minutes. This suite had zero scroll / recordActivity coverage before.
|
|
591
|
+
it('resets the lock idle timer when the document is scrolled in edit mode', async () => {
|
|
592
|
+
const user = userEvent.setup();
|
|
593
|
+
lockActivity.recordActivity.mockClear();
|
|
594
|
+
render(<ViewerHarness initialContent="a long document" />);
|
|
595
|
+
|
|
596
|
+
await user.click(screen.getByRole('button', { name: 'Edit' }));
|
|
597
|
+
// Edit mode is what arms the scroll listener.
|
|
598
|
+
await screen.findByRole('textbox');
|
|
599
|
+
lockActivity.recordActivity.mockClear();
|
|
600
|
+
|
|
601
|
+
const shell = screen.getByTestId('kb-document-shell');
|
|
602
|
+
await act(async () => {
|
|
603
|
+
shell.dispatchEvent(new Event('scroll'));
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
expect(lockActivity.recordActivity).toHaveBeenCalled();
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
it('leads the page with the document column, not a full-bleed pane', () => {
|
|
610
|
+
render(<ViewerHarness initialContent="measured" />);
|
|
611
|
+
const shell = screen.getByTestId('kb-document-shell');
|
|
612
|
+
// A markdown file is a document, so it gets the prose measure.
|
|
613
|
+
expect(shell.getAttribute('data-variant')).toBe('prose');
|
|
614
|
+
// …and the tab strip lives inside it, so tabs and text share one edge.
|
|
615
|
+
expect(shell.querySelector('[role="tablist"]')).not.toBeNull();
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
// ── WP4: the document names itself ──
|
|
619
|
+
|
|
620
|
+
it('names the file in an h1 and keeps no 40px chrome strip', () => {
|
|
621
|
+
render(<ViewerHarness initialContent="titled" />);
|
|
622
|
+
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('Foo');
|
|
623
|
+
// The trio of sub-tabs went behind ⋯; Content is the page now.
|
|
624
|
+
expect(screen.queryByRole('button', { name: 'Content' })).not.toBeInTheDocument();
|
|
625
|
+
expect(screen.queryByRole('button', { name: 'History' })).not.toBeInTheDocument();
|
|
626
|
+
expect(screen.queryByRole('button', { name: 'Compare' })).not.toBeInTheDocument();
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
it('opens Version history from ⋯ and offers a way back to the document', async () => {
|
|
630
|
+
const user = userEvent.setup();
|
|
631
|
+
render(<ViewerHarness initialContent="historic" />);
|
|
632
|
+
|
|
633
|
+
await user.click(screen.getByRole('button', { name: 'More actions' }));
|
|
634
|
+
await user.click(screen.getByRole('menuitem', { name: /Version history/ }));
|
|
635
|
+
|
|
636
|
+
const back = await screen.findByRole('button', { name: /Back to the document/ });
|
|
637
|
+
await user.click(back);
|
|
638
|
+
// The document is back, and so is its Edit affordance.
|
|
639
|
+
expect(await screen.findByRole('button', { name: 'Edit' })).toBeInTheDocument();
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
it('shares the file itself from Share, and the parent folder from the chevron', async () => {
|
|
643
|
+
const user = userEvent.setup();
|
|
644
|
+
render(<ViewerHarness initialContent="shared" />);
|
|
645
|
+
|
|
646
|
+
await user.click(screen.getByRole('button', { name: 'Share' }));
|
|
647
|
+
expect(
|
|
648
|
+
await screen.findByRole('dialog', {
|
|
649
|
+
name: 'Manage access: file knowledge-base/Knowledge/Foo.md',
|
|
650
|
+
}),
|
|
651
|
+
).toBeInTheDocument();
|
|
652
|
+
// And there is no second scope: sharing the whole folder starts at the
|
|
653
|
+
// folder's own row in the tree, beside the children it governs.
|
|
654
|
+
await user.click(screen.getByRole('button', { name: 'More sharing options' }));
|
|
655
|
+
expect(screen.queryByRole('menuitem', { name: /whole folder/i })).not.toBeInTheDocument();
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
// ── WP5: the rail ──
|
|
659
|
+
|
|
660
|
+
// The rail lost its only trigger with the ⋯ menu's File details entry, so
|
|
661
|
+
// the page never mounts it — and never pays for the history request that
|
|
662
|
+
// used to sit behind its "Edited" row.
|
|
663
|
+
it('mounts no rail, and issues no history request for one', () => {
|
|
664
|
+
fetchFileHistoryMock.mockClear();
|
|
665
|
+
render(<ViewerHarness initialContent="railed" />);
|
|
666
|
+
|
|
667
|
+
expect(screen.queryByText('About this file')).not.toBeInTheDocument();
|
|
668
|
+
expect(fetchFileHistoryMock).not.toHaveBeenCalled();
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
// ── WP6: the third place ──
|
|
672
|
+
|
|
673
|
+
// The D3 asymmetry, made visible: this signal comes from the BROAD endpoint,
|
|
674
|
+
// so a request opened by somebody else on a file you can read but not write
|
|
675
|
+
// still says so here — while the dock, which is scoped to you, stays empty.
|
|
676
|
+
// A DOCUMENT shows it as the skill page does: a change box UNDER the file,
|
|
677
|
+
// whose "Read the whole change" opens the shared change-request dialog.
|
|
678
|
+
it('shows an open change request as a box under the document', async () => {
|
|
679
|
+
const user = userEvent.setup();
|
|
680
|
+
render(
|
|
681
|
+
<ViewerHarness
|
|
682
|
+
initialContent="contested"
|
|
683
|
+
changeRequests={[{ number: 32, title: 'Tighten the wording', who: 'Ali Raza' }]}
|
|
684
|
+
/>,
|
|
685
|
+
);
|
|
686
|
+
|
|
687
|
+
expect(await screen.findByText(/proposed a change/)).toBeInTheDocument();
|
|
688
|
+
expect(screen.getByText('Ali Raza')).toBeInTheDocument();
|
|
689
|
+
await user.click(screen.getByRole('button', { name: 'Read the whole change' }));
|
|
690
|
+
// The shared dialog.
|
|
691
|
+
expect(
|
|
692
|
+
await screen.findByRole('dialog', { name: /Change request: Tighten the wording/ }),
|
|
693
|
+
).toBeInTheDocument();
|
|
694
|
+
});
|
|
695
|
+
|
|
696
|
+
it('says nothing on a file nobody has proposed a change to', () => {
|
|
697
|
+
render(<ViewerHarness initialContent="quiet" />);
|
|
698
|
+
expect(screen.queryByText(/proposed a change/)).not.toBeInTheDocument();
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* The unification the skill page and this viewer share: a document renders
|
|
703
|
+
* inside the SAME edged pane card, named by the same mono filename bar. The
|
|
704
|
+
* frame is one declaration (`FilePaneCard`); this pins that this surface
|
|
705
|
+
* actually mounts it.
|
|
706
|
+
*/
|
|
707
|
+
it('frames a prose document in the shared file pane card', () => {
|
|
708
|
+
render(<ViewerHarness initialContent="boxed" />);
|
|
709
|
+
const card = screen.getByTestId('file-pane-card');
|
|
710
|
+
// The bar names the file, extension and all — same as the skill page.
|
|
711
|
+
expect(within(card).getByText('Foo.md')).toBeInTheDocument();
|
|
712
|
+
expect(within(card).getByText('boxed')).toBeInTheDocument();
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
// With no rail to make room for, the column stays on the base measure.
|
|
716
|
+
it('keeps the base measure', () => {
|
|
717
|
+
render(<ViewerHarness initialContent="railed" />);
|
|
718
|
+
const wrap = screen.getByTestId('kb-document-shell').firstElementChild as HTMLElement;
|
|
719
|
+
expect(wrap.className).toContain('max-w-[880px]');
|
|
720
|
+
});
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* The reader's write path. Where a write grant opens the editor, its absence
|
|
725
|
+
* now opens the SAME editor pointed somewhere else: the text goes to the
|
|
726
|
+
* caller's personal suggestions branch as a change request, and the file on
|
|
727
|
+
* this branch is untouched until an owner approves.
|
|
728
|
+
*/
|
|
729
|
+
describe('FileViewer: proposing a change without write access', () => {
|
|
730
|
+
const reader = { id: 'u9', email: 'reader@example.com', name: 'Rae Reader' };
|
|
731
|
+
|
|
732
|
+
function denyWrite() {
|
|
733
|
+
accessMock.result = {
|
|
734
|
+
canWrite: false,
|
|
735
|
+
canOwner: false,
|
|
736
|
+
eligible: { roles: ['Admin'], users: [] },
|
|
737
|
+
owners: EMPTY_ELIGIBLE,
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
afterEach(() => {
|
|
742
|
+
accessMock.result = {
|
|
743
|
+
canWrite: true,
|
|
744
|
+
canOwner: false,
|
|
745
|
+
eligible: { roles: ['Admin'], users: [] },
|
|
746
|
+
owners: EMPTY_ELIGIBLE,
|
|
747
|
+
};
|
|
748
|
+
proposeMock.mockClear();
|
|
749
|
+
proposeMock.mockResolvedValue({ branch: 'suggestions/reader-u9/knowledge' });
|
|
750
|
+
myCrsMock.mockClear();
|
|
751
|
+
myCrsMock.mockResolvedValue([]);
|
|
752
|
+
readBranchMock.mockClear();
|
|
753
|
+
readBranchMock.mockResolvedValue('');
|
|
754
|
+
});
|
|
755
|
+
|
|
756
|
+
it('offers Propose changes exactly where Edit is refused', async () => {
|
|
757
|
+
denyWrite();
|
|
758
|
+
render(
|
|
759
|
+
<ViewerHarness initialContent="official" branch="target-company-state" authUser={reader} />,
|
|
760
|
+
);
|
|
761
|
+
expect(
|
|
762
|
+
await screen.findByRole('button', { name: 'Propose changes' }),
|
|
763
|
+
).toBeInTheDocument();
|
|
764
|
+
expect(screen.queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument();
|
|
765
|
+
});
|
|
766
|
+
|
|
767
|
+
it('does not offer Propose changes to someone who can simply edit', async () => {
|
|
768
|
+
render(
|
|
769
|
+
<ViewerHarness initialContent="official" branch="target-company-state" authUser={reader} />,
|
|
770
|
+
);
|
|
771
|
+
expect(await screen.findByRole('button', { name: 'Edit' })).toBeInTheDocument();
|
|
772
|
+
expect(screen.queryByRole('button', { name: 'Propose changes' })).not.toBeInTheDocument();
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
it('sends the typed text as a knowledge proposal and reports it', async () => {
|
|
776
|
+
denyWrite();
|
|
777
|
+
const user = userEvent.setup();
|
|
778
|
+
render(
|
|
779
|
+
<ViewerHarness
|
|
780
|
+
initialContent="official"
|
|
781
|
+
branch="target-company-state"
|
|
782
|
+
authUser={reader}
|
|
783
|
+
captureTyped
|
|
784
|
+
/>,
|
|
785
|
+
);
|
|
786
|
+
|
|
787
|
+
await user.click(await screen.findByRole('button', { name: 'Propose changes' }));
|
|
788
|
+
// The read-only "you can't edit" strip yields to the propose surface —
|
|
789
|
+
// showing both would contradict the open editor.
|
|
790
|
+
expect(screen.queryByText(/You don't have permission to edit/i)).not.toBeInTheDocument();
|
|
791
|
+
expect(screen.getByText(/You're proposing a change/)).toBeInTheDocument();
|
|
792
|
+
|
|
793
|
+
const textarea = await screen.findByRole('textbox');
|
|
794
|
+
await user.clear(textarea);
|
|
795
|
+
await user.type(textarea, 'the corrected paragraph');
|
|
796
|
+
await user.click(screen.getByRole('button', { name: 'Send proposal' }));
|
|
797
|
+
|
|
798
|
+
await waitFor(() =>
|
|
799
|
+
expect(proposeMock).toHaveBeenCalledWith({
|
|
800
|
+
// kbDirName stripped: the propose service takes repo-relative paths.
|
|
801
|
+
repoRelativePath: 'Knowledge/Foo.md',
|
|
802
|
+
content: 'the corrected paragraph',
|
|
803
|
+
userEmail: 'reader@example.com',
|
|
804
|
+
userId: 'u9',
|
|
805
|
+
userName: 'Rae Reader',
|
|
806
|
+
}),
|
|
807
|
+
);
|
|
808
|
+
// Back in read mode, with the one confirmation that the change is now
|
|
809
|
+
// someone else's to act on.
|
|
810
|
+
expect(
|
|
811
|
+
await screen.findByText(/sent as a change request/i),
|
|
812
|
+
).toBeInTheDocument();
|
|
813
|
+
expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
|
|
814
|
+
});
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* Proposing AGAIN is a continuation, not a restart. With an open proposal
|
|
818
|
+
* on the caller's suggestions branch, the editor seeds from the file AS
|
|
819
|
+
* PROPOSED — and sending stacks the new edits into the same change
|
|
820
|
+
* request, never silently reverting the pending one to this branch's text.
|
|
821
|
+
*/
|
|
822
|
+
it('seeds a second proposal from the proposed version, and edits stack', async () => {
|
|
823
|
+
denyWrite();
|
|
824
|
+
myCrsMock.mockResolvedValue([
|
|
825
|
+
{ number: 12, state: 'open', branch: 'suggestions/reader-u9/knowledge' },
|
|
826
|
+
]);
|
|
827
|
+
readBranchMock.mockResolvedValue('first proposed paragraph');
|
|
828
|
+
const user = userEvent.setup();
|
|
829
|
+
render(
|
|
830
|
+
<ViewerHarness
|
|
831
|
+
initialContent="official"
|
|
832
|
+
branch="target-company-state"
|
|
833
|
+
authUser={reader}
|
|
834
|
+
captureTyped
|
|
835
|
+
/>,
|
|
836
|
+
);
|
|
837
|
+
|
|
838
|
+
await user.click(await screen.findByRole('button', { name: 'Propose changes' }));
|
|
839
|
+
|
|
840
|
+
// The editor shows the PROPOSED text, read from the suggestions branch —
|
|
841
|
+
// not this branch's "official".
|
|
842
|
+
const textarea = await screen.findByRole('textbox');
|
|
843
|
+
expect(textarea).toHaveValue('first proposed paragraph');
|
|
844
|
+
expect(readBranchMock).toHaveBeenCalledWith(
|
|
845
|
+
'suggestions/reader-u9/knowledge',
|
|
846
|
+
'Knowledge/Foo.md',
|
|
847
|
+
);
|
|
848
|
+
|
|
849
|
+
await user.type(textarea, ' plus a second thought');
|
|
850
|
+
await user.click(screen.getByRole('button', { name: 'Send proposal' }));
|
|
851
|
+
|
|
852
|
+
await waitFor(() =>
|
|
853
|
+
expect(proposeMock).toHaveBeenCalledWith(
|
|
854
|
+
expect.objectContaining({
|
|
855
|
+
content: 'first proposed paragraph plus a second thought',
|
|
856
|
+
}),
|
|
857
|
+
),
|
|
858
|
+
);
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
it('closes without sending when nothing was typed over the open proposal', async () => {
|
|
862
|
+
denyWrite();
|
|
863
|
+
myCrsMock.mockResolvedValue([
|
|
864
|
+
{ number: 12, state: 'open', branch: 'suggestions/reader-u9/knowledge' },
|
|
865
|
+
]);
|
|
866
|
+
readBranchMock.mockResolvedValue('first proposed paragraph');
|
|
867
|
+
const user = userEvent.setup();
|
|
868
|
+
render(
|
|
869
|
+
<ViewerHarness
|
|
870
|
+
initialContent="official"
|
|
871
|
+
branch="target-company-state"
|
|
872
|
+
authUser={reader}
|
|
873
|
+
captureTyped
|
|
874
|
+
/>,
|
|
875
|
+
);
|
|
876
|
+
|
|
877
|
+
await user.click(await screen.findByRole('button', { name: 'Propose changes' }));
|
|
878
|
+
await screen.findByRole('textbox');
|
|
879
|
+
await user.click(screen.getByRole('button', { name: 'Send proposal' }));
|
|
880
|
+
|
|
881
|
+
// The branch already says exactly this — no write, no empty commit.
|
|
882
|
+
await waitFor(() => expect(screen.queryByRole('textbox')).not.toBeInTheDocument());
|
|
883
|
+
expect(proposeMock).not.toHaveBeenCalled();
|
|
884
|
+
});
|
|
885
|
+
|
|
886
|
+
it('discard walks away without sending anything', async () => {
|
|
887
|
+
denyWrite();
|
|
888
|
+
const user = userEvent.setup();
|
|
889
|
+
render(
|
|
890
|
+
<ViewerHarness
|
|
891
|
+
initialContent="official"
|
|
892
|
+
branch="target-company-state"
|
|
893
|
+
authUser={reader}
|
|
894
|
+
captureTyped
|
|
895
|
+
/>,
|
|
896
|
+
);
|
|
897
|
+
|
|
898
|
+
await user.click(await screen.findByRole('button', { name: 'Propose changes' }));
|
|
899
|
+
const textarea = await screen.findByRole('textbox');
|
|
900
|
+
await user.type(textarea, ': never mind');
|
|
901
|
+
await user.click(screen.getByRole('button', { name: 'Discard' }));
|
|
902
|
+
|
|
903
|
+
expect(proposeMock).not.toHaveBeenCalled();
|
|
904
|
+
expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
|
|
905
|
+
// Back to the read-only view: the propose affordance returns, and no
|
|
906
|
+
// permission stripe with it (removed for readers everywhere).
|
|
907
|
+
expect(await screen.findByRole('button', { name: 'Propose changes' })).toBeInTheDocument();
|
|
908
|
+
expect(screen.queryByText(/You don't have permission to edit/i)).not.toBeInTheDocument();
|
|
909
|
+
});
|
|
492
910
|
});
|