chatEmptyStateRemoteDialogInteraction.test.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // @vitest-environment jsdom
  2. import { createElement } from "react";
  3. import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
  4. import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
  5. vi.mock("@/hooks/useRemoteConnectionEntryVisibility.js", () => ({
  6. useRemoteConnectionEntryVisibility: () => true,
  7. }));
  8. vi.mock("@/i18n/IntlProvider.js", () => ({
  9. useZCodeIntl: () => ({
  10. intl: {
  11. formatMessage: ({ id }: { id: string }) => id,
  12. },
  13. }),
  14. }));
  15. vi.mock("@/logger.js", () => ({
  16. logger: {
  17. info: vi.fn(),
  18. warn: vi.fn(),
  19. error: vi.fn(),
  20. },
  21. }));
  22. vi.mock("@/SSHDialog.js", () => ({
  23. SSHDialog: ({ open }: { open?: boolean }) =>
  24. open
  25. ? createElement("div", {
  26. "aria-label": "remote-dialog",
  27. role: "dialog",
  28. })
  29. : null,
  30. }));
  31. beforeAll(() => {
  32. vi.stubGlobal("PointerEvent", MouseEvent);
  33. vi.stubGlobal(
  34. "ResizeObserver",
  35. class ResizeObserverMock {
  36. observe() {}
  37. unobserve() {}
  38. disconnect() {}
  39. },
  40. );
  41. Object.defineProperties(HTMLElement.prototype, {
  42. hasPointerCapture: {
  43. configurable: true,
  44. value: () => false,
  45. },
  46. releasePointerCapture: {
  47. configurable: true,
  48. value: () => {},
  49. },
  50. scrollIntoView: {
  51. configurable: true,
  52. value: () => {},
  53. },
  54. setPointerCapture: {
  55. configurable: true,
  56. value: () => {},
  57. },
  58. });
  59. });
  60. afterEach(() => {
  61. cleanup();
  62. });
  63. describe("ChatEmptyWorkspacePreviewMenu remote dialog interaction", () => {
  64. it("打开远程连接弹窗时关闭工作区菜单", async () => {
  65. const { ChatEmptyWorkspacePreviewMenu } = await import(
  66. "../src/ChatEmptyState.js"
  67. );
  68. render(
  69. createElement(ChatEmptyWorkspacePreviewMenu, {
  70. workspacePath: "/Users/tester/project",
  71. workspaceTabs: [
  72. {
  73. workspacePath: "/Users/tester/project",
  74. label: "project",
  75. },
  76. ],
  77. onSelectWorkspace: vi.fn(),
  78. onSelectConversationWorkspace: vi.fn(),
  79. onOpenFolder: vi.fn(),
  80. onConnectRemote: vi.fn(async () => "session-id"),
  81. onSelectRemoteProject: vi.fn(async () => {}),
  82. onCancelRemoteProject: vi.fn(async () => {}),
  83. }),
  84. );
  85. fireEvent.pointerDown(
  86. screen.getByRole("button", { name: "chat.empty.workspaceMenu" }),
  87. {
  88. button: 0,
  89. ctrlKey: false,
  90. },
  91. );
  92. const remoteEntry = await screen.findByText("remote.trigger");
  93. fireEvent.click(remoteEntry);
  94. expect(document.querySelector('[role="dialog"][aria-label="remote-dialog"]')).not.toBeNull();
  95. await waitFor(() => {
  96. expect(screen.queryByText("workspace.openFolder")).toBeNull();
  97. });
  98. });
  99. });