From fe64b043390cbbe135f795d2337ae44093c84474 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 24 Jan 2017 13:35:41 +0000 Subject: [PATCH] More test resilience Give the tests more than one chance for the roomview to load. --- test/app-tests/loading.js | 45 ++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/test/app-tests/loading.js b/test/app-tests/loading.js index 2fe82e51f5..4504d00b8d 100644 --- a/test/app-tests/loading.js +++ b/test/app-tests/loading.js @@ -209,14 +209,11 @@ describe('loading:', function () { httpBackend.when('POST', '/filter').respond(200, { filter_id: 'fid' }); httpBackend.when('GET', '/sync').respond(200, {}); return httpBackend.flush(); - }).then(() => { - // Wait for another trip around the event loop for the UI to update - return q.delay(1); }).then(() => { // once the sync completes, we should have a room view + return awaitRoomView(matrixChat); + }).then(() => { httpBackend.verifyNoOutstandingExpectation(); - ReactTestUtils.findRenderedComponentWithType( - matrixChat, sdk.getComponent('structures.RoomView')); expect(windowLocation.hash).toEqual("#/room/!room:id"); // and the localstorage should have been updated @@ -269,9 +266,9 @@ describe('loading:', function () { return httpBackend.flush(); }).then(() => { // once the sync completes, we should have a room view + return awaitRoomView(matrixChat); + }).then(() => { httpBackend.verifyNoOutstandingExpectation(); - ReactTestUtils.findRenderedComponentWithType( - matrixChat, sdk.getComponent('structures.RoomView')); expect(windowLocation.hash).toEqual("#/room/!room:id"); }).done(done, done); @@ -370,14 +367,11 @@ describe('loading:', function () { }).then(() => { httpBackend.when('GET', '/sync').respond(200, {}); return httpBackend.flush(); - }).then(() => { - // Wait for another trip around the event loop for the UI to update - return q.delay(1); }).then(() => { // once the sync completes, we should have a room view + return awaitRoomView(matrixChat); + }).then(() => { httpBackend.verifyNoOutstandingExpectation(); - ReactTestUtils.findRenderedComponentWithType( - matrixChat, sdk.getComponent('structures.RoomView')); expect(windowLocation.hash).toEqual("#/room/!room:id"); }).done(done, done); }); @@ -469,3 +463,30 @@ function assertAtSyncingSpinner(matrixChat) { matrixChat, 'a'); expect(logoutLink.text).toEqual("Logout"); } + +function awaitRoomView(matrixChat, retryLimit, retryCount) { + if (retryLimit === undefined) { + retryLimit = 5; + } + if (retryCount === undefined) { + retryCount = 0; + } + + if (!matrixChat.state.ready) { + console.log(Date.now() + " Awaiting room view: not ready yet."); + if (retryCount >= retryLimit) { + throw new Error("MatrixChat still not ready after " + + retryCount + " tries"); + } + return q.delay(0).then(() => { + return awaitRoomView(matrixChat, retryLimit, retryCount + 1); + }); + } + + console.log(Date.now() + " Awaiting room view: now ready."); + + // state looks good, check the rendered output + ReactTestUtils.findRenderedComponentWithType( + matrixChat, sdk.getComponent('structures.RoomView')); + return q(); +}