chat-page-state.test.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { describe, expect, it } from "vitest";
  2. import { filterModelGroups, shouldUseFreshBookCreateSession } from "./chat-page-state";
  3. describe("shouldUseFreshBookCreateSession", () => {
  4. it("uses a fresh session when there is no active book", () => {
  5. expect(shouldUseFreshBookCreateSession(undefined)).toBe(true);
  6. expect(shouldUseFreshBookCreateSession("")).toBe(true);
  7. });
  8. it("reuses the persisted session when a book is active", () => {
  9. expect(shouldUseFreshBookCreateSession("demo-book")).toBe(false);
  10. });
  11. });
  12. describe("filterModelGroups", () => {
  13. const grouped = [
  14. {
  15. service: "openai",
  16. label: "OpenAI",
  17. models: [
  18. { id: "gpt-5.4", name: "gpt-5.4" },
  19. { id: "gpt-4o", name: "gpt-4o" },
  20. ],
  21. },
  22. {
  23. service: "custom:gemma",
  24. label: "LM Studio",
  25. models: [
  26. { id: "google/gemma-4-27b-it", name: "google/gemma-4-27b-it" },
  27. ],
  28. },
  29. ] as const;
  30. it("returns all groups when search is blank", () => {
  31. expect(filterModelGroups(grouped, "")).toEqual(grouped);
  32. expect(filterModelGroups(grouped, " ")).toEqual(grouped);
  33. });
  34. it("filters by model name and preserves only matching groups", () => {
  35. expect(filterModelGroups(grouped, "gemma")).toEqual([
  36. {
  37. service: "custom:gemma",
  38. label: "LM Studio",
  39. models: [{ id: "google/gemma-4-27b-it", name: "google/gemma-4-27b-it" }],
  40. },
  41. ]);
  42. });
  43. it("filters by service label", () => {
  44. expect(filterModelGroups(grouped, "openai")).toEqual([
  45. {
  46. service: "openai",
  47. label: "OpenAI",
  48. models: [
  49. { id: "gpt-5.4", name: "gpt-5.4" },
  50. { id: "gpt-4o", name: "gpt-4o" },
  51. ],
  52. },
  53. ]);
  54. });
  55. });