stream-chat-react-native-core 5.38.0-beta.2 → 5.38.0-beta.4

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.
@@ -115,7 +115,7 @@ export const Generic = () => {
115
115
  let allReactions;
116
116
  let allReads;
117
117
  const getRandomInt = (lower, upper) => Math.floor(lower + Math.random() * (upper - lower + 1));
118
- const createChannel = () => {
118
+ const createChannel = (messagesOverride) => {
119
119
  const id = uuidv4();
120
120
  const cid = `messaging:${id}`;
121
121
  const begin = getRandomInt(0, allUsers.length - 2); // begin shouldn't be the end of users.length
@@ -127,31 +127,33 @@ export const Generic = () => {
127
127
  user,
128
128
  }),
129
129
  );
130
- const messages = Array(10)
131
- .fill(1)
132
- .map(() => {
133
- const id = uuidv4();
134
- const user = usersForMembers[getRandomInt(0, usersForMembers.length - 1)];
135
-
136
- const begin = getRandomInt(0, usersForMembers.length - 2); // begin shouldn't be the end of users.length
137
- const end = getRandomInt(begin + 1, usersForMembers.length - 1);
138
-
139
- const usersForReactions = usersForMembers.slice(begin, end);
140
- const reactions = usersForReactions.map((user) =>
141
- generateReaction({
142
- message_id: id,
130
+ const messages =
131
+ messagesOverride ||
132
+ Array(10)
133
+ .fill(1)
134
+ .map(() => {
135
+ const id = uuidv4();
136
+ const user = usersForMembers[getRandomInt(0, usersForMembers.length - 1)];
137
+
138
+ const begin = getRandomInt(0, usersForMembers.length - 2); // begin shouldn't be the end of users.length
139
+ const end = getRandomInt(begin + 1, usersForMembers.length - 1);
140
+
141
+ const usersForReactions = usersForMembers.slice(begin, end);
142
+ const reactions = usersForReactions.map((user) =>
143
+ generateReaction({
144
+ message_id: id,
145
+ user,
146
+ }),
147
+ );
148
+ allReactions.push(...reactions);
149
+ return generateMessage({
150
+ cid,
151
+ id,
152
+ latest_reactions: reactions,
143
153
  user,
144
- }),
145
- );
146
- allReactions.push(...reactions);
147
- return generateMessage({
148
- cid,
149
- id,
150
- latest_reactions: reactions,
151
- user,
152
- userId: user.id,
154
+ userId: user.id,
155
+ });
153
156
  });
154
- });
155
157
 
156
158
  const reads = members.map((member) => ({
157
159
  last_read: new Date(new Date().setDate(new Date().getDate() - getRandomInt(0, 20))),
@@ -189,6 +191,7 @@ export const Generic = () => {
189
191
  afterEach(() => {
190
192
  BetterSqlite.dropAllTables();
191
193
  cleanup();
194
+ jest.clearAllMocks();
192
195
  });
193
196
 
194
197
  const filters = {
@@ -313,6 +316,21 @@ export const Generic = () => {
313
316
  expectAllChannelsWithStateToBeInDB(screen.queryAllByLabelText);
314
317
  });
315
318
 
319
+ it('should fetch channels from the db correctly even if they are empty', async () => {
320
+ const emptyChannel = createChannel([]);
321
+ useMockedApis(chatClient, [queryChannelsApi([emptyChannel])]);
322
+ jest.spyOn(chatClient, 'hydrateActiveChannels');
323
+
324
+ renderComponent();
325
+ await act(() => dispatchConnectionChangedEvent(chatClient));
326
+ await waitFor(() => {
327
+ expect(screen.getByTestId('channel-list')).toBeTruthy();
328
+ expect(screen.getByTestId(emptyChannel.cid)).toBeTruthy();
329
+ expect(chatClient.hydrateActiveChannels).toHaveBeenCalledTimes(2);
330
+ expect(chatClient.hydrateActiveChannels.mock.calls[0][0]).toStrictEqual([emptyChannel]);
331
+ });
332
+ });
333
+
316
334
  it('should add a new message to database', async () => {
317
335
  useMockedApis(chatClient, [queryChannelsApi(channels)]);
318
336
 
@@ -207,7 +207,7 @@ const CardWithContext = <
207
207
  imageStyle={styles.cardCover}
208
208
  resizeMode='cover'
209
209
  source={{ uri: makeImageCompatibleUrl(uri) }}
210
- style={[styles.cardCover, cover, stylesProp.cardCover]}
210
+ style={[styles.cardCover, stylesProp.cardCover, cover]}
211
211
  >
212
212
  {isVideoCard ? (
213
213
  <View
@@ -1110,6 +1110,10 @@ const ChannelWithContext = <
1110
1110
  isCurrent: false,
1111
1111
  isLatest: true,
1112
1112
  messages: [],
1113
+ pagination: {
1114
+ hasNext: true,
1115
+ hasPrev: true,
1116
+ },
1113
1117
  });
1114
1118
  });
1115
1119
 
@@ -40,9 +40,9 @@ export const getChannels = <
40
40
  // Enrich the channels with state
41
41
  return channels.map((c) => ({
42
42
  ...mapStorableToChannel<StreamChatGenerics>(c),
43
- members: cidVsMembers[c.cid],
44
- messages: cidVsMessages[c.cid],
43
+ members: cidVsMembers[c.cid] || [],
44
+ messages: cidVsMessages[c.cid] || [],
45
45
  pinned_messages: [],
46
- read: cidVsReads[c.cid],
46
+ read: cidVsReads[c.cid] || [],
47
47
  }));
48
48
  };
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "5.38.0-beta.2"
2
+ "version": "5.38.0-beta.4"
3
3
  }