-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCI.test.tsx
53 lines (47 loc) · 1.79 KB
/
CI.test.tsx
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
53
import { render, screen, fireEvent } from '@testing-library/react';
import ChatInterface from './ChatInterface';
const mockProps = {
theme: 'light',
currentConversationId: 1,
setCurrentConversationId: jest.fn(),
conversations: [
{
id: 1,
title: 'Conversation 1',
messages: [
{ role: 'user', content: 'Hello' },
{ role: 'bot', content: 'Hi there!' }
]
}
],
setConversations: jest.fn()
};
test('renders chat interface with initial state', () => {
render(<ChatInterface {...mockProps} />);
expect(screen.getByPlaceholderText('Type a message...')).toBeInTheDocument();
expect(screen.getByText('Hi there!')).toBeInTheDocument();
});
test('updates input field on typing', () => {
render(<ChatInterface {...mockProps} />);
const inputField = screen.getByPlaceholderText('Type a message...');
fireEvent.change(inputField, { target: { value: 'New message' } });
expect(inputField.value).toBe('New message');
});
test('sends message on send button click', () => {
render(<ChatInterface {...mockProps} />);
const inputField = screen.getByPlaceholderText('Type a message...');
fireEvent.change(inputField, { target: { value: 'New message' } });
fireEvent.click(screen.getByRole('button', { name: /send/i }));
expect(mockProps.setConversations).toHaveBeenCalled();
});
test('shows bot typing indicator when bot is typing', () => {
render(<ChatInterface {...mockProps} />);
fireEvent.click(screen.getByText('Send Message'));
expect(screen.getByText('Bot is typing...')).toBeInTheDocument();
});
test('updates selected option', () => {
render(<ChatInterface {...mockProps} />);
const selectField = screen.getByRole('combobox');
fireEvent.change(selectField, { target: { value: 'New option' } });
expect(selectField.value).toBe('New option');
});