@bevel-software/platform-core-frontend 0.1.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/LICENSE +202 -0
- package/package.json +70 -0
- package/src/core/CoreAppShell.tsx +444 -0
- package/src/core/__tests__/ShellRoutes.test.tsx +95 -0
- package/src/core/events.ts +29 -0
- package/src/core/registry.ts +336 -0
- package/src/css-side-effect-imports.d.ts +7 -0
- package/src/html-extensions.ts +12 -0
- package/src/index.css +49 -0
- package/src/index.ts +23 -0
- package/src/lib/api.ts +57 -0
- package/src/lib/utils.ts +138 -0
- package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +130 -0
- package/src/modules/access/__tests__/useFileAccess.test.tsx +253 -0
- package/src/modules/access/api.ts +205 -0
- package/src/modules/access/components/AccessRestrictedBanner.tsx +31 -0
- package/src/modules/access/components/ManageAccessDialog.tsx +1232 -0
- package/src/modules/access/components/NodeOwnersBanner.tsx +30 -0
- package/src/modules/access/hooks/useFileAccess.ts +151 -0
- package/src/modules/admin/components/AdminRolesPage.tsx +943 -0
- package/src/modules/admin/components/RolesCorruptedBanner.tsx +74 -0
- package/src/modules/admin/services/admin.api.ts +92 -0
- package/src/modules/admin/services/roles.api.ts +136 -0
- package/src/modules/admin/state/admin.context.tsx +223 -0
- package/src/modules/auth/components/LoginScreen.tsx +135 -0
- package/src/modules/auth/hooks/useAuthState.ts +59 -0
- package/src/modules/auth/services/auth.api.ts +24 -0
- package/src/modules/auth/services/microsoft-oauth.ts +57 -0
- package/src/modules/auth/state/auth.context.ts +18 -0
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +347 -0
- package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +201 -0
- package/src/modules/git/__tests__/ProtectedBranchBanner.test.tsx +82 -0
- package/src/modules/git/__tests__/PullNeededBanner.test.tsx +441 -0
- package/src/modules/git/__tests__/git.api.test.ts +113 -0
- package/src/modules/git/__tests__/pr.api.test.ts +44 -0
- package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +212 -0
- package/src/modules/git/components/BranchSwitcher.tsx +527 -0
- package/src/modules/git/components/DiffView.tsx +30 -0
- package/src/modules/git/components/FileComparisonPanel.tsx +377 -0
- package/src/modules/git/components/FileHistoryPanel.tsx +320 -0
- package/src/modules/git/components/ProtectedBranchBanner.tsx +42 -0
- package/src/modules/git/components/PullNeededBanner.tsx +204 -0
- package/src/modules/git/components/PullRequestsForMe.tsx +244 -0
- package/src/modules/git/components/UnifiedDiffView.tsx +37 -0
- package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +99 -0
- package/src/modules/git/hooks/useAutoPullUpdates.ts +121 -0
- package/src/modules/git/hooks/useGitState.ts +335 -0
- package/src/modules/git/services/__tests__/error-messages.test.ts +134 -0
- package/src/modules/git/services/error-messages.ts +257 -0
- package/src/modules/git/services/git.api.ts +163 -0
- package/src/modules/git/services/pr-prompts.ts +159 -0
- package/src/modules/git/services/pr.api.ts +39 -0
- package/src/modules/git/state/auto-update.context.ts +21 -0
- package/src/modules/git/state/git.context.ts +82 -0
- package/src/modules/layout/components/AppLayout.tsx +40 -0
- package/src/modules/layout/components/DemoBanner.tsx +57 -0
- package/src/modules/layout/components/MaintenanceOverlay.tsx +104 -0
- package/src/modules/layout/components/MobileChatLayout.tsx +153 -0
- package/src/modules/layout/components/ResizableThreePaneLayout.tsx +203 -0
- package/src/modules/layout/components/SlideOverlay.tsx +224 -0
- package/src/modules/layout/components/__tests__/MobileChatLayout.test.tsx +77 -0
- package/src/modules/layout/components/__tests__/ResizableThreePaneLayout.test.tsx +57 -0
- package/src/modules/layout/hooks/useMediaQuery.ts +23 -0
- package/src/modules/layout/state/__tests__/layout.context.test.tsx +39 -0
- package/src/modules/layout/state/layout.context.ts +46 -0
- package/src/modules/library/__tests__/DetailDialog.test.tsx +200 -0
- package/src/modules/library/__tests__/diff.test.ts +62 -0
- package/src/modules/library/__tests__/loadout.test.tsx +72 -0
- package/src/modules/library/__tests__/status.test.ts +117 -0
- package/src/modules/library/components/ChangeRequestDock.tsx +47 -0
- package/src/modules/library/components/CompareView.tsx +357 -0
- package/src/modules/library/components/DetailDialog.tsx +566 -0
- package/src/modules/library/components/GearIcon.tsx +12 -0
- package/src/modules/library/components/LibraryCard.tsx +132 -0
- package/src/modules/library/components/LibraryPage.tsx +254 -0
- package/src/modules/library/components/LoadoutSidebar.tsx +156 -0
- package/src/modules/library/components/StatusGem.tsx +21 -0
- package/src/modules/library/components/SuggestChange.tsx +171 -0
- package/src/modules/library/components/particles.ts +50 -0
- package/src/modules/library/hooks/useLibraryData.ts +119 -0
- package/src/modules/library/hooks/useSkillDetail.ts +74 -0
- package/src/modules/library/library.css +320 -0
- package/src/modules/library/services/library.api.ts +164 -0
- package/src/modules/library/state/loadout.tsx +129 -0
- package/src/modules/library/state/toast.tsx +42 -0
- package/src/modules/library/utils/diff.ts +102 -0
- package/src/modules/library/utils/status.ts +116 -0
- package/src/modules/pr/__tests__/PrApprovalBadge.test.tsx +93 -0
- package/src/modules/pr/__tests__/PrCancelButton.test.tsx +158 -0
- package/src/modules/pr/__tests__/PrCancelConfirmDialog.test.tsx +44 -0
- package/src/modules/pr/__tests__/PrMergeButton.test.tsx +360 -0
- package/src/modules/pr/__tests__/bucketize-comments.test.ts +85 -0
- package/src/modules/pr/__tests__/parsePatch.test.ts +104 -0
- package/src/modules/pr/__tests__/usePrViewerState.test.ts +72 -0
- package/src/modules/pr/components/OpenChangeRequestDialog.tsx +193 -0
- package/src/modules/pr/components/PrApprovalBadge.tsx +80 -0
- package/src/modules/pr/components/PrCancelButton.tsx +99 -0
- package/src/modules/pr/components/PrCancelConfirmDialog.tsx +119 -0
- package/src/modules/pr/components/PrCommentComposer.tsx +92 -0
- package/src/modules/pr/components/PrCommentThread.tsx +168 -0
- package/src/modules/pr/components/PrCommentsPanel.tsx +143 -0
- package/src/modules/pr/components/PrDiffPane.tsx +425 -0
- package/src/modules/pr/components/PrFileRow.tsx +164 -0
- package/src/modules/pr/components/PrFilesList.tsx +53 -0
- package/src/modules/pr/components/PrHeader.tsx +45 -0
- package/src/modules/pr/components/PrHeaderOverflowMenu.tsx +58 -0
- package/src/modules/pr/components/PrMergeButton.tsx +268 -0
- package/src/modules/pr/components/PrMergeConfirmDialog.tsx +112 -0
- package/src/modules/pr/components/PrRefreshFromTargetButton.tsx +110 -0
- package/src/modules/pr/components/PrViewer.tsx +364 -0
- package/src/modules/pr/hooks/usePrViewerState.ts +150 -0
- package/src/modules/pr/services/pr-approvals.api.ts +31 -0
- package/src/modules/pr/services/pr-cancel.api.ts +19 -0
- package/src/modules/pr/services/pr-comments.api.ts +45 -0
- package/src/modules/pr/services/pr-detail.api.ts +17 -0
- package/src/modules/pr/services/pr-merge.api.ts +53 -0
- package/src/modules/pr/services/pr-open.api.ts +30 -0
- package/src/modules/pr/state/pr-viewer.context.ts +34 -0
- package/src/modules/pr/utils/bucketize-comments.ts +55 -0
- package/src/modules/pr/utils/parsePatch.ts +57 -0
- package/src/modules/review/__tests__/review.api.test.ts +121 -0
- package/src/modules/review/components/BinaryChangePlaceholder.tsx +15 -0
- package/src/modules/review/components/DiffViewer.tsx +78 -0
- package/src/modules/review/components/MarkdownDiffViewer.tsx +263 -0
- package/src/modules/review/components/ReviewFileRow.tsx +114 -0
- package/src/modules/review/components/ReviewPanel.tsx +260 -0
- package/src/modules/review/components/ReviewPanelSurface.tsx +52 -0
- package/src/modules/review/components/__tests__/ReviewPanel.test.tsx +106 -0
- package/src/modules/review/hooks/__tests__/useReviewState.test.ts +88 -0
- package/src/modules/review/hooks/useReviewState.ts +256 -0
- package/src/modules/review/services/review.api.ts +72 -0
- package/src/modules/review/state/ReviewProvider.tsx +28 -0
- package/src/modules/review/state/review.context.ts +29 -0
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +488 -0
- package/src/modules/secrets-vault/components/SecretsPage.tsx +276 -0
- package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +362 -0
- package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +51 -0
- package/src/modules/secrets-vault/services/connect.api.ts +113 -0
- package/src/modules/secrets-vault/services/secrets.api.ts +82 -0
- package/src/modules/secrets-vault/services/tool-secrets.api.ts +116 -0
- package/src/modules/toolbar/components/AdminMenu.tsx +250 -0
- package/src/modules/toolbar/components/AppSwitcher.tsx +108 -0
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +548 -0
- package/src/modules/toolbar/components/Toolbar.tsx +123 -0
- package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +122 -0
- package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +353 -0
- package/src/modules/toolbar/services/external-api-keys.api.ts +65 -0
- package/src/modules/tools/ToolsExplorerPage.tsx +380 -0
- package/src/modules/workflow/hooks/useEventBusSubscription.ts +24 -0
- package/src/modules/workflow/hooks/useFileLock.ts +430 -0
- package/src/modules/workflow/services/lock.api.ts +139 -0
- package/src/modules/workflow/state/EventBusFocusBinder.tsx +25 -0
- package/src/modules/workflow/state/EventBusProvider.tsx +232 -0
- package/src/modules/workflow/state/event-bus.context.ts +75 -0
- package/src/modules/workspace/__tests__/testFixtures.ts +54 -0
- package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +91 -0
- package/src/modules/workspace/components/EditorTabs.tsx +384 -0
- package/src/modules/workspace/components/FileExplorer.tsx +1068 -0
- package/src/modules/workspace/components/FileRoute.tsx +392 -0
- package/src/modules/workspace/components/FileViewer.tsx +906 -0
- package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +241 -0
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +666 -0
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +330 -0
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +492 -0
- package/src/modules/workspace/components/renderers/CsvRenderer.tsx +174 -0
- package/src/modules/workspace/components/renderers/DocxRenderer.tsx +87 -0
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +231 -0
- package/src/modules/workspace/components/renderers/ImageRenderer.tsx +50 -0
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +287 -0
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +252 -0
- package/src/modules/workspace/components/renderers/MermaidDiagram.tsx +268 -0
- package/src/modules/workspace/components/renderers/PdfRenderer.tsx +81 -0
- package/src/modules/workspace/components/renderers/TextRenderer.tsx +86 -0
- package/src/modules/workspace/components/renderers/ToolForm.tsx +404 -0
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +417 -0
- package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +157 -0
- package/src/modules/workspace/components/renderers/__tests__/CsvRenderer.test.ts +57 -0
- package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +95 -0
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +328 -0
- package/src/modules/workspace/components/renderers/__tests__/PdfRenderer.test.tsx +167 -0
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +318 -0
- package/src/modules/workspace/components/renderers/csvUtils.ts +76 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +332 -0
- package/src/modules/workspace/components/renderers/index.ts +39 -0
- package/src/modules/workspace/components/renderers/types.ts +27 -0
- package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +298 -0
- package/src/modules/workspace/hooks/useWorkspaceState.ts +1315 -0
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +99 -0
- package/src/modules/workspace/routing/kb-routes.ts +266 -0
- package/src/modules/workspace/services/__tests__/workspace.api.test.ts +72 -0
- package/src/modules/workspace/services/workspace.api.ts +185 -0
- package/src/modules/workspace/state/workspace.context.ts +235 -0
- package/src/modules/workspace/utils/__tests__/frontmatter.test.ts +107 -0
- package/src/modules/workspace/utils/diff.ts +53 -0
- package/src/modules/workspace/utils/fileTree.ts +179 -0
- package/src/modules/workspace/utils/frontmatter.ts +80 -0
- package/src/modules/workspace/utils/readDroppedEntries.ts +119 -0
- package/src/modules/workspace/utils/tab-persistence.ts +23 -0
- package/src/shared/components/Dialog.tsx +198 -0
- package/src/shared/components/PageShell.tsx +51 -0
- package/src/shared/components/useModalLayer.ts +35 -0
- package/src/shared/markdown/Markdown.tsx +62 -0
- package/src/test-setup.ts +59 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { render, screen, waitFor, fireEvent } from '@testing-library/react';
|
|
3
|
+
import type { BranchInfo, CommitAttribution, WorkingTreeStatus } from '@bevel-software/platform-shared';
|
|
4
|
+
|
|
5
|
+
// Mock the access API before importing the component tree — useFileAccess
|
|
6
|
+
// fires a fetch in an effect on mount, and we don't want real network in tests.
|
|
7
|
+
const accessMock = vi.hoisted(() => ({
|
|
8
|
+
result: { canWrite: true, eligible: { roles: ['Admin'], users: [] } } as {
|
|
9
|
+
canWrite: boolean;
|
|
10
|
+
eligible: { roles: string[]; users: { name: string; email: string }[] };
|
|
11
|
+
},
|
|
12
|
+
}));
|
|
13
|
+
vi.mock('../../access/api', () => ({
|
|
14
|
+
fetchFileAccess: vi.fn(async () => accessMock.result),
|
|
15
|
+
fetchFileAccessBatch: vi.fn(async () => ({ results: {} })),
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
import { FileHistoryPanel } from '../components/FileHistoryPanel';
|
|
19
|
+
import { GitContext, type GitContextValue } from '../state/git.context';
|
|
20
|
+
import {
|
|
21
|
+
WorkspaceContext,
|
|
22
|
+
type WorkspaceContextValue,
|
|
23
|
+
} from '../../workspace/state/workspace.context';
|
|
24
|
+
|
|
25
|
+
function makeAttr(partial: Partial<CommitAttribution> = {}): CommitAttribution {
|
|
26
|
+
return {
|
|
27
|
+
sha: 'abcdef1234567890',
|
|
28
|
+
authorName: 'Alice',
|
|
29
|
+
authorEmail: 'alice@example.com',
|
|
30
|
+
subject: 'edit file',
|
|
31
|
+
committedAt: '2026-04-17T10:00:00Z',
|
|
32
|
+
...partial,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function makeGit(overrides: Partial<GitContextValue> = {}): GitContextValue {
|
|
37
|
+
const status: WorkingTreeStatus = {
|
|
38
|
+
branch: 'alice/foo',
|
|
39
|
+
hasUpstream: true,
|
|
40
|
+
unmergedFromUpstream: false,
|
|
41
|
+
};
|
|
42
|
+
const branches: BranchInfo[] = [];
|
|
43
|
+
return {
|
|
44
|
+
status,
|
|
45
|
+
branches,
|
|
46
|
+
availability: 'ready',
|
|
47
|
+
lastError: null,
|
|
48
|
+
refreshStatus: async () => null,
|
|
49
|
+
refreshBranches: async () => {},
|
|
50
|
+
createBranch: async () => {},
|
|
51
|
+
pull: async () => {},
|
|
52
|
+
deleteBranch: async () => {},
|
|
53
|
+
fetchForkBase: async () => null,
|
|
54
|
+
revert: async () => makeAttr({ sha: 'revertsha1234567' }),
|
|
55
|
+
fetchFileHistory: async () => [],
|
|
56
|
+
fetchFileDiff: async () => '',
|
|
57
|
+
fetchFileComparison: async () => '',
|
|
58
|
+
...overrides,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const workspace = {
|
|
63
|
+
workspaceId: 'ws-1',
|
|
64
|
+
kbDirName: 'knowledge-base',
|
|
65
|
+
} as unknown as WorkspaceContextValue;
|
|
66
|
+
|
|
67
|
+
function renderWith(git: GitContextValue, onRevert: () => Promise<void> = async () => {}) {
|
|
68
|
+
return render(
|
|
69
|
+
<WorkspaceContext.Provider value={workspace}>
|
|
70
|
+
<GitContext.Provider value={git}>
|
|
71
|
+
<FileHistoryPanel
|
|
72
|
+
filePath="knowledge-base/Knowledge/Foo.md"
|
|
73
|
+
onRevertCompleted={onRevert}
|
|
74
|
+
/>
|
|
75
|
+
</GitContext.Provider>
|
|
76
|
+
</WorkspaceContext.Provider>,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
describe('FileHistoryPanel', () => {
|
|
81
|
+
it('renders the timeline returned from fetchFileHistory', async () => {
|
|
82
|
+
const history = [
|
|
83
|
+
makeAttr({ sha: 'aaaaaaa0000000000', subject: 'first' }),
|
|
84
|
+
makeAttr({ sha: 'bbbbbbb0000000000', subject: 'second', authorName: 'Bob' }),
|
|
85
|
+
];
|
|
86
|
+
renderWith(makeGit({ fetchFileHistory: async () => history }));
|
|
87
|
+
expect(await screen.findByText('first')).toBeInTheDocument();
|
|
88
|
+
expect(screen.getByText('second')).toBeInTheDocument();
|
|
89
|
+
// Author is rendered alongside a relative timestamp in a single line, e.g. "Bob · 2w ago".
|
|
90
|
+
expect(screen.getByText(/Bob\s*·/)).toBeInTheDocument();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('shows an empty state when the file has no saves', async () => {
|
|
94
|
+
renderWith(makeGit({ fetchFileHistory: async () => [] }));
|
|
95
|
+
expect(await screen.findByText(/Nothing has been saved to this file/i)).toBeInTheDocument();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('loads the diff when a commit is selected', async () => {
|
|
99
|
+
const fetchFileDiff = vi.fn(async () => '--- a\n+++ b\n@@ -1 +1 @@\n-foo\n+bar\n');
|
|
100
|
+
const history = [makeAttr({ sha: 'aaaaaaa0000000000', subject: 'edit' })];
|
|
101
|
+
renderWith(
|
|
102
|
+
makeGit({
|
|
103
|
+
fetchFileHistory: async () => history,
|
|
104
|
+
fetchFileDiff,
|
|
105
|
+
}),
|
|
106
|
+
);
|
|
107
|
+
const row = await screen.findByText('edit');
|
|
108
|
+
fireEvent.click(row);
|
|
109
|
+
await waitFor(() =>
|
|
110
|
+
expect(fetchFileDiff).toHaveBeenCalledWith(
|
|
111
|
+
'knowledge-base/Knowledge/Foo.md',
|
|
112
|
+
'aaaaaaa0000000000',
|
|
113
|
+
),
|
|
114
|
+
);
|
|
115
|
+
expect(await screen.findByText(/\+bar/)).toBeInTheDocument();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('renders "No file changes in this save" when the selected diff is empty', async () => {
|
|
119
|
+
const history = [makeAttr({ sha: 'aaaaaaa0000000000', subject: 'edit' })];
|
|
120
|
+
renderWith(
|
|
121
|
+
makeGit({
|
|
122
|
+
fetchFileHistory: async () => history,
|
|
123
|
+
fetchFileDiff: async () => '',
|
|
124
|
+
}),
|
|
125
|
+
);
|
|
126
|
+
fireEvent.click(await screen.findByText('edit'));
|
|
127
|
+
expect(await screen.findByText(/No file changes in this save/i)).toBeInTheDocument();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('calls revert and fires onRevertCompleted on success', async () => {
|
|
131
|
+
const onRevert = vi.fn();
|
|
132
|
+
const revert = vi.fn(async () => makeAttr({ sha: 'reverteddeadbeef' }));
|
|
133
|
+
const history = [makeAttr({ sha: 'aaaaaaa0000000000', subject: 'edit' })];
|
|
134
|
+
renderWith(
|
|
135
|
+
makeGit({
|
|
136
|
+
fetchFileHistory: async () => history,
|
|
137
|
+
revert,
|
|
138
|
+
}),
|
|
139
|
+
onRevert,
|
|
140
|
+
);
|
|
141
|
+
fireEvent.click(await screen.findByText('edit'));
|
|
142
|
+
const undoButton = await screen.findByRole('button', { name: /Undo this save/i });
|
|
143
|
+
fireEvent.click(undoButton);
|
|
144
|
+
await waitFor(() => expect(revert).toHaveBeenCalledWith('aaaaaaa0000000000'));
|
|
145
|
+
await waitFor(() => expect(onRevert).toHaveBeenCalled());
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it.each(['current-company-state', 'target-company-state'] as const)(
|
|
149
|
+
'enables the undo button on protected branch %s when the user has write access',
|
|
150
|
+
async (branch) => {
|
|
151
|
+
// The historical gate was "protected branch → disabled." Revert is now
|
|
152
|
+
// gated by per-path write access (canWrite) instead — admins on a
|
|
153
|
+
// canonical branch can undo directly.
|
|
154
|
+
const history = [makeAttr({ sha: 'aaaaaaa0000000000', subject: 'edit' })];
|
|
155
|
+
renderWith(
|
|
156
|
+
makeGit({
|
|
157
|
+
status: {
|
|
158
|
+
branch,
|
|
159
|
+
hasUpstream: true,
|
|
160
|
+
unmergedFromUpstream: false,
|
|
161
|
+
},
|
|
162
|
+
fetchFileHistory: async () => history,
|
|
163
|
+
}),
|
|
164
|
+
);
|
|
165
|
+
fireEvent.click(await screen.findByText('edit'));
|
|
166
|
+
const undoButton = await screen.findByRole('button', { name: /Undo this save/i });
|
|
167
|
+
await waitFor(() => expect(undoButton).not.toBeDisabled());
|
|
168
|
+
},
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
it('disables the undo button when the user lacks write access on a protected branch', async () => {
|
|
172
|
+
// The revert gate is only consulted on protected branches — drafts are
|
|
173
|
+
// free-for-all (the backend's revertCommit skips the access check on
|
|
174
|
+
// non-protected branches, so the editor mirrors that by leaving the
|
|
175
|
+
// button enabled). Reproducing the disabled state requires a protected
|
|
176
|
+
// branch where the gate actually runs.
|
|
177
|
+
accessMock.result = {
|
|
178
|
+
canWrite: false,
|
|
179
|
+
eligible: { roles: ['Admin'], users: [] },
|
|
180
|
+
};
|
|
181
|
+
try {
|
|
182
|
+
const history = [makeAttr({ sha: 'aaaaaaa0000000000', subject: 'edit' })];
|
|
183
|
+
renderWith(
|
|
184
|
+
makeGit({
|
|
185
|
+
status: {
|
|
186
|
+
branch: 'current-company-state',
|
|
187
|
+
hasUpstream: true,
|
|
188
|
+
unmergedFromUpstream: false,
|
|
189
|
+
},
|
|
190
|
+
fetchFileHistory: async () => history,
|
|
191
|
+
}),
|
|
192
|
+
);
|
|
193
|
+
fireEvent.click(await screen.findByText('edit'));
|
|
194
|
+
const undoButton = await screen.findByRole('button', { name: /Undo this save/i });
|
|
195
|
+
await waitFor(() => expect(undoButton).toBeDisabled());
|
|
196
|
+
expect(undoButton.getAttribute('title')).toMatch(/don't have permission/i);
|
|
197
|
+
} finally {
|
|
198
|
+
accessMock.result = { canWrite: true, eligible: { roles: ['Admin'], users: [] } };
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import type { BranchInfo, WorkingTreeStatus } from '@bevel-software/platform-shared';
|
|
4
|
+
import {
|
|
5
|
+
ProtectedBranchBanner,
|
|
6
|
+
isProtectedBranchName,
|
|
7
|
+
} from '../components/ProtectedBranchBanner';
|
|
8
|
+
import { GitContext, type GitContextValue } from '../state/git.context';
|
|
9
|
+
|
|
10
|
+
function makeGit(
|
|
11
|
+
overrides: { status?: WorkingTreeStatus | null; availability?: GitContextValue['availability'] } = {},
|
|
12
|
+
): GitContextValue {
|
|
13
|
+
const status: WorkingTreeStatus | null =
|
|
14
|
+
overrides.status === undefined
|
|
15
|
+
? {
|
|
16
|
+
branch: 'current-company-state',
|
|
17
|
+
hasUpstream: true,
|
|
18
|
+
unmergedFromUpstream: false,
|
|
19
|
+
}
|
|
20
|
+
: overrides.status;
|
|
21
|
+
const branches: BranchInfo[] = [];
|
|
22
|
+
return {
|
|
23
|
+
status,
|
|
24
|
+
branches,
|
|
25
|
+
availability: overrides.availability ?? 'ready',
|
|
26
|
+
lastError: null,
|
|
27
|
+
refreshStatus: async () => null,
|
|
28
|
+
refreshBranches: async () => {},
|
|
29
|
+
createBranch: async () => {},
|
|
30
|
+
pull: async () => {},
|
|
31
|
+
deleteBranch: async () => {},
|
|
32
|
+
fetchForkBase: async () => null,
|
|
33
|
+
revert: async () => ({ authorName: '', authorEmail: '', sha: '', subject: '', committedAt: '' }),
|
|
34
|
+
fetchFileHistory: async () => [],
|
|
35
|
+
fetchFileDiff: async () => '',
|
|
36
|
+
fetchFileComparison: async () => '',
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function renderWith(git: GitContextValue) {
|
|
41
|
+
return render(
|
|
42
|
+
<GitContext.Provider value={git}>
|
|
43
|
+
<ProtectedBranchBanner />
|
|
44
|
+
</GitContext.Provider>,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe('isProtectedBranchName', () => {
|
|
49
|
+
it('recognises current-company-state and target-company-state', () => {
|
|
50
|
+
expect(isProtectedBranchName('current-company-state')).toBe(true);
|
|
51
|
+
expect(isProtectedBranchName('target-company-state')).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
it('does not flag user branches', () => {
|
|
54
|
+
expect(isProtectedBranchName('alice/foo')).toBe(false);
|
|
55
|
+
expect(isProtectedBranchName('main')).toBe(false);
|
|
56
|
+
expect(isProtectedBranchName(null)).toBe(false);
|
|
57
|
+
expect(isProtectedBranchName(undefined)).toBe(false);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('ProtectedBranchBanner', () => {
|
|
62
|
+
it('shows the warning when on a protected branch', () => {
|
|
63
|
+
renderWith(makeGit());
|
|
64
|
+
expect(screen.getByText(/Current company state/)).toBeInTheDocument();
|
|
65
|
+
expect(screen.getByText(/Target company state/)).toBeInTheDocument();
|
|
66
|
+
expect(screen.getByText('current-company-state')).toBeInTheDocument();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('renders nothing on a user branch', () => {
|
|
70
|
+
const { container } = renderWith(
|
|
71
|
+
makeGit({
|
|
72
|
+
status: { branch: 'alice/foo', hasUpstream: true, unmergedFromUpstream: false },
|
|
73
|
+
}),
|
|
74
|
+
);
|
|
75
|
+
expect(container.firstChild).toBeNull();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('renders nothing while loading (no status yet)', () => {
|
|
79
|
+
const { container } = renderWith(makeGit({ status: null, availability: 'loading' }));
|
|
80
|
+
expect(container.firstChild).toBeNull();
|
|
81
|
+
});
|
|
82
|
+
});
|