File size: 1,418 Bytes
52efc7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

import { render } from '../../../test-utils/render.js';
import { describe, it, expect } from 'vitest';
import { ChatList } from './ChatList.js';
import type { ChatDetail } from '../../types.js';

const mockChats: ChatDetail[] = [
  {
    name: 'chat-1',
    mtime: '2025-10-02T10:00:00.000Z',
  },
  {
    name: 'another-chat',
    mtime: '2025-10-01T12:30:00.000Z',
  },
];

describe('<ChatList />', () => {
  it('renders correctly with a list of chats', async () => {
    const { lastFrame, unmount } = await render(<ChatList chats={mockChats} />);
    expect(lastFrame()).toMatchSnapshot();
    unmount();
  });

  it('renders correctly with no chats', async () => {
    const { lastFrame, unmount } = await render(<ChatList chats={[]} />);
    expect(lastFrame()).toContain('No saved conversation checkpoints found.');
    expect(lastFrame()).toMatchSnapshot();
    unmount();
  });

  it('handles invalid date formats gracefully', async () => {
    const mockChatsWithInvalidDate: ChatDetail[] = [
      {
        name: 'bad-date-chat',
        mtime: 'an-invalid-date-string',
      },
    ];
    const { lastFrame, unmount } = await render(
      <ChatList chats={mockChatsWithInvalidDate} />,
    );
    expect(lastFrame()).toContain('(Invalid Date)');
    expect(lastFrame()).toMatchSnapshot();
    unmount();
  });
});