Skip to content

Commit

Permalink
Merge pull request #3537 from vector-im/luke/fix-flaky-tests-maybe
Browse files Browse the repository at this point in the history
Fix tests to reflect recent changes
  • Loading branch information
lukebarnard1 authored Mar 29, 2017
2 parents e248a7f + e40d385 commit 6380f1a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
5 changes: 2 additions & 3 deletions test/app-tests/joining.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand Down
28 changes: 20 additions & 8 deletions test/app-tests/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
Expand Down Expand Up @@ -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 " +
Expand Down

0 comments on commit 6380f1a

Please sign in to comment.