rootWorkspaceContentVisibility.test.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { createElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { beforeEach, describe, expect, it, vi } from "vitest";
  4. import type { AppProps } from "@/app-shell/types.js";
  5. const appRenderProps = vi.hoisted(() => [] as AppProps[]);
  6. vi.mock("@/App.js", () => ({
  7. App: (props: AppProps) => {
  8. appRenderProps.push(props);
  9. return createElement("div", { "data-testid": "workspace-app" });
  10. },
  11. }));
  12. vi.mock("@/hooks/useServices.js", () => ({
  13. ServiceProvider: ({ children }: { children: unknown }) => children,
  14. }));
  15. vi.mock("@/i18n/IntlProvider.js", () => ({
  16. useZCodeIntl: () => ({
  17. intl: {
  18. formatMessage: ({ id }: { id: string }) => id,
  19. },
  20. }),
  21. }));
  22. vi.mock("@/root/WorkspaceSettingsLayer.js", () => ({
  23. WorkspaceSettingsLayer: () => createElement("div", { "data-testid": "settings-layer" }),
  24. }));
  25. function renderRootWorkspaceContent(
  26. isSettingsTabActive: boolean,
  27. params?: {
  28. workspaceIdentity?: string;
  29. workspaceRemoteSessionId?: string;
  30. },
  31. ) {
  32. return import("@/root/RootWorkspaceContent.js").then(({ RootWorkspaceContent }) =>
  33. renderToStaticMarkup(
  34. createElement(RootWorkspaceContent, {
  35. workspaceScopedServices: {},
  36. workspaceShellPath: "/workspace/z-code",
  37. workspaceIdentity: params?.workspaceIdentity,
  38. workspaceRemoteSessionId: params?.workspaceRemoteSessionId,
  39. activeWorkspacePath: "/workspace/z-code",
  40. isSettingsTabActive,
  41. handleConnectRemote: vi.fn(),
  42. handleSelectRemoteProject: vi.fn(),
  43. handleCancelRemoteProject: vi.fn(),
  44. handleReconnectRemoteWorkspace: vi.fn(),
  45. handleCreateTask: vi.fn(),
  46. handleOpenWorkspace: vi.fn(),
  47. remoteWorkspaceSessions: [],
  48. handleBackFromSettings: vi.fn(),
  49. user: null,
  50. reconnectingRemoteWorkspaceKeys: [],
  51. remoteWorkspaceErrorByWorkspaceKey: {},
  52. reconnectingRemoteWorkspaceLogsByWorkspaceKey: {},
  53. allowOpenWorkspace: true,
  54. }),
  55. ),
  56. );
  57. }
  58. describe("RootWorkspaceContent", () => {
  59. beforeEach(() => {
  60. appRenderProps.length = 0;
  61. });
  62. it("keeps workspace layout mounted when settings is active so quickpick can stay visible", async () => {
  63. const html = await renderRootWorkspaceContent(true);
  64. expect(html).toContain('aria-hidden="true"');
  65. expect(html).toContain("opacity-0");
  66. expect(html).toContain("pointer-events-none");
  67. expect(html).toContain('data-root-workspace-surface="inert"');
  68. expect(html).toContain('inert=""');
  69. expect(html).not.toContain(" hidden ");
  70. expect(html).toContain('data-testid="workspace-app"');
  71. expect(html).toContain('data-testid="settings-layer"');
  72. });
  73. it("restores workspace interaction after settings closes", async () => {
  74. const html = await renderRootWorkspaceContent(false);
  75. expect(html).toContain('data-root-workspace-surface="interactive"');
  76. expect(html).not.toContain('aria-hidden="true"');
  77. expect(html).not.toContain('inert=""');
  78. });
  79. it("keeps rendering App for a disconnected remote workspace", async () => {
  80. const workspaceIdentity = "remote:docker:zcode-ssh-linux-amd64:/root";
  81. const html = await renderRootWorkspaceContent(false, {
  82. workspaceIdentity,
  83. });
  84. expect(html).toContain('data-testid="workspace-app"');
  85. expect(html).not.toContain("workspace.disconnectedRemote.title");
  86. expect(appRenderProps[0]?.workspaceIdentity).toBe(workspaceIdentity);
  87. });
  88. });