mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-05-19 11:40:49 +08:00
155a226e6a
Merge previously unreleased v3.12.4 content into v3.12.3: - CHANGELOG: combine [Unreleased] into [3.12.3], clear [Unreleased] - Release notes (zh/en/ja): add Copilot proxy, macOS signing, Reasoning Effort, OpenCode SQLite, Codex 1M toggle, Disable Auto-Upgrade toggle, and contributor thanks - Fix test mocks for skill backup/restore hooks - Fix schema migration test missing providers table - Fix TempHome to save/restore CC_SWITCH_TEST_HOME env var
112 lines
2.8 KiB
TypeScript
112 lines
2.8 KiB
TypeScript
import { createRef } from "react";
|
|
import { render, screen, waitFor, act } from "@testing-library/react";
|
|
import { describe, expect, it, vi, beforeEach } from "vitest";
|
|
|
|
import UnifiedSkillsPanel, {
|
|
type UnifiedSkillsPanelHandle,
|
|
} from "@/components/skills/UnifiedSkillsPanel";
|
|
|
|
const scanUnmanagedMock = vi.fn();
|
|
const toggleSkillAppMock = vi.fn();
|
|
const uninstallSkillMock = vi.fn();
|
|
const importSkillsMock = vi.fn();
|
|
const installFromZipMock = vi.fn();
|
|
const deleteSkillBackupMock = vi.fn();
|
|
const restoreSkillBackupMock = vi.fn();
|
|
|
|
vi.mock("sonner", () => ({
|
|
toast: {
|
|
success: vi.fn(),
|
|
error: vi.fn(),
|
|
info: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
vi.mock("@/hooks/useSkills", () => ({
|
|
useInstalledSkills: () => ({
|
|
data: [],
|
|
isLoading: false,
|
|
}),
|
|
useSkillBackups: () => ({
|
|
data: [],
|
|
refetch: vi.fn(),
|
|
isFetching: false,
|
|
}),
|
|
useDeleteSkillBackup: () => ({
|
|
mutateAsync: deleteSkillBackupMock,
|
|
isPending: false,
|
|
}),
|
|
useToggleSkillApp: () => ({
|
|
mutateAsync: toggleSkillAppMock,
|
|
}),
|
|
useRestoreSkillBackup: () => ({
|
|
mutateAsync: restoreSkillBackupMock,
|
|
isPending: false,
|
|
}),
|
|
useUninstallSkill: () => ({
|
|
mutateAsync: uninstallSkillMock,
|
|
}),
|
|
useScanUnmanagedSkills: () => ({
|
|
data: [
|
|
{
|
|
directory: "shared-skill",
|
|
name: "Shared Skill",
|
|
description: "Imported from Claude",
|
|
foundIn: ["claude"],
|
|
path: "/tmp/shared-skill",
|
|
},
|
|
],
|
|
refetch: scanUnmanagedMock,
|
|
}),
|
|
useImportSkillsFromApps: () => ({
|
|
mutateAsync: importSkillsMock,
|
|
}),
|
|
useInstallSkillsFromZip: () => ({
|
|
mutateAsync: installFromZipMock,
|
|
}),
|
|
}));
|
|
|
|
describe("UnifiedSkillsPanel", () => {
|
|
beforeEach(() => {
|
|
scanUnmanagedMock.mockResolvedValue({
|
|
data: [
|
|
{
|
|
directory: "shared-skill",
|
|
name: "Shared Skill",
|
|
description: "Imported from Claude",
|
|
foundIn: ["claude"],
|
|
path: "/tmp/shared-skill",
|
|
},
|
|
],
|
|
});
|
|
toggleSkillAppMock.mockReset();
|
|
uninstallSkillMock.mockReset();
|
|
importSkillsMock.mockReset();
|
|
installFromZipMock.mockReset();
|
|
deleteSkillBackupMock.mockReset();
|
|
restoreSkillBackupMock.mockReset();
|
|
});
|
|
|
|
it("opens the import dialog without crashing when app toggles render", async () => {
|
|
const ref = createRef<UnifiedSkillsPanelHandle>();
|
|
|
|
render(
|
|
<UnifiedSkillsPanel
|
|
ref={ref}
|
|
onOpenDiscovery={() => {}}
|
|
currentApp="claude"
|
|
/>,
|
|
);
|
|
|
|
await act(async () => {
|
|
await ref.current?.openImport();
|
|
});
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByText("skills.import")).toBeInTheDocument();
|
|
expect(screen.getByText("Shared Skill")).toBeInTheDocument();
|
|
expect(screen.getByText("/tmp/shared-skill")).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|