Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
240 lines
7.9 KiB
TypeScript
240 lines
7.9 KiB
TypeScript
import { act, fireEvent, renderHook } from "@testing-library/react";
|
|
import type { Editor } from "@tiptap/core";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import type { AgentRichTextEditorHandle } from "../agentRichText/AgentRichTextEditor";
|
|
import type { AgentContextMentionItem } from "../agentRichText/agentFileMentionExtension";
|
|
import { buildAgentComposerDraft } from "../model/agentComposerDraft";
|
|
import { useComposerMentionActions } from "./useComposerMentionActions";
|
|
|
|
describe("useComposerMentionActions directory navigation", () => {
|
|
it("clears the editor query before entering a searched workspace folder", () => {
|
|
const calls: string[] = [];
|
|
const replaceTextBeforeSelection = vi.fn(() => {
|
|
calls.push("replace");
|
|
return "@";
|
|
});
|
|
const updateQuery = vi.fn(() => calls.push("update"));
|
|
const selectFileMentionNavigationItem = vi.fn(() => {
|
|
calls.push("select");
|
|
return true;
|
|
});
|
|
const input = createInput({
|
|
replaceTextBeforeSelection,
|
|
selectFileMentionNavigationItem,
|
|
updateQuery
|
|
});
|
|
const { result } = renderHook(() => useComposerMentionActions(input));
|
|
|
|
act(() => {
|
|
expect(result.current.navigateIntoFileMentionItem(folderItem)).toBe(true);
|
|
});
|
|
|
|
expect(replaceTextBeforeSelection).toHaveBeenCalledWith(4, "@");
|
|
expect(updateQuery).toHaveBeenCalledWith({
|
|
workspaceId: "workspace-1",
|
|
currentUserId: "user-1",
|
|
query: "",
|
|
sectionKey: "section-1",
|
|
sessionCwd: "C:/workspace"
|
|
});
|
|
expect(selectFileMentionNavigationItem).toHaveBeenCalledWith(folderItem);
|
|
expect(calls).toEqual(["replace", "update", "select"]);
|
|
});
|
|
|
|
it("does not navigate when the active editor query cannot be replaced", () => {
|
|
const selectFileMentionNavigationItem = vi.fn(() => true);
|
|
const updateQuery = vi.fn();
|
|
const input = createInput({
|
|
replaceTextBeforeSelection: vi.fn(() => null),
|
|
selectFileMentionNavigationItem,
|
|
updateQuery
|
|
});
|
|
const { result } = renderHook(() => useComposerMentionActions(input));
|
|
|
|
act(() => {
|
|
expect(result.current.navigateIntoFileMentionItem(folderItem)).toBe(
|
|
false
|
|
);
|
|
});
|
|
|
|
expect(updateQuery).not.toHaveBeenCalled();
|
|
expect(selectFileMentionNavigationItem).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe("useComposerMentionActions palette dismissal", () => {
|
|
it("closes the mention palette when pointer or focus moves outside", () => {
|
|
const input = createInput({
|
|
replaceTextBeforeSelection: vi.fn(() => null),
|
|
selectFileMentionNavigationItem: vi.fn(() => false),
|
|
updateQuery: vi.fn()
|
|
});
|
|
const close = vi.fn();
|
|
const setIsPaletteOpen = vi.fn();
|
|
const composer = document.createElement("form");
|
|
const palette = document.createElement("div");
|
|
document.body.append(composer, palette);
|
|
input.fileMentionSuggestion = null;
|
|
input.showFileMentionPalette = true;
|
|
input.setIsPaletteOpen = setIsPaletteOpen;
|
|
input.mentionControllerRef.current = { close } as never;
|
|
input.composerRef.current = composer;
|
|
input.paletteContentRef.current = palette;
|
|
|
|
renderHook(() => useComposerMentionActions(input));
|
|
|
|
act(() => {
|
|
fireEvent.pointerDown(document.body);
|
|
});
|
|
|
|
expect(close).toHaveBeenCalledOnce();
|
|
expect(setIsPaletteOpen).toHaveBeenCalledWith(false);
|
|
|
|
act(() => {
|
|
fireEvent.focusIn(document.body);
|
|
});
|
|
|
|
expect(close).toHaveBeenCalledTimes(2);
|
|
expect(setIsPaletteOpen).toHaveBeenCalledTimes(2);
|
|
composer.remove();
|
|
palette.remove();
|
|
});
|
|
|
|
it("keeps the mention palette open when focus moves inside its portal", () => {
|
|
const input = createInput({
|
|
replaceTextBeforeSelection: vi.fn(() => null),
|
|
selectFileMentionNavigationItem: vi.fn(() => false),
|
|
updateQuery: vi.fn()
|
|
});
|
|
const close = vi.fn();
|
|
const setIsPaletteOpen = vi.fn();
|
|
const composer = document.createElement("form");
|
|
const palette = document.createElement("div");
|
|
const paletteButton = document.createElement("button");
|
|
palette.append(paletteButton);
|
|
document.body.append(composer, palette);
|
|
input.fileMentionSuggestion = null;
|
|
input.showFileMentionPalette = true;
|
|
input.setIsPaletteOpen = setIsPaletteOpen;
|
|
input.mentionControllerRef.current = { close } as never;
|
|
input.composerRef.current = composer;
|
|
input.paletteContentRef.current = palette;
|
|
|
|
renderHook(() => useComposerMentionActions(input));
|
|
|
|
act(() => {
|
|
fireEvent.focusIn(paletteButton);
|
|
});
|
|
|
|
expect(close).not.toHaveBeenCalled();
|
|
expect(setIsPaletteOpen).not.toHaveBeenCalled();
|
|
composer.remove();
|
|
palette.remove();
|
|
});
|
|
|
|
it("closes the mention palette when its host surface loses activity", () => {
|
|
const input = createInput({
|
|
replaceTextBeforeSelection: vi.fn(() => null),
|
|
selectFileMentionNavigationItem: vi.fn(() => false),
|
|
updateQuery: vi.fn()
|
|
});
|
|
const close = vi.fn();
|
|
const setIsPaletteOpen = vi.fn();
|
|
input.fileMentionSuggestion = null;
|
|
input.showFileMentionPalette = true;
|
|
input.setIsPaletteOpen = setIsPaletteOpen;
|
|
input.mentionControllerRef.current = { close } as never;
|
|
input.isActive = true;
|
|
|
|
const { rerender } = renderHook(() => useComposerMentionActions(input));
|
|
|
|
input.isActive = false;
|
|
rerender();
|
|
|
|
expect(close).toHaveBeenCalledOnce();
|
|
expect(setIsPaletteOpen).toHaveBeenCalledWith(false);
|
|
});
|
|
});
|
|
|
|
const folderItem: AgentContextMentionItem = {
|
|
kind: "file",
|
|
path: "/workspace/src",
|
|
href: "/workspace/src",
|
|
name: "src",
|
|
entryKind: "directory",
|
|
directoryPath: "/workspace",
|
|
mentionNavigation: "workspace-folder"
|
|
};
|
|
|
|
function createInput(mocks: {
|
|
replaceTextBeforeSelection: AgentRichTextEditorHandle["replaceTextBeforeSelection"];
|
|
selectFileMentionNavigationItem: (item: AgentContextMentionItem) => boolean;
|
|
updateQuery: (input: unknown) => void;
|
|
}): Parameters<typeof useComposerMentionActions>[0] {
|
|
const draftContent = buildAgentComposerDraft({ prompt: "@src" });
|
|
return {
|
|
workspaceId: "workspace-1",
|
|
currentUserId: "user-1",
|
|
selectedProjectPath: "C:/workspace",
|
|
selectedProjectSectionKey: "section-1",
|
|
draftContent,
|
|
fileMentionSuggestion: {
|
|
editor: {} as Editor,
|
|
range: { from: 1, to: 5 },
|
|
query: "src",
|
|
text: "@src",
|
|
command: vi.fn()
|
|
},
|
|
setFileMentionSuggestion: vi.fn(),
|
|
mentionControllerRef: {
|
|
current: {
|
|
updateQuery: mocks.updateQuery,
|
|
selectFileMentionNavigationItem: mocks.selectFileMentionNavigationItem
|
|
}
|
|
},
|
|
editorHandleRef: {
|
|
current: {
|
|
replaceTextBeforeSelection: mocks.replaceTextBeforeSelection
|
|
} as AgentRichTextEditorHandle
|
|
},
|
|
draftPromptRef: { current: "@src" },
|
|
setPaletteDraftPrompt: vi.fn(),
|
|
setIsPaletteOpen: vi.fn(),
|
|
onDraftContentChange: vi.fn(),
|
|
showFileMentionPalette: false,
|
|
mentionHighlightedKey: null,
|
|
mentionSearchState: {
|
|
status: "ready",
|
|
query: "src",
|
|
mode: "results",
|
|
filter: "file",
|
|
categories: [],
|
|
groups: [],
|
|
error: null
|
|
},
|
|
setMentionHighlightedKey: vi.fn(),
|
|
setShouldCenterMentionHighlight: vi.fn(),
|
|
setShouldResetMentionHighlightToFilter: vi.fn(),
|
|
autoMentionHighlightedKeyRef: { current: null },
|
|
composerSettings: {
|
|
draftSettings: { planMode: false },
|
|
supportsPlanMode: false,
|
|
isSettingsLoading: false
|
|
} as unknown as Parameters<
|
|
typeof useComposerMentionActions
|
|
>[0]["composerSettings"],
|
|
isSendingTurn: false,
|
|
isSubmittingPrompt: false,
|
|
showStopButton: false,
|
|
isActive: true,
|
|
onSettingsChange: vi.fn(),
|
|
handleSlashPaletteKeyDown: vi.fn(() => false),
|
|
handleSlashCommandMenuKeyDown: vi.fn(() => false),
|
|
showPalette: false,
|
|
workspaceReferencePickerOpen: false,
|
|
composerRef: { current: null },
|
|
paletteContentRef: { current: null },
|
|
shouldCenterMentionHighlight: false
|
|
} as unknown as Parameters<typeof useComposerMentionActions>[0];
|
|
}
|