test(ai-toolbar): cover paste gating behavior

This commit is contained in:
old4ever committed 2026-04-22 17:58:14 -04:00
1 parent bfb29d3986
commit 9f23597e53
2 files changed
+69 -8

No files matched your search

+44 -7
View File
@@ -1,5 +1,6 @@
import { describe, expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import { shouldEnableGlobalPasteCapture } from "@/components/ai-toolbar";
import { buttonVariants } from "@/components/ui/button";
import { getAiDisabledMessage } from "@/lib/ai-feature-flags";
import { cn } from "@/lib/utils";
@@ -325,14 +326,50 @@ describe("Keyboard shortcuts – toolbar integration contract", () => {
describe("Global paste capture – AI availability gate", () => {
test("document-level paste handlers only arm when AI is actually usable", () => {
const source = readToolbarSource();
expect(
shouldEnableGlobalPasteCapture({
isAuthenticated: true,
isPending: false,
canUseAi: true,
aiLoading: false,
}),
).toBe(true);
expect(source).toContain(
"if (!isAuthenticated || isPending || !canUseAi || aiLoading) return;",
);
expect(source).toContain(
"}, [isAuthenticated, isPending, canUseAi, aiLoading]);",
);
expect(
shouldEnableGlobalPasteCapture({
isAuthenticated: false,
isPending: false,
canUseAi: true,
aiLoading: false,
}),
).toBe(false);
expect(
shouldEnableGlobalPasteCapture({
isAuthenticated: true,
isPending: true,
canUseAi: true,
aiLoading: false,
}),
).toBe(false);
expect(
shouldEnableGlobalPasteCapture({
isAuthenticated: true,
isPending: false,
canUseAi: false,
aiLoading: false,
}),
).toBe(false);
expect(
shouldEnableGlobalPasteCapture({
isAuthenticated: true,
isPending: false,
canUseAi: true,
aiLoading: true,
}),
).toBe(false);
});
});