A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode,DeepSeek Harness and more. Only official website: ccswitch.io
Rust ai-toolsclaude-codecodexdeepseek-harnessdesktop-appgrokgrokbuildhermeskimi-codemcpopen-sourceopencodepiprovider-managementrustskillsskills-managementtauriwsl-support
import type { ReactNode } from "react";
import { act, renderHook } from "@testing-library/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { describe, expect, it, vi } from "vitest";
import { useSaveSettingsMutation } from "@/lib/query/mutations";
import type { Settings } from "@/types";
function setup(saved: Partial<Settings>) {
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false }, mutations: { retry: false } },
});
queryClient.setQueryData(["settings"], saved as Settings);
const invalidate = vi.spyOn(queryClient, "invalidateQueries");
const wrapper = ({ children }: { children: ReactNode }) => (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
);
const { result } = renderHook(() => useSaveSettingsMutation(), { wrapper });
const qoderInvalidated = () =>
invalidate.mock.calls.some(
([filters]) =>
JSON.stringify(filters?.queryKey) ===
JSON.stringify(["providers", "qoder"]),
);
return { result, qoderInvalidated };
}
describe("useSaveSettingsMutation", () => {
it("re-reads the Qoder provider list when the edition changes", async () => {
const { result, qoderInvalidated } = setup({ qoderEdition: "global" });
await act(() =>
result.current.mutateAsync({ qoderEdition: "cn" } as Settings),
);
expect(qoderInvalidated()).toBe(true);
});
it("treats a language change as an edition change when no edition was chosen", async () => {
const { result, qoderInvalidated } = setup({ language: "zh" });
await act(() => result.current.mutateAsync({ language: "en" } as Settings));
expect(qoderInvalidated()).toBe(true);
});
it("leaves the Qoder provider list alone when the edition stays the same", async () => {
const { result, qoderInvalidated } = setup({
qoderEdition: "cn",
language: "zh",
});
await act(() =>
result.current.mutateAsync({
qoderEdition: "cn",
language: "en",
} as Settings),
);
expect(qoderInvalidated()).toBe(false);
});
});