fixing test cases after main merged
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { render, screen, fireEvent } from "@testing-library/react";
|
import { render, screen, fireEvent, act } from "@testing-library/react";
|
||||||
import "@testing-library/jest-dom";
|
import "@testing-library/jest-dom";
|
||||||
import { describe, it, beforeEach, jest } from "@jest/globals";
|
import { describe, it, beforeEach, jest } from "@jest/globals";
|
||||||
import Sidebar from "../Sidebar";
|
import Sidebar from "../Sidebar";
|
||||||
@@ -14,7 +14,7 @@ jest.mock("../../lib/hooks/useTheme", () => ({
|
|||||||
|
|
||||||
// Mock toast hook
|
// Mock toast hook
|
||||||
const mockToast = jest.fn();
|
const mockToast = jest.fn();
|
||||||
jest.mock("@/hooks/use-toast", () => ({
|
jest.mock("@/lib/hooks/useToast", () => ({
|
||||||
useToast: () => ({
|
useToast: () => ({
|
||||||
toast: mockToast,
|
toast: mockToast,
|
||||||
}),
|
}),
|
||||||
@@ -28,6 +28,9 @@ Object.defineProperty(navigator, "clipboard", {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Setup fake timers
|
||||||
|
jest.useFakeTimers();
|
||||||
|
|
||||||
describe("Sidebar Environment Variables", () => {
|
describe("Sidebar Environment Variables", () => {
|
||||||
const defaultProps = {
|
const defaultProps = {
|
||||||
connectionStatus: "disconnected" as const,
|
connectionStatus: "disconnected" as const,
|
||||||
@@ -69,6 +72,7 @@ describe("Sidebar Environment Variables", () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
|
jest.clearAllTimers();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Basic Operations", () => {
|
describe("Basic Operations", () => {
|
||||||
@@ -642,9 +646,10 @@ describe("Sidebar Environment Variables", () => {
|
|||||||
describe("Copy Configuration Features", () => {
|
describe("Copy Configuration Features", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
|
jest.clearAllTimers();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should copy server entry configuration to clipboard for STDIO transport", () => {
|
it("should copy server entry configuration to clipboard for STDIO transport", async () => {
|
||||||
const command = "node";
|
const command = "node";
|
||||||
const args = "--inspect server.js";
|
const args = "--inspect server.js";
|
||||||
const env = { API_KEY: "test-key", DEBUG: "true" };
|
const env = { API_KEY: "test-key", DEBUG: "true" };
|
||||||
@@ -656,11 +661,17 @@ describe("Sidebar Environment Variables", () => {
|
|||||||
env,
|
env,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Use act to properly wrap the clipboard operations
|
||||||
|
await act(async () => {
|
||||||
const copyServerEntryButton = screen.getByRole("button", {
|
const copyServerEntryButton = screen.getByRole("button", {
|
||||||
name: /server entry/i,
|
name: /server entry/i,
|
||||||
});
|
});
|
||||||
fireEvent.click(copyServerEntryButton);
|
fireEvent.click(copyServerEntryButton);
|
||||||
|
|
||||||
|
// Fast-forward timers to handle the setTimeout
|
||||||
|
jest.runAllTimers();
|
||||||
|
});
|
||||||
|
|
||||||
// Check clipboard API was called with the correct configuration
|
// Check clipboard API was called with the correct configuration
|
||||||
expect(mockClipboardWrite).toHaveBeenCalledTimes(1);
|
expect(mockClipboardWrite).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
@@ -677,7 +688,7 @@ describe("Sidebar Environment Variables", () => {
|
|||||||
expect(mockClipboardWrite).toHaveBeenCalledWith(expectedConfig);
|
expect(mockClipboardWrite).toHaveBeenCalledWith(expectedConfig);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should copy servers file configuration to clipboard for STDIO transport", () => {
|
it("should copy servers file configuration to clipboard for STDIO transport", async () => {
|
||||||
const command = "node";
|
const command = "node";
|
||||||
const args = "--inspect server.js";
|
const args = "--inspect server.js";
|
||||||
const env = { API_KEY: "test-key", DEBUG: "true" };
|
const env = { API_KEY: "test-key", DEBUG: "true" };
|
||||||
@@ -689,11 +700,16 @@ describe("Sidebar Environment Variables", () => {
|
|||||||
env,
|
env,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
const copyServersFileButton = screen.getByRole("button", {
|
const copyServersFileButton = screen.getByRole("button", {
|
||||||
name: /servers file/i,
|
name: /servers file/i,
|
||||||
});
|
});
|
||||||
fireEvent.click(copyServersFileButton);
|
fireEvent.click(copyServersFileButton);
|
||||||
|
|
||||||
|
// Fast-forward timers to handle the setTimeout
|
||||||
|
jest.runAllTimers();
|
||||||
|
});
|
||||||
|
|
||||||
// Check clipboard API was called with the correct configuration
|
// Check clipboard API was called with the correct configuration
|
||||||
expect(mockClipboardWrite).toHaveBeenCalledTimes(1);
|
expect(mockClipboardWrite).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
@@ -714,7 +730,7 @@ describe("Sidebar Environment Variables", () => {
|
|||||||
expect(mockClipboardWrite).toHaveBeenCalledWith(expectedConfig);
|
expect(mockClipboardWrite).toHaveBeenCalledWith(expectedConfig);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should copy servers file configuration to clipboard for SSE transport", () => {
|
it("should copy servers file configuration to clipboard for SSE transport", async () => {
|
||||||
const sseUrl = "http://localhost:3000/events";
|
const sseUrl = "http://localhost:3000/events";
|
||||||
|
|
||||||
renderSidebar({
|
renderSidebar({
|
||||||
@@ -722,11 +738,16 @@ describe("Sidebar Environment Variables", () => {
|
|||||||
sseUrl,
|
sseUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
const copyServersFileButton = screen.getByRole("button", {
|
const copyServersFileButton = screen.getByRole("button", {
|
||||||
name: /servers file/i,
|
name: /servers file/i,
|
||||||
});
|
});
|
||||||
fireEvent.click(copyServersFileButton);
|
fireEvent.click(copyServersFileButton);
|
||||||
|
|
||||||
|
// Fast-forward timers to handle the setTimeout
|
||||||
|
jest.runAllTimers();
|
||||||
|
});
|
||||||
|
|
||||||
// Check clipboard API was called with the correct configuration
|
// Check clipboard API was called with the correct configuration
|
||||||
expect(mockClipboardWrite).toHaveBeenCalledTimes(1);
|
expect(mockClipboardWrite).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
@@ -747,7 +768,7 @@ describe("Sidebar Environment Variables", () => {
|
|||||||
expect(mockClipboardWrite).toHaveBeenCalledWith(expectedConfig);
|
expect(mockClipboardWrite).toHaveBeenCalledWith(expectedConfig);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should handle empty args in STDIO transport", () => {
|
it("should handle empty args in STDIO transport", async () => {
|
||||||
const command = "python";
|
const command = "python";
|
||||||
const args = "";
|
const args = "";
|
||||||
|
|
||||||
@@ -757,11 +778,16 @@ describe("Sidebar Environment Variables", () => {
|
|||||||
args,
|
args,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
const copyServerEntryButton = screen.getByRole("button", {
|
const copyServerEntryButton = screen.getByRole("button", {
|
||||||
name: /server entry/i,
|
name: /server entry/i,
|
||||||
});
|
});
|
||||||
fireEvent.click(copyServerEntryButton);
|
fireEvent.click(copyServerEntryButton);
|
||||||
|
|
||||||
|
// Fast-forward timers to handle the setTimeout
|
||||||
|
jest.runAllTimers();
|
||||||
|
});
|
||||||
|
|
||||||
// Check clipboard API was called with empty args array
|
// Check clipboard API was called with empty args array
|
||||||
expect(mockClipboardWrite).toHaveBeenCalledTimes(1);
|
expect(mockClipboardWrite).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user