| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import { describe, expect, it } from "vitest";
- import { filterModelGroups, shouldUseFreshBookCreateSession } from "./chat-page-state";
- describe("shouldUseFreshBookCreateSession", () => {
- it("uses a fresh session when there is no active book", () => {
- expect(shouldUseFreshBookCreateSession(undefined)).toBe(true);
- expect(shouldUseFreshBookCreateSession("")).toBe(true);
- });
- it("reuses the persisted session when a book is active", () => {
- expect(shouldUseFreshBookCreateSession("demo-book")).toBe(false);
- });
- });
- describe("filterModelGroups", () => {
- const grouped = [
- {
- service: "openai",
- label: "OpenAI",
- models: [
- { id: "gpt-5.4", name: "gpt-5.4" },
- { id: "gpt-4o", name: "gpt-4o" },
- ],
- },
- {
- service: "custom:gemma",
- label: "LM Studio",
- models: [
- { id: "google/gemma-4-27b-it", name: "google/gemma-4-27b-it" },
- ],
- },
- ] as const;
- it("returns all groups when search is blank", () => {
- expect(filterModelGroups(grouped, "")).toEqual(grouped);
- expect(filterModelGroups(grouped, " ")).toEqual(grouped);
- });
- it("filters by model name and preserves only matching groups", () => {
- expect(filterModelGroups(grouped, "gemma")).toEqual([
- {
- service: "custom:gemma",
- label: "LM Studio",
- models: [{ id: "google/gemma-4-27b-it", name: "google/gemma-4-27b-it" }],
- },
- ]);
- });
- it("filters by service label", () => {
- expect(filterModelGroups(grouped, "openai")).toEqual([
- {
- service: "openai",
- label: "OpenAI",
- models: [
- { id: "gpt-5.4", name: "gpt-5.4" },
- { id: "gpt-4o", name: "gpt-4o" },
- ],
- },
- ]);
- });
- });
|