Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

thread-settings-sheet-state.test.ts

119 lines3.3 KB

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