83 lines · 2.4 KB · TypeScript
RawDownload
import { createElement } from "react";import { renderToStaticMarkup } from "react-dom/server";import { describe, expect, it } from "vite-plus/test";import {  ProviderDriverKind,  ProviderInstanceId,  type ServerProvider,  type ServerProviderModel,} from "@t3tools/contracts"; import { deriveProviderModelsForDisplay, ProviderInstanceCard } from "./ProviderInstanceCard"; describe("deriveProviderModelsForDisplay", () => {  it("uses current config custom models instead of stale live custom rows", () => {    const liveModels: ReadonlyArray<ServerProviderModel> = [      {        slug: "server-model",        name: "Server Model",        isCustom: false,        capabilities: null,      },      {        slug: "removed-custom",        name: "Removed Custom",        isCustom: true,        capabilities: null,      },      {        slug: "kept-custom",        name: "Kept Custom",        isCustom: true,        capabilities: null,      },    ];     expect(      deriveProviderModelsForDisplay({        liveModels,        customModels: ["kept-custom"],      }).map((model) => model.slug),    ).toEqual(["server-model", "kept-custom"]);  });   it("shows a redacted provider email in Configuration", () => {    const instanceId = ProviderInstanceId.make("codex");    const driver = ProviderDriverKind.make("codex");    const liveProvider: ServerProvider = {      instanceId,      driver,      enabled: true,      installed: true,      version: "1.0.0",      status: "ready",      auth: { status: "authenticated", email: "developer@example.com" },      checkedAt: "2026-08-27T12:00:00.000Z",      models: [],      slashCommands: [],      skills: [],    };     const markup = renderToStaticMarkup(      createElement(ProviderInstanceCard, {        instanceId,        instance: { driver },        driverOption: undefined,        liveProvider,        mode: "editor",        onUpdate: () => undefined,        hiddenModels: [],        favoriteModels: [],        modelOrder: [],        onHiddenModelsChange: () => undefined,        onFavoriteModelsChange: () => undefined,        onModelOrderChange: () => undefined,      }),    );     expect(markup).toContain("Account email");    expect(markup).toContain('aria-label="Toggle account email visibility"');    expect(markup).toContain("blur-[2px]");    expect(markup).not.toContain("developer@example.com");  });});