@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,241 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { render, screen, fireEvent, within } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
5
|
+
import type { ReactNode } from 'react';
|
|
6
|
+
import { EditorTabs } from '../EditorTabs';
|
|
7
|
+
import {
|
|
8
|
+
WorkspaceContext,
|
|
9
|
+
type WorkspaceContextValue,
|
|
10
|
+
type OpenTab,
|
|
11
|
+
} from '../../state/workspace.context';
|
|
12
|
+
import { makeWorkspaceFixture } from '../../__tests__/testFixtures';
|
|
13
|
+
|
|
14
|
+
function makeTab(path: string, overrides: Partial<OpenTab> = {}): OpenTab {
|
|
15
|
+
const content = overrides.content ?? `content:${path}`;
|
|
16
|
+
return {
|
|
17
|
+
path,
|
|
18
|
+
content,
|
|
19
|
+
savedContent: content,
|
|
20
|
+
isDirty: false,
|
|
21
|
+
pendingFileContent: null,
|
|
22
|
+
...overrides,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function makeWorkspace(
|
|
27
|
+
tabs: OpenTab[],
|
|
28
|
+
activePath: string | null,
|
|
29
|
+
overrides: Partial<WorkspaceContextValue> = {},
|
|
30
|
+
): WorkspaceContextValue {
|
|
31
|
+
const activeTab = tabs.find((t) => t.path === activePath) ?? null;
|
|
32
|
+
return makeWorkspaceFixture({
|
|
33
|
+
openTabs: tabs,
|
|
34
|
+
activeTab,
|
|
35
|
+
dirtyTabFilenames: tabs.filter((t) => t.isDirty).map((t) => {
|
|
36
|
+
const i = t.path.lastIndexOf('/');
|
|
37
|
+
return i >= 0 ? t.path.slice(i + 1) : t.path;
|
|
38
|
+
}),
|
|
39
|
+
openFilePath: activeTab?.path ?? null,
|
|
40
|
+
openFileContent: activeTab?.content ?? null,
|
|
41
|
+
openFileSavedContent: activeTab?.savedContent ?? null,
|
|
42
|
+
hasUnsavedFileChanges: tabs.some((t) => t.isDirty),
|
|
43
|
+
pendingFileContent: activeTab?.pendingFileContent ?? null,
|
|
44
|
+
...overrides,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const mockNavigate = vi.fn();
|
|
49
|
+
vi.mock('react-router-dom', async () => {
|
|
50
|
+
const actual = await vi.importActual<typeof import('react-router-dom')>('react-router-dom');
|
|
51
|
+
return {
|
|
52
|
+
...actual,
|
|
53
|
+
useNavigate: () => mockNavigate,
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// useFileNav reads gitState.status.branch from GitContext. To keep these
|
|
58
|
+
// tests focused on the tab strip, stub useFileNav directly.
|
|
59
|
+
vi.mock('../../routing/kb-routes', () => ({
|
|
60
|
+
useFileNav: () => ({
|
|
61
|
+
openFile: (path: string) => mockNavigate(path),
|
|
62
|
+
closeFile: () => mockNavigate(null),
|
|
63
|
+
}),
|
|
64
|
+
}));
|
|
65
|
+
|
|
66
|
+
function Wrap({ workspace, children }: { workspace: WorkspaceContextValue; children: ReactNode }) {
|
|
67
|
+
return (
|
|
68
|
+
<MemoryRouter>
|
|
69
|
+
<WorkspaceContext.Provider value={workspace}>
|
|
70
|
+
{children}
|
|
71
|
+
</WorkspaceContext.Provider>
|
|
72
|
+
</MemoryRouter>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
describe('EditorTabs', () => {
|
|
77
|
+
beforeEach(() => {
|
|
78
|
+
mockNavigate.mockClear();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
afterEach(() => {
|
|
82
|
+
vi.restoreAllMocks();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('renders nothing when no tabs are open', () => {
|
|
86
|
+
const ws = makeWorkspace([], null);
|
|
87
|
+
const { container } = render(<Wrap workspace={ws}><EditorTabs /></Wrap>);
|
|
88
|
+
expect(container.firstChild).toBeNull();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('renders all tabs in order with the active one highlighted', () => {
|
|
92
|
+
const tabs = [makeTab('a.md'), makeTab('Knowledge/b.md'), makeTab('c.md')];
|
|
93
|
+
const ws = makeWorkspace(tabs, 'Knowledge/b.md');
|
|
94
|
+
render(<Wrap workspace={ws}><EditorTabs /></Wrap>);
|
|
95
|
+
|
|
96
|
+
const allTabs = screen.getAllByRole('tab');
|
|
97
|
+
const filenames = allTabs.map((el) => el.querySelector('.truncate')?.textContent ?? '');
|
|
98
|
+
expect(filenames).toEqual(['a.md', 'b.md', 'c.md']);
|
|
99
|
+
const activeTab = allTabs[1];
|
|
100
|
+
expect(activeTab.getAttribute('aria-selected')).toBe('true');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('shows a dirty dot when a tab has unsaved changes', () => {
|
|
104
|
+
const tabs = [makeTab('a.md', { isDirty: true })];
|
|
105
|
+
const ws = makeWorkspace(tabs, 'a.md');
|
|
106
|
+
render(<Wrap workspace={ws}><EditorTabs /></Wrap>);
|
|
107
|
+
expect(screen.getByLabelText('Unsaved changes')).toBeInTheDocument();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('shows the AI badge when a tab has pending agent content', () => {
|
|
111
|
+
const tabs = [makeTab('a.md', { pendingFileContent: 'agent says hi' })];
|
|
112
|
+
const ws = makeWorkspace(tabs, 'a.md');
|
|
113
|
+
render(<Wrap workspace={ws}><EditorTabs /></Wrap>);
|
|
114
|
+
expect(screen.getByLabelText('Agent has pending changes')).toBeInTheDocument();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('clicking a tab navigates via useFileNav', async () => {
|
|
118
|
+
const user = userEvent.setup();
|
|
119
|
+
const tabs = [makeTab('a.md'), makeTab('b.md')];
|
|
120
|
+
const ws = makeWorkspace(tabs, 'a.md');
|
|
121
|
+
render(<Wrap workspace={ws}><EditorTabs /></Wrap>);
|
|
122
|
+
|
|
123
|
+
const tabB = screen.getAllByRole('tab')[1];
|
|
124
|
+
await user.click(tabB);
|
|
125
|
+
expect(mockNavigate).toHaveBeenCalledWith('b.md');
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('clicking the close button closes that tab', async () => {
|
|
129
|
+
const user = userEvent.setup();
|
|
130
|
+
const closeTab = vi.fn<WorkspaceContextValue['closeTab']>(async () => ({ closed: true, newActivePath: null }));
|
|
131
|
+
const tabs = [makeTab('a.md'), makeTab('b.md')];
|
|
132
|
+
const ws = makeWorkspace(tabs, 'a.md', { closeTab });
|
|
133
|
+
render(<Wrap workspace={ws}><EditorTabs /></Wrap>);
|
|
134
|
+
|
|
135
|
+
const closeBtn = screen.getByLabelText('Close b.md');
|
|
136
|
+
await user.click(closeBtn);
|
|
137
|
+
expect(closeTab).toHaveBeenCalledWith(tabs[1]);
|
|
138
|
+
// The tab onClick (activate) should NOT fire when clicking close.
|
|
139
|
+
expect(mockNavigate).not.toHaveBeenCalled();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('right-click opens the context menu with bulk-close actions', async () => {
|
|
143
|
+
const tabs = [makeTab('a.md'), makeTab('b.md'), makeTab('c.md')];
|
|
144
|
+
const ws = makeWorkspace(tabs, 'b.md');
|
|
145
|
+
render(<Wrap workspace={ws}><EditorTabs /></Wrap>);
|
|
146
|
+
|
|
147
|
+
const tabB = screen.getAllByRole('tab')[1];
|
|
148
|
+
fireEvent.contextMenu(tabB);
|
|
149
|
+
|
|
150
|
+
const menu = screen.getByRole('menu');
|
|
151
|
+
expect(within(menu).getByText('Close')).toBeInTheDocument();
|
|
152
|
+
expect(within(menu).getByText('Close others')).toBeInTheDocument();
|
|
153
|
+
expect(within(menu).getByText('Close tabs to the right')).toBeInTheDocument();
|
|
154
|
+
expect(within(menu).getByText('Close all')).toBeInTheDocument();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('Escape closes the context menu', async () => {
|
|
158
|
+
const tabs = [makeTab('a.md')];
|
|
159
|
+
const ws = makeWorkspace(tabs, 'a.md');
|
|
160
|
+
render(<Wrap workspace={ws}><EditorTabs /></Wrap>);
|
|
161
|
+
fireEvent.contextMenu(screen.getAllByRole('tab')[0]);
|
|
162
|
+
expect(screen.getByRole('menu')).toBeInTheDocument();
|
|
163
|
+
fireEvent.keyDown(window, { key: 'Escape' });
|
|
164
|
+
expect(screen.queryByRole('menu')).not.toBeInTheDocument();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('"Close others" closes every other tab via skipConfirm', async () => {
|
|
168
|
+
const user = userEvent.setup();
|
|
169
|
+
const closeTab = vi.fn<WorkspaceContextValue['closeTab']>(async () => ({ closed: true, newActivePath: null }));
|
|
170
|
+
const tabs = [makeTab('a.md'), makeTab('b.md'), makeTab('c.md')];
|
|
171
|
+
const ws = makeWorkspace(tabs, 'b.md', { closeTab });
|
|
172
|
+
render(<Wrap workspace={ws}><EditorTabs /></Wrap>);
|
|
173
|
+
|
|
174
|
+
fireEvent.contextMenu(screen.getAllByRole('tab')[1]); // right-click on b
|
|
175
|
+
await user.click(screen.getByText('Close others'));
|
|
176
|
+
|
|
177
|
+
expect(closeTab).toHaveBeenCalledTimes(2);
|
|
178
|
+
expect(closeTab.mock.calls[0]).toEqual([tabs[0], { skipConfirm: true }]);
|
|
179
|
+
expect(closeTab.mock.calls[1]).toEqual([tabs[2], { skipConfirm: true }]);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('"Close tabs to the right" only closes tabs after the target', async () => {
|
|
183
|
+
const user = userEvent.setup();
|
|
184
|
+
const closeTab = vi.fn<WorkspaceContextValue['closeTab']>(async () => ({ closed: true, newActivePath: null }));
|
|
185
|
+
const tabs = [makeTab('a.md'), makeTab('b.md'), makeTab('c.md')];
|
|
186
|
+
const ws = makeWorkspace(tabs, 'a.md', { closeTab });
|
|
187
|
+
render(<Wrap workspace={ws}><EditorTabs /></Wrap>);
|
|
188
|
+
|
|
189
|
+
fireEvent.contextMenu(screen.getAllByRole('tab')[0]); // right-click on a
|
|
190
|
+
await user.click(screen.getByText('Close tabs to the right'));
|
|
191
|
+
|
|
192
|
+
expect(closeTab).toHaveBeenCalledTimes(2);
|
|
193
|
+
expect(closeTab.mock.calls[0][0]).toEqual(tabs[1]);
|
|
194
|
+
expect(closeTab.mock.calls[1][0]).toEqual(tabs[2]);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('bulk close shows ONE confirm when multiple tabs are dirty', async () => {
|
|
198
|
+
const user = userEvent.setup();
|
|
199
|
+
const closeTab = vi.fn<WorkspaceContextValue['closeTab']>(async () => ({ closed: true, newActivePath: null }));
|
|
200
|
+
const confirmSpy = vi.spyOn(window, 'confirm').mockReturnValue(true);
|
|
201
|
+
const tabs = [
|
|
202
|
+
makeTab('a.md', { isDirty: true }),
|
|
203
|
+
makeTab('b.md'),
|
|
204
|
+
makeTab('c.md', { isDirty: true }),
|
|
205
|
+
];
|
|
206
|
+
const ws = makeWorkspace(tabs, 'b.md', { closeTab });
|
|
207
|
+
render(<Wrap workspace={ws}><EditorTabs /></Wrap>);
|
|
208
|
+
|
|
209
|
+
fireEvent.contextMenu(screen.getAllByRole('tab')[1]); // right-click on b
|
|
210
|
+
await user.click(screen.getByText('Close all'));
|
|
211
|
+
|
|
212
|
+
expect(confirmSpy).toHaveBeenCalledTimes(1);
|
|
213
|
+
expect(confirmSpy.mock.calls[0][0]).toMatch(/a\.md/);
|
|
214
|
+
expect(confirmSpy.mock.calls[0][0]).toMatch(/c\.md/);
|
|
215
|
+
// All three tabs requested for close, with skipConfirm.
|
|
216
|
+
expect(closeTab).toHaveBeenCalledTimes(3);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('reorders via drag and drop', () => {
|
|
220
|
+
const reorderTab = vi.fn();
|
|
221
|
+
const tabs = [makeTab('a.md'), makeTab('b.md'), makeTab('c.md')];
|
|
222
|
+
const ws = makeWorkspace(tabs, 'a.md', { reorderTab });
|
|
223
|
+
render(<Wrap workspace={ws}><EditorTabs /></Wrap>);
|
|
224
|
+
|
|
225
|
+
const [tabA, , tabC] = screen.getAllByRole('tab');
|
|
226
|
+
const dataTransfer = {
|
|
227
|
+
setData: vi.fn(),
|
|
228
|
+
getData: vi.fn(() => 'a.md'),
|
|
229
|
+
types: ['application/x-bevel-tab-path'],
|
|
230
|
+
effectAllowed: 'move',
|
|
231
|
+
dropEffect: 'move',
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
fireEvent.dragStart(tabA, { dataTransfer });
|
|
235
|
+
fireEvent.dragEnter(tabC, { dataTransfer });
|
|
236
|
+
fireEvent.dragOver(tabC, { dataTransfer });
|
|
237
|
+
fireEvent.drop(tabC, { dataTransfer });
|
|
238
|
+
|
|
239
|
+
expect(reorderTab).toHaveBeenCalledWith(tabs[0], 2);
|
|
240
|
+
});
|
|
241
|
+
});
|