conversationShareConfirmationDock.test.ts 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  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 { ConversationShareConfirmationDock } from "@/v4/ConversationShareConfirmationDock.js";
  6. import enUS from "@/i18n/locales/en-US.js";
  7. import zhCN from "@/i18n/locales/zh-CN.js";
  8. vi.mock("@/i18n/IntlProvider.js", () => ({
  9. useZCodeIntl: () => ({
  10. intl: {
  11. formatMessage: ({ id }: { id: string }, values?: Record<string, string | number>) =>
  12. values ? `${id}:${JSON.stringify(values)}` : id,
  13. },
  14. }),
  15. }));
  16. afterEach(() => {
  17. cleanup();
  18. vi.unstubAllGlobals();
  19. });
  20. describe("ConversationShareConfirmationDock error details", () => {
  21. it("keeps the failed publish phase and its last progress instead of showing 100%", () => {
  22. render(
  23. createElement(ConversationShareConfirmationDock, {
  24. selectedCount: 2,
  25. totalCount: 3,
  26. progressLabel: "Uploading artifacts",
  27. progressPhase: "uploading",
  28. error: {
  29. issueCount: 1,
  30. issues: [{ code: "upload_incomplete", scope: "artifact", phase: "uploading" }],
  31. },
  32. onCancel: vi.fn(),
  33. onBack: vi.fn(),
  34. onConfirm: vi.fn(),
  35. }),
  36. );
  37. const progress = screen.getByRole("progressbar");
  38. expect(progress.getAttribute("aria-valuenow")).toBe("58");
  39. expect(
  40. progress
  41. .querySelector('[data-testid="conversation-share-progress-fill"]')
  42. ?.getAttribute("style"),
  43. ).toContain("width: 58%");
  44. expect(
  45. screen
  46. .getByTestId("conversation-share-publish-phase-uploading")
  47. .getAttribute("data-phase-state"),
  48. ).toBe("failed");
  49. expect(
  50. screen
  51. .getByTestId("conversation-share-publish-phase-collecting")
  52. .getAttribute("data-phase-state"),
  53. ).toBe("complete");
  54. });
  55. it("keeps retry available after an error even when the disclosure checkbox is not rendered", () => {
  56. const onConfirm = vi.fn();
  57. render(
  58. createElement(ConversationShareConfirmationDock, {
  59. selectedCount: 1,
  60. totalCount: 1,
  61. title: "Share",
  62. disclosureAccepted: false,
  63. error: {
  64. issueCount: 1,
  65. messageId: "conversationShare.error.network",
  66. issues: [{ code: "unknown", scope: "transport", phase: "collecting" }],
  67. },
  68. onCancel: vi.fn(),
  69. onBack: vi.fn(),
  70. onConfirm,
  71. }),
  72. );
  73. const retry = screen.getByTestId("conversation-share-confirm");
  74. expect(retry).toHaveProperty("disabled", false);
  75. expect(retry.getAttribute("data-size")).toBe("lg");
  76. fireEvent.click(retry);
  77. expect(onConfirm).toHaveBeenCalledTimes(1);
  78. });
  79. it("keeps the publish progress in the same dock and removes edit actions", () => {
  80. render(
  81. createElement(ConversationShareConfirmationDock, {
  82. selectedCount: 2,
  83. totalCount: 3,
  84. progressLabel: "Uploading artifacts",
  85. progressPhase: "uploading",
  86. pending: true,
  87. onCancel: vi.fn(),
  88. onBack: vi.fn(),
  89. onConfirm: vi.fn(),
  90. }),
  91. );
  92. expect(screen.getByTestId("conversation-share-publish-progress").textContent).toContain(
  93. "Uploading artifacts",
  94. );
  95. expect(screen.queryByTestId("conversation-share-publish-lock-note")).toBeNull();
  96. expect(screen.queryByTestId("conversation-share-disclosure-checkbox")).toBeNull();
  97. expect(screen.queryByTestId("conversation-share-back")).toBeNull();
  98. expect(screen.queryByText("conversationShare.partial.cancel")).toBeNull();
  99. expect(screen.getByTestId("conversation-share-confirm")).toHaveProperty("disabled", true);
  100. expect(screen.getByTestId("conversation-share-confirm").getAttribute("data-size")).toBe("lg");
  101. });
  102. it("uses one explicit natural-language footer summary for publish metadata", () => {
  103. expect(zhCN["conversationShare.publish.footerMeta"]).toBe(
  104. "分享 {selected} 个对话轮次,{access}",
  105. );
  106. expect(zhCN["conversationShare.permission.linkEditorSummary"]).toBe("链接持有者可导入并继续");
  107. expect(zhCN["conversationShare.permission.linkViewerSummary"]).toBe("链接持有者可查看");
  108. expect(enUS["conversationShare.publish.footerMeta"]).toBe(
  109. "Share {selected} conversation turn(s), {access}",
  110. );
  111. expect(enUS["conversationShare.permission.linkEditorSummary"]).toBe(
  112. "Link holders can import and continue",
  113. );
  114. });
  115. it("renders publish phases as aligned cards with artifact progress", () => {
  116. render(
  117. createElement(ConversationShareConfirmationDock, {
  118. selectedCount: 3,
  119. totalCount: 3,
  120. progressLabel: "Uploading artifacts",
  121. progressPhase: "uploading",
  122. completedArtifacts: 2,
  123. totalArtifacts: 3,
  124. pending: true,
  125. onCancel: vi.fn(),
  126. onBack: vi.fn(),
  127. onConfirm: vi.fn(),
  128. }),
  129. );
  130. expect(
  131. screen.getByTestId("conversation-share-publish-phase-uploading").parentElement?.className,
  132. ).toContain("@min-[640px]/share:grid-cols-3");
  133. expect(screen.getByTestId("conversation-share-publish-phase-uploading").textContent).toContain(
  134. "conversationShare.phase.uploadingActive",
  135. );
  136. });
  137. it("keeps disclosure confirmation inside the dock before publishing", () => {
  138. const onDisclosureAcceptedChange = vi.fn();
  139. const onConfirm = vi.fn();
  140. const { rerender } = render(
  141. createElement(ConversationShareConfirmationDock, {
  142. selectedCount: 2,
  143. totalCount: 3,
  144. onCancel: vi.fn(),
  145. onBack: vi.fn(),
  146. onConfirm,
  147. disclosureAccepted: false,
  148. onDisclosureAcceptedChange,
  149. }),
  150. );
  151. const disclosure = screen.getByTestId("conversation-share-disclosure-checkbox");
  152. const confirm = screen.getByTestId("conversation-share-confirm");
  153. expect(screen.getByTestId("conversation-share-disclosure").textContent).not.toContain(
  154. "conversationShare.publicWarning",
  155. );
  156. expect(disclosure).toHaveProperty("checked", false);
  157. expect(confirm).toHaveProperty("disabled", false);
  158. expect(screen.queryByTestId("conversation-share-disclosure-confirm")).toBeNull();
  159. fireEvent.click(disclosure);
  160. expect(onDisclosureAcceptedChange).toHaveBeenCalledWith(true);
  161. rerender(
  162. createElement(ConversationShareConfirmationDock, {
  163. selectedCount: 2,
  164. totalCount: 3,
  165. onCancel: vi.fn(),
  166. onBack: vi.fn(),
  167. onConfirm,
  168. disclosureAccepted: true,
  169. onDisclosureAcceptedChange,
  170. }),
  171. );
  172. expect(screen.getByTestId("conversation-share-confirm")).toHaveProperty("disabled", false);
  173. fireEvent.click(screen.getByTestId("conversation-share-confirm"));
  174. expect(onConfirm).toHaveBeenCalledTimes(1);
  175. });
  176. it("highlights the review checkbox without publishing and requires a second click after acceptance", () => {
  177. const props = {
  178. selectedCount: 1,
  179. totalCount: 1,
  180. onCancel: vi.fn(),
  181. onBack: vi.fn(),
  182. onConfirm: vi.fn(),
  183. };
  184. const onDisclosureAcceptedChange = vi.fn();
  185. const { rerender } = render(
  186. createElement(ConversationShareConfirmationDock, {
  187. ...props,
  188. onDisclosureAcceptedChange,
  189. }),
  190. );
  191. const disclosure = screen.getByTestId("conversation-share-disclosure");
  192. vi.stubGlobal(
  193. "matchMedia",
  194. vi.fn(() => ({ matches: false })),
  195. );
  196. const cancel = vi.fn();
  197. const animate = vi.fn(() => ({ cancel }));
  198. disclosure.animate = animate;
  199. disclosure.scrollIntoView = vi.fn();
  200. fireEvent.click(screen.getByTestId("conversation-share-confirm"));
  201. expect(props.onConfirm).not.toHaveBeenCalled();
  202. expect(document.activeElement).toBe(
  203. screen.getByTestId("conversation-share-disclosure-checkbox"),
  204. );
  205. expect(disclosure.scrollIntoView).toHaveBeenCalledTimes(1);
  206. expect(screen.queryByTestId("conversation-share-review-hint")).toBeNull();
  207. expect(disclosure.className).not.toContain("ring-warning");
  208. expect(animate).toHaveBeenCalledTimes(1);
  209. // 勾选复选框会取消仍在播放的提示动画,避免高亮残留到已确认状态。
  210. fireEvent.click(screen.getByTestId("conversation-share-disclosure-checkbox"));
  211. expect(cancel).toHaveBeenCalledTimes(1);
  212. expect(onDisclosureAcceptedChange).toHaveBeenCalledWith(true);
  213. fireEvent.click(screen.getByTestId("conversation-share-confirm"));
  214. expect(animate).toHaveBeenCalledTimes(2);
  215. vi.stubGlobal(
  216. "matchMedia",
  217. vi.fn(() => ({ matches: true })),
  218. );
  219. fireEvent.click(screen.getByTestId("conversation-share-confirm"));
  220. expect(animate).toHaveBeenCalledTimes(2);
  221. // 减少动态效果时仍需定位与聚焦,只是不播放高亮动画。
  222. expect(disclosure.scrollIntoView).toHaveBeenCalledTimes(3);
  223. rerender(
  224. createElement(ConversationShareConfirmationDock, { ...props, disclosureAccepted: true }),
  225. );
  226. expect(screen.queryByTestId("conversation-share-review-hint")).toBeNull();
  227. expect(props.onConfirm).not.toHaveBeenCalled();
  228. fireEvent.click(screen.getByTestId("conversation-share-confirm"));
  229. expect(props.onConfirm).toHaveBeenCalledTimes(1);
  230. });
  231. it("caps the dock height and scrolls only the body above the pinned actions (SHARE28)", () => {
  232. render(
  233. createElement(ConversationShareConfirmationDock, {
  234. selectedCount: 1,
  235. totalCount: 1,
  236. onCancel: vi.fn(),
  237. onBack: vi.fn(),
  238. onConfirm: vi.fn(),
  239. }),
  240. );
  241. // 根因:窗口断点无法反映侧栏挤压后的 Dock 实际宽度,必须按容器内容盒宽度响应。
  242. const dock = screen.getByTestId("conversation-share-confirmation-dock");
  243. expect(dock.className).toContain("@container/share");
  244. expect(dock.className).toContain("max-h-[70dvh]");
  245. expect(dock.className).toContain("flex-col");
  246. // 窄面板下表单增高由正文独立滚动吸收,操作区不能随正文滚出视口。
  247. const body = screen.getByTestId("conversation-share-confirmation-body");
  248. expect(body.className).toContain("overflow-y-auto");
  249. expect(body.className).toContain("min-h-0");
  250. expect(screen.getByTestId("conversation-share-confirmation-actions").className).toContain(
  251. "shrink-0",
  252. );
  253. expect(body.compareDocumentPosition(screen.getByTestId("conversation-share-back"))).toBe(
  254. Node.DOCUMENT_POSITION_FOLLOWING,
  255. );
  256. });
  257. it("stacks the primary action above the secondary actions below the 480px container", () => {
  258. render(
  259. createElement(ConversationShareConfirmationDock, {
  260. selectedCount: 1,
  261. totalCount: 1,
  262. onCancel: vi.fn(),
  263. onBack: vi.fn(),
  264. onConfirm: vi.fn(),
  265. }),
  266. );
  267. const actions = screen.getByTestId("conversation-share-confirmation-actions");
  268. const buttonRow = actions.lastElementChild!;
  269. expect(buttonRow.className).toContain("grid-cols-2");
  270. expect(buttonRow.className).toContain("@min-[480px]/share:flex");
  271. const confirm = screen.getByTestId("conversation-share-confirm");
  272. expect(confirm.className).toContain("col-span-2");
  273. expect(confirm.className).toContain("@min-[480px]/share:order-last");
  274. // 主操作在 DOM 中先行:窄屏(主操作第一行)视觉顺序与键盘顺序一致;宽容器用
  275. // order-last 把主操作视觉后置到最右,此时 Tab 序(主操作先)与视觉序(主操作最后)
  276. // 方向相反,是 spec(docs/conversation-share-v1.md SHARE28)记录的已知取舍,非回归。
  277. expect(confirm.compareDocumentPosition(screen.getByTestId("conversation-share-back"))).toBe(
  278. Node.DOCUMENT_POSITION_FOLLOWING,
  279. );
  280. // 窄屏文案允许换行,不再强制单行裁切。
  281. expect(confirm.className).toContain("whitespace-normal");
  282. expect(confirm.className).not.toContain("truncate");
  283. });
  284. it("switches the compact permission grid by container width with full labels", () => {
  285. render(
  286. createElement(ConversationShareConfirmationDock, {
  287. selectedCount: 1,
  288. totalCount: 1,
  289. onCancel: vi.fn(),
  290. onBack: vi.fn(),
  291. onConfirm: vi.fn(),
  292. }),
  293. );
  294. const radiogroup = screen.getByRole("radiogroup", {
  295. name: "conversationShare.permissionLabel",
  296. });
  297. expect(radiogroup.className).toContain("@min-[640px]/share:grid-cols-3");
  298. expect(radiogroup.className).not.toContain("md:grid-cols-3");
  299. // 权限文案完整换行展示,不允许 truncate 截断。
  300. const option = screen.getByRole("radio", { name: "conversationShare.permission.linkEditor" });
  301. const textSpans = [...option.querySelectorAll<HTMLElement>("span > span")];
  302. expect(textSpans.length).toBeGreaterThan(0);
  303. for (const span of textSpans) {
  304. expect(span.className).toContain("whitespace-normal");
  305. expect(span.className).not.toContain("truncate");
  306. }
  307. });
  308. it("aligns the permission rail with the title rail", () => {
  309. render(
  310. createElement(ConversationShareConfirmationDock, {
  311. selectedCount: 1,
  312. totalCount: 1,
  313. onCancel: vi.fn(),
  314. onBack: vi.fn(),
  315. onConfirm: vi.fn(),
  316. }),
  317. );
  318. expect(screen.getByTestId("conversation-share-confirmation-header").className).toContain("p-3");
  319. expect(
  320. screen.getByTestId("conversation-share-permission-picker").getAttribute("data-variant"),
  321. ).toBe("compact");
  322. expect(screen.getByTestId("conversation-share-permission-label").className).toContain(
  323. "text-ui-sm",
  324. );
  325. expect(screen.getByTestId("conversation-share-permission-picker").className).not.toContain(
  326. "p-2",
  327. );
  328. });
  329. it("defaults to the importable link permission when no access mode is provided", () => {
  330. render(
  331. createElement(ConversationShareConfirmationDock, {
  332. selectedCount: 1,
  333. totalCount: 1,
  334. onCancel: vi.fn(),
  335. onBack: vi.fn(),
  336. onConfirm: vi.fn(),
  337. }),
  338. );
  339. expect(
  340. screen
  341. .getByRole("radio", { name: "conversationShare.permission.linkEditor" })
  342. .getAttribute("aria-checked"),
  343. ).toBe("true");
  344. expect(
  345. screen
  346. .getByRole("radio", { name: "conversationShare.permission.private" })
  347. .getAttribute("aria-checked"),
  348. ).toBe("false");
  349. });
  350. it("uses the designed warning surface for the sensitive-content acknowledgement", () => {
  351. render(
  352. createElement(ConversationShareConfirmationDock, {
  353. selectedCount: 1,
  354. totalCount: 1,
  355. onCancel: vi.fn(),
  356. onBack: vi.fn(),
  357. onConfirm: vi.fn(),
  358. }),
  359. );
  360. const disclosure = screen.getByTestId("conversation-share-disclosure");
  361. expect(disclosure.className).toContain("mx-3");
  362. expect(disclosure.className).toContain("mt-3");
  363. expect(disclosure.className).toContain("border-l-2");
  364. expect(disclosure.className).toContain("border-l-warning");
  365. expect(disclosure.className).toContain("bg-surface");
  366. expect(disclosure.className).toContain("rounded-xl");
  367. expect(screen.getByTestId("conversation-share-disclosure-icon")).toBeTruthy();
  368. expect(screen.getByTestId("conversation-share-disclosure-checkbox")).toBeTruthy();
  369. });
  370. it("opens the sensitive-content review scope above the disclosure and toggles it closed", () => {
  371. render(
  372. createElement(ConversationShareConfirmationDock, {
  373. selectedCount: 1,
  374. totalCount: 1,
  375. onCancel: vi.fn(),
  376. onBack: vi.fn(),
  377. onConfirm: vi.fn(),
  378. }),
  379. );
  380. const trigger = screen.getByTestId("conversation-share-disclosure-scope-trigger");
  381. expect(trigger.getAttribute("aria-expanded")).toBe("false");
  382. expect(screen.queryByTestId("conversation-share-disclosure-scope-content")).toBeNull();
  383. fireEvent.click(trigger);
  384. expect(trigger.getAttribute("aria-expanded")).toBe("true");
  385. const content = screen.getByTestId("conversation-share-disclosure-scope-content");
  386. expect(content.textContent).toContain("conversationShare.disclosure.scope.title");
  387. expect(content.textContent).toContain("conversationShare.disclosure.scope.conversation");
  388. expect(content.textContent).toContain("conversationShare.disclosure.scope.sensitive");
  389. fireEvent.click(trigger);
  390. expect(trigger.getAttribute("aria-expanded")).toBe("false");
  391. expect(screen.queryByTestId("conversation-share-disclosure-scope-content")).toBeNull();
  392. });
  393. it("keeps the disclosure copy and review-scope action on one content row", () => {
  394. render(
  395. createElement(ConversationShareConfirmationDock, {
  396. selectedCount: 1,
  397. totalCount: 1,
  398. onCancel: vi.fn(),
  399. onBack: vi.fn(),
  400. onConfirm: vi.fn(),
  401. }),
  402. );
  403. const contentRow = screen.getByTestId("conversation-share-disclosure-content-row");
  404. const supportingRow = screen.getByTestId("conversation-share-disclosure-supporting-row");
  405. expect(contentRow.textContent).toContain("conversationShare.disclosure.checkbox");
  406. expect(contentRow.textContent).toContain("conversationShare.disclosure.description");
  407. expect(contentRow.textContent).toContain("conversationShare.disclosure.scope.trigger");
  408. expect(supportingRow.className).toContain("ml-auto");
  409. expect(supportingRow.className).toContain("justify-end");
  410. expect(supportingRow.className).toContain("text-ui-xs");
  411. });
  412. it("renders actionable artifact details and deselects the affected turn", () => {
  413. const onDeselectTurn = vi.fn();
  414. const onCopyRequestId = vi.fn();
  415. render(
  416. createElement(ConversationShareConfirmationDock, {
  417. selectedCount: 1,
  418. totalCount: 2,
  419. title: "Share",
  420. onCancel: vi.fn(),
  421. onBack: vi.fn(),
  422. onConfirm: vi.fn(),
  423. error: {
  424. issueCount: 1,
  425. requestId: "server-request-123",
  426. issues: [
  427. {
  428. code: "artifact_type_not_allowed",
  429. scope: "artifact",
  430. // turnOrdinal 只用于文案;「取消该轮」按 productTurnId 定位。
  431. turnOrdinal: 2,
  432. productTurnId: "product-turn-2",
  433. artifactDisplayName: "晨报.pdf",
  434. artifactType: "pdf",
  435. extension: "pdf",
  436. mimeType: "application/pdf",
  437. allowedFormats: ["PPTX (.pptx)", "DOCX (.docx)"],
  438. },
  439. ],
  440. },
  441. onDeselectTurn,
  442. onCopyRequestId,
  443. }),
  444. );
  445. expect(screen.getByTestId("conversation-share-error-details").textContent).toContain(
  446. "晨报.pdf",
  447. );
  448. expect(screen.getByTestId("conversation-share-error-details").textContent).toContain("pdf");
  449. const errorDetails = screen.getByTestId("conversation-share-error-details");
  450. expect(errorDetails.textContent).not.toContain("server-request-123");
  451. expect(screen.queryByTestId("conversation-share-request-id-content")).toBeNull();
  452. const requestDetailsTrigger = screen.getByTestId("conversation-share-request-id-trigger");
  453. expect(requestDetailsTrigger.getAttribute("aria-label")).toBe(
  454. "conversationShare.issue.details",
  455. );
  456. fireEvent.click(requestDetailsTrigger);
  457. expect(screen.getByTestId("conversation-share-request-id-content").textContent).toContain(
  458. "server-request-123",
  459. );
  460. fireEvent.click(screen.getByRole("button", { name: "conversationShare.issue.copyRequestId" }));
  461. expect(onCopyRequestId).toHaveBeenCalledTimes(1);
  462. fireEvent.click(screen.getByRole("button", { name: "conversationShare.issue.deselectTurn" }));
  463. expect(onDeselectTurn).toHaveBeenCalledWith("product-turn-2");
  464. });
  465. it("shows a stable missing request id state without a copy action", () => {
  466. render(
  467. createElement(ConversationShareConfirmationDock, {
  468. selectedCount: 1,
  469. totalCount: 1,
  470. onCancel: vi.fn(),
  471. onBack: vi.fn(),
  472. onConfirm: vi.fn(),
  473. error: {
  474. issueCount: 1,
  475. issues: [{ code: "unknown", scope: "transport" }],
  476. },
  477. }),
  478. );
  479. expect(screen.queryByTestId("conversation-share-request-id-content")).toBeNull();
  480. fireEvent.click(screen.getByTestId("conversation-share-request-id-trigger"));
  481. expect(screen.getByTestId("conversation-share-request-id-content").textContent).toContain(
  482. "conversationShare.issue.requestIdMissing",
  483. );
  484. expect(
  485. screen.queryByRole("button", { name: "conversationShare.issue.copyRequestId" }),
  486. ).toBeNull();
  487. });
  488. it("keeps the request id hidden until the inline error details button is opened", () => {
  489. render(
  490. createElement(ConversationShareConfirmationDock, {
  491. selectedCount: 1,
  492. totalCount: 1,
  493. onCancel: vi.fn(),
  494. onBack: vi.fn(),
  495. onConfirm: vi.fn(),
  496. error: {
  497. messageId: "conversationShare.error.invalidConversation",
  498. issueCount: 1,
  499. requestId: "server-request-456",
  500. issues: [{ code: "invalid_conversation", scope: "conversation" }],
  501. },
  502. onCopyRequestId: vi.fn(),
  503. }),
  504. );
  505. expect(screen.getByTestId("conversation-share-error-message").textContent).toContain(
  506. "conversationShare.error.invalidConversation",
  507. );
  508. expect(screen.getByTestId("conversation-share-error-message").textContent).not.toContain(
  509. "server-request-456",
  510. );
  511. expect(screen.queryByText("server-request-456")).toBeNull();
  512. fireEvent.click(screen.getByTestId("conversation-share-request-id-trigger"));
  513. expect(screen.getByTestId("conversation-share-request-id-content").textContent).toContain(
  514. "server-request-456",
  515. );
  516. });
  517. it("shows the actionable publish error instead of a generic transport issue", () => {
  518. render(
  519. createElement(ConversationShareConfirmationDock, {
  520. selectedCount: 1,
  521. totalCount: 1,
  522. onCancel: vi.fn(),
  523. onBack: vi.fn(),
  524. onConfirm: vi.fn(),
  525. error: {
  526. messageId: "conversationShare.error.authenticationRequired",
  527. issueCount: 1,
  528. issues: [{ code: "unknown", scope: "transport", phase: "collecting" }],
  529. },
  530. }),
  531. );
  532. const details = screen.getByTestId("conversation-share-error-details");
  533. expect(screen.getByTestId("conversation-share-confirmation-header").textContent).toContain(
  534. "conversationShare.publish.failedTitle",
  535. );
  536. expect(screen.getByTestId("conversation-share-publish-progress")).toBeTruthy();
  537. expect(screen.queryByTestId("conversation-share-permission-picker")).toBeNull();
  538. expect(details.textContent).toContain("conversationShare.error.authenticationRequired");
  539. expect(details.textContent).not.toContain("conversationShare.issue.unknown");
  540. });
  541. it("keeps a single-line publish error vertically centered in a compact card", () => {
  542. render(
  543. createElement(ConversationShareConfirmationDock, {
  544. selectedCount: 1,
  545. totalCount: 1,
  546. onCancel: vi.fn(),
  547. onBack: vi.fn(),
  548. onConfirm: vi.fn(),
  549. error: {
  550. messageId: "conversationShare.error.invalidConversation",
  551. issueCount: 1,
  552. issues: [{ code: "invalid_conversation", scope: "conversation" }],
  553. },
  554. }),
  555. );
  556. const errorCard = screen.getByTestId("conversation-share-error-details");
  557. const errorRow = screen.getByTestId("conversation-share-error-row");
  558. expect(errorCard.className).toContain("p-2");
  559. expect(errorCard.className).not.toContain("p-2.5");
  560. expect(errorCard.className).toContain("mb-2");
  561. expect(errorCard.className).not.toContain("mb-3");
  562. expect(errorRow.className).toContain("items-center");
  563. expect(errorRow.className).not.toContain("mb-1.5");
  564. });
  565. it("uses one 24px center line for the error copy, details button, and dismiss action", () => {
  566. render(
  567. createElement(ConversationShareConfirmationDock, {
  568. selectedCount: 1,
  569. totalCount: 1,
  570. onCancel: vi.fn(),
  571. onBack: vi.fn(),
  572. onConfirm: vi.fn(),
  573. onDismissError: vi.fn(),
  574. error: {
  575. messageId: "conversationShare.error.invalidConversation",
  576. issueCount: 1,
  577. issues: [{ code: "invalid_conversation", scope: "conversation" }],
  578. },
  579. }),
  580. );
  581. const errorMessage = screen.getByTestId("conversation-share-error-message");
  582. const dismiss = screen.getByTestId("conversation-share-error-dismiss");
  583. expect(errorMessage.className).toContain("items-center");
  584. expect(errorMessage.className).toContain("leading-6");
  585. expect(dismiss.className).toContain("leading-6");
  586. });
  587. });