96 lines
4.0 KiB
TypeScript
96 lines
4.0 KiB
TypeScript
import { cleanup, fireEvent, render } from "@testing-library/react";
|
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
|
|
import { ProviderIcon } from "@/components/settings/models/ProviderSettings";
|
|
import { __clearLogoFallbackCacheForTests } from "@/hooks/useLogoFallback";
|
|
import { providerBrand } from "@/lib/provider-brand";
|
|
|
|
describe("settings provider icons", () => {
|
|
beforeEach(__clearLogoFallbackCacheForTests);
|
|
afterEach(cleanup);
|
|
|
|
function expectFootprint(icon: Element) {
|
|
expect(icon).toHaveClass("h-8", "w-8", "shrink-0", "overflow-hidden", "rounded-[9px]");
|
|
expect(icon.className.split(/\s+/).some((value) => value.startsWith("border"))).toBe(false);
|
|
}
|
|
|
|
it.each(["openai_codex", "anthropic", "deepseek", "gemini", "xai_grok"])(
|
|
"shows %s as a single full-size logo after loading",
|
|
(provider) => {
|
|
const { container } = render(<ProviderIcon provider={provider} showBrandLogos />);
|
|
const icon = container.firstElementChild!;
|
|
const image = icon.querySelector("img")!;
|
|
const fallback = icon.querySelector("span")!;
|
|
|
|
expectFootprint(icon);
|
|
expect(icon).toHaveClass("bg-muted");
|
|
expect(fallback).toHaveTextContent(providerBrand(provider)!.initials);
|
|
expect(fallback).toHaveClass("opacity-100");
|
|
expect(image).toHaveClass("h-full", "w-full", "object-contain", "opacity-0");
|
|
expect(image).toHaveAttribute("alt", "");
|
|
|
|
fireEvent.load(image);
|
|
|
|
expectFootprint(icon);
|
|
expect(icon).toHaveClass("bg-transparent");
|
|
expect(icon).not.toHaveClass("bg-muted");
|
|
expect(icon).not.toHaveAttribute("style");
|
|
expect(fallback).toHaveClass("opacity-0");
|
|
expect(image).toHaveClass("opacity-100");
|
|
expect(image).not.toHaveClass("invert", "grayscale");
|
|
},
|
|
);
|
|
|
|
it("keeps its placeholder through alternate URLs and complete image failure", () => {
|
|
const { container } = render(<ProviderIcon provider="openai_codex" showBrandLogos />);
|
|
const icon = container.firstElementChild!;
|
|
const fallback = icon.querySelector("span")!;
|
|
|
|
for (const url of providerBrand("openai_codex")!.logoUrls) {
|
|
const image = icon.querySelector("img")!;
|
|
expect(image).toHaveAttribute("src", url);
|
|
expect(image).toHaveClass("opacity-0");
|
|
fireEvent.error(image);
|
|
expect(container.firstElementChild).toBe(icon);
|
|
expectFootprint(icon);
|
|
expect(icon).toHaveClass("bg-muted");
|
|
expect(fallback).toHaveClass("opacity-100");
|
|
}
|
|
|
|
expect(icon.querySelector("img")).toBeNull();
|
|
expect(fallback).toHaveTextContent("AI");
|
|
expect(icon).toHaveAttribute("aria-hidden", "true");
|
|
});
|
|
|
|
it("respects disabled brand logos without changing footprint, including cached logos", () => {
|
|
const { container, rerender } = render(<ProviderIcon provider="openai_codex" showBrandLogos />);
|
|
const icon = container.firstElementChild!;
|
|
fireEvent.load(icon.querySelector("img")!);
|
|
|
|
rerender(<ProviderIcon provider="openai_codex" showBrandLogos={false} />);
|
|
expect(container.firstElementChild).toBe(icon);
|
|
expectFootprint(icon);
|
|
expect(icon).toHaveClass("bg-muted");
|
|
expect(icon.querySelector("img")).toBeNull();
|
|
expect(icon.querySelector("svg")).not.toBeNull();
|
|
expect(icon).not.toHaveTextContent("AI");
|
|
|
|
rerender(<ProviderIcon provider="openai_codex" showBrandLogos />);
|
|
expectFootprint(icon);
|
|
expect(icon).toHaveClass("bg-transparent");
|
|
expect(icon.querySelector("img")).toHaveClass("opacity-100");
|
|
});
|
|
|
|
it("uses the same footprint for unknown and custom providers", () => {
|
|
const { container, rerender } = render(<ProviderIcon provider="custom" showBrandLogos />);
|
|
expectFootprint(container.firstElementChild!);
|
|
expect(container.querySelector("img")).toBeNull();
|
|
expect(container.querySelector("svg")).not.toBeNull();
|
|
|
|
rerender(<ProviderIcon provider="my-provider" showBrandLogos />);
|
|
expectFootprint(container.firstElementChild!);
|
|
expect(container.querySelector("img")).toBeNull();
|
|
expect(container.querySelector("svg")).not.toBeNull();
|
|
});
|
|
});
|