share-selection-boundaries.mjs 15 KB

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