openSplitButtonOpenWithOrdering.test.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { readFileSync } from "node:fs";
  2. import { resolve } from "node:path";
  3. import { describe, expect, it } from "vitest";
  4. function readOpenSplitButtonSource() {
  5. return readFileSync(
  6. resolve(process.cwd(), "packages/ui/src/OpenSplitButton.tsx"),
  7. "utf8",
  8. );
  9. }
  10. function readAssistantPreviewCardsSource() {
  11. return readFileSync(
  12. resolve(process.cwd(), "packages/ui/src/AssistantPreviewCards.tsx"),
  13. "utf8",
  14. );
  15. }
  16. describe("OpenSplitButton open-with ordering", () => {
  17. it("renders file preview open-with items through the shared sorted editor list", () => {
  18. const source = readOpenSplitButtonSource();
  19. expect(source).toContain("resolveWorkspaceEditorSelection({");
  20. expect(source).toContain("remoteTarget: openInEditorRemoteTarget");
  21. expect(source).toContain("sortedEditors.map((editor)");
  22. expect(source).not.toContain("editors.map((editor)");
  23. });
  24. it("本地 HTML 外部打开保留文件路径并走平台文件打开接口", () => {
  25. const source = readOpenSplitButtonSource();
  26. const cardSource = readAssistantPreviewCardsSource();
  27. // localPath 直开只允许 file:// 形式的 html 引用卡;localhost 活服务卡必须继续走 URL。
  28. expect(cardSource).toContain('card.url.startsWith("file:") ? card.filePath : undefined');
  29. expect(source).toContain("localPath?: string");
  30. expect(source).toContain("platform.openExternalFile");
  31. expect(source).toContain("toast(");
  32. });
  33. });