diff --git a/frontend/src/views/admin/__tests__/groupsOpenAIFast.spec.ts b/frontend/src/views/admin/__tests__/groupsOpenAIFast.spec.ts new file mode 100644 index 0000000000..e94ee5a36c --- /dev/null +++ b/frontend/src/views/admin/__tests__/groupsOpenAIFast.spec.ts @@ -0,0 +1,36 @@ +import { describe, expect, it } from "vitest"; + +import { + normalizeGroupOpenAIFast, + supportsGroupOpenAIFast, +} from "../groupsOpenAIFast"; +import en from "@/i18n/locales/en/admin/overview"; +import zh from "@/i18n/locales/zh/admin/overview"; + +describe("groupsOpenAIFast", () => { + it("supports OpenAI and composite groups", () => { + expect(supportsGroupOpenAIFast("openai")).toBe(true); + expect(supportsGroupOpenAIFast("composite")).toBe(true); + expect(supportsGroupOpenAIFast("anthropic")).toBe(false); + }); + + it("clears stale enabled state on unsupported platforms", () => { + expect(normalizeGroupOpenAIFast("openai", true)).toBe(true); + expect(normalizeGroupOpenAIFast("composite", true)).toBe(true); + expect(normalizeGroupOpenAIFast("anthropic", true)).toBe(false); + expect(normalizeGroupOpenAIFast("openai", false)).toBe(false); + }); + + it("provides localized switch labels", () => { + expect(zh.groups.openaiFast).toMatchObject({ + title: expect.any(String), + force: expect.any(String), + hint: expect.stringContaining("service_tier=priority"), + }); + expect(en.groups.openaiFast).toMatchObject({ + title: expect.any(String), + force: expect.any(String), + hint: expect.stringContaining("service_tier=priority"), + }); + }); +}); diff --git a/frontend/src/views/admin/groupsOpenAIFast.ts b/frontend/src/views/admin/groupsOpenAIFast.ts new file mode 100644 index 0000000000..a4e3f544a2 --- /dev/null +++ b/frontend/src/views/admin/groupsOpenAIFast.ts @@ -0,0 +1,10 @@ +export function supportsGroupOpenAIFast(platform: string): boolean { + return platform === "openai" || platform === "composite"; +} + +export function normalizeGroupOpenAIFast( + platform: string, + enabled: boolean, +): boolean { + return supportsGroupOpenAIFast(platform) && enabled; +}