@@ -50,6 +50,8 @@ describe('loading:', function () {
50
50
// document.body.appendChild(parentDiv);
51
51
52
52
windowLocation = null ;
53
+
54
+ window . localStorage . clear ( ) ;
53
55
} ) ;
54
56
55
57
afterEach ( function ( ) {
@@ -131,8 +133,7 @@ describe('loading:', function () {
131
133
q . delay ( 1 ) . then ( ( ) => {
132
134
// at this point, we're trying to do a guest registration;
133
135
// we expect a spinner
134
- ReactTestUtils . findRenderedComponentWithType (
135
- matrixChat , sdk . getComponent ( 'elements.Spinner' ) ) ;
136
+ assertAtLoadingSpinner ( matrixChat ) ;
136
137
137
138
httpBackend . when ( 'POST' , '/register' ) . check ( function ( req ) {
138
139
expect ( req . queryParams . kind ) . toEqual ( 'guest' ) ;
@@ -153,8 +154,7 @@ describe('loading:', function () {
153
154
q . delay ( 1 ) . then ( ( ) => {
154
155
// at this point, we're trying to do a guest registration;
155
156
// we expect a spinner
156
- ReactTestUtils . findRenderedComponentWithType (
157
- matrixChat , sdk . getComponent ( 'elements.Spinner' ) ) ;
157
+ assertAtLoadingSpinner ( matrixChat ) ;
158
158
159
159
httpBackend . when ( 'POST' , '/register' ) . check ( function ( req ) {
160
160
expect ( req . queryParams . kind ) . toEqual ( 'guest' ) ;
@@ -193,14 +193,10 @@ describe('loading:', function () {
193
193
194
194
describe ( "MatrixClient rehydrated from stored credentials:" , function ( ) {
195
195
beforeEach ( function ( ) {
196
- // start with a logged-in client
197
- MatrixClientPeg . replaceUsingCreds ( {
198
- homeserverUrl : 'http://localhost' ,
199
- identityServerUrl : 'http://localhost' ,
200
- userId : '@me:localhost' ,
201
- accessToken : 'access_token' ,
202
- guest : false ,
203
- } ) ;
196
+ localStorage . setItem ( "mx_hs_url" , "http://localhost" ) ;
197
+ localStorage . setItem ( "mx_is_url" , "http://localhost" ) ;
198
+ localStorage . setItem ( "mx_access_token" , "access_token" ) ;
199
+ localStorage . setItem ( "mx_user_id" , "@me:localhost" ) ;
204
200
} ) ;
205
201
206
202
it ( 'shows a directory by default if we have no joined rooms' , function ( done ) {
@@ -212,8 +208,8 @@ describe('loading:', function () {
212
208
213
209
q . delay ( 1 ) . then ( ( ) => {
214
210
// we expect a spinner
215
- ReactTestUtils . findRenderedComponentWithType (
216
- matrixChat , sdk . getComponent ( 'elements.Spinner' ) ) ;
211
+ assertAtSyncingSpinner ( matrixChat ) ;
212
+
217
213
return httpBackend . flush ( ) ;
218
214
} ) . then ( ( ) => {
219
215
// once the sync completes, we should have a directory
@@ -233,8 +229,8 @@ describe('loading:', function () {
233
229
234
230
q . delay ( 1 ) . then ( ( ) => {
235
231
// we expect a spinner
236
- ReactTestUtils . findRenderedComponentWithType (
237
- matrixChat , sdk . getComponent ( 'elements.Spinner' ) ) ;
232
+ assertAtSyncingSpinner ( matrixChat ) ;
233
+
238
234
return httpBackend . flush ( ) ;
239
235
} ) . then ( ( ) => {
240
236
// once the sync completes, we should have a room view
@@ -246,4 +242,89 @@ describe('loading:', function () {
246
242
247
243
} ) ;
248
244
} ) ;
245
+
246
+ describe ( 'Guest auto-registration:' , function ( ) {
247
+ it ( 'shows a directory by default' , function ( done ) {
248
+ let matrixChat = loadApp ( "" ) ;
249
+
250
+ q . delay ( 1 ) . then ( ( ) => {
251
+ // at this point, we're trying to do a guest registration;
252
+ // we expect a spinner
253
+ assertAtLoadingSpinner ( matrixChat ) ;
254
+
255
+ httpBackend . when ( 'POST' , '/register' ) . check ( function ( req ) {
256
+ expect ( req . queryParams . kind ) . toEqual ( 'guest' ) ;
257
+ } ) . respond ( 200 , {
258
+ user_id : "@guest:localhost" ,
259
+ access_token : "secret_token" ,
260
+ } ) ;
261
+
262
+ return httpBackend . flush ( ) ;
263
+ } ) . then ( ( ) => {
264
+ // now we should have a spinner with a logout link
265
+ assertAtSyncingSpinner ( matrixChat ) ;
266
+
267
+ httpBackend . when ( 'GET' , '/sync' ) . respond ( 200 , { } ) ;
268
+ return httpBackend . flush ( ) ;
269
+ } ) . then ( ( ) => {
270
+ // once the sync completes, we should have a directory
271
+ httpBackend . verifyNoOutstandingExpectation ( ) ;
272
+ ReactTestUtils . findRenderedComponentWithType (
273
+ matrixChat , sdk . getComponent ( 'structures.RoomDirectory' ) ) ;
274
+ expect ( windowLocation . hash ) . toEqual ( "#/directory" ) ;
275
+ } ) . done ( done , done ) ;
276
+ } ) ;
277
+
278
+ it ( 'shows a room view if we followed a room link' , function ( done ) {
279
+ let matrixChat = loadApp ( "#/room/!room:id" ) ;
280
+ q . delay ( 10 ) . then ( ( ) => {
281
+ // at this point, we're trying to do a guest registration;
282
+ // we expect a spinner
283
+ assertAtLoadingSpinner ( matrixChat ) ;
284
+
285
+ httpBackend . when ( 'POST' , '/register' ) . check ( function ( req ) {
286
+ expect ( req . queryParams . kind ) . toEqual ( 'guest' ) ;
287
+ } ) . respond ( 200 , {
288
+ user_id : "@guest:localhost" ,
289
+ access_token : "secret_token" ,
290
+ } ) ;
291
+
292
+ return httpBackend . flush ( ) ;
293
+ } ) . then ( ( ) => {
294
+ // now we should have a spinner with a logout link
295
+ assertAtSyncingSpinner ( matrixChat ) ;
296
+
297
+ httpBackend . when ( 'GET' , '/sync' ) . respond ( 200 , { } ) ;
298
+ return httpBackend . flush ( ) ;
299
+ } ) . then ( ( ) => {
300
+ // once the sync completes, we should have a room view
301
+ httpBackend . verifyNoOutstandingExpectation ( ) ;
302
+ ReactTestUtils . findRenderedComponentWithType (
303
+ matrixChat , sdk . getComponent ( 'structures.RoomView' ) ) ;
304
+ expect ( windowLocation . hash ) . toEqual ( "#/room/!room:id" ) ;
305
+ } ) . done ( done , done ) ;
306
+ } ) ;
307
+ } ) ;
249
308
} ) ;
309
+
310
+ // assert that we are on the loading page
311
+ function assertAtLoadingSpinner ( matrixChat ) {
312
+ var domComponent = ReactDOM . findDOMNode ( matrixChat ) ;
313
+ expect ( domComponent . className ) . toEqual ( "mx_MatrixChat_splash" ) ;
314
+
315
+ // just the spinner
316
+ expect ( domComponent . children . length ) . toEqual ( 1 ) ;
317
+ }
318
+
319
+ // we've got login creds, and are waiting for the sync to finish.
320
+ // the page includes a logout link.
321
+ function assertAtSyncingSpinner ( matrixChat ) {
322
+ var domComponent = ReactDOM . findDOMNode ( matrixChat ) ;
323
+ expect ( domComponent . className ) . toEqual ( "mx_MatrixChat_splash" ) ;
324
+
325
+ ReactTestUtils . findRenderedComponentWithType (
326
+ matrixChat , sdk . getComponent ( 'elements.Spinner' ) ) ;
327
+ var logoutLink = ReactTestUtils . findRenderedDOMComponentWithTag (
328
+ matrixChat , 'a' ) ;
329
+ expect ( logoutLink . text ) . toEqual ( "Logout" ) ;
330
+ }
0 commit comments