Skip to content

Commit

Permalink
Create Chat.test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored May 9, 2024
1 parent a5f7969 commit 056e879
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/models/Chat.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import Chat from '../../components/Chat';

describe('Chat', () => {
it('renders the Chat component', () => {
const { getByText } = render(<Chat />);
const chatTitle = getByText(/Chat/i);
expect(chatTitle).toBeInTheDocument();
});

it('renders the chat messages', () => {
const messages = ['Hello, world!', 'This is a test message.'];
const { getByTestId } = render(<Chat messages={messages} />);
const chatMessages = getByTestId('chat-messages');
expect(chatMessages).toHaveLength(messages.length);
});

it('allows users to send messages', () => {
const { getByLabelText, getByTestId } = render(<Chat />);
const chatInput = getByLabelText(/Send a message/i);
const chatMessages = getByTestId('chat-messages');
fireEvent.change(chatInput, { target: { value: 'Hello, test!' } });
fireEvent.submit(chatInput);
expect(chatMessages.children).toHaveLength(1);
});
});

0 comments on commit 056e879

Please sign in to comment.