From c12f80678b1316c5c05ed4308ec66dcb1e225a17 Mon Sep 17 00:00:00 2001 From: Anton Arnautov <43254280+arnautov-anton@users.noreply.github.com> Date: Sat, 21 Sep 2024 00:07:04 +0200 Subject: [PATCH] chore(tests): adjust problematic tests with proper created_at (#2516) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### 🎯 Goal Follow-up for [#1370](https://github.com/GetStream/stream-chat-js/pull/1370/files). --- .../Channel/__tests__/Channel.test.js | 48 +++++++++++++------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/src/components/Channel/__tests__/Channel.test.js b/src/components/Channel/__tests__/Channel.test.js index ed83503b2..298a0f4fc 100644 --- a/src/components/Channel/__tests__/Channel.test.js +++ b/src/components/Channel/__tests__/Channel.test.js @@ -565,8 +565,12 @@ describe('Channel', () => { const { channel, chatClient } = await initClient(); const getRepliesSpy = jest.spyOn(channel, 'getReplies'); const threadMessage = messages[0]; - const replies = Array.from({ length: DEFAULT_THREAD_PAGE_SIZE }, () => - generateMessage({ parent_id: threadMessage.id }), + const timestamp = new Date('2024-01-01T00:00:00.000Z').getTime(); + const replies = Array.from({ length: DEFAULT_THREAD_PAGE_SIZE }, (_, index) => + generateMessage({ + created_at: new Date(timestamp + index * 1000), + parent_id: threadMessage.id, + }), ); useMockedApis(chatClient, [threadRepliesApi(replies)]); @@ -1241,16 +1245,23 @@ describe('Channel', () => { }); }); + // const timestamp = new Date('2024-01-01T00:00:00.000Z').getTime(); it.each([ [ false, 'last page', 'first unread message', [ - generateMessage(), - generateMessage({ id: last_read_message_id }), - generateMessage({ id: first_unread_message_id }), - generateMessage(), + generateMessage({ created_at: new Date('2024-01-01T00:00:00.000Z') }), + generateMessage({ + created_at: new Date('2024-01-01T00:00:00.001Z'), + id: last_read_message_id, + }), + generateMessage({ + created_at: new Date('2024-01-01T00:00:00.002Z'), + id: first_unread_message_id, + }), + generateMessage({ created_at: new Date('2024-01-01T00:00:00.003Z') }), ], first_unread_message_id, ], @@ -1259,10 +1270,16 @@ describe('Channel', () => { 'other than last page', 'first unread message', [ - generateMessage(), - generateMessage(), - generateMessage({ id: last_read_message_id }), - generateMessage({ id: first_unread_message_id }), + generateMessage({ created_at: new Date('2024-01-01T00:00:00.000Z') }), + generateMessage({ created_at: new Date('2024-01-01T00:00:00.001Z') }), + generateMessage({ + created_at: new Date('2024-01-01T00:00:00.002Z'), + id: last_read_message_id, + }), + generateMessage({ + created_at: new Date('2024-01-01T00:00:00.003Z'), + id: first_unread_message_id, + }), ], first_unread_message_id, ], @@ -1271,10 +1288,13 @@ describe('Channel', () => { 'other than last page', 'last read message', [ - generateMessage(), - generateMessage(), - generateMessage(), - generateMessage({ id: last_read_message_id }), + generateMessage({ created_at: new Date('2024-01-01T00:00:00.000Z') }), + generateMessage({ created_at: new Date('2024-01-01T00:00:00.001Z') }), + generateMessage({ created_at: new Date('2024-01-01T00:00:00.002Z') }), + generateMessage({ + created_at: new Date('2024-01-01T00:00:00.003Z'), + id: last_read_message_id, + }), ], undefined, ],