@@ -74,7 +74,6 @@ describe('joining a room', function () {
7474
7575 httpBackend . when ( 'GET' , '/pushrules' ) . respond ( 200 , { } ) ;
7676 httpBackend . when ( 'POST' , '/filter' ) . respond ( 200 , { filter_id : 'fid' } ) ;
77- httpBackend . when ( 'GET' , '/sync' ) . respond ( 200 , { } ) ;
7877
7978 // note that we deliberately do *not* set an expectation for a
8079 // presence update - setting one makes the first httpBackend.flush
@@ -86,18 +85,36 @@ describe('joining a room', function () {
8685 localStorage . setItem ( "mx_access_token" , ACCESS_TOKEN ) ;
8786 localStorage . setItem ( "mx_user_id" , USER_ID ) ;
8887
89- var mc = < MatrixChat config = { { } } /> ;
88+ var mc = (
89+ < MatrixChat config = { { } }
90+ makeRegistrationUrl = { ( ) => { throw new Error ( "unimplemented" ) ; } }
91+ />
92+ ) ;
9093 matrixChat = ReactDOM . render ( mc , parentDiv ) ;
9194
9295 // switch to the Directory
9396 matrixChat . _setPage ( PageTypes . RoomDirectory ) ;
9497
9598 var roomView ;
9699
97- // wait for /sync to happen
98- return q . delay ( 1 ) . then ( ( ) => {
99- return httpBackend . flush ( ) ;
100- } ) . then ( ( ) => {
100+ // wait for /sync to happen. This may take some time, as the client
101+ // has to initialise indexeddb.
102+ console . log ( "waiting for /sync" ) ;
103+ let syncDone = false ;
104+ httpBackend . when ( 'GET' , '/sync' )
105+ . check ( ( r ) => { syncDone = true ; } )
106+ . respond ( 200 , { } ) ;
107+ function awaitSync ( attempts ) {
108+ if ( syncDone ) {
109+ return q ( ) ;
110+ }
111+ if ( ! attempts ) {
112+ throw new Error ( "Gave up waiting for /sync" )
113+ }
114+ return httpBackend . flush ( ) . then ( ( ) => awaitSync ( attempts - 1 ) ) ;
115+ }
116+
117+ return awaitSync ( 10 ) . then ( ( ) => {
101118 // wait for the directory requests
102119 httpBackend . when ( 'POST' , '/publicRooms' ) . respond ( 200 , { chunk : [ ] } ) ;
103120 httpBackend . when ( 'GET' , '/thirdparty/protocols' ) . respond ( 200 , { } ) ;
0 commit comments