Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

composerMenuHighlight.test.ts

51 lines1.4 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { resolveComposerMenuActiveItemId } from "./composerMenuHighlight";
4​
5describe("resolveComposerMenuActiveItemId", () => {
6 const items = [{ id: "top" }, { id: "second" }, { id: "third" }] as const;
7​
8 it("defaults to the first item when nothing is highlighted", () => {
9 expect(
10 resolveComposerMenuActiveItemId({
11 items,
12 highlightedItemId: null,
13 currentSearchKey: "skill:u",
14 highlightedSearchKey: null,
15 }),
16 ).toBe("top");
17 });
18​
19 it("preserves the highlighted item within the same query", () => {
20 expect(
21 resolveComposerMenuActiveItemId({
22 items,
23 highlightedItemId: "second",
24 currentSearchKey: "skill:u",
25 highlightedSearchKey: "skill:u",
26 }),
27 ).toBe("second");
28 });
29​
30 it("resets to the top result when the query changes", () => {
31 expect(
32 resolveComposerMenuActiveItemId({
33 items,
34 highlightedItemId: "second",
35 currentSearchKey: "skill:ui",
36 highlightedSearchKey: "skill:u",
37 }),
38 ).toBe("top");
39 });
40​
41 it("falls back to the first item when the highlighted item disappears", () => {
42 expect(
43 resolveComposerMenuActiveItemId({
44 items,
45 highlightedItemId: "missing",
46 currentSearchKey: "skill:ui",
47 highlightedSearchKey: "skill:ui",
48 }),
49 ).toBe("top");
50 });
51});