Skip to content

Commit

Permalink
test: add more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
varshamenon4 committed Nov 22, 2024
1 parent 5a82ccb commit 0db591c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/components/ChatBox/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,21 @@ describe('<ChatBox />', () => {
expect(screen.queryByText('Today')).toBeInTheDocument();
});

// todo: correctly divides old and new messages, check order
it('correctly divides old and new messages', () => {
const today = new Date();
const messageList = [
{ role: 'user', content: 'hi yesterday', timestamp: today.setDate(today.getDate() - 1) },
{ role: 'user', content: 'hi today', timestamp: +Date.now() },
{ role: 'user', content: 'Today yesterday', timestamp: today.setDate(today.getDate() - 1) },
{ role: 'user', content: 'Today today', timestamp: +Date.now() },
];
const sliceState = {
messageList,
};
render(undefined, sliceState);

expect(screen.queryByText('hi yesterday')).toBeInTheDocument();
expect(screen.queryByText('hi today')).toBeInTheDocument();
expect(screen.queryByText('Today')).toBeInTheDocument();
const results = screen.getAllByText('Today', { exact: false });
expect(results.length).toBe(3);
expect(results[0]).toHaveTextContent('Today yesterday');
expect(results[1]).toHaveTextContent('Today');
expect(results[2]).toHaveTextContent('Today today');
});
});

0 comments on commit 0db591c

Please sign in to comment.