Skip to content

Commit 2357664

Browse files
ishammahajangnprice
authored andcommitted
Make pmConversationsSelectors-test.js flow strict.
The tests for `pmConversationsSelectors` are now `@flow strict-local`. To aid this process, we make use of the 'new' way of making tests, which is using `src/__tests__/exampleData.js`. A few examples of such tests include the unit tests at `src/users/__tests__/userSelectors-test.js` and `src/webview/html/__tests__/messageHeaderAsHtml-test.js`. Note that this is just a translation, and not a behavorial change.
1 parent 44d15d0 commit 2357664

File tree

1 file changed

+100
-106
lines changed

1 file changed

+100
-106
lines changed
Lines changed: 100 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,161 +1,155 @@
1-
import deepFreeze from 'deep-freeze';
1+
/* @flow strict-local */
22

33
import { getRecentConversations } from '../pmConversationsSelectors';
4+
import * as eg from '../../__tests__/lib/exampleData';
45

56
describe('getRecentConversations', () => {
67
test('when no recent conversations, return no conversations', () => {
7-
const state = deepFreeze({
8-
realm: { email: '[email protected]' },
9-
recentPrivateConversations: [],
10-
users: [{ user_id: 0, email: '[email protected]' }],
11-
unread: {
12-
pms: [],
13-
huddles: [],
14-
},
8+
const state = eg.reduxState({
9+
realm: eg.realmState({ email: eg.selfUser.email }),
10+
users: [eg.selfUser],
1511
});
1612

17-
const actual = getRecentConversations(state);
18-
19-
expect(actual).toEqual([]);
13+
expect(getRecentConversations(state)).toEqual([]);
2014
});
2115

2216
test('returns unique list of recipients, includes conversations with self', () => {
23-
const state = deepFreeze({
24-
realm: { email: '[email protected]' },
25-
recentPrivateConversations: [
26-
{ max_message_id: 4, user_ids: [] },
27-
{ max_message_id: 3, user_ids: [1] },
28-
{ max_message_id: 2, user_ids: [2] },
29-
{ max_message_id: 0, user_ids: [1, 2] },
17+
const users = [eg.selfUser, eg.makeUser({ name: 'john' }), eg.makeUser({ name: 'mark' })];
18+
const recentPrivateConversations = [
19+
{ max_message_id: 4, user_ids: [] },
20+
{ max_message_id: 3, user_ids: [users[1].user_id] },
21+
{ max_message_id: 2, user_ids: [users[2].user_id] },
22+
{ max_message_id: 0, user_ids: [users[1].user_id, users[2].user_id] },
23+
];
24+
const unread = {
25+
streams: [],
26+
huddles: [
27+
{
28+
user_ids_string: [eg.selfUser.user_id, users[1].user_id, users[2].user_id]
29+
.sort((a, b) => a - b)
30+
.join(),
31+
unread_message_ids: [5],
32+
},
3033
],
31-
users: [
32-
{ user_id: 0, email: '[email protected]' },
33-
{ user_id: 1, email: '[email protected]' },
34-
{ user_id: 2, email: '[email protected]' },
34+
pms: [
35+
{
36+
sender_id: eg.selfUser.user_id,
37+
unread_message_ids: [4],
38+
},
39+
{
40+
sender_id: users[1].user_id,
41+
unread_message_ids: [1, 3],
42+
},
43+
{
44+
sender_id: users[2].user_id,
45+
unread_message_ids: [2],
46+
},
3547
],
36-
unread: {
37-
pms: [
38-
{
39-
sender_id: 0,
40-
unread_message_ids: [4],
41-
},
42-
{
43-
sender_id: 1,
44-
unread_message_ids: [1, 3],
45-
},
46-
{
47-
sender_id: 2,
48-
unread_message_ids: [2],
49-
},
50-
],
51-
huddles: [
52-
{
53-
user_ids_string: '0,1,2',
54-
unread_message_ids: [5],
55-
},
56-
],
57-
},
48+
mentions: [],
49+
};
50+
51+
const state = eg.reduxState({
52+
realm: eg.realmState({ email: eg.selfUser.email }),
53+
users,
54+
recentPrivateConversations,
55+
unread,
5856
});
5957

60-
const expectedResult = [
58+
expect(getRecentConversations(state)).toEqual([
6159
{
62-
ids: '0',
63-
recipients: '[email protected]',
60+
ids: eg.selfUser.user_id.toString(),
61+
recipients: eg.selfUser.email,
6462
msgId: 4,
6563
unread: 1,
6664
},
6765
{
68-
ids: '1',
69-
recipients: '[email protected]',
66+
ids: users[1].user_id.toString(),
67+
recipients: users[1].email,
7068
msgId: 3,
7169
unread: 2,
7270
},
7371
{
74-
ids: '2',
75-
recipients: '[email protected]',
72+
ids: users[2].user_id.toString(),
73+
recipients: users[2].email,
7674
msgId: 2,
7775
unread: 1,
7876
},
7977
{
80-
ids: '0,1,2',
81-
78+
ids: [eg.selfUser.user_id, users[1].user_id, users[2].user_id].sort((a, b) => a - b).join(),
79+
recipients: [users[1].email, users[2].email].join(),
8280
msgId: 0,
8381
unread: 1,
8482
},
85-
];
86-
87-
const actual = getRecentConversations(state);
88-
89-
expect(actual).toEqual(expectedResult);
83+
]);
9084
});
9185

9286
test('returns recipients sorted by last activity', () => {
93-
const state = deepFreeze({
94-
realm: { email: '[email protected]' },
95-
recentPrivateConversations: [
96-
{ max_message_id: 6, user_ids: [] },
97-
{ max_message_id: 5, user_ids: [1, 2] },
98-
{ max_message_id: 4, user_ids: [1] },
99-
{ max_message_id: 3, user_ids: [2] },
87+
const users = [eg.selfUser, eg.makeUser({ name: 'john' }), eg.makeUser({ name: 'mark' })];
88+
const recentPrivateConversations = [
89+
{ max_message_id: 6, user_ids: [] },
90+
{ max_message_id: 5, user_ids: [users[1].user_id, users[2].user_id] },
91+
{ max_message_id: 4, user_ids: [users[1].user_id] },
92+
{ max_message_id: 3, user_ids: [users[2].user_id] },
93+
];
94+
const unread = {
95+
streams: [],
96+
huddles: [
97+
{
98+
user_ids_string: [eg.selfUser.user_id, users[1].user_id, users[2].user_id]
99+
.sort((a, b) => a - b)
100+
.join(),
101+
unread_message_ids: [5],
102+
},
100103
],
101-
users: [
102-
{ user_id: 0, email: '[email protected]' },
103-
{ user_id: 1, email: '[email protected]' },
104-
{ user_id: 2, email: '[email protected]' },
104+
pms: [
105+
{
106+
sender_id: eg.selfUser.user_id,
107+
unread_message_ids: [4],
108+
},
109+
{
110+
sender_id: users[1].user_id,
111+
unread_message_ids: [1, 3],
112+
},
113+
{
114+
sender_id: users[2].user_id,
115+
unread_message_ids: [2],
116+
},
105117
],
106-
unread: {
107-
pms: [
108-
{
109-
sender_id: 0,
110-
unread_message_ids: [4],
111-
},
112-
{
113-
sender_id: 1,
114-
unread_message_ids: [1, 3],
115-
},
116-
{
117-
sender_id: 2,
118-
unread_message_ids: [2],
119-
},
120-
],
121-
huddles: [
122-
{
123-
user_ids_string: '0,1,2',
124-
unread_message_ids: [5],
125-
},
126-
],
127-
},
118+
mentions: [],
119+
};
120+
121+
const state = eg.reduxState({
122+
realm: eg.realmState({ email: eg.selfUser.email }),
123+
users,
124+
recentPrivateConversations,
125+
unread,
128126
});
129127

130-
const expectedResult = [
128+
expect(getRecentConversations(state)).toEqual([
131129
{
132-
ids: '0',
133-
recipients: '[email protected]',
130+
ids: eg.selfUser.user_id.toString(),
131+
recipients: eg.selfUser.email,
134132
msgId: 6,
135133
unread: 1,
136134
},
137135
{
138-
ids: '0,1,2',
139-
136+
ids: [eg.selfUser.user_id, users[1].user_id, users[2].user_id].sort((a, b) => a - b).join(),
137+
recipients: [users[1].email, users[2].email].join(),
140138
msgId: 5,
141139
unread: 1,
142140
},
143141
{
144-
ids: '1',
145-
recipients: '[email protected]',
142+
ids: users[1].user_id.toString(),
143+
recipients: users[1].email,
146144
msgId: 4,
147145
unread: 2,
148146
},
149147
{
150-
ids: '2',
151-
recipients: '[email protected]',
148+
ids: users[2].user_id.toString(),
149+
recipients: users[2].email,
152150
msgId: 3,
153151
unread: 1,
154152
},
155-
];
156-
157-
const actual = getRecentConversations(state);
158-
159-
expect(actual).toEqual(expectedResult);
153+
]);
160154
});
161155
});

0 commit comments

Comments
 (0)