Skip to content

Commit

Permalink
Merge pull request #9279 from jryans/storage-edge-cases
Browse files Browse the repository at this point in the history
Use `on_logged_in` action in tests
  • Loading branch information
jryans committed Mar 27, 2019
2 parents 2e24b0c + fef69b5 commit e8ec6cc
Showing 1 changed file with 26 additions and 48 deletions.
74 changes: 26 additions & 48 deletions test/app-tests/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ describe('loading:', function() {

loadApp();

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

loadApp();

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

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

return httpBackend.flush();
}).then(() => {
return awaitSyncingSpinner(matrixChat);
return awaitLoggedIn(matrixChat);
}).then(() => {
// we got a sync spinner - let the sync complete
// we are logged in - let the sync complete
return expectAndAwaitSync({isGuest: true});
}).then(() => {
// once the sync completes, we should have a welcome page
Expand Down Expand Up @@ -448,7 +448,7 @@ describe('loading:', function() {

return httpBackend.flush();
}).then(() => {
return awaitSyncingSpinner(matrixChat);
return awaitLoggedIn(matrixChat);
}).then(() => {
return expectAndAwaitSync({isGuest: true});
}).then((req) => {
Expand Down Expand Up @@ -482,7 +482,7 @@ describe('loading:', function() {

return httpBackend.flush();
}).then(() => {
return awaitSyncingSpinner(matrixChat);
return awaitLoggedIn(matrixChat);
}).then(() => {
return expectAndAwaitSync({isGuest: true});
}).then(() => {
Expand All @@ -507,7 +507,7 @@ describe('loading:', function() {
});

return httpBackend.flush().then(() => {
return awaitSyncingSpinner(matrixChat);
return awaitLoggedIn(matrixChat);
}).then(() => {
// we got a sync spinner - let the sync complete
return expectAndAwaitSync();
Expand Down Expand Up @@ -654,44 +654,22 @@ function assertAtLoadingSpinner(matrixChat) {
expect(domComponent.children.length).toEqual(1);
}

// we've got login creds, and are waiting for the sync to finish.
// the page includes a logout link.
function awaitSyncingSpinner(matrixChat, retryLimit, retryCount) {
if (retryLimit === undefined) {
retryLimit = 10;
}
if (retryCount === undefined) {
retryCount = 0;
function awaitLoggedIn(matrixChat) {
if (matrixChat.state.view === VIEWS.LOGGED_IN) {
return Promise.resolve();
}

if (matrixChat.state.view === VIEWS.LOADING ||
matrixChat.state.view === VIEWS.LOGGING_IN) {
console.log(Date.now() + " Awaiting sync spinner: still loading.");
if (retryCount >= retryLimit) {
throw new Error("MatrixChat still not loaded after " +
retryCount + " tries");
}
// loading can take quite a long time, because we delete the
// indexedDB store.
return Promise.delay(5).then(() => {
return awaitSyncingSpinner(matrixChat, retryLimit, retryCount + 1);
});
}

console.log(Date.now() + " Awaiting sync spinner: load complete.");

return Promise.resolve();
}

function assertAtSyncingSpinner(matrixChat) {
const domComponent = ReactDOM.findDOMNode(matrixChat);
expect(domComponent.className).toEqual("mx_MatrixChat_splash");

ReactTestUtils.findRenderedComponentWithType(
matrixChat, sdk.getComponent('elements.Spinner'));
const logoutLink = ReactTestUtils.findRenderedDOMComponentWithTag(
matrixChat, 'a');
expect(logoutLink.text).toEqual("Logout");
return new Promise(resolve => {
const onAction = ({ action }) => {
if (action !== "on_logged_in") {
return;
}
console.log(Date.now() + ": Received on_logged_in action");
dis.unregister(dispatcherRef);
resolve();
};
const dispatcherRef = dis.register(onAction);
console.log(Date.now() + ": Waiting for on_logged_in action");
});
}

function awaitRoomView(matrixChat, retryLimit, retryCount) {
Expand Down

0 comments on commit e8ec6cc

Please sign in to comment.