taskFindNavigationState.test.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. changeTaskFindSelection,
  4. createTaskFindNavigationState,
  5. navigateTaskFindSelection,
  6. } from "@/quickpick/taskFindNavigationState.js";
  7. describe("taskFindNavigationState", () => {
  8. it("increments the request id for consecutive navigation to the same index", () => {
  9. const initial = createTaskFindNavigationState();
  10. const first = navigateTaskFindSelection(initial, "needle", 0);
  11. const second = navigateTaskFindSelection(first, "needle", 0);
  12. expect(first).toEqual({
  13. activeIndex: 0,
  14. navigationRequestId: 1,
  15. query: "needle",
  16. });
  17. expect(second).toEqual({
  18. activeIndex: 0,
  19. navigationRequestId: 2,
  20. query: "needle",
  21. });
  22. });
  23. it("preserves the request id for ordinary query and selection changes", () => {
  24. const navigated = navigateTaskFindSelection(
  25. createTaskFindNavigationState(),
  26. "needle",
  27. 0,
  28. );
  29. expect(changeTaskFindSelection(navigated, "other", 2)).toEqual({
  30. activeIndex: 2,
  31. navigationRequestId: 1,
  32. query: "other",
  33. });
  34. });
  35. });