Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

1.5 KB
Raw Blame
import { render, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';

import { getUserInitials, UserAvatar } from '@/atoms/UserAvatar.js';
import { CurrentUserProvider } from '@/contexts/CurrentUserContext.js';

describe('getUserInitials', () => {
  it.each([
    ['Ada Lovelace', 'A'],
    ['Ada King Lovelace', 'A'],
    ['Ada', 'A'],
    ['bob', 'B'],
    ['  ada   lovelace  ', 'A'],
    ['', ''],
    ['   ', ''],
  ])('returns the first character for %j', (displayName, expected) => {
    expect(getUserInitials(displayName)).toBe(expected);
  });
});

describe('UserAvatar', () => {
  it('shows the first character with the full display name underneath', () => {
    render(
      <CurrentUserProvider currentUser={{ displayName: 'Ada Lovelace' }}>
        <UserAvatar labeled />
      </CurrentUserProvider>,
    );

    const avatar = screen.getByLabelText('Ada Lovelace');
    expect(avatar).toHaveTextContent('A');
    expect(avatar).toHaveTextContent('Ada Lovelace');
    expect(avatar).toHaveAttribute('title', 'Ada Lovelace');
    expect(avatar).toHaveClass('w-14.5');
  });

  it('renders nothing without a non-empty display name', () => {
    const { container, rerender } = render(<UserAvatar />);
    expect(container).toBeEmptyDOMElement();

    rerender(
      <CurrentUserProvider currentUser={{ displayName: '   ' }}>
        <UserAvatar />
      </CurrentUserProvider>,
    );
    expect(container).toBeEmptyDOMElement();
  });
});