share-selection-boundaries.mjs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. import assert from "node:assert/strict";
  2. import { test } from "node:test";
  3. export function registerShareBoundaryTests(environment) {
  4. const open = async (query = "") => {
  5. const { browser, origin } = environment();
  6. const page = await browser.newPage({ viewport: { width: 1200, height: 900 } });
  7. await page.goto(`${origin}fixture?theme=light&locale=zh-CN&${query}`);
  8. await page.getByTestId("conversation-share-trigger").click();
  9. await page.getByTestId("conversation-share-adjust").click();
  10. const panel = page.getByTestId("conversation-share-selection-panel");
  11. await panel.waitFor();
  12. return {
  13. page,
  14. panel,
  15. apply: panel.getByTestId("conversation-share-selection-apply"),
  16. summary: panel.getByTestId("conversation-share-selection-summary"),
  17. };
  18. };
  19. for (const [count, limit] of [
  20. [499, 500],
  21. [500, 500],
  22. [501, 500],
  23. [251, 250],
  24. ]) {
  25. test(`SHARE34 capacity ${count}/${limit}`, async () => {
  26. const { page, apply, summary } = await open(`items=2&budget=${count}&limit=${limit}`);
  27. assert.equal(await apply.isDisabled(), count > limit);
  28. if (count > limit) assert.equal(await summary.innerText(), `超出上限 ${count - limit} 行`);
  29. else assert.equal(await summary.innerText(), "已选 2 轮");
  30. await page.close();
  31. });
  32. }
  33. for (const query of ["items=0", "items=2&running=1"]) {
  34. test(`SHARE34 no eligible turns ${query}`, async () => {
  35. const { page, panel, apply, summary } = await open(query);
  36. assert.equal(await panel.getByTestId("conversation-share-selection-all").isDisabled(), true);
  37. assert.equal(await apply.isDisabled(), true);
  38. assert.equal(await summary.innerText(), "已选 0 轮");
  39. if (query.includes("running")) {
  40. const toggle = panel.getByTestId("conversation-share-selection-toggle").first();
  41. assert.equal(await toggle.isDisabled(), true);
  42. await panel.getByTestId("conversation-share-selection-locate").first().click();
  43. assert.equal(await page.getByTestId("inspected").innerText(), "1");
  44. assert.equal(await summary.innerText(), "已选 0 轮");
  45. }
  46. await page.close();
  47. });
  48. }
  49. test("SHARE34 grouped product turns stay atomic", async () => {
  50. const { page, panel, summary } = await open("items=3&grouped=1");
  51. const toggles = panel.getByTestId("conversation-share-selection-toggle");
  52. const rows = panel.locator("[data-conversation-share-selection-item]");
  53. assert.equal(await summary.innerText(), "已选 2 轮");
  54. await toggles.first().press("Enter");
  55. assert.equal(await summary.innerText(), "已选 1 轮");
  56. for (const i of [0, 1])
  57. assert.equal(await rows.nth(i).getByRole("checkbox").isChecked(), false);
  58. await panel.getByTestId("conversation-share-selection-all").click();
  59. assert.equal(await summary.innerText(), "已选 2 轮");
  60. assert.equal(await rows.locator('[role="checkbox"][data-state="checked"]').count(), 3);
  61. await page.close();
  62. });
  63. test("SHARE34 over-limit draft cancels or commits independently", async () => {
  64. const { page, panel, apply, summary } = await open();
  65. await page.getByTestId("toggle-limit").click();
  66. assert.equal(await summary.innerText(), "超出上限 110 行");
  67. const range = page.getByTestId("conversation-share-range-summary");
  68. const initial = await range.innerText();
  69. await panel.getByTestId("conversation-share-selection-toggle").first().click();
  70. assert.equal(await summary.innerText(), "已选 7 轮");
  71. assert.equal(await range.innerText(), initial);
  72. await panel.getByTestId("conversation-share-selection-cancel").click();
  73. await page.getByTestId("conversation-share-adjust").click();
  74. assert.equal(await summary.innerText(), "超出上限 110 行");
  75. await panel.getByTestId("conversation-share-selection-toggle").first().click();
  76. await apply.click();
  77. assert.match(await range.innerText(), /7/);
  78. await page.getByTestId("conversation-share-adjust").click();
  79. assert.equal(await summary.innerText(), "已选 7 轮");
  80. await page.close();
  81. });
  82. test("SHARE34 resize and shorter content remove obsolete masks", async () => {
  83. const { page, panel } = await open("items=25");
  84. const viewport = panel.locator('[data-slot="scroll-area-viewport"]');
  85. await viewport.evaluate((node) => {
  86. node.scrollTop = 200;
  87. });
  88. await page.waitForFunction(() =>
  89. document.querySelector('[data-slot="scroll-area-viewport"]').style.maskImage.includes("32px"),
  90. );
  91. await page.setViewportSize({ width: 1100, height: 700 });
  92. const header = panel.getByTestId("conversation-share-selection-header");
  93. const footer = panel.getByTestId("conversation-share-selection-footer");
  94. await page.getByTestId("short-list").click();
  95. await page.waitForFunction(() => {
  96. const node = document.querySelector('[data-slot="scroll-area-viewport"]');
  97. return (
  98. node.scrollHeight <= node.clientHeight + 1 && getComputedStyle(node).maskImage === "none"
  99. );
  100. });
  101. assert.equal((await header.boundingBox()).y, (await panel.boundingBox()).y);
  102. const p = await panel.boundingBox(),
  103. f = await footer.boundingBox();
  104. assert.ok(Math.abs(p.y + p.height - f.y - f.height) < 1);
  105. assert.ok(f.y + f.height <= 700);
  106. assert.equal(await panel.getByTestId("conversation-share-selection-apply").isVisible(), true);
  107. await page.close();
  108. });
  109. test("SHARE34 task drafts, failed retry and result actions", async () => {
  110. const { page, panel } = await open("items=3");
  111. await panel.getByTestId("conversation-share-selection-toggle").first().click();
  112. await panel.getByTestId("conversation-share-selection-apply").click();
  113. const popover = page.getByTestId("conversation-share-popover");
  114. await popover.getByRole("textbox").fill("任务 A 分享");
  115. await page.getByTestId("conversation-share-disclosure-checkbox").check();
  116. await page.getByTestId("switch").click();
  117. await popover.waitFor({ state: "hidden" });
  118. await page.getByTestId("conversation-share-trigger").click();
  119. assert.notEqual(await popover.getByRole("textbox").inputValue(), "任务 A 分享");
  120. assert.equal(
  121. await page.getByTestId("conversation-share-disclosure-checkbox").isChecked(),
  122. false,
  123. );
  124. assert.match(await page.getByTestId("conversation-share-range-summary").innerText(), /3/);
  125. await popover.getByRole("textbox").fill("任务 B 分享");
  126. await page.getByTestId("switch").click();
  127. assert.equal(await popover.getByRole("textbox").inputValue(), "任务 A 分享");
  128. assert.match(await page.getByTestId("conversation-share-range-summary").innerText(), /2/);
  129. assert.equal(
  130. await page.getByTestId("conversation-share-disclosure-checkbox").isChecked(),
  131. true,
  132. );
  133. await page.getByTestId("conversation-share-confirm").click();
  134. await page.getByTestId("advance-publish").click();
  135. await page.getByTestId("switch").click();
  136. assert.equal(await popover.getByRole("textbox").inputValue(), "任务 B 分享");
  137. assert.equal(await page.getByTestId("conversation-share-publish-progress").count(), 0);
  138. await page.getByTestId("switch").click();
  139. assert.equal(
  140. await page
  141. .getByTestId("conversation-share-publish-phase-uploading")
  142. .getAttribute("data-phase-state"),
  143. "active",
  144. );
  145. await page.getByTestId("fail-publish").click();
  146. await page.getByTestId("conversation-share-error-details").waitFor();
  147. await page.keyboard.press("Escape");
  148. await popover.waitFor({ state: "hidden" });
  149. await page.getByTestId("conversation-share-trigger").click();
  150. await page.getByTestId("conversation-share-error-details").waitFor();
  151. await page.getByTestId("conversation-share-confirm").click();
  152. await page.getByTestId("conversation-share-error-details").waitFor({ state: "hidden" });
  153. assert.match(
  154. await page.getByTestId("conversation-share-publish-progress").innerText(),
  155. /任务 A 分享/,
  156. );
  157. await page.getByTestId("resolve-publish").click();
  158. const url = await popover.getByRole("textbox").inputValue();
  159. await page.getByTestId("conversation-share-copy-link").click();
  160. await page.getByTestId("conversation-share-open-browser").click();
  161. assert.equal(await page.getByTestId("copied-url").innerText(), url);
  162. assert.equal(await page.getByTestId("opened-url").innerText(), url);
  163. await page.getByTestId("switch").click();
  164. assert.equal(await popover.getByRole("textbox").inputValue(), "任务 B 分享");
  165. assert.equal(await page.getByTestId("conversation-share-success-dock").count(), 0);
  166. await page.close();
  167. });
  168. test("SHARE34 preflight hint stays compact and aligned", async () => {
  169. const { browser, origin } = environment();
  170. for (const width of [390, 1200])
  171. for (const theme of ["light", "dark"]) {
  172. const locale = theme === "dark" ? "en-US" : "zh-CN";
  173. const page = await browser.newPage({ viewport: { width, height: 900 } });
  174. await page.goto(`${origin}fixture?theme=${theme}&locale=${locale}&items=50&issue=1`);
  175. await page.getByTestId("conversation-share-trigger").click();
  176. const trigger = page.getByTestId("conversation-share-selection-preflight-status");
  177. await trigger.waitFor();
  178. await page.evaluate(async () => {
  179. await Promise.all(
  180. document.getAnimations().map((animation) => animation.finished.catch(() => {})),
  181. );
  182. });
  183. const metrics = await trigger.evaluate((node) => {
  184. const icon = node.querySelector("svg");
  185. const text = node.querySelector("span");
  186. const bounds = node.getBoundingClientRect();
  187. return {
  188. align: getComputedStyle(node).textAlign,
  189. height: bounds.height,
  190. iconWidth: icon.getBoundingClientRect().width,
  191. textHeight: text.getBoundingClientRect().height,
  192. text: text.textContent,
  193. overflow: node.scrollWidth > node.clientWidth,
  194. };
  195. });
  196. assert.equal(metrics.align, "left");
  197. assert.equal(metrics.iconWidth, 16);
  198. assert.ok(metrics.textHeight <= 20, JSON.stringify(metrics));
  199. assert.equal(metrics.overflow, false);
  200. assert.equal(
  201. metrics.text,
  202. locale === "en-US" ? "Review share issues" : "有内容无法分享,查看问题",
  203. );
  204. await page.screenshot({ path: `/tmp/share-preflight-${width}-${theme}.png` });
  205. await trigger.click();
  206. await page.getByTestId("conversation-share-selection-preflight-popover").waitFor();
  207. assert.equal(
  208. await page
  209. .getByTestId("conversation-share-selection-preflight-popover")
  210. .getByRole("button")
  211. .count(),
  212. 1,
  213. );
  214. await page.close();
  215. }
  216. });
  217. for (const action of ["cancel", "apply"]) {
  218. test(`SHARE34 issue deselection respects pending ${action}`, async () => {
  219. const { page, panel } = await open("items=3&issue=1");
  220. await page.getByTestId("conversation-share-selection-preflight-status").click();
  221. await page
  222. .getByTestId("conversation-share-selection-preflight-popover")
  223. .getByRole("button", { name: "取消选择此轮" })
  224. .click();
  225. assert.equal(
  226. await panel
  227. .locator("[data-conversation-share-selection-item]")
  228. .first()
  229. .getByRole("checkbox")
  230. .isChecked(),
  231. false,
  232. );
  233. assert.equal(
  234. await panel.getByTestId("conversation-share-selection-summary").innerText(),
  235. "已选 2 轮",
  236. );
  237. assert.match(await page.getByTestId("conversation-share-range-summary").innerText(), /3/);
  238. await panel.getByTestId(`conversation-share-selection-${action}`).click();
  239. assert.match(
  240. await page.getByTestId("conversation-share-range-summary").innerText(),
  241. action === "apply" ? /2/ : /3/,
  242. );
  243. await page.getByTestId("conversation-share-adjust").click();
  244. assert.equal(
  245. await panel
  246. .locator("[data-conversation-share-selection-item]")
  247. .first()
  248. .getByRole("checkbox")
  249. .isChecked(),
  250. action === "cancel",
  251. );
  252. await page.close();
  253. });
  254. }
  255. for (const mode of ["reopen", "open"]) {
  256. test(`SHARE34 new completed content invalidates disclosure ${mode}`, async () => {
  257. const { page, panel } = await open();
  258. await panel.getByTestId("conversation-share-selection-cancel").click();
  259. const disclosure = page.getByTestId("conversation-share-disclosure-checkbox");
  260. await disclosure.check();
  261. if (mode === "reopen") {
  262. await page.keyboard.press("Escape");
  263. await page.getByTestId("conversation-share-popover").waitFor({ state: "hidden" });
  264. }
  265. await page.getByTestId("complete-turn").click();
  266. if (mode === "reopen") await page.getByTestId("conversation-share-trigger").click();
  267. assert.match(await page.getByTestId("conversation-share-range-summary").innerText(), /9/);
  268. assert.equal(await disclosure.isChecked(), false);
  269. await page.getByTestId("conversation-share-confirm").click();
  270. assert.equal(await page.getByTestId("conversation-share-publish-progress").count(), 0);
  271. await disclosure.check();
  272. await page.getByTestId("conversation-share-confirm").click();
  273. await page.getByTestId("conversation-share-publish-progress").waitFor();
  274. await page.close();
  275. });
  276. }
  277. }