From 98e694646c7fa983ebeb87e94cf4b741cc342f03 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Thu, 15 Jun 2017 02:17:24 +0100 Subject: [PATCH 1/2] Add a test for the login flow when there is a teamserver - just to check it keeps working. --- test/app-tests/loading.js | 45 +++++++++++++++++++++++++++++++++++---- test/mock-request.js | 27 +++++++++++++++++++++++ 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/test/app-tests/loading.js b/test/app-tests/loading.js index 0132be3ce0..a507fb9683 100644 --- a/test/app-tests/loading.js +++ b/test/app-tests/loading.js @@ -135,14 +135,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 0ebabb038c..cddeb1aeee 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 = { /** From ca736cfce8ab9f8f9bf084e64b5ae337db8a75bf Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Thu, 15 Jun 2017 14:54:32 +0100 Subject: [PATCH 2/2] fix test description logs in, not registers --- test/app-tests/loading.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/app-tests/loading.js b/test/app-tests/loading.js index a507fb9683..3792689da7 100644 --- a/test/app-tests/loading.js +++ b/test/app-tests/loading.js @@ -346,7 +346,7 @@ describe('loading:', function () { }).done(done, done); }); - it("registers correctly with a Riot Team Server", function() { + it("logs in correctly with a Riot Team Server", function() { sdk.setFetch(httpBackend.fetchFn); // XXX: ought to restore this! httpBackend.when('GET', '/pushrules').respond(200, {});