diff --git a/test/app-tests/loading.js b/test/app-tests/loading.js index 80fcc020..a323a262 100644 --- a/test/app-tests/loading.js +++ b/test/app-tests/loading.js @@ -121,14 +121,17 @@ describe('loading:', function () { const MatrixChat = sdk.getComponent('structures.MatrixChat'); const fragParts = parseQsFromFragment(windowLocation); + + const config = Object.assign({ + default_hs_url: DEFAULT_HS_URL, + default_is_url: DEFAULT_IS_URL, + }, opts.config || {}); + var params = parseQs(windowLocation); matrixChat = ReactDOM.render( { + // we expect a loading spinner while we log into the RTS + assertAtLoadingSpinner(matrixChat); + + httpBackend.when('GET', 'my_team_server/login').respond(200, { + team_token: 'nom', + }); + return httpBackend.flush(); + }).then(() => { + return awaitSyncingSpinner(matrixChat) + }).then(() => { + // we got a sync spinner - let the sync complete + return expectAndAwaitSync(); + }).then(() => { + // once the sync completes, we should have a home page + ReactTestUtils.findRenderedComponentWithType( + matrixChat, sdk.getComponent('structures.HomePage')); + }); + }); + describe('/#/login link:', function() { beforeEach(function() { loadApp({ diff --git a/test/mock-request.js b/test/mock-request.js index 0ebabb03..cddeb1ae 100644 --- a/test/mock-request.js +++ b/test/mock-request.js @@ -30,6 +30,33 @@ function HttpBackend() { abort: abort, }; }; + + // very simplistic mapping from the whatwg fetch interface onto the request + // interface, so we can use the same mock backend for both. + this.fetchFn = function(input, init) { + init = init || {}; + const requestOpts = { + uri: input, + method: init.method || 'GET', + body: init.body, + }; + + return new Promise((resolve, reject) => { + function callback(err, response, body) { + if (err) { + reject(err); + } + resolve({ + ok: response.statusCode >= 200 && response.statusCode < 300, + json: () => body, + }); + }; + + const req = new Request(requestOpts, callback); + console.log(`HTTP backend received request: ${req}`); + self.requests.push(req); + }); + }; } HttpBackend.prototype = { /**