Files
t3code/apps/web/src/components/chat/composerMenuHighlight.test.ts
T
2026-09-30 17:54:00 -07:00

69 lines
1.9 KiB
TypeScript

import { describe, expect, it } from "vite-plus/test";
import { resolveComposerMenuActiveItemId } from "./composerMenuHighlight";
describe("resolveComposerMenuActiveItemId", () => {
const items = [{ id: "top" }, { id: "second" }, { id: "third" }] as const;
it("defaults to the first item when nothing is highlighted", () => {
expect(
resolveComposerMenuActiveItemId({
items,
highlightedItemId: null,
currentSearchKey: "skill:u",
highlightedSearchKey: null,
}),
).toBe("top");
});
it("preserves the highlighted item within the same query", () => {
expect(
resolveComposerMenuActiveItemId({
items,
highlightedItemId: "second",
currentSearchKey: "skill:u",
highlightedSearchKey: "skill:u",
}),
).toBe("second");
});
it("resets to the top result when the query changes", () => {
expect(
resolveComposerMenuActiveItemId({
items,
highlightedItemId: "second",
currentSearchKey: "skill:ui",
highlightedSearchKey: "skill:u",
}),
).toBe("top");
});
it("falls back to the first item when the highlighted item disappears", () => {
expect(
resolveComposerMenuActiveItemId({
items,
highlightedItemId: "missing",
currentSearchKey: "skill:ui",
highlightedSearchKey: "skill:ui",
}),
).toBe("top");
});
it("clears the active result while async results are empty and resolves against restored results", () => {
const search = {
highlightedItemId: "second",
currentSearchKey: "path:src",
highlightedSearchKey: "path:src",
};
const cleared = resolveComposerMenuActiveItemId({ ...search, items: [] });
expect(cleared).toBeNull();
expect(
resolveComposerMenuActiveItemId({
...search,
highlightedItemId: cleared,
items: [{ id: "new-result" }, { id: "second" }],
}),
).toBe("new-result");
});
});