fix assistant prompt submission

This commit is contained in:
ajnart committed 2026-08-14 11:32:10 +02:00
1 parent 37f5473054
commit d40e6852e6
6 files changed
+141 -47

No files matched your search

@@ -4,9 +4,11 @@ import { createAssistantPromptInteraction } from "./assistant-spotlight";
describe("createAssistantPromptInteraction", () => {
it("sends an existing default-search query immediately", () => {
const sendPrompt = vi.fn();
const sendPrompt = vi.fn(() => true);
const onPromptAccepted = vi.fn();
const interaction = createAssistantPromptInteraction({
sendPrompt,
onPromptAccepted,
prompt: " Check my services ",
});
@@ -14,13 +16,15 @@ describe("createAssistantPromptInteraction", () => {
if (interaction.type !== "javaScript") return;
interaction.onSelect();
expect(interaction.closeSpotlightOnTrigger).toBe(true);
expect(interaction.closeSpotlightOnTrigger).toBe(false);
expect(sendPrompt).toHaveBeenCalledWith("Check my services");
expect(onPromptAccepted).toHaveBeenCalledOnce();
});
it("keeps Spotlight open when the prompt is empty", () => {
const sendPrompt = vi.fn();
const interaction = createAssistantPromptInteraction({ sendPrompt });
const onPromptAccepted = vi.fn();
const interaction = createAssistantPromptInteraction({ sendPrompt, onPromptAccepted });
expect(interaction.type).toBe("children");
if (interaction.type !== "children") return;
@@ -35,11 +39,13 @@ describe("createAssistantPromptInteraction", () => {
sendInteraction.onSelect();
expect(sendInteraction.closeSpotlightOnTrigger).toBe(false);
expect(sendPrompt).not.toHaveBeenCalled();
expect(onPromptAccepted).not.toHaveBeenCalled();
});
it("trims and sends a prompt in the background", () => {
const sendPrompt = vi.fn();
const interaction = createAssistantPromptInteraction({ sendPrompt });
const sendPrompt = vi.fn(() => true);
const onPromptAccepted = vi.fn();
const interaction = createAssistantPromptInteraction({ sendPrompt, onPromptAccepted });
expect(interaction.type).toBe("children");
if (interaction.type !== "children") return;
@@ -52,7 +58,39 @@ describe("createAssistantPromptInteraction", () => {
if (sendInteraction.type !== "javaScript") return;
sendInteraction.onSelect();
expect(sendInteraction.closeSpotlightOnTrigger).toBe(true);
expect(sendInteraction.closeSpotlightOnTrigger).toBe(false);
expect(sendPrompt).toHaveBeenCalledWith("Check my services");
expect(onPromptAccepted).toHaveBeenCalledOnce();
});
it("keeps Spotlight open when the runtime rejects the prompt", () => {
const sendPrompt = vi.fn(() => false);
const onPromptAccepted = vi.fn();
const interaction = createAssistantPromptInteraction({
sendPrompt,
onPromptAccepted,
prompt: "Check my services",
});
expect(interaction.type).toBe("javaScript");
if (interaction.type !== "javaScript") return;
interaction.onSelect();
expect(interaction.closeSpotlightOnTrigger).toBe(false);
expect(sendPrompt).toHaveBeenCalledWith("Check my services");
expect(onPromptAccepted).not.toHaveBeenCalled();
});
it("cannot trigger while the assistant is already handling a request", () => {
const sendPrompt = vi.fn();
const interaction = createAssistantPromptInteraction({
sendPrompt,
onPromptAccepted: vi.fn(),
prompt: "Check my services",
canSend: false,
});
expect(interaction).toEqual({ type: "none" });
expect(sendPrompt).not.toHaveBeenCalled();
});
});