From 0db591cfc6f5687bd34c0e690a17cd7e0a1ea63c Mon Sep 17 00:00:00 2001 From: Varsha Menon Date: Thu, 21 Nov 2024 21:00:17 -0500 Subject: [PATCH] test: add more testing --- src/components/ChatBox/index.test.jsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/ChatBox/index.test.jsx b/src/components/ChatBox/index.test.jsx index 915199a6..889ac6de 100644 --- a/src/components/ChatBox/index.test.jsx +++ b/src/components/ChatBox/index.test.jsx @@ -82,20 +82,21 @@ describe('', () => { 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'); }); });