feishu-bound-groups-ui.test.ts 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { skipOccupationOnboardingIfPresent } from "#e2e/helpers/occupation-onboarding";
  2. import { mkdir, readFile, writeFile } from "node:fs/promises";
  3. import { join } from "node:path";
  4. import type { BotsStateFile } from "@zcode/shared";
  5. import {
  6. getE2EAppDataPaths,
  7. seedSettings,
  8. waitForDefaultWorkspaceReady,
  9. } from "#e2e/helpers/desktop-app";
  10. import { prepareV4ConversationE2E } from "#e2e/helpers/v4-conversation";
  11. import { createFeishuConfig } from "#e2e/bots/helpers/bots-service-harness";
  12. /** BOT-E2E-GR-UI-01:真实 Desktop → RPC → Bot repo;无平台凭据,不向真实群发消息。 */
  13. describe("bound groups Desktop controls", () => {
  14. it("counts topics, persists a group switch and isolates other groups and bots", async () => {
  15. await skipOccupationOnboardingIfPresent();
  16. await prepareV4ConversationE2E({ skipProvider: true });
  17. const { appDataDir } = getE2EAppDataPaths();
  18. const config = createFeishuConfig("feishu", "groups-ui");
  19. // 保留绑定形状但不写任何密钥,避免页面自动启动飞书扫码注册。
  20. config.bots[0]!.credentialRef = "bot:groups-ui:isolated-missing";
  21. config.bots[0]!.name = "E2E Bound Groups";
  22. const state: BotsStateFile = { version: 3, bots: {} };
  23. const add = (botId: string, chatId: string, threadId?: string) => {
  24. state.bots[JSON.stringify([botId, chatId, ...(threadId ? [threadId] : [])])] = {
  25. botId,
  26. workspacePath: appDataDir,
  27. mode: "draft",
  28. activeTaskId: null,
  29. updatedAt: Date.now(),
  30. group: {
  31. chatId,
  32. threadId,
  33. name: `E2E ${chatId}`,
  34. ownerId: "ou_e2e_user",
  35. enabled: true,
  36. authorizationId: `auth-${chatId}`,
  37. taskIds: [],
  38. currentOptions: {},
  39. },
  40. };
  41. };
  42. add("groups-ui", "group-a");
  43. add("groups-ui", "group-a", "topic-1");
  44. add("groups-ui", "group-a", "topic-2");
  45. add("groups-ui", "group-b");
  46. add("other-bot", "group-c");
  47. await mkdir(appDataDir, { recursive: true });
  48. const stateFile = join(appDataDir, "bot-state.v3.json");
  49. await writeFile(join(appDataDir, "bot-config.v3.json"), JSON.stringify(config));
  50. await writeFile(stateFile, JSON.stringify(state));
  51. await seedSettings({ locale: "zh-CN", localePreference: "zh-CN" });
  52. await browser.refresh();
  53. await waitForDefaultWorkspaceReady(60000);
  54. const remote = await $('button[aria-label="移动端远程控制"]');
  55. await remote.waitForClickable({ timeout: 20000 });
  56. await remote.click();
  57. await $('[data-testid="web-remote-control-open-bots"]').click();
  58. const row = await $('[data-testid="bot-bound-groups"] [data-group-id="group-a"]');
  59. await row.waitForDisplayed({ timeout: 20000 });
  60. expect(await row.getText()).toMatch(/2/);
  61. expect(await $$('[data-testid="bot-bound-groups"] [data-group-id]')).toHaveLength(2);
  62. const toggle = await row.$('[role="switch"]');
  63. expect(await toggle.getAttribute("aria-checked")).toBe("true");
  64. await toggle.click();
  65. await browser.waitUntil(async () => (await toggle.getAttribute("aria-checked")) === "false", {
  66. timeout: 15000,
  67. });
  68. const persisted = JSON.parse(await readFile(stateFile, "utf8")) as BotsStateFile;
  69. expect(persisted.bots[JSON.stringify(["groups-ui", "group-a"])]!.group!.enabled).toBe(false);
  70. expect(persisted.bots[JSON.stringify(["groups-ui", "group-b"])]).toEqual(
  71. state.bots[JSON.stringify(["groups-ui", "group-b"])],
  72. );
  73. expect(persisted.bots[JSON.stringify(["other-bot", "group-c"])]).toEqual(
  74. state.bots[JSON.stringify(["other-bot", "group-c"])],
  75. );
  76. // 保留话题记录;关闭授权不能把历史数量清空。
  77. expect(await row.getText()).toMatch(/2/);
  78. await row.scrollIntoView({ block: "center" });
  79. const artifactDir = process.env.ZCODE_E2E_ARTIFACT_DIR;
  80. if (artifactDir) await browser.saveScreenshot(join(artifactDir, "BOT-E2E-GR-UI-01.png"));
  81. });
  82. });