conversationShareSuccessDock.test.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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(dock.className).toContain("w-full");
  31. expect(dock.className).not.toContain("max-w-[43.75rem]");
  32. expect(dock.className).toContain("border-input-border");
  33. expect(dock.className).toContain("bg-input");
  34. expect(dock.className).toContain("text-foreground");
  35. expect(dock.className).not.toContain("bg-popover");
  36. expect(dock.className).not.toContain("text-popover-foreground");
  37. expect(dock.className).not.toContain("shadow-lg");
  38. expect(dock.className).not.toContain("ring-1");
  39. expect(screen.getByTestId("conversation-share-success-status").textContent).toContain(
  40. "conversationShare.result.title",
  41. );
  42. expect(screen.getByTestId("conversation-share-result-title").textContent).toBe(
  43. "每日 AI 新闻汇总",
  44. );
  45. expect(screen.queryByTestId("conversation-share-permission-picker")).toBeNull();
  46. expect(screen.queryByTestId("conversation-share-back")).toBeNull();
  47. expect(screen.queryByText("conversationShare.partial.cancel")).toBeNull();
  48. expect(screen.queryByTestId("conversation-share-selection-hint")).toBeNull();
  49. const actions = screen
  50. .getByTestId("conversation-share-success-actions")
  51. .querySelectorAll("button");
  52. expect(actions).toHaveLength(2);
  53. expect([...actions].map((action) => action.getAttribute("data-size"))).toEqual(["lg", "lg"]);
  54. expect(screen.getByTestId("conversation-share-open-browser").getAttribute("data-variant")).toBe(
  55. "outline",
  56. );
  57. expect(screen.getByTestId("conversation-share-copy-link").getAttribute("data-variant")).toBe(
  58. "default",
  59. );
  60. fireEvent.click(screen.getByTestId("conversation-share-open-browser"));
  61. fireEvent.click(screen.getByTestId("conversation-share-copy-link"));
  62. expect(onOpen).toHaveBeenCalledTimes(1);
  63. expect(onCopy).toHaveBeenCalledTimes(1);
  64. fireEvent.click(screen.getByTestId("conversation-share-success-dismiss"));
  65. expect(onDismiss).toHaveBeenCalledTimes(1);
  66. });
  67. it("部分成功时保留成功状态并展示被跳过文件提示", () => {
  68. render(
  69. createElement(ConversationShareSuccessDock, {
  70. title: "Share",
  71. onOpen: vi.fn(),
  72. onCopy: vi.fn(),
  73. onDismiss: vi.fn(),
  74. warnings: {
  75. issueCount: 2,
  76. issues: [
  77. {
  78. code: "artifact_read_failed",
  79. scope: "artifact",
  80. artifactDisplayName: "报告.pdf",
  81. },
  82. ],
  83. },
  84. }),
  85. );
  86. expect(screen.getByTestId("conversation-share-success-status").textContent).toContain(
  87. "conversationShare.result.title",
  88. );
  89. expect(screen.getByTestId("conversation-share-success-warning").textContent).toContain("2");
  90. });
  91. });