| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | import type { ServerProviderModel } from "@t3tools/contracts"; |
| 3 | |
| 4 | import { groupModelsForDisplay, nextHiddenModelsForBulkToggle } from "./ProviderModelsSection"; |
| 5 | |
| 6 | function model(slug: string, isCustom = false): ServerProviderModel { |
| 7 | return { slug, name: slug, isCustom, capabilities: null }; |
| 8 | } |
| 9 | |
| 10 | describe("groupModelsForDisplay", () => { |
| 11 | it("lists favorites first, then visible models in user order, then hidden ones", () => { |
| 12 | const models = [model("a"), model("b"), model("c"), model("d"), model("custom", true)]; |
| 13 | |
| 14 | const display = groupModelsForDisplay(models, { |
| 15 | favoriteModels: new Set(["c"]), |
| 16 | hiddenModels: new Set(["a", "custom"]), |
| 17 | modelOrder: ["d", "b"], |
| 18 | }); |
| 19 | |
| 20 | // A custom model is never hidden, even if its slug is in the hidden set. |
| 21 | expect(display.map((entry) => entry.slug)).toEqual(["c", "d", "b", "custom", "a"]); |
| 22 | }); |
| 23 | }); |
| 24 | |
| 25 | describe("nextHiddenModelsForBulkToggle", () => { |
| 26 | it("hides every built-in model without hiding custom models", () => { |
| 27 | const models = [model("a"), model("b"), model("custom", true)]; |
| 28 | |
| 29 | expect(nextHiddenModelsForBulkToggle(models, ["a"])).toEqual(["a", "b"]); |
| 30 | }); |
| 31 | |
| 32 | it("shows every built-in model while preserving unrelated hidden entries", () => { |
| 33 | const models = [model("a"), model("b"), model("custom", true)]; |
| 34 | |
| 35 | expect(nextHiddenModelsForBulkToggle(models, ["a", "b", "legacy", "custom"])).toEqual([ |
| 36 | "legacy", |
| 37 | "custom", |
| 38 | ]); |
| 39 | }); |
| 40 | }); |