openWithEditors.test.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { describe, expect, it } from "vitest";
  2. import type { EditorInfo } from "@zcode/shared";
  3. import { isFileManagerOpenTarget, sortInstalledEditorsForOpenWith } from "@/lib/openWithEditors.js";
  4. function makeEditor(id: string): EditorInfo {
  5. return {
  6. id,
  7. name: id,
  8. iconDataUrl: `data:image/png;base64,${id}`,
  9. };
  10. }
  11. describe("open-with editor ordering", () => {
  12. it("通用模式仅保留各平台文件管理器", () => {
  13. const editors = [
  14. "vscode",
  15. "finder",
  16. "terminal",
  17. "qspace",
  18. "qspace-pro",
  19. "explorer",
  20. "cursor",
  21. ].map(makeEditor);
  22. expect(editors.filter(isFileManagerOpenTarget).map((editor) => editor.id)).toEqual([
  23. "finder",
  24. "qspace",
  25. "qspace-pro",
  26. "explorer",
  27. ]);
  28. expect(editors).toHaveLength(7);
  29. });
  30. it("pins file managers before regular editors in a stable shared order", () => {
  31. const sortedEditors = sortInstalledEditorsForOpenWith([
  32. makeEditor("cursor"),
  33. makeEditor("qspace-pro"),
  34. makeEditor("vscode"),
  35. makeEditor("explorer"),
  36. makeEditor("qspace"),
  37. makeEditor("finder"),
  38. ]);
  39. expect(sortedEditors.map((editor) => editor.id)).toEqual([
  40. "finder",
  41. "qspace",
  42. "qspace-pro",
  43. "explorer",
  44. "cursor",
  45. "vscode",
  46. ]);
  47. });
  48. });