|
1 import { |
|
2 getOnline, |
|
3 getToken, |
|
4 isAuthenticated, |
|
5 getCurrentUser, |
|
6 getClientId, |
|
7 getCurrentGroupName, |
|
8 getCreateGroup, |
|
9 getAutoSubmit, |
|
10 getGroups, |
|
11 getCurrentGroup |
|
12 } from '../authSelectors'; |
|
13 |
|
14 import asyncRequest from '../../constants/asyncRequest'; |
|
15 |
|
16 |
|
17 describe('Auth selector test', () => { |
|
18 |
|
19 test('getOnline', () => { |
|
20 const inputState = { |
|
21 status: { |
|
22 isSynchronizing: false, |
|
23 online: false |
|
24 }, |
|
25 }; |
|
26 |
|
27 expect(getOnline(inputState)).toBe(false); |
|
28 }) |
|
29 |
|
30 test('getToken', () => { |
|
31 const inputState = { |
|
32 status: { |
|
33 isSynchronizing: false, |
|
34 online: false |
|
35 }, |
|
36 authStatus: { |
|
37 token: 'abc', |
|
38 }, |
|
39 }; |
|
40 |
|
41 expect(getToken(inputState)).toBe('abc'); |
|
42 }) |
|
43 |
|
44 test('isAuthenticated', () => { |
|
45 const inputState = { |
|
46 status: { |
|
47 isSynchronizing: false, |
|
48 online: false |
|
49 }, |
|
50 authStatus: { |
|
51 token: 'abc', |
|
52 isAuthenticated: false, |
|
53 }, |
|
54 }; |
|
55 |
|
56 expect(isAuthenticated(inputState)).toBe(false); |
|
57 }) |
|
58 |
|
59 |
|
60 test('getCurrentUser', () => { |
|
61 const inputState = { |
|
62 status: { |
|
63 isSynchronizing: false, |
|
64 online: false |
|
65 }, |
|
66 authStatus: { |
|
67 token: 'abc', |
|
68 isAuthenticated: false, |
|
69 currentUser: 'admin', |
|
70 }, |
|
71 }; |
|
72 |
|
73 expect(getCurrentUser(inputState)).toBe('admin'); |
|
74 }) |
|
75 |
|
76 test('getClientId', () => { |
|
77 const inputState = { |
|
78 status: { |
|
79 isSynchronizing: false, |
|
80 online: false |
|
81 }, |
|
82 authStatus: { |
|
83 token: 'abc', |
|
84 isAuthenticated: false, |
|
85 clientId: '12345', |
|
86 currentUser: 'admin', |
|
87 }, |
|
88 }; |
|
89 |
|
90 expect(getClientId(inputState)).toBe('12345'); |
|
91 }) |
|
92 |
|
93 test('getCurrentGroupName', () => { |
|
94 const inputState = { |
|
95 status: { |
|
96 isSynchronizing: false, |
|
97 online: false |
|
98 }, |
|
99 authStatus: { |
|
100 token: 'abc', |
|
101 isAuthenticated: false, |
|
102 clientId: '12345', |
|
103 currentUser: 'admin', |
|
104 currentGroup: 'adminGroup' |
|
105 }, |
|
106 }; |
|
107 |
|
108 expect(getCurrentGroupName(inputState)).toBe('adminGroup'); |
|
109 }) |
|
110 |
|
111 test('getCurrentGroupName', () => { |
|
112 const inputState = { |
|
113 status: { |
|
114 isSynchronizing: false, |
|
115 online: false |
|
116 }, |
|
117 authStatus: { |
|
118 token: 'abc', |
|
119 isAuthenticated: false, |
|
120 clientId: '12345', |
|
121 currentUser: 'admin', |
|
122 currentGroup: 'adminGroup' |
|
123 }, |
|
124 }; |
|
125 |
|
126 expect(getCurrentGroupName(inputState)).toBe('adminGroup'); |
|
127 }) |
|
128 |
|
129 test('getCreateGroup', () => { |
|
130 const inputState = { |
|
131 status: { |
|
132 isSynchronizing: false, |
|
133 online: false |
|
134 }, |
|
135 authStatus: { |
|
136 token: 'abc', |
|
137 isAuthenticated: false, |
|
138 clientId: '12345', |
|
139 currentUser: 'admin', |
|
140 currentGroup: 'adminGroup' |
|
141 }, |
|
142 createGroup: asyncRequest |
|
143 }; |
|
144 |
|
145 expect(getCreateGroup(inputState)).toBe(asyncRequest); |
|
146 }) |
|
147 |
|
148 test('getAutoSubmit', () => { |
|
149 const inputState = { |
|
150 status: { |
|
151 isSynchronizing: false, |
|
152 online: false |
|
153 }, |
|
154 authStatus: { |
|
155 token: 'abc', |
|
156 isAuthenticated: false, |
|
157 clientId: '12345', |
|
158 currentUser: 'admin', |
|
159 currentGroup: 'adminGroup' |
|
160 }, |
|
161 autoSubmit: false |
|
162 }; |
|
163 |
|
164 expect(getAutoSubmit(inputState)).toBe(false); |
|
165 }) |
|
166 |
|
167 test('getGroups', () => { |
|
168 const inputState = { |
|
169 status: { |
|
170 isSynchronizing: false, |
|
171 online: false |
|
172 }, |
|
173 authStatus: { |
|
174 token: 'abc', |
|
175 isAuthenticated: false, |
|
176 clientId: '12345', |
|
177 currentUser: 'admin', |
|
178 currentGroup: 'adminGroup' |
|
179 }, |
|
180 autoSubmit: false, |
|
181 groups: [ |
|
182 { name: 'group1'}, |
|
183 { name: 'group2'}, |
|
184 ] |
|
185 }; |
|
186 |
|
187 expect(getGroups(inputState)).toEqual([ |
|
188 { name: 'group1'}, |
|
189 { name: 'group2'}, |
|
190 ]); |
|
191 }) |
|
192 |
|
193 test('getCurrentGroupOk', () => { |
|
194 const inputState = { |
|
195 status: { |
|
196 isSynchronizing: false, |
|
197 online: false |
|
198 }, |
|
199 authStatus: { |
|
200 token: 'abc', |
|
201 isAuthenticated: false, |
|
202 clientId: '12345', |
|
203 currentUser: 'admin', |
|
204 currentGroup: 'group1' |
|
205 }, |
|
206 autoSubmit: false, |
|
207 groups: [ |
|
208 { name: 'group1'}, |
|
209 { name: 'group2'}, |
|
210 ] |
|
211 }; |
|
212 |
|
213 expect(getCurrentGroup(inputState)).toEqual({ name: 'group1'}); |
|
214 }) |
|
215 |
|
216 |
|
217 test('getCurrentGroupOther', () => { |
|
218 const inputState = { |
|
219 status: { |
|
220 isSynchronizing: false, |
|
221 online: false |
|
222 }, |
|
223 authStatus: { |
|
224 token: 'abc', |
|
225 isAuthenticated: false, |
|
226 clientId: '12345', |
|
227 currentUser: 'admin', |
|
228 currentGroup: 'group2' |
|
229 }, |
|
230 autoSubmit: false, |
|
231 groups: [ |
|
232 { name: 'group1'}, |
|
233 { name: 'group2'}, |
|
234 { name: 'group3'}, |
|
235 { name: 'group4'}, |
|
236 ] |
|
237 }; |
|
238 |
|
239 expect(getCurrentGroup(inputState)).toEqual({ name: 'group2'}); |
|
240 }) |
|
241 |
|
242 |
|
243 test('getCurrentGroupUndefined', () => { |
|
244 const inputState = { |
|
245 status: { |
|
246 isSynchronizing: false, |
|
247 online: false |
|
248 }, |
|
249 authStatus: { |
|
250 token: 'abc', |
|
251 isAuthenticated: false, |
|
252 clientId: '12345', |
|
253 currentUser: 'admin', |
|
254 currentGroup: 'unknownGroup' |
|
255 }, |
|
256 autoSubmit: false, |
|
257 groups: [ |
|
258 { name: 'group1'}, |
|
259 { name: 'group2'}, |
|
260 ] |
|
261 }; |
|
262 |
|
263 expect(getCurrentGroup(inputState)).toEqual(undefined); |
|
264 }) |
|
265 |
|
266 |
|
267 }) |