conversation-session-archive-management.test.ts 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. import { DatabaseSync } from "node:sqlite";
  2. import { readFile } from "node:fs/promises";
  3. import { join, basename } from "node:path";
  4. import { restartIntoWorkspacePreservingProfile } from "#e2e/helpers/model-provider-restart-runtime";
  5. import { waitForWorkspaceApp, DEFAULT_WORKSPACE } from "../helpers/desktop-app.js";
  6. const row = (id: string) => $(`[data-testid="archive-task"][data-task-id="${id}"]`);
  7. const home = process.env.ZCODE_E2E_HOME_DIR!;
  8. const ids = ["arm-alpha", "arm-beta", "arm-scheduled", "arm-loose", "arm-removed"];
  9. function readRow(id: string) {
  10. const db = new DatabaseSync(join(home, ".zcode/v2/tasks-index.sqlite"), { readOnly: true });
  11. try {
  12. return db
  13. .prepare("SELECT archived,cli_deleted,project_id FROM tasks WHERE task_id=?")
  14. .get(id) as { archived: number; cli_deleted: number; project_id: string | null };
  15. } finally {
  16. db.close();
  17. }
  18. }
  19. async function clearSearch() {
  20. await $('[data-testid="archive-search"]').click();
  21. await browser.keys([process.platform === "darwin" ? "Meta" : "Control", "a"]);
  22. await browser.keys("Backspace");
  23. }
  24. async function setArchiveGroupsOpen(open: boolean) {
  25. await waitForArchiveAnimations();
  26. for (const toggle of await $$('[data-testid="archive-group-toggle"]')) {
  27. if ((await toggle.getAttribute("aria-expanded")) !== String(open)) {
  28. // 上一组高度动画会移动下一组的点击位置,等布局稳定再继续逐组操作。
  29. await toggle.click();
  30. await expect(toggle).toHaveAttribute("aria-expanded", String(open));
  31. await waitForArchiveAnimations();
  32. }
  33. }
  34. }
  35. async function waitForArchiveAnimations() {
  36. await browser.waitUntil(() =>
  37. browser.execute(() =>
  38. document
  39. .querySelector('[data-testid="archive-management"]')!
  40. .getAnimations({ subtree: true })
  41. .every((animation) => animation.playState !== "running"),
  42. ),
  43. );
  44. }
  45. describe("归档管理", () => {
  46. before(async function () {
  47. this.timeout(60000);
  48. // 原因:批量 runner 使用 runId 隔离 HOME,不能只接受早期手工回放的目录名。
  49. if (!home || !/^(?:zcode-archive-e2e-|\.e2e-home-)/u.test(basename(home)))
  50. throw new Error("isolated archive HOME required");
  51. await waitForWorkspaceApp(DEFAULT_WORKSPACE, 45000);
  52. // 旧夹具在运行中的 Host 下写库且缺少必填 meta,列表可见不代表任务命令能读取它。
  53. await restartIntoWorkspacePreservingProfile(DEFAULT_WORKSPACE, {
  54. afterElectronProcessExit: async () => {
  55. const db = new DatabaseSync(join(home, ".zcode/v2/tasks-index.sqlite"));
  56. const cli = new DatabaseSync(join(home, ".zcode/cli/db/db.sqlite"));
  57. try {
  58. for (const [i, name] of [
  59. "E2E 虚拟项目甲",
  60. "E2E 虚拟项目乙",
  61. "E2E 已移除项目",
  62. ].entries()) {
  63. db.prepare(
  64. "INSERT INTO projects(project_id,host_id,name,position,deleted,created_at,updated_at) VALUES(?,'local',?,?,?,1,1)",
  65. ).run(`arm-project-${i}`, name, i, i === 2 ? 1 : 0);
  66. db.prepare(
  67. "INSERT INTO project_roots(project_id,root_path,position,is_primary) VALUES(?,?,0,1)",
  68. ).run(`arm-project-${i}`, DEFAULT_WORKSPACE);
  69. }
  70. const baseTime = Date.now() - 100000;
  71. for (const [i, id] of ids.entries()) {
  72. const title = [
  73. "E2E Alpha " + "long title ".repeat(20),
  74. "E2E Beta",
  75. "E2E Scheduled",
  76. "E2E Unclassified",
  77. "E2E Removed",
  78. ][i]!;
  79. const now = baseTime + i;
  80. const updated = baseTime + 100 - i;
  81. // 真实历史 fixture 同时提供 CLI 存在性与 Host 归档组织态;删除必须实际写 CLI 软删除。
  82. cli
  83. .prepare(
  84. "INSERT INTO session(id,project_id,slug,directory,title,version,time_created,time_updated,title_source,last_outcome) VALUES(?,?,?,?,?,'1',?,?,'custom','completed')",
  85. )
  86. .run(id, "arm-cli-scope", id, DEFAULT_WORKSPACE, title, now, updated);
  87. db.prepare(
  88. "INSERT INTO tasks(workspace_key,workspace_path,task_id,title,provider,created_at,updated_at,host_id,root_path,project_id,archived,cli_title,cli_title_source,cli_created_at,cli_updated_at,cli_last_outcome,cli_deleted,meta_json) VALUES(?,?,?,?,'glm',?,?,'local',?,?,1,?,'custom',?,?,'completed',0,?)",
  89. ).run(
  90. DEFAULT_WORKSPACE,
  91. DEFAULT_WORKSPACE,
  92. id,
  93. title,
  94. now,
  95. updated,
  96. DEFAULT_WORKSPACE,
  97. i === 3 ? null : `arm-project-${i === 4 ? 2 : i === 1 ? 1 : 0}`,
  98. title,
  99. now,
  100. updated,
  101. JSON.stringify({
  102. taskId: id,
  103. traceId: id,
  104. title,
  105. workspacePath: DEFAULT_WORKSPACE,
  106. createdAt: now,
  107. updatedAt: updated,
  108. mode: "default",
  109. archived: true,
  110. ...(i === 2 ? { cronAutomationId: "arm-cron" } : {}),
  111. }),
  112. );
  113. }
  114. } finally {
  115. db.close();
  116. cli.close();
  117. }
  118. },
  119. });
  120. await waitForWorkspaceApp(DEFAULT_WORKSPACE, 45000);
  121. await browser.execute(() => {
  122. (
  123. window as typeof window & { __testActions: { setLocale(value: string): void } }
  124. ).__testActions.setLocale("zh-CN");
  125. });
  126. // 通过已存在的设置导航入口打开,再点新分区。
  127. await $('[data-testid="task-settings-button"]').click();
  128. await $('[data-testid="settings-section-nav-archives"]').click();
  129. await $('[data-testid="archive-management"]').waitForDisplayed();
  130. });
  131. it("ARM08:页面标题与固定文案统一为会话", async () => {
  132. const heading = $("h2=归档管理");
  133. await expect(heading).toBeDisplayed();
  134. await expect($('[data-testid="archive-management"] h2')).toHaveText("已归档的会话");
  135. await expect($('[data-testid="archive-search"]')).toHaveAttribute(
  136. "placeholder",
  137. "搜索已归档会话",
  138. );
  139. await expect($('[data-testid="archive-auto-archive-switch"]')).toHaveAttribute(
  140. "aria-label",
  141. "自动归档旧会话",
  142. );
  143. const main = $('main:has([data-testid="archive-management"])');
  144. expect(await main.getText()).not.toMatch(/任务|对话|聊天/);
  145. expect(await main.getText()).toContain("2 个会话");
  146. const titleAboveSettings = await browser.execute(() => {
  147. const title = [...document.querySelectorAll("main h2")].find(
  148. (el) => el.textContent === "归档管理",
  149. )!;
  150. const settings = document.querySelector('[data-testid="archive-auto-archive-switch"]')!;
  151. return title.getBoundingClientRect().bottom < settings.getBoundingClientRect().top;
  152. });
  153. expect(titleAboveSettings).toBe(true);
  154. await $('[data-testid="archive-search"]').setValue("E2E_NO_ARCHIVE_MATCH");
  155. await expect($('[data-testid="archive-management"]')).toHaveText(
  156. expect.stringContaining("没有匹配的归档会话"),
  157. );
  158. await clearSearch();
  159. await $('[data-testid="archive-delete-all"]').click();
  160. const confirmation = $('[data-confirm-intent="archive-management-delete"]');
  161. await expect(confirmation).toHaveText(expect.stringContaining("删除这 5 个归档会话?"));
  162. expect(await confirmation.getText()).toContain("只删除当前确认范围内的会话。");
  163. await browser.keys("Escape");
  164. });
  165. it("ARM07:默认 30 天,关闭时可先保存时长,开启与刷新保留选择", async () => {
  166. await $('[data-testid="settings-section-nav-general"]').click();
  167. expect(await $('//*[normalize-space(text())="自动归档旧会话"]').isExisting()).toBe(false);
  168. expect(await $('//*[normalize-space(text())="归档保留时长"]').isExisting()).toBe(false);
  169. await $('[data-testid="settings-section-nav-archives"]').click();
  170. const toggle = $('[data-testid="archive-auto-archive-switch"]');
  171. const days = $('[data-testid="archive-auto-archive-days"]');
  172. await expect(toggle).toHaveAttribute("aria-checked", "false");
  173. await expect(days).toBeEnabled();
  174. await expect(days).toHaveText("30 天后归档");
  175. const placement = await browser.execute(() => ({
  176. settingsBottom: document
  177. .querySelector('[data-testid="archive-auto-archive-days"]')!
  178. .getBoundingClientRect().bottom,
  179. listTop: document.querySelector('[data-testid="archive-management"]')!.getBoundingClientRect()
  180. .top,
  181. }));
  182. expect(placement.settingsBottom).toBeLessThan(placement.listTop);
  183. // 先保存时长再开启,避免开关一开就按旧阈值归档。
  184. await days.click();
  185. await $('[role="option"]*=7 天后归档').click();
  186. await expect(days).toHaveText("7 天后归档");
  187. await browser.waitUntil(async () => {
  188. const settings = JSON.parse(await readFile(join(home, ".zcode/v2/setting.json"), "utf8"));
  189. return (
  190. settings.taskAutoArchiveEnabled === false && settings.taskAutoArchiveOlderThanDays === 7
  191. );
  192. });
  193. await browser.refresh();
  194. await waitForWorkspaceApp(DEFAULT_WORKSPACE, 45000);
  195. await $('[data-testid="task-settings-button"]').click();
  196. await $('[data-testid="settings-section-nav-archives"]').click();
  197. await expect(toggle).toHaveAttribute("aria-checked", "false");
  198. await expect(days).toBeEnabled();
  199. await expect(days).toHaveText("7 天后归档");
  200. await toggle.click();
  201. await expect(toggle).toHaveAttribute("aria-checked", "true");
  202. expect(JSON.parse(await readFile(join(home, ".zcode/v2/setting.json"), "utf8"))).toMatchObject({
  203. taskAutoArchiveEnabled: true,
  204. taskAutoArchiveOlderThanDays: 7,
  205. });
  206. await days.click();
  207. await $('[role="option"]*=14 天后归档').click();
  208. await expect(days).toHaveText("14 天后归档");
  209. await browser.waitUntil(async () => {
  210. const settings = JSON.parse(await readFile(join(home, ".zcode/v2/setting.json"), "utf8"));
  211. return (
  212. settings.taskAutoArchiveEnabled === true && settings.taskAutoArchiveOlderThanDays === 14
  213. );
  214. });
  215. await browser.refresh();
  216. await waitForWorkspaceApp(DEFAULT_WORKSPACE, 45000);
  217. await $('[data-testid="task-settings-button"]').click();
  218. await $('[data-testid="settings-section-nav-archives"]').click();
  219. await expect(toggle).toHaveAttribute("aria-checked", "true");
  220. await expect(days).toHaveText("14 天后归档");
  221. await toggle.click();
  222. await expect(toggle).toHaveAttribute("aria-checked", "false");
  223. await expect(days).toBeEnabled();
  224. await expect(days).toHaveText("14 天后归档");
  225. await days.click();
  226. await $('[role="option"]*=30 天后归档').click();
  227. await expect(days).toHaveText("30 天后归档");
  228. await browser.waitUntil(async () => {
  229. const settings = JSON.parse(await readFile(join(home, ".zcode/v2/setting.json"), "utf8"));
  230. return (
  231. settings.taskAutoArchiveEnabled === false && settings.taskAutoArchiveOlderThanDays === 30
  232. );
  233. });
  234. expect(ids.map((id) => readRow(id).archived)).toEqual(ids.map(() => 1));
  235. await browser.saveScreenshot(
  236. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, "ARM07-disabled-30-days.png"),
  237. );
  238. });
  239. it("ARM01/05/06:分组折叠、搜索、时间排序和项目选择", async () => {
  240. expect(await $$('[data-testid="archive-group"]').length).toBe(4);
  241. expect(await $$('[data-testid="archive-task"]').length).toBe(0);
  242. const firstGroup = $('[data-testid="archive-group"][data-project-id="arm-project-0"]');
  243. const toggle = firstGroup.$('[data-testid="archive-group-toggle"]');
  244. expect(await toggle.getAttribute("aria-expanded")).toBe("false");
  245. expect(await firstGroup.getText()).toContain("2");
  246. await toggle.click();
  247. await row("arm-alpha").waitForDisplayed();
  248. // 展开只挂载当前组;键盘收起后必须真正移除行,不只是 CSS 隐藏。
  249. expect(await $$('[data-testid="archive-task"]').length).toBe(2);
  250. await browser.keys("Enter");
  251. await row("arm-alpha").waitForExist({ reverse: true });
  252. expect(await toggle.getAttribute("aria-expanded")).toBe("false");
  253. expect(await $$('[data-testid="archive-task"]').length).toBe(0);
  254. await firstGroup.$('[data-testid="archive-group-menu"]').click();
  255. expect(await toggle.getAttribute("aria-expanded")).toBe("false");
  256. expect(await $$('[data-testid="archive-task"]').length).toBe(0);
  257. await browser.keys("Escape");
  258. await setArchiveGroupsOpen(true);
  259. expect(await $$('[data-testid="archive-task"]').length).toBe(5);
  260. expect(await $('[data-testid="archive-management"]').getText()).toContain("E2E 虚拟项目甲");
  261. // 防止将静态标签和业务图标再次塞进触发框,扩大下拉点击区域。
  262. expect(await $('[data-testid="archive-sort"]').getText()).toBe("更新时间");
  263. expect(await $('[data-testid="archive-project-filter"]').getText()).toBe("所有项目");
  264. // 筛选栏只保留搜索图标和两个下拉箭头,不再显示排序/项目装饰图标。
  265. expect(await $('[data-testid="archive-filters"]').$$("svg").length).toBe(3);
  266. for (const testId of ["archive-sort", "archive-project-filter"]) {
  267. expect(await $(`[data-testid="${testId}"]`).$$("svg").length).toBe(1);
  268. }
  269. const sortLabel = await browser.execute(() => {
  270. const trigger = document.querySelector<HTMLButtonElement>('[data-testid="archive-sort"]')!;
  271. const label = trigger.labels?.[0];
  272. return { text: label?.textContent, outside: Boolean(label && !trigger.contains(label)) };
  273. });
  274. expect(sortLabel).toEqual({ text: "排序方式", outside: true });
  275. await $('[data-testid="archive-project-filter"]').click();
  276. const options = await $$('[role="option"]');
  277. expect((await options.map((o) => o.getText())).join("\n")).toContain("E2E 虚拟项目乙");
  278. expect((await options.map((o) => o.getText())).join("\n")).not.toContain(DEFAULT_WORKSPACE);
  279. await $('[data-testid="archive-project-option-arm-project-1"]').click();
  280. expect(await $$('[data-testid="archive-task"]').length).toBe(1);
  281. expect(await row("arm-beta").isDisplayed()).toBe(true);
  282. await $('[data-testid="archive-project-filter"]').click();
  283. await $('[data-testid="archive-project-all"]').click();
  284. expect(await toggle.getAttribute("aria-expanded")).toBe("false");
  285. expect(
  286. await $('[data-testid="archive-group"][data-project-id="arm-project-1"]')
  287. .$('[data-testid="archive-group-toggle"]')
  288. .getAttribute("aria-expanded"),
  289. ).toBe("true");
  290. await setArchiveGroupsOpen(true);
  291. await $('[data-testid="archive-sort"]').click();
  292. // Radix 异步移动选项焦点;确认焦点后再回车,避免同批按键选中旧项。
  293. await browser.keys("End");
  294. await expect($('[data-testid="archive-sort-created"]')).toBeFocused();
  295. await browser.keys("Enter");
  296. await expect($('[data-testid="archive-sort"]')).toHaveText("创建时间");
  297. expect(
  298. await $('[data-testid="archive-group"][data-project-id="arm-project-0"]')
  299. .$$('[data-testid="archive-task"]')
  300. .map((r) => r.getAttribute("data-task-id")),
  301. ).toEqual(["arm-scheduled", "arm-alpha"]);
  302. expect(await $('[data-testid="archive-sort"]').getAttribute("aria-label")).toBeTruthy();
  303. await $('[data-testid="archive-sort"]').click();
  304. await $('[data-testid="archive-sort-updated"]').click();
  305. expect(
  306. await $('[data-testid="archive-group"][data-project-id="arm-project-0"]')
  307. .$$('[data-testid="archive-task"]')
  308. .map((r) => r.getAttribute("data-task-id")),
  309. ).toEqual(["arm-alpha", "arm-scheduled"]);
  310. await $('[data-testid="archive-search"]').setValue("alpha");
  311. expect(await $$('[data-testid="archive-task"]').length).toBe(1);
  312. await clearSearch();
  313. await captureArchiveLayouts();
  314. await setArchiveGroupsOpen(true);
  315. });
  316. it("ARM02:取消归档、取消删除与确认删除后刷新不复活", async () => {
  317. await row("arm-alpha").$('[data-testid="archive-unarchive"]').click();
  318. await row("arm-alpha").waitForExist({ reverse: true });
  319. expect(readRow("arm-alpha").archived).toBe(0);
  320. await row("arm-beta").$('[data-testid="archive-delete"]').click();
  321. await browser.keys("Escape");
  322. expect(readRow("arm-beta").cli_deleted).toBe(0);
  323. await row("arm-beta").$('[data-testid="archive-delete"]').click();
  324. await $('[data-testid="confirm-dialog-confirm"]').click();
  325. await row("arm-beta").waitForExist({ reverse: true });
  326. expect(readRow("arm-beta").cli_deleted).toBe(1);
  327. const cli = new DatabaseSync(join(home, ".zcode/cli/db/db.sqlite"), { readOnly: true });
  328. try {
  329. expect(
  330. (
  331. cli.prepare("SELECT time_deleted FROM session WHERE id=?").get("arm-beta") as {
  332. time_deleted: number;
  333. }
  334. ).time_deleted,
  335. ).toBeGreaterThan(0);
  336. } finally {
  337. cli.close();
  338. }
  339. await browser.refresh();
  340. await waitForWorkspaceApp(DEFAULT_WORKSPACE, 45000);
  341. // 刷新按既有行为回工作区,重新打开设置才能核对持久化后的列表。
  342. await $('[data-testid="task-settings-button"]').click();
  343. await $('[data-testid="settings-section-nav-archives"]').click();
  344. await $('[data-testid="archive-management"]').waitForDisplayed();
  345. expect(await $$('[data-testid="archive-task"]').length).toBe(0);
  346. expect(
  347. await $('[data-testid="archive-group"][data-project-id="arm-project-1"]').isExisting(),
  348. ).toBe(false);
  349. expect(await row("arm-beta").isExisting()).toBe(false);
  350. });
  351. it("ARM03:全部删除仅作用于当前筛选,分组更多取消归档", async () => {
  352. await $('[data-testid="archive-search"]').setValue("Unclassified");
  353. await $('[data-testid="archive-delete-all"]').click();
  354. expect(await $('[data-confirm-intent="archive-management-delete"]').getText()).toContain("1");
  355. await $('[data-testid="confirm-dialog-confirm"]').click();
  356. // 折叠组没有行 DOM,等整个分组消失并核对落库,避免把未渲染误当成已删除。
  357. await $('[data-testid="archive-group"][data-project-id=""]').waitForExist({ reverse: true });
  358. expect(readRow("arm-loose").cli_deleted).toBe(1);
  359. expect(readRow("arm-scheduled").cli_deleted).toBe(0);
  360. expect(readRow("arm-removed").cli_deleted).toBe(0);
  361. await clearSearch();
  362. const group = $('[data-testid="archive-group"][data-project-id="arm-project-0"]');
  363. expect(
  364. await group.$('[data-testid="archive-group-toggle"]').getAttribute("aria-expanded"),
  365. ).toBe("false");
  366. await group.$('[data-testid="archive-group-menu"]').click();
  367. await $('[data-testid="archive-group-unarchive"]').click();
  368. await group.waitForExist({ reverse: true });
  369. expect(readRow("arm-scheduled").archived).toBe(0);
  370. });
  371. });
  372. async function captureArchiveLayouts() {
  373. const original = await browser.execute(() =>
  374. (window as typeof window & { __testActions: { getTheme(): string } }).__testActions.getTheme(),
  375. );
  376. try {
  377. for (const width of [1200, 390]) {
  378. await browser.electron.execute(async (electron, width) => {
  379. const target = electron.BrowserWindow.getAllWindows().find(
  380. (w) => w.isVisible() && !w.isDestroyed(),
  381. )!;
  382. if (!target.webContents.debugger.isAttached()) target.webContents.debugger.attach("1.3");
  383. await target.webContents.debugger.sendCommand("Emulation.setDeviceMetricsOverride", {
  384. width,
  385. height: 844,
  386. deviceScaleFactor: 1,
  387. mobile: false,
  388. });
  389. }, width);
  390. for (const [locale, theme] of [
  391. ["zh-CN", "zai-light"],
  392. ["zh-CN", "zai-dark"],
  393. ["en-US", "zai-light"],
  394. ["en-US", "zai-dark"],
  395. ] as const) {
  396. await browser.execute(
  397. ({ locale, theme }) => {
  398. const actions = (
  399. window as typeof window & {
  400. __testActions: { setTheme(value: string): void; setLocale(value: string): void };
  401. }
  402. ).__testActions;
  403. actions.setTheme(theme);
  404. actions.setLocale(locale);
  405. },
  406. { locale, theme },
  407. );
  408. await browser.waitUntil(() =>
  409. browser.execute(
  410. (theme) => document.documentElement.classList.contains(`theme-${theme}`),
  411. theme,
  412. ),
  413. );
  414. await expect($('[data-testid="archive-sort"]')).toHaveText(
  415. locale === "zh-CN" ? "更新时间" : "Updated time",
  416. );
  417. await setArchiveGroupsOpen(false);
  418. expect(await $$('[data-testid="archive-task"]').length).toBe(0);
  419. await waitForArchiveAnimations();
  420. const dimensions = await browser.execute(() => {
  421. const page = document.querySelector<HTMLElement>('[data-testid="archive-management"]')!;
  422. const box = page.getBoundingClientRect();
  423. return {
  424. left: box.left,
  425. right: box.right,
  426. width: innerWidth,
  427. scrollWidth: page.scrollWidth,
  428. clientWidth: page.clientWidth,
  429. filters: ["archive-sort", "archive-project-filter"].map((id) => {
  430. const trigger = page.querySelector<HTMLButtonElement>(`[data-testid="${id}"]`)!;
  431. return {
  432. left: trigger.getBoundingClientRect().left,
  433. labelRight: trigger.labels?.[0]?.getBoundingClientRect().right ?? null,
  434. };
  435. }),
  436. };
  437. });
  438. expect(dimensions.right).toBeLessThanOrEqual(dimensions.width);
  439. expect(dimensions.left).toBeGreaterThanOrEqual(0);
  440. expect(dimensions.scrollWidth).toBeLessThanOrEqual(dimensions.clientWidth + 1);
  441. const heading = $(`h2=${locale === "zh-CN" ? "归档管理" : "Archive management"}`);
  442. await heading.scrollIntoView();
  443. await expect(heading).toBeDisplayed();
  444. await expect($('[data-testid="archive-management"] h2')).toHaveText(
  445. locale === "zh-CN" ? "已归档的会话" : "Archived sessions",
  446. );
  447. const autoArchive = $('[data-testid="archive-auto-archive-switch"]');
  448. await autoArchive.scrollIntoView();
  449. await expect(autoArchive).toHaveAttribute(
  450. "aria-label",
  451. locale === "zh-CN" ? "自动归档旧会话" : "Auto-archive old sessions",
  452. );
  453. const controlBounds = await browser.execute(() =>
  454. ["archive-auto-archive-switch", "archive-auto-archive-days"].map((id) => {
  455. const box = document.querySelector(`[data-testid="${id}"]`)!.getBoundingClientRect();
  456. return box.left >= 0 && box.right <= innerWidth;
  457. }),
  458. );
  459. expect(controlBounds).toEqual([true, true]);
  460. for (const filter of dimensions.filters) {
  461. if (filter.labelRight !== null) expect(filter.labelRight).toBeLessThan(filter.left);
  462. }
  463. await browser.saveScreenshot(
  464. join(
  465. process.env.ZCODE_E2E_ARTIFACT_DIR!,
  466. `archive-${width}-${locale}-${theme}-collapsed.png`,
  467. ),
  468. );
  469. await $('[data-testid="archive-group-toggle"]').click();
  470. await $('[data-testid="archive-task"]').waitForDisplayed();
  471. await waitForArchiveAnimations();
  472. expect(
  473. await browser.execute(() => {
  474. const page = document.querySelector<HTMLElement>('[data-testid="archive-management"]')!;
  475. return page.scrollWidth <= page.clientWidth + 1;
  476. }),
  477. ).toBe(true);
  478. await browser.saveScreenshot(
  479. join(
  480. process.env.ZCODE_E2E_ARTIFACT_DIR!,
  481. `archive-${width}-${locale}-${theme}-expanded.png`,
  482. ),
  483. );
  484. }
  485. }
  486. } finally {
  487. await browser.electron.execute(async (electron) => {
  488. const target = electron.BrowserWindow.getAllWindows().find(
  489. (w) => w.isVisible() && !w.isDestroyed(),
  490. )!;
  491. await target.webContents.debugger.sendCommand("Emulation.clearDeviceMetricsOverride");
  492. });
  493. await browser.execute((value) => {
  494. const actions = (
  495. window as typeof window & {
  496. __testActions: { setTheme(value: string): void; setLocale(value: string): void };
  497. }
  498. ).__testActions;
  499. actions.setTheme(value);
  500. actions.setLocale("zh-CN");
  501. }, original);
  502. }
  503. }