-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathApp.autoConnect.test.tsx
More file actions
127 lines (107 loc) · 3.61 KB
/
App.autoConnect.test.tsx
File metadata and controls
127 lines (107 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { render, waitFor } from "@testing-library/react";
import App from "../App";
import { DEFAULT_INSPECTOR_CONFIG } from "../lib/constants";
import { InspectorConfig } from "../lib/configurationTypes";
import * as configUtils from "../utils/configUtils";
// Mock auth dependencies first
jest.mock("@modelcontextprotocol/sdk/client/auth.js", () => ({
auth: jest.fn(),
}));
jest.mock("../lib/oauth-state-machine", () => ({
OAuthStateMachine: jest.fn(),
}));
jest.mock("../lib/auth", () => ({
InspectorOAuthClientProvider: jest.fn().mockImplementation(() => ({
tokens: jest.fn().mockResolvedValue(null),
clear: jest.fn(),
})),
DebugInspectorOAuthClientProvider: jest.fn(),
}));
// Mock the config utils — keep the real implementations but allow overriding
jest.mock("../utils/configUtils", () => ({
...jest.requireActual("../utils/configUtils"),
getMCPProxyAddress: jest.fn(() => "http://localhost:6277"),
getMCPProxyAuthToken: jest.fn((config: InspectorConfig) => ({
token: config.MCP_PROXY_AUTH_TOKEN.value,
header: "X-MCP-Proxy-Auth",
})),
getInitialTransportType: jest.fn(() => "stdio"),
getInitialSseUrl: jest.fn(() => "http://localhost:3001/sse"),
getInitialCommand: jest.fn(() => "mcp-server-everything"),
getInitialArgs: jest.fn(() => ""),
initializeInspectorConfig: jest.fn(() => DEFAULT_INSPECTOR_CONFIG),
saveInspectorConfig: jest.fn(),
getAutoConnect: jest.fn(() => false),
stripAutoConnectParam: jest.fn(),
}));
const mockGetAutoConnect = configUtils.getAutoConnect as jest.Mock;
const mockStripAutoConnectParam =
configUtils.stripAutoConnectParam as jest.Mock;
// Mock useConnection to capture the connect function
const mockConnect = jest.fn();
jest.mock("../lib/hooks/useConnection", () => ({
useConnection: () => ({
connectionStatus: "disconnected",
serverCapabilities: null,
mcpClient: null,
requestHistory: [],
clearRequestHistory: jest.fn(),
makeRequest: jest.fn(),
sendNotification: jest.fn(),
handleCompletion: jest.fn(),
completionsSupported: false,
connect: mockConnect,
disconnect: jest.fn(),
}),
}));
jest.mock("../lib/hooks/useDraggablePane", () => ({
useDraggablePane: () => ({
height: 300,
handleDragStart: jest.fn(),
}),
useDraggableSidebar: () => ({
width: 320,
isDragging: false,
handleDragStart: jest.fn(),
}),
}));
jest.mock("../components/Sidebar", () => ({
__esModule: true,
default: () => <div>Sidebar</div>,
}));
// Mock fetch
global.fetch = jest.fn().mockResolvedValue({
json: () => Promise.resolve({}),
});
describe("App - autoConnect query param", () => {
beforeEach(() => {
jest.clearAllMocks();
(global.fetch as jest.Mock).mockResolvedValue({
json: () => Promise.resolve({}),
});
});
test("calls connectMcpServer on mount when autoConnect=true", async () => {
mockGetAutoConnect.mockReturnValue(true);
render(<App />);
await waitFor(() => {
expect(mockConnect).toHaveBeenCalledTimes(1);
});
});
test("strips autoConnect param from URL after consuming it", async () => {
mockGetAutoConnect.mockReturnValue(true);
render(<App />);
await waitFor(() => {
expect(mockStripAutoConnectParam).toHaveBeenCalledTimes(1);
});
});
test("does not call connectMcpServer when autoConnect is not set", async () => {
mockGetAutoConnect.mockReturnValue(false);
render(<App />);
// Wait for initial render effects to settle
await waitFor(() => {
expect(mockGetAutoConnect).toHaveBeenCalled();
});
expect(mockConnect).not.toHaveBeenCalled();
expect(mockStripAutoConnectParam).not.toHaveBeenCalled();
});
});