conversation-session-virtual-project-mentions.test.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. import { execFile } from "node:child_process";
  2. import { isE2EHomeDirName } from "#e2e/helpers/e2e-runtime-paths";
  3. import { promisify } from "node:util";
  4. import { selectNativeProjectDirectories } from "#e2e/helpers/project-sidebar";
  5. import { basename, join } from "node:path";
  6. import { DatabaseSync } from "node:sqlite";
  7. import { mkdir, writeFile } from "node:fs/promises";
  8. import {
  9. TID_V4_COMPOSER_INPUT,
  10. TID_V4_COMPOSER_SEND,
  11. TID_COMPOSER_WORKSPACE_TRIGGER,
  12. TID_PROMPT_SUGGESTION_PANEL,
  13. TID_TASK_ITEM,
  14. TID_CONFIRM_DIALOG_CONFIRM,
  15. testId,
  16. } from "@zcode/shared/test-ids";
  17. import {
  18. clearAppData,
  19. setInputValueByTestIdDom,
  20. waitForWorkspaceApp,
  21. DEFAULT_WORKSPACE,
  22. } from "#e2e/helpers/desktop-app";
  23. // 修复原因:Windows 路径含反斜杠,直接拼进 CSS 属性选择器的引号字符串会被当成 CSS 转义
  24. // (如 `\U`、`\e2e`),选择器匹配不到真实 DOM 的 data-option-id;这里转义反斜杠与双引号。
  25. const cssString = (value: string) => value.replace(/[\\"]/g, "\\$&");
  26. describe("虚拟项目 Composer 候选", () => {
  27. after(async () => {
  28. await clearAppData();
  29. });
  30. it("VP14:多 root 文件分别可选,# 在全局草稿显示已有项目任务", async () => {
  31. await waitForWorkspaceApp(DEFAULT_WORKSPACE, 45_000);
  32. const home = process.env.ZCODE_E2E_HOME_DIR!;
  33. // 同时接受统一 runner 与旧手工入口的隔离 HOME,禁止写入日常用户目录。
  34. if (
  35. !home ||
  36. // 修复原因:Windows CI 单 WDIO job 使用默认 `.e2e-home`(无 runId 后缀),旧前缀
  37. // `.e2e-home-` 把隔离 HOME 误判为日常目录;改用 isE2EHomeDirName,只接受 `.e2e-home` 与 `.e2e-home-*` 两种布局。
  38. !(isE2EHomeDirName(basename(home)) || basename(home).startsWith("zcode-virtual-project-e2e-"))
  39. )
  40. throw new Error("隔离 HOME required");
  41. const roots = [join(home, "E2E_VP14_A"), join(home, "E2E_VP14_B")];
  42. for (const root of roots) {
  43. await mkdir(join(root, "src"), { recursive: true });
  44. await writeFile(join(root, "src", "same.ts"), "export const same = 1;\n");
  45. }
  46. await promisify(execFile)("git", ["init", "--initial-branch=main", roots[0]!]);
  47. const initialProject = await $(`[data-testid="${TID_COMPOSER_WORKSPACE_TRIGGER}"]`).getText();
  48. expect(await $('[data-testid="composer-edit-project"]').isExisting()).toBe(false);
  49. await openComposerProjectEditor();
  50. await $('[data-testid="virtual-project-name"]').setValue("E2E_COMPOSER_CANCELLED");
  51. await $('//button[normalize-space(.)="Cancel" or normalize-space(.)="取消"]').click();
  52. await $('[data-testid="virtual-project-name"]').waitForDisplayed({ reverse: true });
  53. expect(await $('[data-project-name="E2E_COMPOSER_CANCELLED"]').isExisting()).toBe(false);
  54. expect(await $(`[data-testid="${TID_COMPOSER_WORKSPACE_TRIGGER}"]`).getText()).toBe(
  55. initialProject,
  56. );
  57. await openComposerProjectEditor();
  58. await $('[data-testid="virtual-project-name"]').setValue("E2E_VP14_PROJECT");
  59. for (const root of roots) {
  60. await chooseProjectRoot(root);
  61. }
  62. await $('[data-testid="virtual-project-save"]').click();
  63. await $('[data-testid="project-folder-trust-confirm"]').waitForDisplayed();
  64. await $('[data-testid="project-folder-trust-confirm"]').click();
  65. const project = $('[data-project-name="E2E_VP14_PROJECT"]');
  66. await project.waitForDisplayed();
  67. // PCD01:在草稿创建项目成功后自动选中新项目,取消仍保持原选择。
  68. await browser.waitUntil(async () =>
  69. (await $(`[data-testid="${TID_COMPOSER_WORKSPACE_TRIGGER}"]`).getText()).includes(
  70. "E2E_VP14_PROJECT",
  71. ),
  72. );
  73. await project.$('[data-testid="virtual-project-create-task"]').click();
  74. const input = $(`[data-testid="${TID_V4_COMPOSER_INPUT}"]`);
  75. await input.waitForDisplayed();
  76. const workspaceTrigger = $(`[data-testid="${TID_COMPOSER_WORKSPACE_TRIGGER}"]`);
  77. for (const theme of ["zai-light", "zai-dark"]) {
  78. await browser.execute(
  79. (theme) =>
  80. (
  81. window as Window & { __testActions?: { setTheme(theme: string): void } }
  82. ).__testActions!.setTheme(theme),
  83. theme,
  84. );
  85. const toggle = project.$('[data-testid="virtual-project-toggle"]');
  86. await toggle.$(".lucide-folders-open").waitForExist();
  87. await project.saveScreenshot(
  88. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, `VP14-folders-open-${theme}.png`),
  89. );
  90. await toggle.click();
  91. await toggle.$(".lucide-folders").waitForExist();
  92. await project.saveScreenshot(
  93. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, `VP14-folders-closed-${theme}.png`),
  94. );
  95. await toggle.click();
  96. await workspaceTrigger.$(".lucide-folders").waitForExist();
  97. // 修复原因:点完侧栏折叠按钮后指针停在项目行上,项目目录 hover 卡会弹出并盖住输入区的
  98. // 项目入口(失败截图可见),点击报 "element click intercepted"。先把指针移到视口左上角,
  99. // 等 hover 卡关闭、入口可点后再点。不能用 `$("body").moveTo({xOffset:1,yOffset:1})`:WDIO v9
  100. // 的偏移相对元素中心,CI 窗口 1024×768 时 body 中心正好落在 hover 卡内,卡片一直不关
  101. // (Windows CI 失败录像末帧可见)。
  102. await browser.action("pointer").move({ x: 0, y: 0, origin: "viewport" }).perform();
  103. await workspaceTrigger.waitForClickable({ timeout: 15000 });
  104. await workspaceTrigger.click();
  105. const menu = $('[data-testid="composer-project-menu"]');
  106. await menu.$('[data-project-name="E2E_VP14_PROJECT"] .lucide-folders').waitForDisplayed();
  107. await menu.saveScreenshot(
  108. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, `VP14-folders-composer-${theme}.png`),
  109. );
  110. await browser.keys("Escape");
  111. await menu.waitForDisplayed({ reverse: true });
  112. const edit = $('[data-testid="composer-edit-project"]');
  113. await edit.waitForDisplayed();
  114. await $('[data-branch-switcher-primary-icon="true"]').waitForDisplayed();
  115. const placement = await browser.execute(() => {
  116. const button = document.querySelector('[data-testid="composer-edit-project"]')!;
  117. const branch = button.parentElement!.querySelector(
  118. '[data-branch-switcher-primary-icon="true"]',
  119. )!.parentElement!;
  120. return {
  121. branchRight: branch.getBoundingClientRect().right,
  122. editLeft: button.getBoundingClientRect().left,
  123. };
  124. });
  125. expect(placement.editLeft).toBeGreaterThanOrEqual(placement.branchRight);
  126. await setInputValueByTestIdDom(TID_V4_COMPOSER_INPUT, "E2E_COMPOSER_EDIT_DRAFT");
  127. await browser.saveScreenshot(
  128. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, `VP14-composer-edit-${theme}.png`),
  129. );
  130. await edit.click();
  131. const name = $('[data-testid="virtual-project-name"]');
  132. await name.waitForDisplayed();
  133. expect(await name.getValue()).toBe("E2E_VP14_PROJECT");
  134. await browser.saveScreenshot(
  135. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, `VP14-project-editor-${theme}.png`),
  136. );
  137. await name.setValue("E2E_EDIT_CANCELLED");
  138. await $('//button[normalize-space(.)="Cancel" or normalize-space(.)="取消"]').click();
  139. await name.waitForDisplayed({ reverse: true });
  140. expect(await workspaceTrigger.getText()).toContain("E2E_VP14_PROJECT");
  141. if (theme === "zai-light") {
  142. const originalId = await project.getAttribute("data-project-id");
  143. await edit.click();
  144. await name.setValue("E2E_VP14_EDITED");
  145. await $('[data-testid="virtual-project-save"]').click();
  146. await name.waitForDisplayed({ reverse: true });
  147. const renamed = $('[data-project-name="E2E_VP14_EDITED"]');
  148. await renamed.waitForDisplayed();
  149. expect(await renamed.getAttribute("data-project-id")).toBe(originalId);
  150. expect(await workspaceTrigger.getText()).toContain("E2E_VP14_EDITED");
  151. expect(await input.getText()).toBe("E2E_COMPOSER_EDIT_DRAFT");
  152. await edit.click();
  153. await name.setValue("E2E_VP14_PROJECT");
  154. await $('[data-testid="virtual-project-save"]').click();
  155. await name.waitForDisplayed({ reverse: true });
  156. await project.waitForDisplayed();
  157. }
  158. expect(await input.getText()).toBe("E2E_COMPOSER_EDIT_DRAFT");
  159. }
  160. await setInputValueByTestIdDom(TID_V4_COMPOSER_INPUT, "@same.ts", {
  161. stabilizeLexicalCaretAtEnd: true,
  162. });
  163. const panel = $(`[data-testid="${TID_PROMPT_SUGGESTION_PANEL}"]`);
  164. await panel.waitForDisplayed();
  165. for (const root of roots) {
  166. const option = panel.$(`[data-option-id="file:${cssString(join(root, "src", "same.ts"))}"]`);
  167. await option.waitForDisplayed();
  168. expect(await option.getText()).toContain(basename(root));
  169. }
  170. const readMarkdown = () =>
  171. browser.execute(
  172. (testId) =>
  173. (
  174. document.querySelector(`[data-testid="${testId}"]`) as HTMLElement & {
  175. __zcodeLexicalInputE2E?: { getText(): string };
  176. }
  177. )?.__zcodeLexicalInputE2E?.getText(),
  178. TID_V4_COMPOSER_INPUT,
  179. );
  180. await panel
  181. .$(`[data-option-id="file:${cssString(join(roots[0]!, "src", "same.ts"))}"]`)
  182. .click();
  183. await browser.waitUntil(
  184. async () => (await readMarkdown())?.includes("[same.ts](./src/same.ts)") ?? false,
  185. );
  186. await setInputValueByTestIdDom(TID_V4_COMPOSER_INPUT, "@same.ts", {
  187. stabilizeLexicalCaretAtEnd: true,
  188. });
  189. await panel.waitForDisplayed();
  190. const second = panel.$(
  191. `[data-option-id="file:${cssString(join(roots[1]!, "src", "same.ts"))}"]`,
  192. );
  193. await second.click();
  194. expect(await input.$('[data-mention-category="files"]').getAttribute("data-mention-id")).toBe(
  195. `file:${join(roots[1]!, "src", "same.ts")}`,
  196. );
  197. // 修复原因:mention markdown 的链接目标会把反斜杠转义成 `\`(escapeMarkdownDestination),
  198. // Windows 路径需按同样规则转义后再比较。
  199. expect(await readMarkdown()).toContain(
  200. `[same.ts](${join(roots[1]!, "src", "same.ts").replaceAll("\\", "\\\\")})`,
  201. );
  202. await setInputValueByTestIdDom(
  203. TID_V4_COMPOSER_INPUT,
  204. "E2E_VP14_HISTORY: Reply with E2E_VP14_READY.",
  205. );
  206. await $(`[data-testid="${TID_V4_COMPOSER_SEND}"]`).click();
  207. await $('//*[normalize-space(.)="E2E_VP14_READY" and not(*)]').waitForDisplayed({
  208. timeout: 60_000,
  209. });
  210. const taskId = await browser.execute(() => {
  211. const state = (
  212. window as Window & {
  213. __zcodeSessionStoreE2E?: {
  214. getState(): { workspaces: Record<string, { activeTaskId?: string | null }> };
  215. };
  216. }
  217. ).__zcodeSessionStoreE2E?.getState();
  218. return (
  219. Object.values(state?.workspaces ?? {}).find((workspace) => workspace.activeTaskId)
  220. ?.activeTaskId ?? null
  221. );
  222. });
  223. expect(taskId).toBeTruthy();
  224. // 顶部新建继承当前项目;这里显式进入未归类草稿,才能覆盖跨项目 # 候选。
  225. await $('[data-testid="virtual-project-new-task"]').click();
  226. await input.waitForDisplayed();
  227. await setInputValueByTestIdDom(TID_V4_COMPOSER_INPUT, "#", {
  228. stabilizeLexicalCaretAtEnd: true,
  229. });
  230. await panel.waitForDisplayed();
  231. await panel.$(`[data-option-id="session:${taskId}"]`).waitForDisplayed();
  232. expect(await panel.getText()).toContain("E2E_VP14_PROJECT");
  233. await browser.saveScreenshot(
  234. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, "VP14-project-mentions.png"),
  235. );
  236. // # 候选验证结束后清空查询;只按 Escape 会在项目切换恢复草稿时再次弹出候选并遮住项目入口。
  237. await setInputValueByTestIdDom(TID_V4_COMPOSER_INPUT, "");
  238. await panel.waitForDisplayed({ reverse: true });
  239. await openLocalProjectEditor();
  240. await $('[data-testid="virtual-project-name"]').setValue("E2E_VP15_TARGET");
  241. await chooseProjectRoot(roots[1]!);
  242. await $('[data-testid="virtual-project-save"]').click();
  243. await $('[data-testid="project-folder-trust-confirm"]').waitForDisplayed();
  244. await $('[data-testid="project-folder-trust-confirm"]').click();
  245. const destination = $('[data-project-name="E2E_VP15_TARGET"]');
  246. await destination.waitForDisplayed();
  247. // 创建完成先发布目录再关闭信任/编辑器;等待遮罩退出,避免点击被旧弹窗截获。
  248. await $('[data-slot="dialog-overlay"]').waitForExist({ reverse: true });
  249. // PCD01 会跨 root 切换草稿;列表出现并不表示新 workspace 的 Composer 已接管。
  250. await waitForWorkspaceApp(roots[1]!, 30000);
  251. const destinationTrigger = $(`[data-testid="${TID_COMPOSER_WORKSPACE_TRIGGER}"]`);
  252. await browser.waitUntil(async () =>
  253. (await destinationTrigger.getText()).includes("E2E_VP15_TARGET"),
  254. );
  255. await destinationTrigger.waitForClickable();
  256. await destinationTrigger.click();
  257. const projectMenu = $('[data-testid="composer-project-menu"]');
  258. await projectMenu.$('[data-project-name="E2E_VP15_TARGET"] .lucide-folder').waitForDisplayed();
  259. await projectMenu
  260. .$('[data-project-name="E2E_VP14_PROJECT"] .lucide-folders')
  261. .waitForDisplayed();
  262. await browser.keys("Escape");
  263. await projectMenu.waitForDisplayed({ reverse: true });
  264. const targetId = await destination.getAttribute("data-project-id");
  265. const sourceId = await project.getAttribute("data-project-id");
  266. const row = project.$(`[data-testid="${testId(TID_TASK_ITEM, taskId!)}"]`);
  267. await row.waitForDisplayed();
  268. // 只观察原生拖动事件,不在测试里直接发组织命令或写 dataTransfer。
  269. await browser.execute(() => {
  270. const trace: unknown[] = [];
  271. (window as Window & { __vp15DragTrace?: unknown[] }).__vp15DragTrace = trace;
  272. for (const name of ["dragstart", "dragenter", "dragover", "drop", "dragend"]) {
  273. document.addEventListener(name, (event) => {
  274. const e = event as DragEvent;
  275. if (trace.length < 100)
  276. trace.push({
  277. type: e.type,
  278. allowed: e.dataTransfer?.effectAllowed,
  279. effect: e.dataTransfer?.dropEffect,
  280. project: (e.target as HTMLElement)
  281. .closest?.("[data-project-id]")
  282. ?.getAttribute("data-project-id"),
  283. });
  284. });
  285. }
  286. });
  287. const readOwnership = () => {
  288. const db = new DatabaseSync(join(home, ".zcode", "v2", "tasks-index.sqlite"), {
  289. readOnly: true,
  290. });
  291. try {
  292. return {
  293. task: db
  294. .prepare("SELECT project_id,workspace_path FROM tasks WHERE task_id=?")
  295. .get(taskId!),
  296. roots: db
  297. .prepare("SELECT root_path FROM project_roots WHERE project_id=? ORDER BY position")
  298. .all(targetId!),
  299. };
  300. } finally {
  301. db.close();
  302. }
  303. };
  304. const confirm = $(`[data-testid="${TID_CONFIRM_DIALOG_CONFIRM}"]`);
  305. const rowSelector = `[data-testid="${testId(TID_TASK_ITEM, taskId!)}"]`;
  306. const targetSelector = '[data-project-name="E2E_VP15_TARGET"]';
  307. const sourceSelector = '[data-project-name="E2E_VP14_PROJECT"]';
  308. try {
  309. for (const theme of ["zai-light", "zai-dark"]) {
  310. await browser.execute(
  311. (theme) =>
  312. (
  313. window as Window & { __testActions?: { setTheme(theme: string): void } }
  314. ).__testActions!.setTheme(theme),
  315. theme,
  316. );
  317. const before = await destination.getSize();
  318. await hoverSessionOnProject(rowSelector, sourceSelector);
  319. const sourceIndicator = project.$('[data-testid="project-session-drop-target"]');
  320. await sourceIndicator.waitForDisplayed();
  321. expect((await sourceIndicator.getSize()).height).toBeGreaterThan(40);
  322. await moveSessionPointer(`${sourceSelector} [data-testid="virtual-project-toggle"]`);
  323. await sourceIndicator.waitForDisplayed();
  324. await browser.saveScreenshot(
  325. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, `VP15-project-drop-${theme}.png`),
  326. );
  327. await project.saveScreenshot(
  328. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, `VP15-project-drop-panel-${theme}.png`),
  329. );
  330. await moveSessionPointer(`${targetSelector} [data-testid="virtual-project-toggle"]`);
  331. await destination.$('[data-testid="project-session-drop-target"]').waitForDisplayed();
  332. expect(await sourceIndicator.isExisting()).toBe(false);
  333. expect(await destination.getSize()).toEqual(before);
  334. // WebDriver 的 Escape 不会取消原生拖拽;离开项目再松手,避免误触发落点确认。
  335. await moveSessionPointer('[data-testid="task-new-button"]');
  336. await $('[data-testid="project-session-drop-target"]').waitForExist({ reverse: true });
  337. await browser.releaseActions();
  338. await $('[data-testid="project-session-drop-target"]').waitForExist({ reverse: true });
  339. expect(readOwnership().task).toEqual({ project_id: sourceId, workspace_path: roots[0] });
  340. }
  341. await row.dragAndDrop(destination.$('[data-testid="virtual-project-toggle"]'), {
  342. duration: 700,
  343. });
  344. await confirm.waitForDisplayed({ timeout: 8_000 });
  345. expect(await $('[data-testid="project-session-drop-target"]').isExisting()).toBe(false);
  346. await browser.keys("Escape");
  347. await confirm.waitForDisplayed({ reverse: true });
  348. expect(readOwnership()).toEqual({
  349. task: { project_id: sourceId, workspace_path: roots[0] },
  350. roots: [{ root_path: roots[1] }],
  351. });
  352. await row.dragAndDrop(destination.$('[data-testid="virtual-project-toggle"]'), {
  353. duration: 700,
  354. });
  355. await confirm.waitForDisplayed();
  356. await confirm.click();
  357. await destination.$(`[data-testid="${testId(TID_TASK_ITEM, taskId!)}"]`).waitForDisplayed();
  358. expect(readOwnership()).toEqual({
  359. task: { project_id: targetId, workspace_path: roots[0] },
  360. roots: [{ root_path: roots[1] }, { root_path: roots[0] }],
  361. });
  362. // 确认框退出动画仍会接收指针;等它退出后再开始下一次真实拖拽。
  363. await confirm.waitForDisplayed({ reverse: true });
  364. await hoverSessionOnProject(`${targetSelector} ${rowSelector}`, sourceSelector);
  365. await project.$('[data-testid="project-session-drop-target"]').waitForDisplayed();
  366. await browser.performActions([
  367. {
  368. type: "pointer",
  369. id: "session-project-drag",
  370. parameters: { pointerType: "mouse" },
  371. actions: [{ type: "pointerUp", button: 0 }],
  372. },
  373. ]);
  374. await row.waitForDisplayed();
  375. expect(readOwnership().task).toEqual({ project_id: sourceId, workspace_path: roots[0] });
  376. expect(await $('[data-testid="project-session-drop-target"]').isExisting()).toBe(false);
  377. await row.click();
  378. await $('//*[normalize-space(.)="E2E_VP14_READY" and not(*)]').waitForDisplayed();
  379. await browser.saveScreenshot(
  380. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, "VP15-project-move.png"),
  381. );
  382. } finally {
  383. await browser.releaseActions();
  384. process.stderr.write(
  385. `VP15 native drag: ${JSON.stringify(await browser.execute(() => (window as Window & { __vp15DragTrace?: unknown[] }).__vp15DragTrace))}\n`,
  386. );
  387. }
  388. });
  389. });
  390. async function openLocalProjectEditor() {
  391. await $('[data-testid="project-section"]').moveTo();
  392. await $('[data-testid="virtual-project-add"]').click();
  393. await $('[data-testid="virtual-project-name"]').waitForDisplayed();
  394. }
  395. async function openComposerProjectEditor() {
  396. await $(`[data-testid="${TID_COMPOSER_WORKSPACE_TRIGGER}"]`).click();
  397. const menu = $('[data-testid="composer-project-menu"]');
  398. const create = menu.$('[data-testid="composer-create-project"]');
  399. // 修复原因:Radix 菜单淡入首帧元素已显示但文本为空,立即 getText 读到 "";等文本就绪后再断言。
  400. await browser.waitUntil(async () => /^(创建项目|Create project)$/.test(await create.getText()), {
  401. timeout: 10_000,
  402. timeoutMsg: "创建项目菜单项文本未就绪",
  403. });
  404. await create.click();
  405. await menu.waitForDisplayed({ reverse: true });
  406. await $('[data-testid="virtual-project-name"]').waitForDisplayed();
  407. }
  408. async function chooseProjectRoot(path: string) {
  409. await selectNativeProjectDirectories([path]);
  410. }
  411. async function moveSessionPointer(selector: string) {
  412. const point = await browser.execute((selector) => {
  413. const r = document.querySelector(selector)!.getBoundingClientRect();
  414. return { x: Math.round(r.left + r.width / 2), y: Math.round(r.top + r.height / 2) };
  415. }, selector);
  416. await browser.performActions([
  417. {
  418. type: "pointer",
  419. id: "session-project-drag",
  420. parameters: { pointerType: "mouse" },
  421. actions: [{ type: "pointerMove", ...point, duration: 350 }],
  422. },
  423. ]);
  424. // 首次进入仅触发 dragenter;第二次真实位移触发 dragover,让浏览器采用目标的 move 效果。
  425. await browser.performActions([
  426. {
  427. type: "pointer",
  428. id: "session-project-drag",
  429. parameters: { pointerType: "mouse" },
  430. actions: [{ type: "pointerMove", x: point.x + 1, y: point.y, duration: 0 }],
  431. },
  432. ]);
  433. }
  434. async function hoverSessionOnProject(source: string, target: string) {
  435. await browser.releaseActions();
  436. const point = await browser.execute((selector) => {
  437. const r = document.querySelector(selector)!.getBoundingClientRect();
  438. return { x: Math.round(r.left + 60), y: Math.round(r.top + r.height / 2) };
  439. }, source);
  440. await browser.performActions([
  441. {
  442. type: "pointer",
  443. id: "session-project-drag",
  444. parameters: { pointerType: "mouse" },
  445. actions: [
  446. { type: "pointerMove", ...point, duration: 0 },
  447. { type: "pointerDown", button: 0 },
  448. { type: "pointerMove", x: point.x + 10, y: point.y, duration: 100 },
  449. ],
  450. },
  451. ]);
  452. await moveSessionPointer(`${target} [data-testid="virtual-project-toggle"]`);
  453. }