Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ui/litellm-dashboard/eslint-metrics.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"@typescript-eslint/no-explicit-any": 2016,
"complexity": 127,
"@typescript-eslint/no-explicit-any": 2014,
"complexity": 126,
"max-depth": 61
}
5 changes: 0 additions & 5 deletions ui/litellm-dashboard/eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -873,11 +873,6 @@
"count": 1
}
},
"src/components/claude_code_plugins/helpers.test.ts": {
"unused-imports/no-unused-imports": {
"count": 1
}
},
"src/components/claude_code_plugins/plugin_table.tsx": {
"no-restricted-imports": {
"count": 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,48 @@ import { act, fireEvent, screen, waitFor } from "@testing-library/react";
import { describe, it, expect, vi, beforeEach } from "vitest";
import { renderWithProviders } from "../../../tests/test-utils";
import AddPluginForm from "./add_plugin_form";
import { registerClaudeCodePlugin } from "../networking";
import MessageManager from "@/components/molecules/message_manager";

vi.mock("../networking", () => ({
registerClaudeCodePlugin: vi.fn().mockResolvedValue({ status: "success" }),
}));

vi.mock("@/components/molecules/message_manager", () => ({
default: { error: vi.fn(), success: vi.fn() },
}));

const mockRegister = vi.mocked(registerClaudeCodePlugin);
const mockMessageError = vi.mocked(MessageManager.error);

const DEFAULT_PROPS = {
visible: true,
onClose: vi.fn(),
accessToken: "sk-test",
onSuccess: vi.fn(),
};

const URL_PLACEHOLDER = "https://github.com/org/repo or https://gitlab.com/org/repo";
const SUBPATH_PLACEHOLDER = "plugins/my-skill";

describe("AddPluginForm", () => {
beforeEach(() => {
vi.clearAllMocks();
});

it("renders with GitHub URL input", () => {
it("renders the host-agnostic repository URL input and subfolder field", () => {
renderWithProviders(<AddPluginForm {...DEFAULT_PROPS} />);

expect(screen.getByText("GitHub URL")).toBeInTheDocument();
expect(screen.getByPlaceholderText("https://github.com/org/repo/tree/main/my-skill")).toBeInTheDocument();
expect(screen.getByText("Repository URL")).toBeInTheDocument();
expect(screen.getByPlaceholderText(URL_PLACEHOLDER)).toBeInTheDocument();
expect(screen.getByText("Subfolder path (Optional)")).toBeInTheDocument();
expect(screen.getByPlaceholderText(SUBPATH_PLACEHOLDER)).toBeInTheDocument();
});

it("shows GitHub repo preview for a plain repo URL", async () => {
renderWithProviders(<AddPluginForm {...DEFAULT_PROPS} />);

const urlInput = screen.getByPlaceholderText("https://github.com/org/repo/tree/main/my-skill");
const urlInput = screen.getByPlaceholderText(URL_PLACEHOLDER);

await act(async () => {
fireEvent.change(urlInput, {
Expand All @@ -43,10 +57,10 @@ describe("AddPluginForm", () => {
});
});

it("shows git-subdir preview for a tree URL", async () => {
it("shows git-subdir preview for a tree URL and disables the subfolder field", async () => {
renderWithProviders(<AddPluginForm {...DEFAULT_PROPS} />);

const urlInput = screen.getByPlaceholderText("https://github.com/org/repo/tree/main/my-skill");
const urlInput = screen.getByPlaceholderText(URL_PLACEHOLDER);

await act(async () => {
fireEvent.change(urlInput, {
Expand All @@ -59,12 +73,51 @@ describe("AddPluginForm", () => {
await waitFor(() => {
expect(screen.getByText(/GitHub subdir/)).toBeInTheDocument();
});
expect(screen.getByPlaceholderText(SUBPATH_PLACEHOLDER)).toBeDisabled();
});

it("shows a raw url preview for a non-github host", async () => {
renderWithProviders(<AddPluginForm {...DEFAULT_PROPS} />);

const urlInput = screen.getByPlaceholderText(URL_PLACEHOLDER);

await act(async () => {
fireEvent.change(urlInput, {
target: { value: "https://gitlab.com/group/repo" },
});
});

await waitFor(() => {
expect(screen.getByText(/Git repo/)).toBeInTheDocument();
});
expect(screen.getByPlaceholderText(SUBPATH_PLACEHOLDER)).not.toBeDisabled();
});

it("combines a repo URL with a subfolder into a git-subdir preview", async () => {
renderWithProviders(<AddPluginForm {...DEFAULT_PROPS} />);

const urlInput = screen.getByPlaceholderText(URL_PLACEHOLDER);
await act(async () => {
fireEvent.change(urlInput, {
target: { value: "https://gitlab.com/group/repo" },
});
});

const subPathInput = screen.getByPlaceholderText(SUBPATH_PLACEHOLDER);
await act(async () => {
fireEvent.change(subPathInput, { target: { value: "plugins/x" } });
});

await waitFor(() => {
expect(screen.getByText(/Git subdir/)).toBeInTheDocument();
expect(screen.getByText(/plugins\/x/)).toBeInTheDocument();
});
});

it("auto-fills skill name from repo URL", async () => {
renderWithProviders(<AddPluginForm {...DEFAULT_PROPS} />);

const urlInput = screen.getByPlaceholderText("https://github.com/org/repo/tree/main/my-skill");
const urlInput = screen.getByPlaceholderText(URL_PLACEHOLDER);

await act(async () => {
fireEvent.change(urlInput, {
Expand All @@ -84,7 +137,7 @@ describe("AddPluginForm", () => {
const nameInput = screen.getByPlaceholderText("my-skill") as HTMLInputElement;
fireEvent.change(nameInput, { target: { value: "existing-name" } });

const urlInput = screen.getByPlaceholderText("https://github.com/org/repo/tree/main/my-skill");
const urlInput = screen.getByPlaceholderText(URL_PLACEHOLDER);

await act(async () => {
fireEvent.change(urlInput, {
Expand All @@ -96,4 +149,125 @@ describe("AddPluginForm", () => {
expect(nameInput.value).toBe("existing-name");
});
});

const typeUrl = async (value: string) => {
await act(async () => {
fireEvent.change(screen.getByPlaceholderText(URL_PLACEHOLDER), { target: { value } });
});
};

const typeSubPath = async (value: string) => {
await act(async () => {
fireEvent.change(screen.getByPlaceholderText(SUBPATH_PLACEHOLDER), { target: { value } });
});
};

const submit = async () => {
await act(async () => {
fireEvent.click(screen.getByRole("button", { name: "Add Skill" }));
});
};

it("submits a github repo source", async () => {
renderWithProviders(<AddPluginForm {...DEFAULT_PROPS} />);

await typeUrl("https://github.com/anthropics/claude-code");
await submit();

await waitFor(() => {
expect(mockRegister).toHaveBeenCalledWith(
"sk-test",
expect.objectContaining({ source: { source: "github", repo: "anthropics/claude-code" } }),
);
});
});

it("submits a github subdir source from a tree URL", async () => {
renderWithProviders(<AddPluginForm {...DEFAULT_PROPS} />);

await typeUrl("https://github.com/anthropics/claude-code/tree/main/plugins/my-skill");
await submit();

await waitFor(() => {
expect(mockRegister).toHaveBeenCalledWith(
"sk-test",
expect.objectContaining({
source: { source: "git-subdir", url: "https://github.com/anthropics/claude-code", path: "plugins/my-skill" },
}),
);
});
});

it("submits a raw url source for a gitlab repo", async () => {
renderWithProviders(<AddPluginForm {...DEFAULT_PROPS} />);

await typeUrl("https://gitlab.com/group/repo");
await submit();

await waitFor(() => {
expect(mockRegister).toHaveBeenCalledWith(
"sk-test",
expect.objectContaining({ source: { source: "url", url: "https://gitlab.com/group/repo" } }),
);
});
});

it("submits a git-subdir source from a gitlab repo plus subfolder field", async () => {
renderWithProviders(<AddPluginForm {...DEFAULT_PROPS} />);

await typeUrl("https://gitlab.com/group/repo");
await typeSubPath("plugins/x");
await submit();

await waitFor(() => {
expect(mockRegister).toHaveBeenCalledWith(
"sk-test",
expect.objectContaining({
source: { source: "git-subdir", url: "https://gitlab.com/group/repo", path: "plugins/x" },
}),
);
});
});

it("clears the subfolder field and uses the URL path once a tree URL is entered", async () => {
renderWithProviders(<AddPluginForm {...DEFAULT_PROPS} />);

await typeSubPath("plugins/x");
const subPathInput = screen.getByPlaceholderText(SUBPATH_PLACEHOLDER) as HTMLInputElement;
expect(subPathInput.value).toBe("plugins/x");

await typeUrl("https://github.com/anthropics/claude-code/tree/main/plugins/from-url");

await waitFor(() => {
expect(subPathInput.value).toBe("");
expect(subPathInput).toBeDisabled();
});

await submit();

await waitFor(() => {
expect(mockRegister).toHaveBeenCalledWith(
"sk-test",
expect.objectContaining({
source: {
source: "git-subdir",
url: "https://github.com/anthropics/claude-code",
path: "plugins/from-url",
},
}),
);
});
});

it("surfaces the backend error message when registration fails", async () => {
mockRegister.mockRejectedValueOnce(new Error("Plugin 'claude-code' already exists"));
renderWithProviders(<AddPluginForm {...DEFAULT_PROPS} />);

await typeUrl("https://github.com/anthropics/claude-code");
await submit();

await waitFor(() => {
expect(mockMessageError).toHaveBeenCalledWith(expect.stringContaining("Plugin 'claude-code' already exists"));
});
});
});
Loading
Loading