Skip to content

Commit e8ec6cc

Browse files
authored
Merge pull request element-hq#9279 from jryans/storage-edge-cases
Use `on_logged_in` action in tests
2 parents 2e24b0c + fef69b5 commit e8ec6cc

1 file changed

Lines changed: 26 additions & 48 deletions

File tree

‎test/app-tests/loading.js‎

Lines changed: 26 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ describe('loading:', function() {
307307

308308
loadApp();
309309

310-
return awaitSyncingSpinner(matrixChat).then(() => {
311-
// we got a sync spinner - let the sync complete
310+
return awaitLoggedIn(matrixChat).then(() => {
311+
// we are logged in - let the sync complete
312312
return expectAndAwaitSync();
313313
}).then(() => {
314314
// once the sync completes, we should have a room view
@@ -327,8 +327,8 @@ describe('loading:', function() {
327327

328328
loadApp();
329329

330-
return awaitSyncingSpinner(matrixChat).then(() => {
331-
// we got a sync spinner - let the sync complete
330+
return awaitLoggedIn(matrixChat).then(() => {
331+
// we are logged in - let the sync complete
332332
return expectAndAwaitSync();
333333
}).then(() => {
334334
// once the sync completes, we should have a home page
@@ -347,8 +347,8 @@ describe('loading:', function() {
347347
uriFragment: "#/room/!room:id",
348348
});
349349

350-
return awaitSyncingSpinner(matrixChat).then(() => {
351-
// we got a sync spinner - let the sync complete
350+
return awaitLoggedIn(matrixChat).then(() => {
351+
// we are logged in - let the sync complete
352352
return expectAndAwaitSync();
353353
}).then(() => {
354354
// once the sync completes, we should have a room view
@@ -417,9 +417,9 @@ describe('loading:', function() {
417417

418418
return httpBackend.flush();
419419
}).then(() => {
420-
return awaitSyncingSpinner(matrixChat);
420+
return awaitLoggedIn(matrixChat);
421421
}).then(() => {
422-
// we got a sync spinner - let the sync complete
422+
// we are logged in - let the sync complete
423423
return expectAndAwaitSync({isGuest: true});
424424
}).then(() => {
425425
// once the sync completes, we should have a welcome page
@@ -448,7 +448,7 @@ describe('loading:', function() {
448448

449449
return httpBackend.flush();
450450
}).then(() => {
451-
return awaitSyncingSpinner(matrixChat);
451+
return awaitLoggedIn(matrixChat);
452452
}).then(() => {
453453
return expectAndAwaitSync({isGuest: true});
454454
}).then((req) => {
@@ -482,7 +482,7 @@ describe('loading:', function() {
482482

483483
return httpBackend.flush();
484484
}).then(() => {
485-
return awaitSyncingSpinner(matrixChat);
485+
return awaitLoggedIn(matrixChat);
486486
}).then(() => {
487487
return expectAndAwaitSync({isGuest: true});
488488
}).then(() => {
@@ -507,7 +507,7 @@ describe('loading:', function() {
507507
});
508508

509509
return httpBackend.flush().then(() => {
510-
return awaitSyncingSpinner(matrixChat);
510+
return awaitLoggedIn(matrixChat);
511511
}).then(() => {
512512
// we got a sync spinner - let the sync complete
513513
return expectAndAwaitSync();
@@ -654,44 +654,22 @@ function assertAtLoadingSpinner(matrixChat) {
654654
expect(domComponent.children.length).toEqual(1);
655655
}
656656

657-
// we've got login creds, and are waiting for the sync to finish.
658-
// the page includes a logout link.
659-
function awaitSyncingSpinner(matrixChat, retryLimit, retryCount) {
660-
if (retryLimit === undefined) {
661-
retryLimit = 10;
662-
}
663-
if (retryCount === undefined) {
664-
retryCount = 0;
657+
function awaitLoggedIn(matrixChat) {
658+
if (matrixChat.state.view === VIEWS.LOGGED_IN) {
659+
return Promise.resolve();
665660
}
666-
667-
if (matrixChat.state.view === VIEWS.LOADING ||
668-
matrixChat.state.view === VIEWS.LOGGING_IN) {
669-
console.log(Date.now() + " Awaiting sync spinner: still loading.");
670-
if (retryCount >= retryLimit) {
671-
throw new Error("MatrixChat still not loaded after " +
672-
retryCount + " tries");
673-
}
674-
// loading can take quite a long time, because we delete the
675-
// indexedDB store.
676-
return Promise.delay(5).then(() => {
677-
return awaitSyncingSpinner(matrixChat, retryLimit, retryCount + 1);
678-
});
679-
}
680-
681-
console.log(Date.now() + " Awaiting sync spinner: load complete.");
682-
683-
return Promise.resolve();
684-
}
685-
686-
function assertAtSyncingSpinner(matrixChat) {
687-
const domComponent = ReactDOM.findDOMNode(matrixChat);
688-
expect(domComponent.className).toEqual("mx_MatrixChat_splash");
689-
690-
ReactTestUtils.findRenderedComponentWithType(
691-
matrixChat, sdk.getComponent('elements.Spinner'));
692-
const logoutLink = ReactTestUtils.findRenderedDOMComponentWithTag(
693-
matrixChat, 'a');
694-
expect(logoutLink.text).toEqual("Logout");
661+
return new Promise(resolve => {
662+
const onAction = ({ action }) => {
663+
if (action !== "on_logged_in") {
664+
return;
665+
}
666+
console.log(Date.now() + ": Received on_logged_in action");
667+
dis.unregister(dispatcherRef);
668+
resolve();
669+
};
670+
const dispatcherRef = dis.register(onAction);
671+
console.log(Date.now() + ": Waiting for on_logged_in action");
672+
});
695673
}
696674

697675
function awaitRoomView(matrixChat, retryLimit, retryCount) {

0 commit comments

Comments
 (0)