preview-card-actions.fixture.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { useCallback, useState } from "react";
  2. import { createRoot } from "react-dom/client";
  3. import type { IServiceAccessor } from "@zcode/services";
  4. import type { IPlatformService } from "@zcode/shared";
  5. import { AssistantPreviewCards } from "@/AssistantPreviewCards.js";
  6. import { MessageChangeSummaryPanel } from "@/MessageChangeSummaryPanel.js";
  7. import { PlatformProvider } from "@/hooks/usePlatform.js";
  8. import { ServiceProvider } from "@/hooks/useServices.js";
  9. import { TabStoreProvider } from "@/store/TabStoreProvider.js";
  10. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  11. import "@/styles.css";
  12. const params = new URLSearchParams(location.search);
  13. const locale = params.get("locale") === "en-US" ? "en-US" : "zh-CN";
  14. localStorage.setItem("zcode-locale-preference", locale);
  15. const theme = params.get("theme");
  16. document.documentElement.className =
  17. theme === "light"
  18. ? ""
  19. : theme === "dark"
  20. ? "dark"
  21. : theme === "zai-light"
  22. ? "theme-zai-light"
  23. : "theme-zai-dark dark";
  24. // 浏览器夹具没有桌面宿主:整卡点击契约只关心回调是否恰好触发一次,
  25. // 平台能力按 Web 形态关闭本地文件通道,fileService 固定回显存在。
  26. const platform = { canOpenLocalFiles: false } as IPlatformService;
  27. const services = {
  28. fileService: {
  29. checkFilesExist: async ({ paths }: { paths: string[] }) =>
  30. paths.map((path) => ({ path, exists: true })),
  31. },
  32. } as unknown as IServiceAccessor;
  33. const cards = [
  34. {
  35. id: "file-card",
  36. type: "file" as const,
  37. kind: "docx" as const,
  38. title: "项目 简介.docx",
  39. subtitleId: "chat.previewCards.docx" as const,
  40. path: "/workspace/项目 简介.docx",
  41. },
  42. {
  43. id: "web-card",
  44. type: "website" as const,
  45. title: "APC Local Preview",
  46. subtitleId: "chat.previewCards.website" as const,
  47. url: "http://127.0.0.1:41789/assistant-preview",
  48. },
  49. ];
  50. function Fixture() {
  51. const [events, setEvents] = useState<string[]>([]);
  52. const record = useCallback((event: string) => {
  53. setEvents((previous) => [...previous, event]);
  54. }, []);
  55. return (
  56. <main className="min-h-screen bg-background p-4 text-foreground">
  57. <div className="flex w-full max-w-2xl flex-col gap-3">
  58. <AssistantPreviewCards
  59. cards={cards}
  60. workspacePath="/workspace"
  61. onOpenCodeViewer={(source) => record(`codeViewer:${source.title}`)}
  62. onOpenBrowserUrl={(url) => record(`browserUrl:${url}`)}
  63. />
  64. <div data-testid="hover-summary">
  65. <MessageChangeSummaryPanel
  66. workspacePath="/workspace"
  67. summary={{
  68. fileCount: 1,
  69. added: 3,
  70. removed: 0,
  71. files: [],
  72. }}
  73. />
  74. </div>
  75. </div>
  76. <ol data-testid="preview-events" aria-label="preview events">
  77. {events.map((event, index) => (
  78. <li key={index}>{event}</li>
  79. ))}
  80. </ol>
  81. </main>
  82. );
  83. }
  84. createRoot(document.getElementById("root")!).render(
  85. <ZCodeIntlProvider initialLocale={locale}>
  86. <ServiceProvider services={services}>
  87. <PlatformProvider platform={platform}>
  88. <TabStoreProvider>
  89. <Fixture />
  90. </TabStoreProvider>
  91. </PlatformProvider>
  92. </ServiceProvider>
  93. </ZCodeIntlProvider>,
  94. );