changes:
- change button names - adding unit test cases - updated landing page image - updating README file as discussed here: https://github.com/modelcontextprotocol/inspector/pull/334#issuecomment-2852394054
This commit is contained in:
@@ -12,6 +12,22 @@ jest.mock("../../lib/useTheme", () => ({
|
||||
default: () => ["light", jest.fn()],
|
||||
}));
|
||||
|
||||
// Mock toast hook
|
||||
const mockToast = jest.fn();
|
||||
jest.mock("@/hooks/use-toast", () => ({
|
||||
useToast: () => ({
|
||||
toast: mockToast,
|
||||
}),
|
||||
}));
|
||||
|
||||
// Mock navigator clipboard
|
||||
const mockClipboardWrite = jest.fn(() => Promise.resolve());
|
||||
Object.defineProperty(navigator, "clipboard", {
|
||||
value: {
|
||||
writeText: mockClipboardWrite,
|
||||
},
|
||||
});
|
||||
|
||||
describe("Sidebar Environment Variables", () => {
|
||||
const defaultProps = {
|
||||
connectionStatus: "disconnected" as const,
|
||||
@@ -622,4 +638,144 @@ describe("Sidebar Environment Variables", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Copy Configuration Features", () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it("should copy server entry configuration to clipboard for STDIO transport", () => {
|
||||
const command = "node";
|
||||
const args = "--inspect server.js";
|
||||
const env = { API_KEY: "test-key", DEBUG: "true" };
|
||||
|
||||
renderSidebar({
|
||||
transportType: "stdio",
|
||||
command,
|
||||
args,
|
||||
env,
|
||||
});
|
||||
|
||||
const copyServerEntryButton = screen.getByRole("button", {
|
||||
name: /server entry/i,
|
||||
});
|
||||
fireEvent.click(copyServerEntryButton);
|
||||
|
||||
// Check clipboard API was called with the correct configuration
|
||||
expect(mockClipboardWrite).toHaveBeenCalledTimes(1);
|
||||
|
||||
const expectedConfig = JSON.stringify(
|
||||
{
|
||||
command,
|
||||
args: ["--inspect", "server.js"],
|
||||
env,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
);
|
||||
|
||||
expect(mockClipboardWrite).toHaveBeenCalledWith(expectedConfig);
|
||||
});
|
||||
|
||||
it("should copy servers file configuration to clipboard for STDIO transport", () => {
|
||||
const command = "node";
|
||||
const args = "--inspect server.js";
|
||||
const env = { API_KEY: "test-key", DEBUG: "true" };
|
||||
|
||||
renderSidebar({
|
||||
transportType: "stdio",
|
||||
command,
|
||||
args,
|
||||
env,
|
||||
});
|
||||
|
||||
const copyServersFileButton = screen.getByRole("button", {
|
||||
name: /servers file/i,
|
||||
});
|
||||
fireEvent.click(copyServersFileButton);
|
||||
|
||||
// Check clipboard API was called with the correct configuration
|
||||
expect(mockClipboardWrite).toHaveBeenCalledTimes(1);
|
||||
|
||||
const expectedConfig = JSON.stringify(
|
||||
{
|
||||
mcpServers: {
|
||||
"default-server": {
|
||||
command,
|
||||
args: ["--inspect", "server.js"],
|
||||
env,
|
||||
},
|
||||
},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
);
|
||||
|
||||
expect(mockClipboardWrite).toHaveBeenCalledWith(expectedConfig);
|
||||
});
|
||||
|
||||
it("should copy servers file configuration to clipboard for SSE transport", () => {
|
||||
const sseUrl = "http://localhost:3000/events";
|
||||
|
||||
renderSidebar({
|
||||
transportType: "sse",
|
||||
sseUrl,
|
||||
});
|
||||
|
||||
const copyServersFileButton = screen.getByRole("button", {
|
||||
name: /servers file/i,
|
||||
});
|
||||
fireEvent.click(copyServersFileButton);
|
||||
|
||||
// Check clipboard API was called with the correct configuration
|
||||
expect(mockClipboardWrite).toHaveBeenCalledTimes(1);
|
||||
|
||||
const expectedConfig = JSON.stringify(
|
||||
{
|
||||
mcpServers: {
|
||||
"default-server": {
|
||||
type: "sse",
|
||||
url: sseUrl,
|
||||
note: "For SSE connections, add this URL directly in Client",
|
||||
},
|
||||
},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
);
|
||||
|
||||
expect(mockClipboardWrite).toHaveBeenCalledWith(expectedConfig);
|
||||
});
|
||||
|
||||
it("should handle empty args in STDIO transport", () => {
|
||||
const command = "python";
|
||||
const args = "";
|
||||
|
||||
renderSidebar({
|
||||
transportType: "stdio",
|
||||
command,
|
||||
args,
|
||||
});
|
||||
|
||||
const copyServerEntryButton = screen.getByRole("button", {
|
||||
name: /server entry/i,
|
||||
});
|
||||
fireEvent.click(copyServerEntryButton);
|
||||
|
||||
// Check clipboard API was called with empty args array
|
||||
expect(mockClipboardWrite).toHaveBeenCalledTimes(1);
|
||||
|
||||
const expectedConfig = JSON.stringify(
|
||||
{
|
||||
command,
|
||||
args: [],
|
||||
env: {},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
);
|
||||
|
||||
expect(mockClipboardWrite).toHaveBeenCalledWith(expectedConfig);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user