conversationFindSearch.test.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. getConversationFindState,
  4. moveConversationFindSelection,
  5. resolveConversationFindNavigationSelection,
  6. resolveConversationFindNavigationDirection,
  7. } from "@/quickpick/conversationFindSearch.js";
  8. describe("conversationFindSearch", () => {
  9. it("resets to the first result when active index is outside the current matches", () => {
  10. expect(getConversationFindState(3, 7)).toEqual({ currentIndex: 0, total: 3 });
  11. expect(getConversationFindState(0, 7)).toEqual({ currentIndex: -1, total: 0 });
  12. });
  13. it("wraps result navigation", () => {
  14. expect(moveConversationFindSelection({ currentIndex: 2, total: 3 }, "next")).toBe(0);
  15. expect(moveConversationFindSelection({ currentIndex: 0, total: 3 }, "previous")).toBe(2);
  16. expect(moveConversationFindSelection({ currentIndex: -1, total: 0 }, "next")).toBe(-1);
  17. });
  18. it("maps buttons and Enter shortcuts to the same navigation directions", () => {
  19. expect(resolveConversationFindNavigationDirection("ArrowUp", false)).toBe("previous");
  20. expect(resolveConversationFindNavigationDirection("ArrowDown", false)).toBe("next");
  21. expect(resolveConversationFindNavigationDirection("Enter", false)).toBe("next");
  22. expect(resolveConversationFindNavigationDirection("Enter", true)).toBe("previous");
  23. });
  24. it("resolves the same selection when one match wraps", () => {
  25. expect(
  26. resolveConversationFindNavigationSelection("needle", { currentIndex: 0, total: 1 }, "next"),
  27. ).toEqual({ activeIndex: 0, query: "needle" });
  28. expect(
  29. resolveConversationFindNavigationSelection(
  30. "needle",
  31. { currentIndex: 0, total: 1 },
  32. "previous",
  33. ),
  34. ).toEqual({ activeIndex: 0, query: "needle" });
  35. });
  36. });