@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,224 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState, type ReactNode } from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
3
|
+
|
|
4
|
+
const TRANSITION_MS = 220;
|
|
5
|
+
// Pull-down distance (in px) beyond which release dismisses the sheet. Below
|
|
6
|
+
// this the sheet snaps back to its open position. Tuned for thumb gestures on
|
|
7
|
+
// a phone — small enough that a deliberate pull dismisses, large enough that
|
|
8
|
+
// an accidental nudge doesn't.
|
|
9
|
+
const SWIPE_CLOSE_THRESHOLD_PX = 100;
|
|
10
|
+
|
|
11
|
+
interface SlideOverlayProps {
|
|
12
|
+
open: boolean;
|
|
13
|
+
onClose: () => void;
|
|
14
|
+
side: 'left' | 'right' | 'bottom';
|
|
15
|
+
/** Tailwind classes for the panel itself. Caller controls width/height/rounding. */
|
|
16
|
+
panelClassName?: string;
|
|
17
|
+
/** Optional label for the dialog (read by screen readers). */
|
|
18
|
+
ariaLabel?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Enables swipe-down-to-close on bottom sheets. The gesture only initiates
|
|
21
|
+
* on descendants marked `data-swipe-handle="true"` so scrollable content
|
|
22
|
+
* inside the panel is unaffected.
|
|
23
|
+
*/
|
|
24
|
+
swipeToClose?: boolean;
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function SlideOverlay({
|
|
29
|
+
open,
|
|
30
|
+
onClose,
|
|
31
|
+
side,
|
|
32
|
+
panelClassName,
|
|
33
|
+
ariaLabel,
|
|
34
|
+
swipeToClose,
|
|
35
|
+
children,
|
|
36
|
+
}: SlideOverlayProps) {
|
|
37
|
+
// `mounted` lags behind `open` on close so the exit transition has time to play
|
|
38
|
+
// before the panel unmounts. `visible` toggles the open-state class one frame
|
|
39
|
+
// after mount so the browser registers the transition's starting state.
|
|
40
|
+
const [mounted, setMounted] = useState(open);
|
|
41
|
+
const [visible, setVisible] = useState(false);
|
|
42
|
+
// Pixel offset from the resting (open) position while a swipe is in progress
|
|
43
|
+
// or animating out. 0 means "at the open position"; a positive value (bottom
|
|
44
|
+
// sheet only, for now) means "pulled down by that many px".
|
|
45
|
+
const [dragOffset, setDragOffset] = useState(0);
|
|
46
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
47
|
+
const dragPointerId = useRef<number | null>(null);
|
|
48
|
+
const dragStartY = useRef(0);
|
|
49
|
+
// Track both rAF handles so the cleanup can cancel the inner frame too — the
|
|
50
|
+
// earlier version only cancelled r1, which left r2 free to fire and flip
|
|
51
|
+
// `visible` back to true after a fast close had already flipped it to false.
|
|
52
|
+
const r1Ref = useRef<number | null>(null);
|
|
53
|
+
const r2Ref = useRef<number | null>(null);
|
|
54
|
+
// The swipe-close gesture schedules onClose() after TRANSITION_MS so the
|
|
55
|
+
// exit animation can play out. Track that handle so a reopen (or a second
|
|
56
|
+
// gesture) can cancel a still-pending timer before it fires onClose on the
|
|
57
|
+
// wrong instance of the sheet.
|
|
58
|
+
const closeTimeoutRef = useRef<number | null>(null);
|
|
59
|
+
|
|
60
|
+
const clearCloseTimeout = useCallback(() => {
|
|
61
|
+
if (closeTimeoutRef.current !== null) {
|
|
62
|
+
window.clearTimeout(closeTimeoutRef.current);
|
|
63
|
+
closeTimeoutRef.current = null;
|
|
64
|
+
}
|
|
65
|
+
}, []);
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (open) {
|
|
69
|
+
// Reopening cancels any in-flight close-after-swipe timer so it can't
|
|
70
|
+
// fire onClose against the now-open sheet.
|
|
71
|
+
clearCloseTimeout();
|
|
72
|
+
setMounted(true);
|
|
73
|
+
setDragOffset(0);
|
|
74
|
+
// Two requestAnimationFrame ticks: the first ensures the element is in the
|
|
75
|
+
// DOM with its initial transform; the second flips `visible` so the browser
|
|
76
|
+
// sees a transition between the two states. A single rAF is enough most of
|
|
77
|
+
// the time but flakes in Safari/Firefox under load.
|
|
78
|
+
r1Ref.current = requestAnimationFrame(() => {
|
|
79
|
+
r1Ref.current = null;
|
|
80
|
+
r2Ref.current = requestAnimationFrame(() => {
|
|
81
|
+
r2Ref.current = null;
|
|
82
|
+
setVisible(true);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
return () => {
|
|
86
|
+
if (r1Ref.current !== null) cancelAnimationFrame(r1Ref.current);
|
|
87
|
+
if (r2Ref.current !== null) cancelAnimationFrame(r2Ref.current);
|
|
88
|
+
r1Ref.current = null;
|
|
89
|
+
r2Ref.current = null;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
setVisible(false);
|
|
93
|
+
const t = window.setTimeout(() => {
|
|
94
|
+
setMounted(false);
|
|
95
|
+
setDragOffset(0);
|
|
96
|
+
}, TRANSITION_MS);
|
|
97
|
+
return () => window.clearTimeout(t);
|
|
98
|
+
}, [open, clearCloseTimeout]);
|
|
99
|
+
|
|
100
|
+
useEffect(() => clearCloseTimeout, [clearCloseTimeout]);
|
|
101
|
+
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (!open) return;
|
|
104
|
+
const handler = (e: KeyboardEvent) => {
|
|
105
|
+
if (e.key === 'Escape') onClose();
|
|
106
|
+
};
|
|
107
|
+
window.addEventListener('keydown', handler);
|
|
108
|
+
return () => window.removeEventListener('keydown', handler);
|
|
109
|
+
}, [open, onClose]);
|
|
110
|
+
|
|
111
|
+
const allowSwipe = swipeToClose && side === 'bottom';
|
|
112
|
+
|
|
113
|
+
const handlePointerDown = useCallback((e: React.PointerEvent) => {
|
|
114
|
+
if (!allowSwipe) return;
|
|
115
|
+
const target = e.target as Element | null;
|
|
116
|
+
// Only initiate the drag if the gesture started on (or inside) an element
|
|
117
|
+
// the caller explicitly designated as a drag handle. That keeps the close
|
|
118
|
+
// button and any scrollable content from accidentally triggering a swipe.
|
|
119
|
+
if (!target?.closest('[data-swipe-handle="true"]')) return;
|
|
120
|
+
dragPointerId.current = e.pointerId;
|
|
121
|
+
dragStartY.current = e.clientY;
|
|
122
|
+
setIsDragging(true);
|
|
123
|
+
}, [allowSwipe]);
|
|
124
|
+
|
|
125
|
+
const handlePointerMove = useCallback((e: React.PointerEvent) => {
|
|
126
|
+
if (dragPointerId.current !== e.pointerId) return;
|
|
127
|
+
const dy = Math.max(0, e.clientY - dragStartY.current);
|
|
128
|
+
// Capture once the user has clearly committed to a vertical drag. Doing
|
|
129
|
+
// this lazily lets a quick tap on the handle still register as a click on
|
|
130
|
+
// descendants if they happen to listen for one.
|
|
131
|
+
if (dy > 4 && !e.currentTarget.hasPointerCapture(e.pointerId)) {
|
|
132
|
+
try { e.currentTarget.setPointerCapture(e.pointerId); } catch { /* element gone */ }
|
|
133
|
+
}
|
|
134
|
+
setDragOffset(dy);
|
|
135
|
+
}, []);
|
|
136
|
+
|
|
137
|
+
const handlePointerEnd = useCallback((e: React.PointerEvent) => {
|
|
138
|
+
if (dragPointerId.current !== e.pointerId) return;
|
|
139
|
+
dragPointerId.current = null;
|
|
140
|
+
setIsDragging(false);
|
|
141
|
+
if (dragOffset > SWIPE_CLOSE_THRESHOLD_PX) {
|
|
142
|
+
// Continue the gesture into a close: drive the panel offscreen with the
|
|
143
|
+
// standard CSS transition (now re-enabled since isDragging is false), and
|
|
144
|
+
// call onClose after the animation completes so the parent's open=false
|
|
145
|
+
// doesn't fight the in-flight transform interpolation.
|
|
146
|
+
setDragOffset(window.innerHeight);
|
|
147
|
+
clearCloseTimeout();
|
|
148
|
+
closeTimeoutRef.current = window.setTimeout(() => {
|
|
149
|
+
closeTimeoutRef.current = null;
|
|
150
|
+
onClose();
|
|
151
|
+
}, TRANSITION_MS);
|
|
152
|
+
} else {
|
|
153
|
+
// Below threshold → snap back to the resting position via the CSS
|
|
154
|
+
// transition. Setting dragOffset = 0 triggers the interpolation.
|
|
155
|
+
setDragOffset(0);
|
|
156
|
+
}
|
|
157
|
+
}, [dragOffset, onClose, clearCloseTimeout]);
|
|
158
|
+
|
|
159
|
+
if (!mounted) return null;
|
|
160
|
+
if (typeof document === 'undefined') return null;
|
|
161
|
+
|
|
162
|
+
// Compute the panel transform inline so the swipe-drag offset and the
|
|
163
|
+
// open/close animation share one source of truth. Class-based transforms
|
|
164
|
+
// would force a hand-off between inline (during drag) and class (during
|
|
165
|
+
// exit) that causes a visible snap when releasing-to-close.
|
|
166
|
+
let transform: string;
|
|
167
|
+
if (dragOffset > 0) {
|
|
168
|
+
transform = side === 'bottom'
|
|
169
|
+
? `translate3d(0, ${dragOffset}px, 0)`
|
|
170
|
+
: `translate3d(${-dragOffset}px, 0, 0)`;
|
|
171
|
+
} else if (visible) {
|
|
172
|
+
transform = 'translate3d(0, 0, 0)';
|
|
173
|
+
} else if (side === 'bottom') {
|
|
174
|
+
transform = 'translate3d(0, 100%, 0)';
|
|
175
|
+
} else if (side === 'right') {
|
|
176
|
+
transform = 'translate3d(100%, 0, 0)';
|
|
177
|
+
} else {
|
|
178
|
+
transform = 'translate3d(-100%, 0, 0)';
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const panelPosition =
|
|
182
|
+
side === 'left'
|
|
183
|
+
? 'top-0 bottom-0 left-0'
|
|
184
|
+
: side === 'right'
|
|
185
|
+
? 'top-0 bottom-0 right-0'
|
|
186
|
+
: 'left-0 right-0 bottom-0';
|
|
187
|
+
|
|
188
|
+
return createPortal(
|
|
189
|
+
<div
|
|
190
|
+
className="fixed inset-0 z-50"
|
|
191
|
+
role="dialog"
|
|
192
|
+
aria-modal="true"
|
|
193
|
+
aria-label={ariaLabel}
|
|
194
|
+
>
|
|
195
|
+
<div
|
|
196
|
+
className="absolute inset-0 bg-slate-900/40"
|
|
197
|
+
// Tying backdrop opacity to drag progress makes the close gesture feel
|
|
198
|
+
// continuous — the sheet and the backdrop both fade together as the
|
|
199
|
+
// user pulls down. Falls back to a fixed CSS transition when nothing
|
|
200
|
+
// is being dragged so the regular open/close still animates cleanly.
|
|
201
|
+
style={{
|
|
202
|
+
opacity: visible ? Math.max(0, 1 - dragOffset / 600) : 0,
|
|
203
|
+
transition: isDragging ? 'none' : `opacity ${TRANSITION_MS}ms ease-out`,
|
|
204
|
+
}}
|
|
205
|
+
onClick={onClose}
|
|
206
|
+
/>
|
|
207
|
+
<div
|
|
208
|
+
className={`absolute ${panelPosition} bg-white shadow-2xl will-change-transform ${panelClassName ?? ''}`}
|
|
209
|
+
style={{
|
|
210
|
+
transform,
|
|
211
|
+
transition: isDragging ? 'none' : `transform ${TRANSITION_MS}ms ease-out`,
|
|
212
|
+
}}
|
|
213
|
+
onPointerDown={handlePointerDown}
|
|
214
|
+
onPointerMove={handlePointerMove}
|
|
215
|
+
onPointerUp={handlePointerEnd}
|
|
216
|
+
onPointerCancel={handlePointerEnd}
|
|
217
|
+
onClick={(e) => e.stopPropagation()}
|
|
218
|
+
>
|
|
219
|
+
{children}
|
|
220
|
+
</div>
|
|
221
|
+
</div>,
|
|
222
|
+
document.body,
|
|
223
|
+
);
|
|
224
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { render, screen, waitForElementToBeRemoved } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
5
|
+
import { MobileChatLayout } from '../MobileChatLayout';
|
|
6
|
+
import { useLayout } from '../../state/layout.context';
|
|
7
|
+
|
|
8
|
+
function HeaderToggle() {
|
|
9
|
+
const { toggleExplorer, canToggleChat } = useLayout();
|
|
10
|
+
return (
|
|
11
|
+
<div>
|
|
12
|
+
<button type="button" onClick={toggleExplorer}>
|
|
13
|
+
open-explorer
|
|
14
|
+
</button>
|
|
15
|
+
<span data-testid="can-toggle-chat">{String(canToggleChat)}</span>
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function renderLayout(initialPath: string) {
|
|
21
|
+
return render(
|
|
22
|
+
<MemoryRouter initialEntries={[initialPath]}>
|
|
23
|
+
<MobileChatLayout
|
|
24
|
+
header={<HeaderToggle />}
|
|
25
|
+
explorer={<div>FILE_EXPLORER</div>}
|
|
26
|
+
viewer={<div>FILE_VIEWER</div>}
|
|
27
|
+
chat={<div>CHAT_PANEL</div>}
|
|
28
|
+
/>
|
|
29
|
+
</MemoryRouter>,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe('MobileChatLayout', () => {
|
|
34
|
+
it('always renders the chat slot and hides the explorer until opened', () => {
|
|
35
|
+
renderLayout('/');
|
|
36
|
+
expect(screen.getByText('CHAT_PANEL')).toBeInTheDocument();
|
|
37
|
+
expect(screen.queryByText('FILE_EXPLORER')).toBeNull();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('exposes canToggleChat=false because chat is pinned full-screen', () => {
|
|
41
|
+
renderLayout('/');
|
|
42
|
+
expect(screen.getByTestId('can-toggle-chat').textContent).toBe('false');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('mounts the explorer drawer when the hamburger toggles it open', async () => {
|
|
46
|
+
const user = userEvent.setup();
|
|
47
|
+
renderLayout('/');
|
|
48
|
+
await user.click(screen.getByRole('button', { name: 'open-explorer' }));
|
|
49
|
+
expect(screen.getByText('FILE_EXPLORER')).toBeInTheDocument();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('does not render the viewer slot when the URL has no file path', () => {
|
|
53
|
+
renderLayout('/workspace/main');
|
|
54
|
+
expect(screen.queryByText('FILE_VIEWER')).toBeNull();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('renders the viewer slot in the sheet when the URL points at a file', () => {
|
|
58
|
+
renderLayout('/workspace/main/foo/bar.md');
|
|
59
|
+
expect(screen.getByText('FILE_VIEWER')).toBeInTheDocument();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('unmounts the viewer when the close button is pressed (post-transition)', async () => {
|
|
63
|
+
const user = userEvent.setup();
|
|
64
|
+
renderLayout('/workspace/main/foo/bar.md');
|
|
65
|
+
expect(screen.getByText('FILE_VIEWER')).toBeInTheDocument();
|
|
66
|
+
const dialog = screen.getByRole('dialog', { name: /file preview/i });
|
|
67
|
+
|
|
68
|
+
await user.click(screen.getByRole('button', { name: /close file/i }));
|
|
69
|
+
|
|
70
|
+
// SlideOverlay defers unmount until after the exit transition (~220ms).
|
|
71
|
+
// FILE_VIEWER text disappears synchronously because the parent conditionally
|
|
72
|
+
// renders the children, so target the dialog element itself — its removal
|
|
73
|
+
// is what actually exercises SlideOverlay's deferred-unmount path.
|
|
74
|
+
await waitForElementToBeRemoved(dialog);
|
|
75
|
+
expect(screen.queryByText('FILE_VIEWER')).toBeNull();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { ResizableThreePaneLayout } from '../ResizableThreePaneLayout';
|
|
4
|
+
import { useLayout } from '../../state/layout.context';
|
|
5
|
+
|
|
6
|
+
function CollapseProbe() {
|
|
7
|
+
const { isExplorerCollapsed, isChatCollapsed } = useLayout();
|
|
8
|
+
return (
|
|
9
|
+
<div>
|
|
10
|
+
<span data-testid="probe-explorer">{String(isExplorerCollapsed)}</span>
|
|
11
|
+
<span data-testid="probe-chat">{String(isChatCollapsed)}</span>
|
|
12
|
+
</div>
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe('ResizableThreePaneLayout', () => {
|
|
17
|
+
it('renders header, explorer, viewer, and chat slots', () => {
|
|
18
|
+
render(
|
|
19
|
+
<ResizableThreePaneLayout
|
|
20
|
+
header={<div data-testid="slot-header">HEADER</div>}
|
|
21
|
+
explorer={<div data-testid="slot-explorer">EXPLORER</div>}
|
|
22
|
+
viewer={<div data-testid="slot-viewer">VIEWER</div>}
|
|
23
|
+
chat={<div data-testid="slot-chat">CHAT</div>}
|
|
24
|
+
/>,
|
|
25
|
+
);
|
|
26
|
+
expect(screen.getByTestId('slot-header')).toHaveTextContent('HEADER');
|
|
27
|
+
expect(screen.getByTestId('slot-explorer')).toHaveTextContent('EXPLORER');
|
|
28
|
+
expect(screen.getByTestId('slot-viewer')).toHaveTextContent('VIEWER');
|
|
29
|
+
expect(screen.getByTestId('slot-chat')).toHaveTextContent('CHAT');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('exposes a LayoutController via context with initial collapsed state of false', () => {
|
|
33
|
+
render(
|
|
34
|
+
<ResizableThreePaneLayout
|
|
35
|
+
header={<CollapseProbe />}
|
|
36
|
+
explorer={<div />}
|
|
37
|
+
viewer={<div />}
|
|
38
|
+
chat={<div />}
|
|
39
|
+
/>,
|
|
40
|
+
);
|
|
41
|
+
expect(screen.getByTestId('probe-explorer').textContent).toBe('false');
|
|
42
|
+
expect(screen.getByTestId('probe-chat').textContent).toBe('false');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('renders two resize handles between the three panels', () => {
|
|
46
|
+
const { container } = render(
|
|
47
|
+
<ResizableThreePaneLayout
|
|
48
|
+
header={<div />}
|
|
49
|
+
explorer={<div />}
|
|
50
|
+
viewer={<div />}
|
|
51
|
+
chat={<div />}
|
|
52
|
+
/>,
|
|
53
|
+
);
|
|
54
|
+
const handles = container.querySelectorAll('[data-separator]');
|
|
55
|
+
expect(handles).toHaveLength(2);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export function useMediaQuery(query: string): boolean {
|
|
4
|
+
const getMatch = () =>
|
|
5
|
+
typeof window !== 'undefined' && typeof window.matchMedia === 'function'
|
|
6
|
+
? window.matchMedia(query).matches
|
|
7
|
+
: false;
|
|
8
|
+
|
|
9
|
+
const [matches, setMatches] = useState(getMatch);
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const mql = window.matchMedia(query);
|
|
16
|
+
const onChange = (e: MediaQueryListEvent) => setMatches(e.matches);
|
|
17
|
+
setMatches(mql.matches);
|
|
18
|
+
mql.addEventListener('change', onChange);
|
|
19
|
+
return () => mql.removeEventListener('change', onChange);
|
|
20
|
+
}, [query]);
|
|
21
|
+
|
|
22
|
+
return matches;
|
|
23
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { LayoutContext, useLayout, type LayoutController } from '../layout.context';
|
|
4
|
+
|
|
5
|
+
function Consumer() {
|
|
6
|
+
const { isExplorerCollapsed, isChatCollapsed } = useLayout();
|
|
7
|
+
return (
|
|
8
|
+
<div>
|
|
9
|
+
<span data-testid="explorer">{String(isExplorerCollapsed)}</span>
|
|
10
|
+
<span data-testid="chat">{String(isChatCollapsed)}</span>
|
|
11
|
+
</div>
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe('useLayout', () => {
|
|
16
|
+
it('throws when used outside a provider', () => {
|
|
17
|
+
expect(() => render(<Consumer />)).toThrow(
|
|
18
|
+
/useLayout must be used within LayoutContext.Provider/,
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('exposes the controller inside a provider', () => {
|
|
23
|
+
const controller: LayoutController = {
|
|
24
|
+
isExplorerCollapsed: false,
|
|
25
|
+
isChatCollapsed: true,
|
|
26
|
+
canToggleExplorer: true,
|
|
27
|
+
canToggleChat: true,
|
|
28
|
+
toggleExplorer: () => {},
|
|
29
|
+
toggleChat: () => {},
|
|
30
|
+
};
|
|
31
|
+
render(
|
|
32
|
+
<LayoutContext.Provider value={controller}>
|
|
33
|
+
<Consumer />
|
|
34
|
+
</LayoutContext.Provider>,
|
|
35
|
+
);
|
|
36
|
+
expect(screen.getByTestId('explorer').textContent).toBe('false');
|
|
37
|
+
expect(screen.getByTestId('chat').textContent).toBe('true');
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface LayoutController {
|
|
4
|
+
isExplorerCollapsed: boolean;
|
|
5
|
+
isChatCollapsed: boolean;
|
|
6
|
+
// Layout-specific affordance: the mobile layout pins the chat full-screen and
|
|
7
|
+
// surfaces the explorer as a drawer, so the chat toggle is hidden there. The
|
|
8
|
+
// desktop layout enables a toggle per registered collapsible pane (and
|
|
9
|
+
// `canToggleChat` is false when no chat pane is registered at all).
|
|
10
|
+
canToggleExplorer: boolean;
|
|
11
|
+
canToggleChat: boolean;
|
|
12
|
+
toggleExplorer: () => void;
|
|
13
|
+
toggleChat: () => void;
|
|
14
|
+
// Generalized per-pane API for registry-contributed panes. The named
|
|
15
|
+
// explorer/chat members above are kept as stable aliases for the
|
|
16
|
+
// 'explorer'/'chat' pane ids. Optional so hand-built controllers (tests)
|
|
17
|
+
// remain valid.
|
|
18
|
+
isPaneCollapsed?: (id: string) => boolean;
|
|
19
|
+
canTogglePane?: (id: string) => boolean;
|
|
20
|
+
togglePane?: (id: string) => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Controller for a surface with no collapsible panes — what the shell provides
|
|
25
|
+
* while an app WITHOUT the pane layout (e.g. Skills & Tools) is active, so the
|
|
26
|
+
* always-mounted Toolbar renders no toggle buttons instead of crashing.
|
|
27
|
+
*/
|
|
28
|
+
export const NO_PANES_LAYOUT: LayoutController = {
|
|
29
|
+
isExplorerCollapsed: false,
|
|
30
|
+
isChatCollapsed: false,
|
|
31
|
+
canToggleExplorer: false,
|
|
32
|
+
canToggleChat: false,
|
|
33
|
+
toggleExplorer: () => {},
|
|
34
|
+
toggleChat: () => {},
|
|
35
|
+
isPaneCollapsed: () => false,
|
|
36
|
+
canTogglePane: () => false,
|
|
37
|
+
togglePane: () => {},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const LayoutContext = createContext<LayoutController | null>(null);
|
|
41
|
+
|
|
42
|
+
export function useLayout(): LayoutController {
|
|
43
|
+
const ctx = useContext(LayoutContext);
|
|
44
|
+
if (!ctx) throw new Error('useLayout must be used within LayoutContext.Provider');
|
|
45
|
+
return ctx;
|
|
46
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
|
3
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
4
|
+
import type { ReactNode } from 'react';
|
|
5
|
+
import {
|
|
6
|
+
WorkspaceContext,
|
|
7
|
+
type WorkspaceContextValue,
|
|
8
|
+
} from '../../workspace/state/workspace.context';
|
|
9
|
+
import { AuthContext, type AuthContextValue } from '../../auth/state/auth.context';
|
|
10
|
+
import type { ToolSecrets } from '../../secrets-vault/services/tool-secrets.api';
|
|
11
|
+
|
|
12
|
+
// Service mocks — the dialog's data loading goes through the module's api
|
|
13
|
+
// service (which wraps authFetch), so mocking here follows the same pattern
|
|
14
|
+
// as the other modules' tests.
|
|
15
|
+
const apiMock = vi.hoisted(() => ({
|
|
16
|
+
getSkill: vi.fn(),
|
|
17
|
+
getSkillFile: vi.fn(),
|
|
18
|
+
readFileOnBranch: vi.fn(),
|
|
19
|
+
suggestChange: vi.fn(),
|
|
20
|
+
}));
|
|
21
|
+
vi.mock('../services/library.api', () => ({
|
|
22
|
+
DEFAULT_WORKSPACE_ID: 'target-company-state',
|
|
23
|
+
getSkill: apiMock.getSkill,
|
|
24
|
+
getSkillFile: apiMock.getSkillFile,
|
|
25
|
+
readFileOnBranch: apiMock.readFileOnBranch,
|
|
26
|
+
suggestChange: apiMock.suggestChange,
|
|
27
|
+
listSkills: vi.fn(),
|
|
28
|
+
listOpenChangeRequests: vi.fn(),
|
|
29
|
+
listMyChangeRequests: vi.fn(),
|
|
30
|
+
suggestionBranchFor: vi.fn(),
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
// Keep the markdown pipeline (mermaid etc.) out of this test — the stub
|
|
34
|
+
// renders the raw source so assertions can see the body text.
|
|
35
|
+
vi.mock('../../workspace/components/renderers/KbMarkdownView', () => ({
|
|
36
|
+
KbMarkdownView: ({ source }: { source: string }) => <div data-testid="md-view">{source}</div>,
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
import { DetailDialog } from '../components/DetailDialog';
|
|
40
|
+
|
|
41
|
+
const workspace = {
|
|
42
|
+
workspaceId: 'target-company-state',
|
|
43
|
+
kbDirName: 'knowledge-base',
|
|
44
|
+
} as unknown as WorkspaceContextValue;
|
|
45
|
+
|
|
46
|
+
const auth = {
|
|
47
|
+
user: { id: 'u1', email: 'razvan@bevel.software', name: 'Razvan' },
|
|
48
|
+
token: 't',
|
|
49
|
+
isLoading: false,
|
|
50
|
+
login: async () => {},
|
|
51
|
+
logout: () => {},
|
|
52
|
+
} as AuthContextValue;
|
|
53
|
+
|
|
54
|
+
function wrap(children: ReactNode) {
|
|
55
|
+
return (
|
|
56
|
+
<MemoryRouter>
|
|
57
|
+
<AuthContext.Provider value={auth}>
|
|
58
|
+
<WorkspaceContext.Provider value={workspace}>{children}</WorkspaceContext.Provider>
|
|
59
|
+
</AuthContext.Provider>
|
|
60
|
+
</MemoryRouter>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const skillSummary = {
|
|
65
|
+
name: 'newsletter',
|
|
66
|
+
description: 'Drafts the Friday newsletter for review.',
|
|
67
|
+
path: 'Skills/newsletter',
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const skillDetail = {
|
|
71
|
+
...skillSummary,
|
|
72
|
+
body: '# Newsletter drafter\nCollect the news and draft the letter.',
|
|
73
|
+
allowedTools: ['slack_post_message'],
|
|
74
|
+
files: ['Skills/newsletter/sources.yaml'],
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const slackTool: ToolSecrets = {
|
|
78
|
+
slug: 'slack',
|
|
79
|
+
name: 'slack',
|
|
80
|
+
path: 'Tools/slack.tool',
|
|
81
|
+
type: 'http',
|
|
82
|
+
setup: null,
|
|
83
|
+
canWrite: false,
|
|
84
|
+
variables: [
|
|
85
|
+
{
|
|
86
|
+
name: 'SIGNIN',
|
|
87
|
+
scope: 'user',
|
|
88
|
+
label: 'Slack sign-in',
|
|
89
|
+
key: 'slack_SIGNIN',
|
|
90
|
+
adminConfigured: true,
|
|
91
|
+
userConfigured: false,
|
|
92
|
+
oauth: true,
|
|
93
|
+
authorized: false,
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
function renderDialog(owned: boolean) {
|
|
99
|
+
return render(
|
|
100
|
+
wrap(
|
|
101
|
+
<DetailDialog
|
|
102
|
+
target={{ kind: 'skill', skill: skillSummary, owned }}
|
|
103
|
+
tools={[slackTool]}
|
|
104
|
+
skills={[skillSummary]}
|
|
105
|
+
allowedToolsBySkill={new Map([['newsletter', ['slack_post_message']]])}
|
|
106
|
+
crs={[]}
|
|
107
|
+
myCrNumbers={new Set()}
|
|
108
|
+
inLoadout={false}
|
|
109
|
+
onToggleLoadout={() => {}}
|
|
110
|
+
onClose={() => {}}
|
|
111
|
+
onDataChanged={() => {}}
|
|
112
|
+
/>,
|
|
113
|
+
),
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
beforeEach(() => {
|
|
118
|
+
apiMock.getSkill.mockReset().mockResolvedValue(skillDetail);
|
|
119
|
+
apiMock.getSkillFile.mockReset().mockResolvedValue('watchlist:\n - topic: AI');
|
|
120
|
+
apiMock.readFileOnBranch.mockReset().mockResolvedValue('');
|
|
121
|
+
apiMock.suggestChange.mockReset();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('DetailDialog (skill)', () => {
|
|
125
|
+
it('loads the skill detail and shows description, needed integrations and files', async () => {
|
|
126
|
+
renderDialog(false);
|
|
127
|
+
|
|
128
|
+
expect(await screen.findByText('Drafts the Friday newsletter for review.')).toBeInTheDocument();
|
|
129
|
+
expect(apiMock.getSkill).toHaveBeenCalledWith('newsletter');
|
|
130
|
+
|
|
131
|
+
// Needed integration derived from allowed-tools, with its connection state.
|
|
132
|
+
expect(screen.getByText('slack')).toBeInTheDocument();
|
|
133
|
+
expect(screen.getByText('Needs your sign-in')).toBeInTheDocument();
|
|
134
|
+
expect(screen.getByRole('button', { name: /Connect/ })).toBeInTheDocument();
|
|
135
|
+
|
|
136
|
+
// File browser: SKILL.md tagged MAIN + the bundled file.
|
|
137
|
+
expect(screen.getAllByText('SKILL.md').length).toBeGreaterThan(0);
|
|
138
|
+
expect(screen.getByText('MAIN')).toBeInTheDocument();
|
|
139
|
+
expect(screen.getByText('sources.yaml')).toBeInTheDocument();
|
|
140
|
+
|
|
141
|
+
// SKILL.md body renders through the markdown view.
|
|
142
|
+
expect(screen.getByTestId('md-view').textContent).toContain('Collect the news');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('loads a bundled file on click and renders it as code', async () => {
|
|
146
|
+
renderDialog(false);
|
|
147
|
+
await screen.findByText('sources.yaml');
|
|
148
|
+
|
|
149
|
+
fireEvent.click(screen.getByText('sources.yaml'));
|
|
150
|
+
await waitFor(() =>
|
|
151
|
+
expect(apiMock.getSkillFile).toHaveBeenCalledWith('newsletter', 'sources.yaml'),
|
|
152
|
+
);
|
|
153
|
+
expect(await screen.findByText(/topic: AI/)).toBeInTheDocument();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('shows owner-only Edit and Manage access when the caller owns the skill', async () => {
|
|
157
|
+
renderDialog(true);
|
|
158
|
+
await screen.findByText('Drafts the Friday newsletter for review.');
|
|
159
|
+
|
|
160
|
+
expect(screen.getByRole('button', { name: 'Manage access' })).toBeInTheDocument();
|
|
161
|
+
expect(screen.getByRole('button', { name: 'Edit' })).toBeInTheDocument();
|
|
162
|
+
expect(screen.getByText('OWNER')).toBeInTheDocument();
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('hides Edit and Manage access for non-owners', async () => {
|
|
166
|
+
renderDialog(false);
|
|
167
|
+
await screen.findByText('Drafts the Friday newsletter for review.');
|
|
168
|
+
|
|
169
|
+
expect(screen.queryByRole('button', { name: 'Manage access' })).toBeNull();
|
|
170
|
+
expect(screen.queryByRole('button', { name: 'Edit' })).toBeNull();
|
|
171
|
+
expect(screen.queryByText('OWNER')).toBeNull();
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe('DetailDialog (integration)', () => {
|
|
176
|
+
it('shows per-connection status with a Connect action and the skills using it', async () => {
|
|
177
|
+
render(
|
|
178
|
+
wrap(
|
|
179
|
+
<DetailDialog
|
|
180
|
+
target={{ kind: 'integration', tool: slackTool }}
|
|
181
|
+
tools={[slackTool]}
|
|
182
|
+
skills={[skillSummary]}
|
|
183
|
+
allowedToolsBySkill={new Map([['newsletter', ['slack_post_message']]])}
|
|
184
|
+
crs={[]}
|
|
185
|
+
myCrNumbers={new Set()}
|
|
186
|
+
inLoadout={false}
|
|
187
|
+
onToggleLoadout={() => {}}
|
|
188
|
+
onClose={() => {}}
|
|
189
|
+
onDataChanged={() => {}}
|
|
190
|
+
/>,
|
|
191
|
+
),
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
expect(screen.getByText('Slack sign-in')).toBeInTheDocument();
|
|
195
|
+
expect(screen.getByText('Needs your sign-in')).toBeInTheDocument();
|
|
196
|
+
expect(screen.getByRole('button', { name: /Connect/ })).toBeInTheDocument();
|
|
197
|
+
// Used by: derived from the skills' allowed-tools.
|
|
198
|
+
expect(screen.getByText('newsletter')).toBeInTheDocument();
|
|
199
|
+
});
|
|
200
|
+
});
|