desktopAppWorkspaceReadiness.test.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // @vitest-environment jsdom
  2. import { afterEach, describe, expect, it, vi } from "vitest";
  3. import { TID_WORKSPACE_ITEM } from "@zcode/shared";
  4. import {
  5. TID_COMPOSER_WORKSPACE_TRIGGER,
  6. TID_V4_SESSION_PANE,
  7. TID_WORKSPACE_PATH,
  8. testId,
  9. } from "@zcode/shared/test-ids";
  10. import { probeWorkspaceAppState } from "./e2e/helpers/desktop-app.js";
  11. const PROJECT_PATH = "/Users/dev/Code/z-code/.e2e-home/ZCodeProject";
  12. function probe(expectedPath = PROJECT_PATH) {
  13. return probeWorkspaceAppState({
  14. workspacePathTestId: TID_WORKSPACE_PATH,
  15. workspaceItemTestId: testId(TID_WORKSPACE_ITEM, expectedPath),
  16. sessionPanePrefix: TID_V4_SESSION_PANE,
  17. composerWorkspaceTriggerTestId: TID_COMPOSER_WORKSPACE_TRIGGER,
  18. expectedPath,
  19. });
  20. }
  21. function appendTestId(testIdValue: string, attributes: Record<string, string> = {}) {
  22. const element = document.createElement("div");
  23. element.dataset.testid = testIdValue;
  24. for (const [name, value] of Object.entries(attributes)) element.setAttribute(name, value);
  25. document.body.append(element);
  26. return element;
  27. }
  28. afterEach(() => {
  29. document.body.replaceChildren();
  30. vi.unstubAllGlobals();
  31. });
  32. describe("desktop e2e workspace readiness probe", () => {
  33. it("reports the occupation onboarding page instead of waiting for a hidden workspace", () => {
  34. appendTestId("onboarding-page");
  35. expect(probe()).toBe("onboarding");
  36. });
  37. it("is ready when the workspace path badge matches", () => {
  38. appendTestId(TID_WORKSPACE_PATH, { "data-workspace-abs-path": PROJECT_PATH });
  39. expect(probe()).toBe("ready");
  40. });
  41. it("does not treat a native title as the workspace path anchor", () => {
  42. // 路径徽标的上下文信息改由 tooltip 承载,DOM 不再有 title;只认数据属性锚点。
  43. appendTestId(TID_WORKSPACE_PATH, { title: PROJECT_PATH });
  44. expect(probe()).toBe("pending");
  45. });
  46. it("is ready when the active workspace and a v4 session pane both exist", () => {
  47. appendTestId(testId(TID_WORKSPACE_ITEM, PROJECT_PATH));
  48. appendTestId(`${TID_V4_SESSION_PANE}-pane-1`);
  49. vi.stubGlobal("__zcodeTabStoreE2E", {
  50. getState: () => ({ activeWorkspacePath: PROJECT_PATH }),
  51. });
  52. expect(probe()).toBe("ready");
  53. });
  54. it("matches a Windows active workspace path", () => {
  55. const windowsPath = String.raw`C:\gitlab-runner\builds\project\packages\desktop\.e2e-home\ZCodeProject`;
  56. appendTestId(testId(TID_WORKSPACE_ITEM, windowsPath));
  57. appendTestId(`${TID_V4_SESSION_PANE}-pane-1`);
  58. vi.stubGlobal("__zcodeTabStoreE2E", { getState: () => ({ activeWorkspacePath: windowsPath }) });
  59. expect(probe(windowsPath)).toBe("ready");
  60. });
  61. it("accepts the default conversation workspace through the composer trigger", () => {
  62. appendTestId(TID_COMPOSER_WORKSPACE_TRIGGER);
  63. appendTestId(`${TID_V4_SESSION_PANE}-pane-1`);
  64. expect(probe("/Users/dev/.zcode/workspace/default")).toBe("ready");
  65. });
  66. it("keeps waiting while neither the workspace nor onboarding is rendered", () => {
  67. appendTestId(testId(TID_WORKSPACE_ITEM, PROJECT_PATH));
  68. expect(probe()).toBe("pending");
  69. });
  70. });