Files
kandev/apps/web/components/task/chat/use-chat-input-container.test.ts
T
2026-06-27 16:11:39 +01:00

90 lines
2.9 KiB
TypeScript

import { createRef } from "react";
import { renderHook } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { shouldShowChatFocusHint, useChatInputContainer } from "./use-chat-input-container";
import type { ChatInputContainerHandle } from "./chat-input-container";
function renderInputState(overrides: Partial<Parameters<typeof useChatInputContainer>[0]> = {}) {
return renderHook(() =>
useChatInputContainer({
ref: createRef<ChatInputContainerHandle>(),
sessionId: "session-1",
isSending: false,
isStarting: false,
isPreparingEnvironment: false,
isMoving: false,
isFailed: false,
needsRecovery: false,
executorUnavailable: false,
isAgentBusy: false,
hasAgentCommands: true,
placeholder: undefined,
contextItems: [],
pendingClarification: null,
onClarificationResolved: undefined,
pendingCommentsByFile: undefined,
hasContextComments: false,
showRequestChangesTooltip: false,
onRequestChangesTooltipDismiss: undefined,
onSubmit: vi.fn(),
...overrides,
}),
);
}
describe("useChatInputContainer", () => {
it("disables the editor while the session is still STARTING", () => {
// The editor must stay uneditable until the agent reaches RUNNING — if
// the user can press Cmd+Enter mid-startup, the backend rejects with
// "Failed to send message to agent" because the agent process isn't
// ready yet. This is the regression from earlier rounds where the e2e
// quick-chat suite kept failing on race conditions.
const { result } = renderInputState({ isStarting: true });
expect(result.current.isDisabled).toBe(true);
expect(result.current.submitDisabled).toBe(true);
expect(result.current.submitDisabledReason).toBeUndefined();
});
it("surfaces the setup tooltip only while a container/sandbox is preparing", () => {
const { result } = renderInputState({
isStarting: true,
isPreparingEnvironment: true,
});
expect(result.current.submitDisabledReason).toBe("The agent is still being set up.");
});
});
describe("shouldShowChatFocusHint", () => {
it("hides the hint when a blurred editor has draft text", () => {
expect(
shouldShowChatFocusHint({
isInputFocused: false,
value: "halle from chat input",
hasClarification: false,
hasPendingComments: false,
}),
).toBe(false);
});
it("shows the hint only for an empty blurred editor without blocking overlays", () => {
expect(
shouldShowChatFocusHint({
isInputFocused: false,
value: " ",
hasClarification: false,
hasPendingComments: false,
}),
).toBe(true);
expect(
shouldShowChatFocusHint({
isInputFocused: true,
value: "",
hasClarification: false,
hasPendingComments: false,
}),
).toBe(false);
});
});