conversation-session-sidebar-show-more-typography.test.ts 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. import { restartIntoWorkspacePreservingProfile } from "#e2e/helpers/model-provider-restart-runtime";
  2. import { mkdir, writeFile } from "node:fs/promises";
  3. import { join } from "node:path";
  4. import { isIsolatedE2EHomeDir } from "#e2e/helpers/e2e-runtime-paths";
  5. import { DatabaseSync } from "node:sqlite";
  6. import { DEFAULT_WORKSPACE, waitForWorkspaceApp } from "#e2e/helpers/desktop-app";
  7. const projectId = "E2E_SHOW_MORE";
  8. const project = `[data-project-id="${projectId}"]`;
  9. const more = `${project} [data-task-list-show-more]`;
  10. const empty = `[data-project-id="${projectId}_EMPTY"] [data-testid="project-no-tasks"]`;
  11. const title = `${project} [data-task-title-copy="original"]`;
  12. // 合成 Host 索引仅用于样式和分页,不恢复任务或请求模型;node:sqlite 仅提供同步 API。
  13. async function seedRows() {
  14. const home = process.env.ZCODE_E2E_HOME_DIR;
  15. // 原因:runner 的隔离 HOME 可能是 .e2e-home、.e2e-home-<runId> 或显式根下的 shard 目录。
  16. if (!isIsolatedE2EHomeDir(home)) throw new Error("需要本 case 的隔离 HOME");
  17. const root = join(DEFAULT_WORKSPACE, ".zcode-e2e", "show-more");
  18. await mkdir(root, { recursive: true });
  19. const db = new DatabaseSync(join(home, ".zcode/v2/tasks-index.sqlite"));
  20. try {
  21. const now = Date.now();
  22. db.exec("BEGIN IMMEDIATE");
  23. for (const [index, id] of [projectId, `${projectId}_EMPTY`].entries()) {
  24. db.prepare(
  25. "INSERT INTO projects(project_id,host_id,name,position,created_at,updated_at) VALUES(?,'local',?,?,?,?)",
  26. ).run(id, id, index - 2, now, now);
  27. db.prepare(
  28. "INSERT INTO project_roots(project_id,root_path,position,is_primary) VALUES(?,?,0,1)",
  29. ).run(id, root);
  30. }
  31. const insert = db.prepare(
  32. `INSERT INTO tasks(workspace_key,workspace_path,task_id,title,created_at,updated_at,provider,host_id,root_path,project_id,cli_title,cli_title_source,cli_created_at,cli_updated_at,cli_last_outcome,cli_deleted,handoff_pending,meta_json)
  33. VALUES(?,?,?,?,?,?,'glm','local',?,?,?,'custom',?,?,'completed',0,8,?)`,
  34. );
  35. for (let index = 0; index < 6; index++) {
  36. const id = `${projectId}_${index}`;
  37. const text = `任务标题 ${index}`;
  38. insert.run(
  39. root,
  40. root,
  41. id,
  42. text,
  43. now,
  44. now,
  45. root,
  46. projectId,
  47. text,
  48. now,
  49. now,
  50. JSON.stringify({
  51. taskId: id,
  52. traceId: id,
  53. title: text,
  54. workspacePath: root,
  55. createdAt: now,
  56. updatedAt: now,
  57. mode: "build",
  58. status: "completed",
  59. }),
  60. );
  61. }
  62. db.exec("COMMIT");
  63. } finally {
  64. db.close();
  65. }
  66. }
  67. async function sample() {
  68. return browser.execute(
  69. (more, empty, title) => {
  70. const button = document.querySelector<HTMLElement>(more)!;
  71. const style = getComputedStyle(button);
  72. const placeholder = getComputedStyle(document.querySelector(empty)!);
  73. const task = getComputedStyle(document.querySelector(title)!);
  74. return {
  75. fontSize: style.fontSize,
  76. color: style.color,
  77. background: style.backgroundColor,
  78. emptyFontSize: placeholder.fontSize,
  79. emptyColor: placeholder.color,
  80. titleFontSize: task.fontSize,
  81. titleColor: task.color,
  82. focusVisible: button.matches(":focus-visible"),
  83. };
  84. },
  85. more,
  86. empty,
  87. title,
  88. );
  89. }
  90. describe("侧栏显示更多文字", () => {
  91. it("VP-MORE-01:与标题/空态同字号、空态同色,hover/focus 提亮且分页可用", async function () {
  92. this.timeout(120_000);
  93. await waitForWorkspaceApp(DEFAULT_WORKSPACE, 45_000);
  94. // 旧夹具未写 provider,被 readTree 的 glm 过滤排除;补齐元数据并在停机后播种。
  95. await restartIntoWorkspacePreservingProfile(DEFAULT_WORKSPACE, {
  96. afterElectronProcessExit: seedRows,
  97. });
  98. await waitForWorkspaceApp(DEFAULT_WORKSPACE, 45_000);
  99. for (const id of [projectId, `${projectId}_EMPTY`]) {
  100. const trigger = $(`[data-project-id="${id}"] [data-testid="virtual-project-toggle"]`);
  101. await trigger.waitForDisplayed();
  102. if ((await trigger.getAttribute("aria-expanded")) === "false") await trigger.click();
  103. }
  104. await $(more).waitForDisplayed();
  105. await $(empty).waitForDisplayed();
  106. expect(await $$(`${project} [data-task-item-key]`).length).toBe(5);
  107. const evidence = [];
  108. for (const width of [1200, 390]) {
  109. await browser.electron.execute(async (electron, width) => {
  110. const window = electron.BrowserWindow.getAllWindows().find((item) => item.isVisible())!;
  111. if (!window.webContents.debugger.isAttached()) window.webContents.debugger.attach("1.3");
  112. await window.webContents.debugger.sendCommand("Emulation.setDeviceMetricsOverride", {
  113. width,
  114. height: 844,
  115. deviceScaleFactor: 1,
  116. mobile: false,
  117. });
  118. }, width);
  119. if (width === 390) {
  120. await browser.waitUntil(
  121. async () => (await $("aside").getAttribute("aria-hidden")) === "true",
  122. );
  123. await $('button[aria-label="Toggle sidebar"], button[aria-label="切换侧边栏"]').click();
  124. }
  125. for (const theme of ["zai-light", "zai-dark"]) {
  126. await browser.execute((value) => {
  127. (
  128. window as Window & { __testActions?: { setTheme(theme: string): void } }
  129. ).__testActions!.setTheme(value);
  130. }, theme);
  131. await browser.waitUntil(() =>
  132. browser.execute(
  133. (value) => document.documentElement.classList.contains(`theme-${value}`),
  134. theme,
  135. ),
  136. );
  137. for (const fontSize of ["14px", "18px"]) {
  138. // 界面设置只改变此变量,不改变根字号;比较真实共享组件的 computed style。
  139. await browser.execute(
  140. (value) => document.documentElement.style.setProperty("--ui-font-size", value),
  141. fontSize,
  142. );
  143. await $(empty).moveTo();
  144. await browser.execute(() => (document.activeElement as HTMLElement)?.blur());
  145. await browser.waitUntil(async () => (await sample()).titleFontSize === fontSize);
  146. // 等待上一轮 hover/focus 的颜色过渡结束,避免把过渡帧当成默认颜色。
  147. await browser.waitUntil(() =>
  148. browser.execute(
  149. (selector) => document.querySelector(selector)!.getAnimations().length === 0,
  150. more,
  151. ),
  152. );
  153. const normal = await sample();
  154. evidence.push({ width, theme, fontSize, normal });
  155. await writeFile(
  156. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, "show-more-styles.json"),
  157. JSON.stringify(evidence, null, 2),
  158. );
  159. await browser.saveScreenshot(
  160. join(
  161. process.env.ZCODE_E2E_ARTIFACT_DIR!,
  162. `show-more-${width}-${theme}-${fontSize}.png`,
  163. ),
  164. );
  165. expect(normal.fontSize).toBe(normal.titleFontSize);
  166. expect(normal.fontSize).toBe(normal.emptyFontSize);
  167. expect(normal.color).toBe(normal.emptyColor);
  168. expect(normal.background).toBe("rgba(0, 0, 0, 0)");
  169. await $(more).moveTo();
  170. await browser.waitUntil(async () => (await sample()).color === normal.titleColor);
  171. await $(empty).moveTo();
  172. await browser.keys("Tab");
  173. await browser.execute(
  174. (selector) => document.querySelector<HTMLElement>(selector)!.focus(),
  175. more,
  176. );
  177. await browser.waitUntil(async () => {
  178. const focused = await sample();
  179. return focused.focusVisible && focused.color === normal.titleColor;
  180. });
  181. }
  182. }
  183. }
  184. await $(more).click();
  185. await browser.waitUntil(async () => (await $$(`${project} [data-task-item-key]`).length) === 6);
  186. expect(await $(more).isExisting()).toBe(false);
  187. });
  188. });