SPB Git

spb/vquant Public MIT

VibeQuant — AI-powered institutional-grade financial intelligence platform.

TypeScript 84.3% Python 11.7% JavaScript 1.6% CSS 1.5% HTML 0.7%
4.4 KB · 128 lines tsx
Raw Blame History
1/*2 * =============================================================================3 *  VibeQuant (vquant) — AI-Powered Financial Intelligence Platform4 * -----------------------------------------------------------------------------5 *  File:      client/src/hooks/useChatSession.test.tsx6 *7 *  Author:    Simon-Pierre Boucher8 *  Contact:   contact@spboucher.ai9 *  Website:   https://www.spboucher.ai10 *  Demo:      https://www.vquant.ai11 *  License:   MIT (see LICENSE)12 *13 *  Copyright © 2026 Simon-Pierre Boucher. All rights reserved.14 * =============================================================================15 */1617import { describe, it, expect } from "vitest";18import { renderHook, act } from "@testing-library/react";19import { QueryClient, QueryClientProvider } from "@tanstack/react-query";20import type { ReactNode } from "react";21import { useChatSession } from "./useChatSession";2223function createWrapper() {24  const queryClient = new QueryClient({25    defaultOptions: {26      queries: { retry: false, gcTime: 0 },27      mutations: { retry: false },28    },29  });3031  return function Wrapper({ children }: { children: ReactNode }) {32    return (33      <QueryClientProvider client={queryClient}>34        {children}35      </QueryClientProvider>36    );37  };38}3940describe("useChatSession", () => {41  it("returns initial state", () => {42    const { result } = renderHook(() => useChatSession(), {43      wrapper: createWrapper(),44    });4546    expect(result.current.currentUser).toBeNull();47    expect(result.current.currentSessionId).toBeNull();48    expect(result.current.conversationHistory).toEqual([]);49    expect(result.current.currentQuestion).toBe("");50    expect(result.current.streamingAnswer).toBe("");51    expect(result.current.sources).toEqual([]);52    expect(result.current.searchQueries).toEqual([]);53    expect(result.current.toolResults).toEqual([]);54    expect(result.current.agentSteps).toEqual([]);55    expect(result.current.pythonCode).toBe("");56    expect(result.current.monteCarloResults).toBeNull();57    expect(result.current.optionsPricingResults).toBeNull();58    expect(result.current.customPythonFigures).toEqual([]);59    expect(result.current.figureUrls).toEqual([]);60    expect(result.current.hasSearched).toBe(false);61    expect(result.current.historyOpen).toBe(false);62  });6364  it("handleNewConversation resets all state", () => {65    const { result } = renderHook(() => useChatSession(), {66      wrapper: createWrapper(),67    });6869    act(() => {70      result.current.handleNewConversation();71    });7273    expect(result.current.currentSessionId).toBeNull();74    expect(result.current.conversationHistory).toEqual([]);75    expect(result.current.currentQuestion).toBe("");76    expect(result.current.streamingAnswer).toBe("");77    expect(result.current.sources).toEqual([]);78    expect(result.current.hasSearched).toBe(false);79  });8081  it("setHistoryOpen toggles history panel", () => {82    const { result } = renderHook(() => useChatSession(), {83      wrapper: createWrapper(),84    });8586    expect(result.current.historyOpen).toBe(false);8788    act(() => {89      result.current.setHistoryOpen(true);90    });9192    expect(result.current.historyOpen).toBe(true);93  });9495  it("exposes chatMutation with expected shape", () => {96    const { result } = renderHook(() => useChatSession(), {97      wrapper: createWrapper(),98    });99100    expect(result.current.chatMutation).toBeDefined();101    expect(typeof result.current.chatMutation.mutate).toBe("function");102    expect(typeof result.current.chatMutation.reset).toBe("function");103    expect(result.current.chatMutation.isPending).toBe(false);104    expect(result.current.chatMutation.isError).toBe(false);105  });106107  it("exposes all action handlers as functions", () => {108    const { result } = renderHook(() => useChatSession(), {109      wrapper: createWrapper(),110    });111112    expect(typeof result.current.handleSearch).toBe("function");113    expect(typeof result.current.handleRetry).toBe("function");114    expect(typeof result.current.handleNewConversation).toBe("function");115    expect(typeof result.current.handleLogout).toBe("function");116    expect(typeof result.current.handleLoadSession).toBe("function");117  });118119  it("resultsRef is a valid ref object", () => {120    const { result } = renderHook(() => useChatSession(), {121      wrapper: createWrapper(),122    });123124    expect(result.current.resultsRef).toBeDefined();125    expect(result.current.resultsRef.current).toBeNull();126  });127});128