From e40d3852ffd8a31d9487666ac146de19036cd6bc Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Wed, 29 Mar 2017 16:07:11 +0100 Subject: [PATCH] Fix tests to reflect recent changes This is an attempt to reduce flakiness (see https://github.com/matrix-org/matrix-react-sdk/pull/781 also) --- test/app-tests/joining.js | 5 ++--- test/app-tests/loading.js | 28 ++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/test/app-tests/joining.js b/test/app-tests/joining.js index 30ef70db90..c564673299 100644 --- a/test/app-tests/joining.js +++ b/test/app-tests/joining.js @@ -23,6 +23,7 @@ var jssdk = require('matrix-js-sdk'); var sdk = require('matrix-react-sdk'); var peg = require('matrix-react-sdk/lib/MatrixClientPeg'); var dis = require('matrix-react-sdk/lib/dispatcher'); +var PageTypes = require('matrix-react-sdk/lib/PageTypes'); var MatrixChat = sdk.getComponent('structures.MatrixChat'); var RoomDirectory = sdk.getComponent('structures.RoomDirectory'); var RoomPreviewBar = sdk.getComponent('rooms.RoomPreviewBar'); @@ -90,9 +91,7 @@ describe('joining a room', function () { matrixChat = ReactDOM.render(mc, parentDiv); // switch to the Directory - dis.dispatch({ - action: 'view_room_directory', - }); + matrixChat._setPage(PageTypes.RoomDirectory); var roomView; // wait for /sync to happen diff --git a/test/app-tests/loading.js b/test/app-tests/loading.js index ef5558308d..22daa39503 100644 --- a/test/app-tests/loading.js +++ b/test/app-tests/loading.js @@ -104,6 +104,23 @@ describe('loading:', function () { } } + // Parse the given window.location and return parameters that can be used when calling + // MatrixChat.showScreen(screen, params) + function getScreenFromLocation(location) { + const fragparts = parseQsFromFragment(location); + return { + screen: fragparts.location.substring(1), + params: fragparts.params, + } + } + + function routeUrl(location, matrixChat) { + console.log(Date.now() + "Routing URL " + location); + const s = getScreenFromLocation(location); + console.log("Showing screen", s); + matrixChat.showScreen(s.screen, s.params); + } + const MatrixChat = sdk.getComponent('structures.MatrixChat'); const fragParts = parseQsFromFragment(windowLocation); var params = parseQs(windowLocation); @@ -118,16 +135,10 @@ describe('loading:', function () { startingFragmentQueryParams={fragParts.params} enableGuest={true} onLoadCompleted={loadCompleteDefer.resolve} + initialScreenAfterLogin={getScreenFromLocation(windowLocation)} />, parentDiv ); - function routeUrl(location, matrixChat) { - console.log(Date.now() + " Routing URL "+location); - var fragparts = parseQsFromFragment(location); - matrixChat.showScreen(fragparts.location.substring(1), - fragparts.params); - } - // pause for a cycle, then simulate the window.onload handler window.setTimeout(() => { console.log(Date.now() + " simulating window.onload"); @@ -476,7 +487,8 @@ function awaitRoomView(matrixChat, retryLimit, retryCount) { retryCount = 0; } - if (!matrixChat.state.ready) { + if (matrixChat.state.loading || + !(matrixChat.state.loggedIn && matrixChat.state.ready)) { console.log(Date.now() + " Awaiting room view: not ready yet."); if (retryCount >= retryLimit) { throw new Error("MatrixChat still not ready after " +