test(ai-toolbar): cover paste gating behavior

This commit is contained in:
2026-04-22 17:58:14 -04:00
parent bfb29d3986
commit 9f23597e53
2 changed files with 69 additions and 8 deletions

View File

@@ -94,6 +94,22 @@ interface AIToolbarProps {
events: CalendarEvent[];
}
interface GlobalPasteCaptureGate {
isAuthenticated: boolean;
isPending: boolean;
canUseAi: boolean;
aiLoading: boolean;
}
export function shouldEnableGlobalPasteCapture({
isAuthenticated,
isPending,
canUseAi,
aiLoading,
}: GlobalPasteCaptureGate): boolean {
return isAuthenticated && !isPending && canUseAi && !aiLoading;
}
// ─── Component ────────────────────────────────────────────────────────────────
export const AIToolbar = ({
@@ -154,7 +170,15 @@ export const AIToolbar = ({
// focused element or OS clipboard model (X11/Wayland).
// This is the approach used by Excalidraw's actionPaste.
useEffect(() => {
if (!isAuthenticated || isPending || !canUseAi || aiLoading) return;
if (
!shouldEnableGlobalPasteCapture({
isAuthenticated,
isPending,
canUseAi,
aiLoading,
})
)
return;
// ── Handler 1: paste event (works when textarea is NOT focused) ───────
const handleDocumentPaste = (e: ClipboardEvent) => {