@@ -18,193 +18,170 @@ describe('userGroupsReducer', () => {
18
18
const group = eg . makeUserGroup ( ) ;
19
19
20
20
const prevState = deepFreeze ( eg . plusReduxState . userGroups ) ;
21
-
22
- const action = eg . mkActionRegisterComplete ( { realm_user_groups : [ group ] } ) ;
23
-
24
- const actualState = userGroupsReducer ( prevState , action ) ;
25
-
26
- expect ( actualState ) . toEqual ( [ group ] ) ;
21
+ expect (
22
+ userGroupsReducer ( prevState , eg . mkActionRegisterComplete ( { realm_user_groups : [ group ] } ) ) ,
23
+ ) . toEqual ( [ group ] ) ;
27
24
} ) ;
28
25
29
26
// TODO(#5102): Remove this test case, which is for pre-1.8 servers.
30
27
test ( 'when no data is given reset state' , ( ) => {
31
28
const prevState = deepFreeze ( [ eg . makeUserGroup ( ) ] ) ;
32
- const action = eg . mkActionRegisterComplete ( {
33
- // Hmm, we should need a Flow suppression here. This property is
34
- // marked required in InitialData, and this explicit undefined is
35
- // meant to defy that; see TODO(#5102) above.
36
- // mkActionRegisterComplete is designed to accept input with this or
37
- // any property *omitted*… and I think, as a side effect of handling
38
- // that, Flow mistakenly accepts an explicit undefined here, so it
39
- // doesn't catch the resulting malformed InitialData.
40
- realm_user_groups : undefined ,
41
- } ) ;
42
- const expectedState = [ ] ;
43
-
44
- const actualState = userGroupsReducer ( prevState , action ) ;
45
-
46
- expect ( actualState ) . toEqual ( expectedState ) ;
29
+ expect (
30
+ userGroupsReducer (
31
+ prevState ,
32
+ eg . mkActionRegisterComplete ( {
33
+ // Hmm, we should need a Flow suppression here. This property is
34
+ // marked required in InitialData, and this explicit undefined is
35
+ // meant to defy that; see TODO(#5102) above.
36
+ // mkActionRegisterComplete is designed to accept input with this or
37
+ // any property *omitted*… and I think, as a side effect of handling
38
+ // that, Flow mistakenly accepts an explicit undefined here, so it
39
+ // doesn't catch the resulting malformed InitialData.
40
+ realm_user_groups : undefined ,
41
+ } ) ,
42
+ ) ,
43
+ ) . toEqual ( [ ] ) ;
47
44
} ) ;
48
45
} ) ;
49
46
50
47
describe ( 'ACCOUNT_SWITCH' , ( ) => {
51
48
test ( 'resets state to initial state' , ( ) => {
52
49
const prevState = deepFreeze ( [ eg . makeUserGroup ( ) ] ) ;
53
-
54
- const action = eg . action . account_switch ;
55
-
56
- const expectedState = [ ] ;
57
-
58
- const actualState = userGroupsReducer ( prevState , action ) ;
59
-
60
- expect ( actualState ) . toEqual ( expectedState ) ;
50
+ expect ( userGroupsReducer ( prevState , eg . action . account_switch ) ) . toEqual ( [ ] ) ;
61
51
} ) ;
62
52
} ) ;
63
53
64
54
describe ( 'EVENT_USER_GROUP_ADD' , ( ) => {
65
55
test ( 'adds a user group to the state' , ( ) => {
66
- const prevState = deepFreeze ( [ ] ) ;
67
56
const group = eg . makeUserGroup ( ) ;
68
- const action = deepFreeze ( {
69
- id : 1 ,
70
- type : EVENT_USER_GROUP_ADD ,
71
- op : 'add' ,
72
- group,
73
- } ) ;
74
-
75
- const expectedState = [ group ] ;
76
57
77
- const actualState = userGroupsReducer ( prevState , action ) ;
78
-
79
- expect ( actualState ) . toEqual ( expectedState ) ;
58
+ const prevState = deepFreeze ( [ ] ) ;
59
+ expect (
60
+ userGroupsReducer (
61
+ prevState ,
62
+ deepFreeze ( { id : 1 , type : EVENT_USER_GROUP_ADD , op : 'add' , group } ) ,
63
+ ) ,
64
+ ) . toEqual ( [ group ] ) ;
80
65
} ) ;
81
66
} ) ;
82
67
83
68
describe ( 'EVENT_USER_GROUP_REMOVE' , ( ) => {
84
69
test ( 'if user group does not exist state does not change' , ( ) => {
85
70
const prevState = deepFreeze ( [ ] ) ;
86
- const action = deepFreeze ( {
87
- id : 1 ,
88
- type : EVENT_USER_GROUP_REMOVE ,
89
- op : 'remove' ,
90
- group_id : 1 ,
91
- } ) ;
92
- const expectedState = [ ] ;
93
-
94
- const actualState = userGroupsReducer ( prevState , action ) ;
95
-
96
- expect ( actualState ) . toEqual ( expectedState ) ;
71
+ expect (
72
+ userGroupsReducer (
73
+ prevState ,
74
+ deepFreeze ( { id : 1 , type : EVENT_USER_GROUP_REMOVE , op : 'remove' , group_id : 1 } ) ,
75
+ ) ,
76
+ ) . toEqual ( [ ] ) ;
97
77
} ) ;
98
78
99
79
test ( 'adds a user group to the state' , ( ) => {
100
80
const group1 = eg . makeUserGroup ( ) ;
101
81
const group2 = eg . makeUserGroup ( ) ;
102
82
103
83
const prevState = deepFreeze ( [ group1 , group2 ] ) ;
104
- const action = deepFreeze ( {
105
- id : 1 ,
106
- type : EVENT_USER_GROUP_REMOVE ,
107
- op : 'remove' ,
108
- group_id : group1 . id ,
109
- } ) ;
110
-
111
- const expectedState = [ group2 ] ;
112
-
113
- const actualState = userGroupsReducer ( prevState , action ) ;
114
-
115
- expect ( actualState ) . toEqual ( expectedState ) ;
84
+ expect (
85
+ userGroupsReducer (
86
+ prevState ,
87
+ deepFreeze ( { id : 1 , type : EVENT_USER_GROUP_REMOVE , op : 'remove' , group_id : group1 . id } ) ,
88
+ ) ,
89
+ ) . toEqual ( [ group2 ] ) ;
116
90
} ) ;
117
91
} ) ;
118
92
119
93
describe ( 'EVENT_USER_GROUP_UPDATE' , ( ) => {
120
94
test ( 'if user group does not exist state does not change' , ( ) => {
121
95
const prevState = deepFreeze ( [ ] ) ;
122
- const action = deepFreeze ( {
123
- id : 1 ,
124
- type : EVENT_USER_GROUP_UPDATE ,
125
- op : 'update' ,
126
- group_id : 1 ,
127
- data : { name : 'Some name' } ,
128
- } ) ;
129
- const expectedState = [ ] ;
130
-
131
- const actualState = userGroupsReducer ( prevState , action ) ;
132
-
133
- expect ( actualState ) . toEqual ( expectedState ) ;
96
+ expect (
97
+ userGroupsReducer (
98
+ prevState ,
99
+ deepFreeze ( {
100
+ id : 1 ,
101
+ type : EVENT_USER_GROUP_UPDATE ,
102
+ op : 'update' ,
103
+ group_id : 1 ,
104
+ data : { name : 'Some name' } ,
105
+ } ) ,
106
+ ) ,
107
+ ) . toEqual ( [ ] ) ;
134
108
} ) ;
135
109
136
110
test ( 'updates an existing user group with supplied new values' , ( ) => {
137
111
const group1 = eg . makeUserGroup ( ) ;
138
112
const group2 = eg . makeUserGroup ( ) ;
139
113
140
114
const prevState = deepFreeze ( [ group1 , group2 ] ) ;
141
- const action = deepFreeze ( {
142
- id : 1 ,
143
- type : EVENT_USER_GROUP_UPDATE ,
144
- op : 'update' ,
145
- group_id : group2 . id ,
146
- data : { name : 'New name' } ,
147
- } ) ;
148
- const expectedState = [ group1 , { ... group2 , name : 'New name' } ] ;
149
-
150
- const actualState = userGroupsReducer ( prevState , action ) ;
151
-
152
- expect ( actualState ) . toEqual ( expectedState ) ;
115
+ expect (
116
+ userGroupsReducer (
117
+ prevState ,
118
+ deepFreeze ( {
119
+ id : 1 ,
120
+ type : EVENT_USER_GROUP_UPDATE ,
121
+ op : 'update' ,
122
+ group_id : group2 . id ,
123
+ data : { name : 'New name' } ,
124
+ } ) ,
125
+ ) ,
126
+ ) . toEqual ( [ group1 , { ... group2 , name : 'New name' } ] ) ;
153
127
} ) ;
154
128
} ) ;
155
129
156
130
describe ( 'EVENT_USER_GROUP_ADD_MEMBERS' , ( ) => {
157
131
test ( 'if user group does not exist state does not change' , ( ) => {
158
132
const prevState = deepFreeze ( [ ] ) ;
159
- const action = deepFreeze ( {
160
- id : 1 ,
161
- type : EVENT_USER_GROUP_ADD_MEMBERS ,
162
- op : 'add_members' ,
163
- group_id : 1 ,
164
- user_ids : [ eg . makeUser ( ) . user_id , eg . makeUser ( ) . user_id , eg . makeUser ( ) . user_id ] ,
165
- } ) ;
166
- const expectedState = [ ] ;
167
-
168
- const actualState = userGroupsReducer ( prevState , action ) ;
169
133
170
- expect ( actualState ) . toEqual ( expectedState ) ;
134
+ expect (
135
+ userGroupsReducer (
136
+ prevState ,
137
+ deepFreeze ( {
138
+ id : 1 ,
139
+ type : EVENT_USER_GROUP_ADD_MEMBERS ,
140
+ op : 'add_members' ,
141
+ group_id : 1 ,
142
+ user_ids : [ eg . makeUser ( ) . user_id , eg . makeUser ( ) . user_id , eg . makeUser ( ) . user_id ] ,
143
+ } ) ,
144
+ ) ,
145
+ ) . toEqual ( [ ] ) ;
171
146
} ) ;
172
147
173
148
test ( 'updates an existing user group with supplied new members' , ( ) => {
174
149
const group = eg . makeUserGroup ( { members : [ eg . selfUser . user_id ] } ) ;
150
+
175
151
const prevState = deepFreeze ( [ group ] ) ;
176
- const action = deepFreeze ( {
177
- id : 1 ,
178
- type : EVENT_USER_GROUP_ADD_MEMBERS ,
179
- op : 'add_members' ,
180
- group_id : group . id ,
181
- user_ids : [ eg . otherUser . user_id , eg . thirdUser . user_id ] ,
182
- } ) ;
183
- const expectedState = [
152
+ expect (
153
+ userGroupsReducer (
154
+ prevState ,
155
+ deepFreeze ( {
156
+ id : 1 ,
157
+ type : EVENT_USER_GROUP_ADD_MEMBERS ,
158
+ op : 'add_members' ,
159
+ group_id : group . id ,
160
+ user_ids : [ eg . otherUser . user_id , eg . thirdUser . user_id ] ,
161
+ } ) ,
162
+ ) ,
163
+ ) . toEqual ( [
184
164
{ ...group , members : [ eg . selfUser . user_id , eg . otherUser . user_id , eg . thirdUser . user_id ] } ,
185
- ] ;
186
-
187
- const actualState = userGroupsReducer ( prevState , action ) ;
188
-
189
- expect ( actualState ) . toEqual ( expectedState ) ;
165
+ ] ) ;
190
166
} ) ;
191
167
} ) ;
192
168
193
169
describe ( 'EVENT_USER_GROUP_REMOVE_MEMBERS' , ( ) => {
194
170
test ( 'if user group does not exist state does not change' , ( ) => {
195
171
const prevState = deepFreeze ( [ ] ) ;
196
- const action = deepFreeze ( {
197
- id : 1 ,
198
- type : EVENT_USER_GROUP_REMOVE_MEMBERS ,
199
- op : 'remove_members' ,
200
- group_id : 1 ,
201
- user_ids : [ eg . makeUser ( ) . user_id ] ,
202
- } ) ;
203
- const expectedState = [ ] ;
204
172
205
- const actualState = userGroupsReducer ( prevState , action ) ;
206
-
207
- expect ( actualState ) . toEqual ( expectedState ) ;
173
+ expect (
174
+ userGroupsReducer (
175
+ prevState ,
176
+ deepFreeze ( {
177
+ id : 1 ,
178
+ type : EVENT_USER_GROUP_REMOVE_MEMBERS ,
179
+ op : 'remove_members' ,
180
+ group_id : 1 ,
181
+ user_ids : [ eg . makeUser ( ) . user_id ] ,
182
+ } ) ,
183
+ ) ,
184
+ ) . toEqual ( [ ] ) ;
208
185
} ) ;
209
186
210
187
test ( 'removes members from an existing user group' , ( ) => {
@@ -221,18 +198,18 @@ describe('userGroupsReducer', () => {
221
198
} ) ;
222
199
223
200
const prevState = deepFreeze ( [ group1 , group2 ] ) ;
224
- const action = deepFreeze ( {
225
- id : 1 ,
226
- type : EVENT_USER_GROUP_REMOVE_MEMBERS ,
227
- op : 'remove_members' ,
228
- group_id : group1 . id ,
229
- user_ids : [ user2 . user_id , user3 . user_id ] ,
230
- } ) ;
231
- const expectedState = [ { ... group1 , members : [ user1 . user_id , user4 . user_id ] } , group2 ] ;
232
-
233
- const actualState = userGroupsReducer ( prevState , action ) ;
234
-
235
- expect ( actualState ) . toEqual ( expectedState ) ;
201
+ expect (
202
+ userGroupsReducer (
203
+ prevState ,
204
+ deepFreeze ( {
205
+ id : 1 ,
206
+ type : EVENT_USER_GROUP_REMOVE_MEMBERS ,
207
+ op : 'remove_members' ,
208
+ group_id : group1 . id ,
209
+ user_ids : [ user2 . user_id , user3 . user_id ] ,
210
+ } ) ,
211
+ ) ,
212
+ ) . toEqual ( [ { ... group1 , members : [ user1 . user_id , user4 . user_id ] } , group2 ] ) ;
236
213
} ) ;
237
214
} ) ;
238
215
} ) ;
0 commit comments