Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { ProviderInstanceId, type ProviderOptionSelection } from "@t3tools/contracts";
4
5import type { ModelOption } from "../../lib/modelOptions";
6import { modelMatchesCatalogQuery, pendingModelAfterPress } from "./thread-settings-sheet-state";
7
8function modelOption(
9 model: string,
10 options: ReadonlyArray<ProviderOptionSelection> = [],
11): ModelOption {
12 return {
13 key: `codex:${model}`,
14 label: model,
15 subtitle: "",
16 providerKey: "codex",
17 providerLabel: "Codex",
18 providerDriver: "codex",
19 isDefault: false,
20 isLegacy: false,
21 capabilities: null,
22 selection: {
23 instanceId: ProviderInstanceId.make("codex"),
24 model,
25 options,
26 },
27 };
28}
29
30describe("thread settings sheet state", () => {
31 it("matches visible model and provider terms", () => {
32 const model = modelOption("gpt-next");
33
34 expect(modelMatchesCatalogQuery({ model, providerLabel: "Codex", query: "NEXT" })).toBe(true);
35 expect(modelMatchesCatalogQuery({ model, providerLabel: "Codex", query: "codex" })).toBe(true);
36 expect(modelMatchesCatalogQuery({ model, providerLabel: "Codex", query: "claude" })).toBe(
37 false,
38 );
39 });
40
41 it("treats whitespace-only catalog searches as empty", () => {
42 expect(
43 modelMatchesCatalogQuery({
44 model: modelOption("gpt-next"),
45 providerLabel: "Codex",
46 query: " ",
47 }),
48 ).toBe(true);
49 });
50
51 it("matches the upstream provider's display name", () => {
52 const model = {
53 ...modelOption("opencode/claude-fable-5"),
54 label: "Claude Fable 5",
55 subtitle: "OpenCode Zen",
56 };
57
58 expect(modelMatchesCatalogQuery({ model, providerLabel: "OpenCode", query: " ZEN " })).toBe(
59 true,
60 );
61 expect(modelMatchesCatalogQuery({ model, providerLabel: "OpenCode", query: "copilot" })).toBe(
62 false,
63 );
64 });
65
66 it("clears staging when the applied model is pressed", () => {
67 expect(
68 pendingModelAfterPress({
69 current: modelOption("gpt-next"),
70 pressed: modelOption("gpt-current"),
71 pressedIsApplied: true,
72 }),
73 ).toBeNull();
74 });
75
76 it("preserves staged options when the highlighted model is pressed again", () => {
77 const pending = modelOption("gpt-next", [{ id: "effort", value: "high" }]);
78
79 expect(
80 pendingModelAfterPress({
81 current: pending,
82 pressed: modelOption("gpt-next"),
83 pressedIsApplied: false,
84 }),
85 ).toBe(pending);
86 });
87
88 it("stages a different model", () => {
89 const pressed = modelOption("gpt-other");
90
91 expect(
92 pendingModelAfterPress({
93 current: modelOption("gpt-next"),
94 pressed,
95 pressedIsApplied: false,
96 }),
97 ).toBe(pressed);
98 });
99});