Skip to content

Commit b2403d5

Browse files
committed
loading tests: wait for login component
Rather than a fixed delay, use matrix-react-test-utils to wait for the login component to appear. Hopefully this will deflakify some tests.
1 parent 0f8a255 commit b2403d5

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
"karma-mocha": "^0.2.2",
122122
"karma-webpack": "^1.7.0",
123123
"matrix-mock-request": "^1.0.0",
124+
"matrix-react-test-utils": "^0.2.0",
124125
"minimist": "^1.2.0",
125126
"mkdirp": "^0.5.1",
126127
"mocha": "^2.4.5",

test/app-tests/loading.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import ReactDOM from 'react-dom';
2323
import ReactTestUtils from 'react-addons-test-utils';
2424
import expect from 'expect';
2525
import q from 'q';
26+
import MatrixReactTestUtils from 'matrix-react-test-utils';
2627

2728
import jssdk from 'matrix-js-sdk';
2829

@@ -183,11 +184,8 @@ describe('loading:', function () {
183184
return httpBackend.flush();
184185
}).then(() => {
185186
// Wait for another trip around the event loop for the UI to update
186-
return q.delay(10);
187+
return awaitLoginComponent(matrixChat);
187188
}).then(() => {
188-
// we expect a single <Login> component following session load
189-
ReactTestUtils.findRenderedComponentWithType(
190-
matrixChat, sdk.getComponent('structures.login.Login'));
191189
expect(windowLocation.hash).toEqual("#/login");
192190
}).done(done, done);
193191
});
@@ -232,7 +230,7 @@ describe('loading:', function () {
232230
uriFragment: "#/login",
233231
});
234232

235-
return q.delay(100).then(() => {
233+
return awaitLoginComponent(matrixChat).then(() => {
236234
// we expect a single <Login> component
237235
ReactTestUtils.findRenderedComponentWithType(
238236
matrixChat, sdk.getComponent('structures.login.Login'));
@@ -366,7 +364,7 @@ describe('loading:', function () {
366364
});
367365

368366
// give the UI a chance to display
369-
return q.delay(50);
367+
return awaitLoginComponent(matrixChat);
370368
});
371369

372370
it('shows a login view', function() {
@@ -530,7 +528,7 @@ describe('loading:', function () {
530528

531529
dis.dispatch({ action: 'start_login' });
532530

533-
return q.delay(1);
531+
return awaitLoginComponent(matrixChat);
534532
});
535533
});
536534

@@ -607,7 +605,6 @@ describe('loading:', function () {
607605
});
608606
});
609607

610-
611608
// check that we have a Login component, send a 'user:pass' login,
612609
// and await the HTTP requests.
613610
function completeLogin(matrixChat) {
@@ -723,3 +720,9 @@ function awaitRoomView(matrixChat, retryLimit, retryCount) {
723720
matrixChat, sdk.getComponent('structures.RoomView'));
724721
return q();
725722
}
723+
724+
function awaitLoginComponent(matrixChat, attempts) {
725+
return MatrixReactTestUtils.waitForRenderedComponentWithType(
726+
matrixChat, sdk.getComponent('structures.login.Login'), attempts,
727+
);
728+
}

0 commit comments

Comments
 (0)