stream-chat-react-native-core 5.4.1 → 5.4.2-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,67 @@
1
+ import React, { FC } from 'react';
2
+
3
+ import { renderHook } from '@testing-library/react-hooks';
4
+ import type { DefaultStreamChatGenerics } from 'src/types/types';
5
+ import type { DefaultGenerics, StreamChat } from 'stream-chat';
6
+
7
+ import { useCreatePaginatedMessageListContext } from '../../../components/Channel/hooks/useCreatePaginatedMessageListContext';
8
+ import {
9
+ ChatContext,
10
+ ChatContextValue,
11
+ PaginatedMessageListContextValue,
12
+ PaginatedMessageListProvider,
13
+ } from '../../../contexts';
14
+
15
+ import { generateMessage } from '../../../mock-builders/generator/message';
16
+ import { generateUser } from '../../../mock-builders/generator/user';
17
+ import { getTestClientWithUser } from '../../../mock-builders/mock';
18
+ import { useMessageList } from '../hooks/useMessageList';
19
+
20
+ jest.mock('react-native-fs', () => ({}));
21
+
22
+ const clientUser = generateUser();
23
+ let chatClient: StreamChat<DefaultGenerics> | StreamChat<DefaultStreamChatGenerics>;
24
+
25
+ beforeEach(async () => {
26
+ chatClient = await getTestClientWithUser(clientUser);
27
+ });
28
+
29
+ const messages = new Array(10)
30
+ .fill(undefined)
31
+ .map((_: undefined, id: number) => generateMessage({ id }));
32
+
33
+ const Providers: FC<{ children: React.ReactNode }> = ({ children }) => {
34
+ const messageListContext = useCreatePaginatedMessageListContext({
35
+ messages,
36
+ } as unknown as PaginatedMessageListContextValue);
37
+
38
+ return (
39
+ <ChatContext.Provider
40
+ value={
41
+ {
42
+ auto_translation_enabled: true,
43
+ client: chatClient,
44
+ } as unknown as ChatContextValue
45
+ }
46
+ >
47
+ <PaginatedMessageListProvider value={messageListContext}>
48
+ {children}
49
+ </PaginatedMessageListProvider>
50
+ </ChatContext.Provider>
51
+ );
52
+ };
53
+
54
+ describe('useMessageList', () => {
55
+ it('should always return a list of reversed messages', () => {
56
+ const { result } = renderHook(
57
+ () =>
58
+ useMessageList({
59
+ noGroupByUser: true,
60
+ threadList: false,
61
+ }),
62
+ { wrapper: Providers },
63
+ );
64
+ const reversedMessages = messages.reverse();
65
+ expect(result.current.map(({ id }) => id)).toEqual(reversedMessages.map(({ id }) => id));
66
+ });
67
+ });
@@ -18,7 +18,6 @@ import { getReadStates } from '../utils/getReadStates';
18
18
 
19
19
  export type UseMessageListParams = {
20
20
  deletedMessagesVisibilityType?: DeletedMessagesVisibilityType;
21
- inverted?: boolean;
22
21
  noGroupByUser?: boolean;
23
22
  threadList?: boolean;
24
23
  };
@@ -52,7 +51,7 @@ export const useMessageList = <
52
51
  >(
53
52
  params: UseMessageListParams,
54
53
  ) => {
55
- const { inverted, noGroupByUser, threadList } = params;
54
+ const { noGroupByUser, threadList } = params;
56
55
  const { client } = useChatContext<StreamChatGenerics>();
57
56
  const { hideDateSeparators, maxTimeBetweenGroupedMessages, read } =
58
57
  useChannelContext<StreamChatGenerics>();
@@ -104,9 +103,7 @@ export const useMessageList = <
104
103
  readBy: msg.id ? readData[msg.id] || false : false,
105
104
  }));
106
105
 
107
- return (
108
- inverted
109
- ? messagesWithStylesReadByAndDateSeparator.reverse()
110
- : messagesWithStylesReadByAndDateSeparator
111
- ) as MessageType<StreamChatGenerics>[];
106
+ return [
107
+ ...messagesWithStylesReadByAndDateSeparator,
108
+ ].reverse() as MessageType<StreamChatGenerics>[];
112
109
  };
@@ -8,7 +8,7 @@ export const generateMessage = (options = {}) => {
8
8
 
9
9
  return {
10
10
  attachments: [],
11
- created_at: timestamp.toString(),
11
+ created_at: timestamp,
12
12
  html: '<p>regular</p>',
13
13
  id: uuidv4(),
14
14
  text: uuidv4(),
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "5.4.1"
2
+ "version": "5.4.2-beta.1"
3
3
  }