|
| 1 | +/** |
| 2 | + * SearchBar coupled tier/model picker tests. |
| 3 | + * |
| 4 | + * The composer's two pills describe ONE resolution — `run.model or the |
| 5 | + * tier's preset` — so the UI must keep them legible as a pair: |
| 6 | + * 1. The model pill's default label NAMES the current tier's preset |
| 7 | + * ("Auto · claude-sonnet-4-6"), never a vague "Default model", once |
| 8 | + * `GET /tiers` resolves. |
| 9 | + * 2. An explicit override replaces that label with the chosen model. |
| 10 | + * 3. The budget dropdown rows carry the budget hints (depth · fan-out) AND |
| 11 | + * each tier's model preset, so picking a tier reads as picking the whole |
| 12 | + * preset. |
| 13 | + * |
| 14 | + * vitest runs WITHOUT globals, so cleanup is wired explicitly (console |
| 15 | + * convention). useTiers/useModels are mocked at the hook seam — the only I/O |
| 16 | + * boundary — everything else renders the real component tree. |
| 17 | + */ |
| 18 | +import { afterEach, describe, expect, it, vi } from "vitest" |
| 19 | +import { cleanup, fireEvent, render, screen } from "@testing-library/react" |
| 20 | +import { QueryClient, QueryClientProvider } from "@tanstack/react-query" |
| 21 | + |
| 22 | +import { SearchBar } from "./SearchBar" |
| 23 | +import type { Workspace } from "../../types/agenticSearch" |
| 24 | + |
| 25 | +vi.mock("../../hooks/useAgenticSearch", async (importOriginal) => { |
| 26 | + const mod = await importOriginal<typeof import("../../hooks/useAgenticSearch")>() |
| 27 | + return { |
| 28 | + ...mod, |
| 29 | + useTiers: () => ({ |
| 30 | + data: { |
| 31 | + default_tier: "auto", |
| 32 | + tiers: { |
| 33 | + fast: "openai/gpt-5.4-nano", |
| 34 | + auto: "anthropic/claude-sonnet-4-6", |
| 35 | + deep: "openai/gpt-5.5", |
| 36 | + }, |
| 37 | + }, |
| 38 | + }), |
| 39 | + } |
| 40 | +}) |
| 41 | + |
| 42 | +vi.mock("../../hooks/useModels", () => ({ |
| 43 | + useModels: () => ({ |
| 44 | + models: ["openai/gpt-5.5", "anthropic/claude-sonnet-4-6"], |
| 45 | + defaultModel: "", |
| 46 | + capabilities: {}, |
| 47 | + loading: false, |
| 48 | + error: null, |
| 49 | + refresh: vi.fn(), |
| 50 | + }), |
| 51 | +})) |
| 52 | + |
| 53 | +afterEach(cleanup) |
| 54 | + |
| 55 | +const MODEL_PILL_TITLE = "Model for this run — overrides the tier's preset" |
| 56 | + |
| 57 | +function workspace(): Workspace { |
| 58 | + return { |
| 59 | + id: "w1", |
| 60 | + name: "Platform", |
| 61 | + desc: "Infra and CI", |
| 62 | + sources: ["github"], |
| 63 | + instructions: "", |
| 64 | + created: "today", |
| 65 | + past_queries: [], |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +function renderBar(over: Partial<Parameters<typeof SearchBar>[0]> = {}) { |
| 70 | + const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } }) |
| 71 | + return render( |
| 72 | + <QueryClientProvider client={qc}> |
| 73 | + <SearchBar |
| 74 | + value="" |
| 75 | + onChange={vi.fn()} |
| 76 | + onSubmit={vi.fn()} |
| 77 | + workspace={workspace()} |
| 78 | + workspaces={[workspace()]} |
| 79 | + onPickWorkspace={vi.fn()} |
| 80 | + onNewWorkspace={vi.fn()} |
| 81 | + tier="auto" |
| 82 | + onTierChange={vi.fn()} |
| 83 | + model="" |
| 84 | + onModelChange={vi.fn()} |
| 85 | + {...over} |
| 86 | + /> |
| 87 | + </QueryClientProvider>, |
| 88 | + ) |
| 89 | +} |
| 90 | + |
| 91 | +describe("SearchBar coupled tier/model pickers", () => { |
| 92 | + it("model pill default label names the current tier's preset", () => { |
| 93 | + renderBar() |
| 94 | + const pill = screen.getByTitle(MODEL_PILL_TITLE) |
| 95 | + expect(pill).toHaveTextContent("Auto · claude-sonnet-4-6") |
| 96 | + }) |
| 97 | + |
| 98 | + it("default label follows the tier prop (Deep names the deep preset)", () => { |
| 99 | + renderBar({ tier: "deep" }) |
| 100 | + expect(screen.getByTitle(MODEL_PILL_TITLE)).toHaveTextContent("Deep · gpt-5.5") |
| 101 | + }) |
| 102 | + |
| 103 | + it("an explicit override replaces the preset label", () => { |
| 104 | + renderBar({ model: "openai/gpt-5.5" }) |
| 105 | + const pill = screen.getByTitle(MODEL_PILL_TITLE) |
| 106 | + expect(pill).toHaveTextContent("gpt-5.5") |
| 107 | + expect(pill).not.toHaveTextContent("Auto ·") |
| 108 | + }) |
| 109 | + |
| 110 | + it("budget dropdown rows show depth/fan-out hints + per-tier model presets", () => { |
| 111 | + renderBar() |
| 112 | + const trigger = screen.getByRole("button", { name: "Search budget" }) |
| 113 | + // Radix DropdownMenu opens from keyboard on the trigger — the reliable |
| 114 | + // jsdom path (no PointerEvent capture semantics needed). |
| 115 | + fireEvent.keyDown(trigger, { key: "Enter" }) |
| 116 | + expect(screen.getByText("Search budget — depth · fan-out · model")).toBeInTheDocument() |
| 117 | + // Budget hints speak depth × probes, not speed adjectives. |
| 118 | + expect(screen.getByText("shallow · few probes")).toBeInTheDocument() |
| 119 | + expect(screen.getByText("max depth · wide fan-out")).toBeInTheDocument() |
| 120 | + // Each tier row names the model preset it runs on. |
| 121 | + expect(screen.getByText("gpt-5.4-nano")).toBeInTheDocument() |
| 122 | + expect(screen.getByText("claude-sonnet-4-6")).toBeInTheDocument() |
| 123 | + }) |
| 124 | + |
| 125 | + it("picking a tier row emits onTierChange with the tier id", () => { |
| 126 | + const onTierChange = vi.fn() |
| 127 | + renderBar({ onTierChange }) |
| 128 | + fireEvent.keyDown(screen.getByRole("button", { name: "Search budget" }), { key: "Enter" }) |
| 129 | + fireEvent.click(screen.getByText("max depth · wide fan-out")) |
| 130 | + expect(onTierChange).toHaveBeenCalledWith("deep") |
| 131 | + }) |
| 132 | +}) |
0 commit comments