Merge pull request #9279 from jryans/storage-edge-cases

Use `on_logged_in` action in tests
pull/9297/head
J. Ryan Stinnett 2019-03-27 09:22:30 +00:00 committed by GitHub
commit e8ec6cc1b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 48 deletions

View File

@ -307,8 +307,8 @@ describe('loading:', function() {
loadApp(); loadApp();
return awaitSyncingSpinner(matrixChat).then(() => { return awaitLoggedIn(matrixChat).then(() => {
// we got a sync spinner - let the sync complete // we are logged in - let the sync complete
return expectAndAwaitSync(); return expectAndAwaitSync();
}).then(() => { }).then(() => {
// once the sync completes, we should have a room view // once the sync completes, we should have a room view
@ -327,8 +327,8 @@ describe('loading:', function() {
loadApp(); loadApp();
return awaitSyncingSpinner(matrixChat).then(() => { return awaitLoggedIn(matrixChat).then(() => {
// we got a sync spinner - let the sync complete // we are logged in - let the sync complete
return expectAndAwaitSync(); return expectAndAwaitSync();
}).then(() => { }).then(() => {
// once the sync completes, we should have a home page // once the sync completes, we should have a home page
@ -347,8 +347,8 @@ describe('loading:', function() {
uriFragment: "#/room/!room:id", uriFragment: "#/room/!room:id",
}); });
return awaitSyncingSpinner(matrixChat).then(() => { return awaitLoggedIn(matrixChat).then(() => {
// we got a sync spinner - let the sync complete // we are logged in - let the sync complete
return expectAndAwaitSync(); return expectAndAwaitSync();
}).then(() => { }).then(() => {
// once the sync completes, we should have a room view // once the sync completes, we should have a room view
@ -417,9 +417,9 @@ describe('loading:', function() {
return httpBackend.flush(); return httpBackend.flush();
}).then(() => { }).then(() => {
return awaitSyncingSpinner(matrixChat); return awaitLoggedIn(matrixChat);
}).then(() => { }).then(() => {
// we got a sync spinner - let the sync complete // we are logged in - let the sync complete
return expectAndAwaitSync({isGuest: true}); return expectAndAwaitSync({isGuest: true});
}).then(() => { }).then(() => {
// once the sync completes, we should have a welcome page // once the sync completes, we should have a welcome page
@ -448,7 +448,7 @@ describe('loading:', function() {
return httpBackend.flush(); return httpBackend.flush();
}).then(() => { }).then(() => {
return awaitSyncingSpinner(matrixChat); return awaitLoggedIn(matrixChat);
}).then(() => { }).then(() => {
return expectAndAwaitSync({isGuest: true}); return expectAndAwaitSync({isGuest: true});
}).then((req) => { }).then((req) => {
@ -482,7 +482,7 @@ describe('loading:', function() {
return httpBackend.flush(); return httpBackend.flush();
}).then(() => { }).then(() => {
return awaitSyncingSpinner(matrixChat); return awaitLoggedIn(matrixChat);
}).then(() => { }).then(() => {
return expectAndAwaitSync({isGuest: true}); return expectAndAwaitSync({isGuest: true});
}).then(() => { }).then(() => {
@ -507,7 +507,7 @@ describe('loading:', function() {
}); });
return httpBackend.flush().then(() => { return httpBackend.flush().then(() => {
return awaitSyncingSpinner(matrixChat); return awaitLoggedIn(matrixChat);
}).then(() => { }).then(() => {
// we got a sync spinner - let the sync complete // we got a sync spinner - let the sync complete
return expectAndAwaitSync(); return expectAndAwaitSync();
@ -654,44 +654,22 @@ function assertAtLoadingSpinner(matrixChat) {
expect(domComponent.children.length).toEqual(1); expect(domComponent.children.length).toEqual(1);
} }
// we've got login creds, and are waiting for the sync to finish. function awaitLoggedIn(matrixChat) {
// the page includes a logout link. if (matrixChat.state.view === VIEWS.LOGGED_IN) {
function awaitSyncingSpinner(matrixChat, retryLimit, retryCount) { return Promise.resolve();
if (retryLimit === undefined) {
retryLimit = 10;
} }
if (retryCount === undefined) { return new Promise(resolve => {
retryCount = 0; const onAction = ({ action }) => {
} if (action !== "on_logged_in") {
return;
if (matrixChat.state.view === VIEWS.LOADING || }
matrixChat.state.view === VIEWS.LOGGING_IN) { console.log(Date.now() + ": Received on_logged_in action");
console.log(Date.now() + " Awaiting sync spinner: still loading."); dis.unregister(dispatcherRef);
if (retryCount >= retryLimit) { resolve();
throw new Error("MatrixChat still not loaded after " + };
retryCount + " tries"); const dispatcherRef = dis.register(onAction);
} console.log(Date.now() + ": Waiting for on_logged_in action");
// 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");
} }
function awaitRoomView(matrixChat, retryLimit, retryCount) { function awaitRoomView(matrixChat, retryLimit, retryCount) {