sidePaneTabSearch.test.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. buildSearchFields,
  4. filterAndRankSearchItems,
  5. normalizeSearchQuery,
  6. } from "../src/app-shell/sidePaneTabSearch.js";
  7. describe("sidePaneTabSearch", () => {
  8. function item(id: string, title: string, hint: string, typeLabel: string) {
  9. return {
  10. id,
  11. searchFields: buildSearchFields(title, hint, typeLabel),
  12. };
  13. }
  14. it("matches every query token across title, path, and type", () => {
  15. const items = [
  16. item("docx", "Knowledge Atlas.docx", "/Users/demo/Downloads", "Code Viewer"),
  17. item("browser", "Nimbus", "https://nimbus.example", "Browser"),
  18. ];
  19. expect(
  20. filterAndRankSearchItems(items, normalizeSearchQuery("atlas downloads")).map(
  21. (result) => result.id,
  22. ),
  23. ).toEqual(["docx"]);
  24. });
  25. it("ranks title matches before path and type matches", () => {
  26. const items = [
  27. item("path", "Downloads note", "/Users/demo/nimbus.md", "Code Viewer"),
  28. item("title", "Nimbus", "https://example.com", "Browser"),
  29. item("type", "Example", "https://example.com", "Nimbus Viewer"),
  30. ];
  31. expect(
  32. filterAndRankSearchItems(items, normalizeSearchQuery("nimbus")).map(
  33. (result) => result.id,
  34. ),
  35. ).toEqual(["title", "path", "type"]);
  36. });
  37. });