desktopAppWorkspaceReadiness.test.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // @vitest-environment jsdom
  2. import { afterEach, describe, expect, it } from "vitest";
  3. import {
  4. TID_COMPOSER_WORKSPACE_TRIGGER,
  5. TID_V4_SESSION_PANE,
  6. TID_WORKSPACE_ITEM,
  7. TID_WORKSPACE_PATH,
  8. testId,
  9. } from "@zcode/shared";
  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. });
  31. describe("desktop e2e workspace readiness probe", () => {
  32. it("reports the occupation onboarding page instead of waiting for a hidden workspace", () => {
  33. appendTestId("onboarding-page");
  34. expect(probe()).toBe("onboarding");
  35. });
  36. it("is ready when the workspace path badge matches", () => {
  37. appendTestId(TID_WORKSPACE_PATH, { title: PROJECT_PATH });
  38. expect(probe()).toBe("ready");
  39. });
  40. it("is ready when the sidebar workspace item and a v4 session pane both exist", () => {
  41. appendTestId(testId(TID_WORKSPACE_ITEM, PROJECT_PATH));
  42. appendTestId(`${TID_V4_SESSION_PANE}-pane-1`);
  43. expect(probe()).toBe("ready");
  44. });
  45. it("matches a Windows workspace item without CSS escaping the path", () => {
  46. const windowsPath = String.raw`C:\gitlab-runner\builds\project\packages\desktop\.e2e-home\ZCodeProject`;
  47. appendTestId(testId(TID_WORKSPACE_ITEM, windowsPath));
  48. appendTestId(`${TID_V4_SESSION_PANE}-pane-1`);
  49. expect(probe(windowsPath)).toBe("ready");
  50. });
  51. it("accepts the default conversation workspace through the composer trigger", () => {
  52. appendTestId(TID_COMPOSER_WORKSPACE_TRIGGER);
  53. appendTestId(`${TID_V4_SESSION_PANE}-pane-1`);
  54. expect(probe("/Users/dev/.zcode/workspace/default")).toBe("ready");
  55. });
  56. it("keeps waiting while neither the workspace nor onboarding is rendered", () => {
  57. appendTestId(testId(TID_WORKSPACE_ITEM, PROJECT_PATH));
  58. expect(probe()).toBe("pending");
  59. });
  60. });