conversationShareSuccessDock.test.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // @vitest-environment jsdom
  2. import { createElement } from "react";
  3. import { cleanup, fireEvent, render, screen } from "@testing-library/react";
  4. import { afterEach, describe, expect, it, vi } from "vitest";
  5. import { ConversationShareSuccessDock } from "@/v4/ConversationShareSuccessDock.js";
  6. vi.mock("@/i18n/IntlProvider.js", () => ({
  7. useZCodeIntl: () => ({
  8. intl: {
  9. formatMessage: ({ id }: { id: string }, values?: Record<string, string | number>) =>
  10. values ? `${id}:${JSON.stringify(values)}` : id,
  11. },
  12. }),
  13. }));
  14. afterEach(() => cleanup());
  15. describe("ConversationShareSuccessDock", () => {
  16. it("成功态只保留标题和打开/复制两个业务操作", () => {
  17. const onOpen = vi.fn();
  18. const onCopy = vi.fn();
  19. const onDismiss = vi.fn();
  20. render(
  21. createElement(ConversationShareSuccessDock, {
  22. title: "每日 AI 新闻汇总",
  23. onOpen,
  24. onCopy,
  25. onDismiss,
  26. }),
  27. );
  28. const dock = screen.getByTestId("conversation-share-success-dock");
  29. expect(dock).toBeTruthy();
  30. expect(screen.getByTestId("conversation-share-success-status").textContent).toContain(
  31. "conversationShare.result.title",
  32. );
  33. expect(screen.getByTestId("conversation-share-result-title").textContent).toBe(
  34. "每日 AI 新闻汇总",
  35. );
  36. expect(screen.queryByTestId("conversation-share-permission-picker")).toBeNull();
  37. expect(screen.queryByTestId("conversation-share-back")).toBeNull();
  38. expect(screen.queryByText("conversationShare.partial.cancel")).toBeNull();
  39. expect(screen.queryByTestId("conversation-share-selection-hint")).toBeNull();
  40. const actions = screen
  41. .getByTestId("conversation-share-success-actions")
  42. .querySelectorAll("button");
  43. expect(actions).toHaveLength(2);
  44. fireEvent.click(screen.getByTestId("conversation-share-open-browser"));
  45. fireEvent.click(screen.getByTestId("conversation-share-copy-link"));
  46. expect(onOpen).toHaveBeenCalledTimes(1);
  47. expect(onCopy).toHaveBeenCalledTimes(1);
  48. fireEvent.click(screen.getByTestId("conversation-share-success-dismiss"));
  49. expect(onDismiss).toHaveBeenCalledTimes(1);
  50. });
  51. it("部分成功时保留成功状态并展示被跳过文件提示", () => {
  52. render(
  53. createElement(ConversationShareSuccessDock, {
  54. title: "Share",
  55. onOpen: vi.fn(),
  56. onCopy: vi.fn(),
  57. onDismiss: vi.fn(),
  58. warnings: {
  59. issueCount: 2,
  60. issues: [
  61. {
  62. code: "artifact_read_failed",
  63. scope: "artifact",
  64. artifactDisplayName: "报告.pdf",
  65. },
  66. ],
  67. },
  68. }),
  69. );
  70. expect(screen.getByTestId("conversation-share-success-status").textContent).toContain(
  71. "conversationShare.result.title",
  72. );
  73. expect(screen.getByTestId("conversation-share-success-warning").textContent).toContain("2");
  74. });
  75. });