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

2.5 KB
Raw Blame
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import AgentContact from '../AgentContact';

jest.mock('~/hooks', () => ({
  useLocalize: () => (key: string) => {
    const translations: Record<string, string> = {
      com_agents_contact: 'Contact',
      com_agents_no_contact_available: 'No contact available',
    };
    return translations[key] || key;
  },
}));

jest.mock('~/utils', () => ({
  cn: (...classes: string[]) => classes.filter(Boolean).join(' '),
}));

describe('AgentContact', () => {
  it('uses support contact before owner contact', () => {
    render(
      <AgentContact
        agent={{
          support_contact: { name: 'Support Team', email: '[email protected]' },
          owner_contact: { name: 'Owner User' },
        }}
      />,
    );

    expect(screen.getByText('Contact:')).toBeInTheDocument();
    expect(screen.getByRole('link', { name: 'Support Team' })).toHaveAttribute(
      'href',
      'mailto:[email protected]',
    );
    expect(screen.queryByText('Owner User')).not.toBeInTheDocument();
  });

  it('falls back to owner contact as a plain name without a mailto link', () => {
    const owner = { name: 'Owner User', email: '[email protected]' };
    render(<AgentContact agent={{ support_contact: undefined, owner_contact: owner }} />);

    expect(screen.getByText('Owner User')).toBeInTheDocument();
    expect(screen.queryByRole('link')).not.toBeInTheDocument();
  });

  it('renders no-contact text when no contact is available', () => {
    render(<AgentContact agent={{ support_contact: {}, owner_contact: undefined }} />);

    expect(screen.getByText('No contact available')).toBeInTheDocument();
  });

  it('omits missing contact information in compact card footers', () => {
    render(<AgentContact compact agent={{ support_contact: { name: '  ', email: ' ' } }} />);
    expect(screen.queryByText('No contact available')).not.toBeInTheDocument();
    expect(screen.queryByText('Contact:')).not.toBeInTheDocument();
  });

  it('keeps an explicit support link available in compact mode', () => {
    render(
      <AgentContact
        compact
        agent={{ support_contact: { name: '  Support Team ', email: ' [email protected] ' } }}
      />,
    );
    expect(screen.getByRole('link', { name: 'Support Team' })).toHaveAttribute(
      'href',
      'mailto:[email protected]',
    );
    expect(screen.queryByText('Contact:')).not.toBeInTheDocument();
  });
});