Tweak tests to match updates to matrixchat

Mostly this is just making it look at the `view` state rather than the
individual boolean flags.

One other tweak merits explanation: we now implement the initial
couldn't-register-as-guest login with an explicit switch to the LOGIN view,
which means that the URL gets updated to #/login.

We also now need to give the login panel a bit longer to appear.
pull/4325/head
Richard van der Hoff 2017-06-13 14:45:05 +01:00
parent 05c667b34b
commit 641f20a4f6
2 changed files with 22 additions and 20 deletions

View File

@ -216,11 +216,10 @@ function getConfig() {
return deferred.promise; return deferred.promise;
} }
function onLoadCompleted() { function onTokenLoginCompleted() {
// if we did a token login, we're now left with the token, hs and is // if we did a token login, we're now left with the token, hs and is
// url as query params in the url; a little nasty but let's redirect to // url as query params in the url; a little nasty but let's redirect to
// clear them. // clear them.
if (window.location.search) {
var parsedUrl = url.parse(window.location.href); var parsedUrl = url.parse(window.location.href);
parsedUrl.search = ""; parsedUrl.search = "";
var formatted = url.format(parsedUrl); var formatted = url.format(parsedUrl);
@ -228,7 +227,6 @@ function onLoadCompleted() {
"from queryparams"); "from queryparams");
window.location.href = formatted; window.location.href = formatted;
} }
}
async function loadApp() { async function loadApp() {
await loadLanguage(); await loadLanguage();
@ -288,7 +286,7 @@ async function loadApp() {
realQueryParams={params} realQueryParams={params}
startingFragmentQueryParams={fragparts.params} startingFragmentQueryParams={fragparts.params}
enableGuest={true} enableGuest={true}
onLoadCompleted={onLoadCompleted} onTokenLoginCompleted={onTokenLoginCompleted}
initialScreenAfterLogin={getScreenFromLocation(window.location)} initialScreenAfterLogin={getScreenFromLocation(window.location)}
defaultDeviceDisplayName={PlatformPeg.get().getDefaultDeviceDisplayName()} defaultDeviceDisplayName={PlatformPeg.get().getDefaultDeviceDisplayName()}
/>, />,

View File

@ -29,6 +29,7 @@ import jssdk from 'matrix-js-sdk';
import sdk from 'matrix-react-sdk'; import sdk from 'matrix-react-sdk';
import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg'; import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg';
import * as languageHandler from 'matrix-react-sdk/lib/languageHandler'; import * as languageHandler from 'matrix-react-sdk/lib/languageHandler';
import {VIEWS} from 'matrix-react-sdk/lib/components/structures/MatrixChat';
import * as test_utils from '../test-utils'; import * as test_utils from '../test-utils';
import MockHttpBackend from '../mock-request'; import MockHttpBackend from '../mock-request';
@ -47,7 +48,7 @@ describe('loading:', function () {
// the mounted MatrixChat // the mounted MatrixChat
let matrixChat; let matrixChat;
// a promise which resolves when the MatrixChat calls onLoadCompleted // a promise which resolves when the MatrixChat calls onTokenLoginCompleted
let loadCompletePromise; let loadCompletePromise;
beforeEach(function() { beforeEach(function() {
@ -135,7 +136,7 @@ describe('loading:', function () {
realQueryParams={params} realQueryParams={params}
startingFragmentQueryParams={fragParts.params} startingFragmentQueryParams={fragParts.params}
enableGuest={true} enableGuest={true}
onLoadCompleted={loadCompleteDefer.resolve} onTokenLoginCompleted={loadCompleteDefer.resolve}
initialScreenAfterLogin={getScreenFromLocation(windowLocation)} initialScreenAfterLogin={getScreenFromLocation(windowLocation)}
makeRegistrationUrl={() => {throw new Error('Not implemented');}} makeRegistrationUrl={() => {throw new Error('Not implemented');}}
/>, parentDiv />, parentDiv
@ -153,8 +154,8 @@ describe('loading:', function () {
.check((r) => {syncRequest = r;}) .check((r) => {syncRequest = r;})
.respond(200, response); .respond(200, response);
console.log("waiting for /sync");
for (let attempts = 10; attempts > 0; attempts--) { for (let attempts = 10; attempts > 0; attempts--) {
console.log(Date.now() + " waiting for /sync");
if (syncRequest) { if (syncRequest) {
return syncRequest; return syncRequest;
} }
@ -179,12 +180,12 @@ describe('loading:', function () {
return httpBackend.flush(); return httpBackend.flush();
}).then(() => { }).then(() => {
// Wait for another trip around the event loop for the UI to update // Wait for another trip around the event loop for the UI to update
return q.delay(1); return q.delay(10);
}).then(() => { }).then(() => {
// we expect a single <Login> component following session load // we expect a single <Login> component following session load
ReactTestUtils.findRenderedComponentWithType( ReactTestUtils.findRenderedComponentWithType(
matrixChat, sdk.getComponent('structures.login.Login')); matrixChat, sdk.getComponent('structures.login.Login'));
expect(windowLocation.hash).toEqual(""); expect(windowLocation.hash).toEqual("#/login");
}).done(done, done); }).done(done, done);
}); });
@ -205,7 +206,7 @@ describe('loading:', function () {
return httpBackend.flush(); return httpBackend.flush();
}).then(() => { }).then(() => {
// Wait for another trip around the event loop for the UI to update // Wait for another trip around the event loop for the UI to update
return q.delay(1); return q.delay(10);
}).then(() => { }).then(() => {
return completeLogin(matrixChat); return completeLogin(matrixChat);
}).then(() => { }).then(() => {
@ -360,6 +361,9 @@ describe('loading:', function () {
loadApp({ loadApp({
uriFragment: "#/login", uriFragment: "#/login",
}); });
// give the UI a chance to display
return q.delay(50);
}); });
it('shows a login view', function() { it('shows a login view', function() {
@ -513,7 +517,7 @@ describe('loading:', function () {
return httpBackend.flush(); return httpBackend.flush();
}).then(() => { }).then(() => {
// at this point, MatrixChat should fire onLoadCompleted, which // at this point, MatrixChat should fire onTokenLoginCompleted, which
// makes index.js reload the app. We're not going to attempt to // makes index.js reload the app. We're not going to attempt to
// simulate the reload - just check that things are left in the // simulate the reload - just check that things are left in the
// right state for the reloaded app. // right state for the reloaded app.
@ -589,7 +593,8 @@ function awaitSyncingSpinner(matrixChat, retryLimit, retryCount) {
retryCount = 0; retryCount = 0;
} }
if (matrixChat.state.loading || matrixChat.state.loggingIn) { if (matrixChat.state.view === VIEWS.LOADING ||
matrixChat.state.view === VIEWS.LOGGING_IN) {
console.log(Date.now() + " Awaiting sync spinner: still loading."); console.log(Date.now() + " Awaiting sync spinner: still loading.");
if (retryCount >= retryLimit) { if (retryCount >= retryLimit) {
throw new Error("MatrixChat still not loaded after " + throw new Error("MatrixChat still not loaded after " +
@ -628,8 +633,7 @@ function awaitRoomView(matrixChat, retryLimit, retryCount) {
retryCount = 0; retryCount = 0;
} }
if (matrixChat.state.loading || if (matrixChat.state.view !== VIEWS.LOGGED_IN || !matrixChat.state.ready) {
!(matrixChat.state.loggedIn && matrixChat.state.ready)) {
console.log(Date.now() + " Awaiting room view: not ready yet."); console.log(Date.now() + " Awaiting room view: not ready yet.");
if (retryCount >= retryLimit) { if (retryCount >= retryLimit) {
throw new Error("MatrixChat still not ready after " + throw new Error("MatrixChat still not ready after " +