pluginSearch.test.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { describe, expect, it } from "vitest";
  2. import type { ZCodePluginInfo } from "@zcode/shared";
  3. import { storeItemMatches, type StorePluginItem } from "../src/settings/pluginStoreListing.js";
  4. import { filterPluginsByQuery } from "../src/settings/pluginCapabilityProjection.js";
  5. describe("plugin name pinyin search", () => {
  6. const plugin = { id: "lark@official", name: "lark", marketplace: "official" } as ZCodePluginInfo;
  7. const item: StorePluginItem = {
  8. ...plugin,
  9. installed: true,
  10. restorable: false,
  11. orphaned: false,
  12. listing: {
  13. displayName: "Lark CLI",
  14. displayNameI18n: { "zh-CN": "飞书 CLI" },
  15. descriptionI18n: { "zh-CN": "文档协作" },
  16. },
  17. };
  18. const items = new Map([[item.id, item]]);
  19. for (const locale of ["zh-CN", "en-US"]) {
  20. it(`matches Chinese names by full pinyin and initials in ${locale}`, () => {
  21. for (const query of ["feishu", " FEI SHU ", "fs", "飞书", "LARK", "official"]) {
  22. expect(storeItemMatches(item, query, locale), query).toBe(true);
  23. expect(filterPluginsByQuery([plugin], query, items, locale), query).toEqual([plugin]);
  24. }
  25. });
  26. }
  27. it("does not add fuzzy typos, description initials, or cross-market aliases", () => {
  28. for (const query of ["feisuh", "wdxz", "nonesuch"])
  29. expect(storeItemMatches(item, query, "zh-CN")).toBe(false);
  30. const other = { ...plugin, id: "lark@other", marketplace: "other" };
  31. expect(filterPluginsByQuery([other], "fs", items, "zh-CN")).toEqual([]);
  32. expect(
  33. filterPluginsByQuery(
  34. [plugin],
  35. "fs",
  36. new Map([[plugin.id, { ...item, id: other.id }]]),
  37. "zh-CN",
  38. ),
  39. ).toEqual([]);
  40. });
  41. it("supports Chinese raw names without listing metadata", () => {
  42. expect(
  43. storeItemMatches({ ...item, name: "文档助手", listing: undefined }, "wdzs", "en-US"),
  44. ).toBe(true);
  45. });
  46. });