Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

3.8 KB
Raw Blame
import React from 'react';
import { render, screen } from '@testing-library/react';
import ChatView from '../ChatView';

let mockConversation: Record<string, unknown> | null;

jest.mock('react-router-dom', () => ({
  useParams: () => ({ conversationId: 'child-thread' }),
}));

jest.mock('recoil', () => ({
  atomFamily: () => () => ({}),
  useRecoilValue: () => false,
  useRecoilCallback: () => () => undefined,
}));

jest.mock('react-hook-form', () => ({
  useForm: () => ({}),
}));

jest.mock('@librechat/client', () => ({
  Spinner: () => <div data-testid="spinner" />,
  cn: (...values: Array<string | false | null | undefined>) => values.filter(Boolean).join(' '),
}));

jest.mock('librechat-data-provider', () => ({
  ...jest.requireActual('librechat-data-provider'),
  Constants: { NEW_CONVO: 'new', SEARCH: 'search' },
  buildTree: ({ messages }: { messages: unknown[] }) => messages,
}));

jest.mock('@librechat/chat/react', () => {
  const actual = jest.requireActual('@librechat/chat/react');
  return {
    ...actual,
    ChatSessionProvider: ({
      children,
    }: {
      children: (session: { messages: unknown[]; isLoading: boolean }) => React.ReactNode;
    }) => (
      <actual.ChatContext.Provider value={{ conversation: mockConversation }}>
        {children({ messages: [{ messageId: 'message-1' }], isLoading: false })}
      </actual.ChatContext.Provider>
    ),
  };
});

jest.mock('~/hooks', () => ({
  useAddedResponse: () => ({}),
  useLocalize: () => (key: string) => key,
}));

jest.mock('~/hooks/Chat/outcomes', () => ({
  getMappingOptions: () => ({}),
}));

jest.mock('~/Providers', () => {
  const Passthrough = ({ children }: { children: React.ReactNode }) => <>{children}</>;
  const Context = { Provider: Passthrough };
  return {
    AddedChatContext: Context,
    useChatContext: jest.requireActual('~/Providers/ChatContext').useChatContext,
    ChatFormProvider: Passthrough,
    ComposerRestoreProvider: Passthrough,
    useFileMapContext: () => new Map(),
  };
});

jest.mock('~/data-provider', () => ({
  useProjectQuery: () => ({ data: undefined }),
}));

jest.mock('../Input/ConversationStarters', () => () => null);
jest.mock('../Messages/MessagesView', () => () => <div data-testid="messages" />);
jest.mock('../Presentation', () => ({ children }: { children: React.ReactNode }) => (
  <>{children}</>
));
jest.mock('../Input/ChatForm', () => () => <div data-testid="chat-form" />);
jest.mock('../Landing', () => () => <div data-testid="landing" />);
jest.mock('~/components/Lia', () => () => null);
jest.mock('../Trace', () => ({
  TraceSurface: ({ children }: { children: React.ReactNode }) => <>{children}</>,
}));
jest.mock('../Footer', () => ({
  __esModule: true,
  default: () => <div data-testid="footer" />,
  useConfiguredFooter: () => false,
  useLandingFooter: () => true,
}));
jest.mock('../Header', () => ({ readOnly }: { readOnly?: boolean }) => (
  <div data-read-only={String(readOnly)} data-testid="header" />
));

jest.mock('~/utils', () => ({
  cn: (...values: Array<string | false | null | undefined>) => values.filter(Boolean).join(' '),
}));

jest.mock('~/store', () => ({
  __esModule: true,
  default: {
    centerFormOnLanding: {},
  },
}));

describe('ChatView child-thread execution identity', () => {
  beforeEach(() => {
    jest.clearAllMocks();
  });

  it('renders a child without a standalone identity as view-only', () => {
    mockConversation = {
      conversationId: 'child-thread',
      title: 'Graph child',
      subagentThread: {
        parentConversationId: 'parent-thread',
      },
    };

    render(<ChatView />);

    expect(screen.queryByTestId('chat-form')).not.toBeInTheDocument();
    expect(screen.getByRole('note')).toHaveTextContent('com_ui_subagent_thread_read_only');
    expect(screen.getByTestId('header')).toHaveAttribute('data-read-only', 'true');
  });
});