test(ai-toolbar): cover paste gating behavior
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user