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

thread-settings-sheet-state.test.ts

84 lines2.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 { 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: "Codex",
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 };
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("clears staging when the applied model is pressed", () => {
52 expect(
53 pendingModelAfterPress({
54 current: modelOption("gpt-next"),
55 pressed: modelOption("gpt-current"),
56 pressedIsApplied: true,
57 }),
58 ).toBeNull();
59 });
60​
61 it("preserves staged options when the highlighted model is pressed again", () => {
62 const pending = modelOption("gpt-next", [{ id: "effort", value: "high" }]);
63​
64 expect(
65 pendingModelAfterPress({
66 current: pending,
67 pressed: modelOption("gpt-next"),
68 pressedIsApplied: false,
69 }),
70 ).toBe(pending);
71 });
72​
73 it("stages a different model", () => {
74 const pressed = modelOption("gpt-other");
75​
76 expect(
77 pendingModelAfterPress({
78 current: modelOption("gpt-next"),
79 pressed,
80 pressedIsApplied: false,
81 }),
82 ).toBe(pressed);
83 });
84});