Skip to content

Commit 7488792

Browse files
ishammahajangnprice
authored andcommitted
recent convs: Add new tests for new selector implementation.
Based closely on the tests for the old implementation. Taken with minimal changes from PR zulip#3535. Co-authored-by: Greg Price <[email protected]> [ray: ported from old PR; wrote new commit message for new context.]
1 parent df31fc7 commit 7488792

File tree

1 file changed

+155
-0
lines changed

1 file changed

+155
-0
lines changed

src/pm-conversations/__tests__/pmConversationsSelectors-test.js

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,158 @@ describe('getRecentConversations: legacy', () => {
135135
expect(actual).toEqual(expectedResult);
136136
});
137137
});
138+
139+
describe('getRecentConversations: modern', () => {
140+
const zulipVersion = new ZulipVersion('2.2.0');
141+
142+
test('when no recent conversations, return no conversations', () => {
143+
const state = eg.reduxState({
144+
accounts: [eg.makeAccount({ user: eg.selfUser, zulipVersion })],
145+
realm: eg.realmState({ email: eg.selfUser.email }),
146+
users: [eg.selfUser],
147+
});
148+
149+
expect(getRecentConversations(state)).toEqual([]);
150+
});
151+
152+
test('returns unique list of recipients, includes conversations with self', () => {
153+
const users = [eg.selfUser, eg.makeUser({ name: 'john' }), eg.makeUser({ name: 'mark' })];
154+
const recentPrivateConversations = [
155+
{ max_message_id: 4, user_ids: [] },
156+
{ max_message_id: 3, user_ids: [users[1].user_id] },
157+
{ max_message_id: 2, user_ids: [users[2].user_id] },
158+
{ max_message_id: 0, user_ids: [users[1].user_id, users[2].user_id] },
159+
];
160+
const unread = {
161+
...eg.baseReduxState.unread,
162+
huddles: [
163+
{
164+
user_ids_string: [eg.selfUser.user_id, users[1].user_id, users[2].user_id]
165+
.sort((a, b) => a - b)
166+
.join(),
167+
unread_message_ids: [5],
168+
},
169+
],
170+
pms: [
171+
{
172+
sender_id: eg.selfUser.user_id,
173+
unread_message_ids: [4],
174+
},
175+
{
176+
sender_id: users[1].user_id,
177+
unread_message_ids: [1, 3],
178+
},
179+
{
180+
sender_id: users[2].user_id,
181+
unread_message_ids: [2],
182+
},
183+
],
184+
};
185+
186+
const state = eg.reduxState({
187+
accounts: [eg.makeAccount({ user: eg.selfUser, zulipVersion })],
188+
realm: eg.realmState({ email: eg.selfUser.email }),
189+
users,
190+
recentPrivateConversations,
191+
unread,
192+
});
193+
194+
expect(getRecentConversations(state)).toEqual([
195+
{
196+
key: eg.selfUser.user_id.toString(),
197+
keyRecipients: [],
198+
msgId: 4,
199+
unread: 1,
200+
},
201+
{
202+
key: users[1].user_id.toString(),
203+
keyRecipients: [users[1]],
204+
msgId: 3,
205+
unread: 2,
206+
},
207+
{
208+
key: users[2].user_id.toString(),
209+
keyRecipients: [users[2]],
210+
msgId: 2,
211+
unread: 1,
212+
},
213+
{
214+
key: [eg.selfUser.user_id, users[1].user_id, users[2].user_id].sort((a, b) => a - b).join(),
215+
keyRecipients: [users[1], users[2]].sort((a, b) => a.user_id - b.user_id),
216+
msgId: 0,
217+
unread: 1,
218+
},
219+
]);
220+
});
221+
222+
test('returns recipients sorted by last activity', () => {
223+
const users = [eg.selfUser, eg.makeUser({ name: 'john' }), eg.makeUser({ name: 'mark' })];
224+
const recentPrivateConversations = [
225+
{ max_message_id: 6, user_ids: [] },
226+
{ max_message_id: 5, user_ids: [users[1].user_id, users[2].user_id] },
227+
{ max_message_id: 4, user_ids: [users[1].user_id] },
228+
{ max_message_id: 3, user_ids: [users[2].user_id] },
229+
];
230+
const unread = {
231+
streams: [],
232+
huddles: [
233+
{
234+
user_ids_string: [eg.selfUser.user_id, users[1].user_id, users[2].user_id]
235+
.sort((a, b) => a - b)
236+
.join(),
237+
unread_message_ids: [5],
238+
},
239+
],
240+
pms: [
241+
{
242+
sender_id: eg.selfUser.user_id,
243+
unread_message_ids: [4],
244+
},
245+
{
246+
sender_id: users[1].user_id,
247+
unread_message_ids: [1, 3],
248+
},
249+
{
250+
sender_id: users[2].user_id,
251+
unread_message_ids: [2],
252+
},
253+
],
254+
mentions: [],
255+
};
256+
257+
const state = eg.reduxState({
258+
accounts: [eg.makeAccount({ user: eg.selfUser, zulipVersion })],
259+
realm: eg.realmState({ email: eg.selfUser.email }),
260+
users,
261+
recentPrivateConversations,
262+
unread,
263+
});
264+
265+
expect(getRecentConversations(state)).toEqual([
266+
{
267+
key: eg.selfUser.user_id.toString(),
268+
keyRecipients: [],
269+
msgId: 6,
270+
unread: 1,
271+
},
272+
{
273+
key: [eg.selfUser.user_id, users[1].user_id, users[2].user_id].sort((a, b) => a - b).join(),
274+
keyRecipients: [users[1], users[2]].sort((a, b) => a.user_id - b.user_id),
275+
msgId: 5,
276+
unread: 1,
277+
},
278+
{
279+
key: users[1].user_id.toString(),
280+
keyRecipients: [users[1]],
281+
msgId: 4,
282+
unread: 2,
283+
},
284+
{
285+
key: users[2].user_id.toString(),
286+
keyRecipients: [users[2]],
287+
msgId: 3,
288+
unread: 1,
289+
},
290+
]);
291+
});
292+
});

0 commit comments

Comments
 (0)