2016-08-10 07:15:04 +08:00
|
|
|
/*
|
|
|
|
Copyright 2016 OpenMarket Ltd
|
2020-01-16 05:05:55 +08:00
|
|
|
Copyright 2020 New Vector Ltd
|
2016-08-10 07:15:04 +08:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* loading.js: test the myriad paths we have for loading the application */
|
|
|
|
|
2019-12-20 09:47:40 +08:00
|
|
|
import PlatformPeg from 'matrix-react-sdk/src/PlatformPeg';
|
2018-12-19 02:13:51 +08:00
|
|
|
import WebPlatform from '../../src/vector/platform/WebPlatform';
|
2020-01-14 08:38:34 +08:00
|
|
|
import '../skin-sdk';
|
2020-01-16 04:00:50 +08:00
|
|
|
import "../jest-mocks";
|
2016-08-10 07:15:04 +08:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
2019-08-01 22:31:33 +08:00
|
|
|
import ReactTestUtils from 'react-dom/test-utils';
|
2017-07-13 07:18:49 +08:00
|
|
|
import MatrixReactTestUtils from 'matrix-react-test-utils';
|
2020-01-14 08:38:34 +08:00
|
|
|
import * as jssdk from 'matrix-js-sdk';
|
|
|
|
import * as sdk from 'matrix-react-sdk';
|
2019-12-20 09:47:40 +08:00
|
|
|
import {MatrixClientPeg} from 'matrix-react-sdk/src/MatrixClientPeg';
|
2020-04-23 17:19:06 +08:00
|
|
|
import {Views} from 'matrix-react-sdk/src/components/structures/MatrixChat';
|
2020-05-14 11:15:30 +08:00
|
|
|
import dis from 'matrix-react-sdk/src/dispatcher/dispatcher';
|
2017-06-15 00:08:49 +08:00
|
|
|
import * as test_utils from '../test-utils';
|
2017-07-04 22:25:09 +08:00
|
|
|
import MockHttpBackend from 'matrix-mock-request';
|
2016-08-10 07:15:04 +08:00
|
|
|
import {parseQs, parseQsFromFragment} from '../../src/vector/url_utils';
|
2019-12-20 09:47:40 +08:00
|
|
|
import {makeType} from "matrix-react-sdk/src/utils/TypeUtils";
|
|
|
|
import {ValidatedServerConfig} from "matrix-react-sdk/src/utils/AutoDiscoveryUtils";
|
2019-11-04 20:46:28 +08:00
|
|
|
import {sleep} from "../test-utils";
|
2020-01-16 04:00:50 +08:00
|
|
|
import "fake-indexeddb/auto";
|
2020-01-16 05:06:24 +08:00
|
|
|
import {cleanLocalstorage} from "../test-utils";
|
2020-01-16 05:06:44 +08:00
|
|
|
import {IndexedDBCryptoStore} from "matrix-js-sdk/src/crypto/store/indexeddb-crypto-store";
|
2016-08-10 07:15:04 +08:00
|
|
|
|
2018-11-23 02:25:55 +08:00
|
|
|
const DEFAULT_HS_URL='http://my_server';
|
|
|
|
const DEFAULT_IS_URL='http://my_is';
|
2016-08-10 07:15:04 +08:00
|
|
|
|
2018-11-23 02:25:55 +08:00
|
|
|
describe('loading:', function() {
|
2016-08-10 07:15:04 +08:00
|
|
|
let parentDiv;
|
|
|
|
let httpBackend;
|
|
|
|
|
|
|
|
// an Object simulating the window.location
|
|
|
|
let windowLocation;
|
|
|
|
|
2016-08-11 09:00:27 +08:00
|
|
|
// the mounted MatrixChat
|
|
|
|
let matrixChat;
|
|
|
|
|
2017-06-16 22:05:14 +08:00
|
|
|
// a promise which resolves when the MatrixChat calls onTokenLoginCompleted
|
2017-06-19 16:04:24 +08:00
|
|
|
let tokenLoginCompletePromise;
|
2016-08-11 09:00:27 +08:00
|
|
|
|
2016-08-10 07:15:04 +08:00
|
|
|
beforeEach(function() {
|
|
|
|
httpBackend = new MockHttpBackend();
|
|
|
|
jssdk.request(httpBackend.requestFn);
|
|
|
|
parentDiv = document.createElement('div');
|
|
|
|
|
|
|
|
// uncomment this to actually add the div to the UI, to help with
|
|
|
|
// debugging (but slow things down)
|
|
|
|
// document.body.appendChild(parentDiv);
|
|
|
|
|
|
|
|
windowLocation = null;
|
2016-08-11 09:00:27 +08:00
|
|
|
matrixChat = null;
|
2016-08-10 07:15:04 +08:00
|
|
|
});
|
|
|
|
|
2018-11-23 02:25:55 +08:00
|
|
|
afterEach(async function() {
|
2017-06-21 00:41:21 +08:00
|
|
|
console.log(`${Date.now()}: loading: afterEach`);
|
2016-08-10 07:15:04 +08:00
|
|
|
if (parentDiv) {
|
|
|
|
ReactDOM.unmountComponentAtNode(parentDiv);
|
|
|
|
parentDiv.remove();
|
|
|
|
parentDiv = null;
|
|
|
|
}
|
2017-06-15 00:08:49 +08:00
|
|
|
|
|
|
|
// unmounting should have cleared the MatrixClientPeg
|
|
|
|
expect(MatrixClientPeg.get()).toBe(null);
|
|
|
|
|
|
|
|
// clear the indexeddbs so we can start from a clean slate next time.
|
2017-07-20 18:01:27 +08:00
|
|
|
await Promise.all([
|
|
|
|
test_utils.deleteIndexedDB('matrix-js-sdk:crypto'),
|
|
|
|
test_utils.deleteIndexedDB('matrix-js-sdk:riot-web-sync'),
|
|
|
|
]);
|
2020-01-16 05:06:24 +08:00
|
|
|
cleanLocalstorage();
|
2017-06-21 00:41:21 +08:00
|
|
|
console.log(`${Date.now()}: loading: afterEach complete`);
|
2016-08-10 07:15:04 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
/* simulate the load process done by index.js
|
|
|
|
*
|
|
|
|
* TODO: it would be nice to factor some of this stuff out of index.js so
|
|
|
|
* that we can test it rather than our own implementation of it.
|
|
|
|
*/
|
2021-10-01 21:41:22 +08:00
|
|
|
function loadApp(opts) {
|
2016-08-11 09:00:27 +08:00
|
|
|
opts = opts || {};
|
|
|
|
const queryString = opts.queryString || "";
|
|
|
|
const uriFragment = opts.uriFragment || "";
|
|
|
|
|
2016-08-10 07:15:04 +08:00
|
|
|
windowLocation = {
|
2016-08-11 09:00:27 +08:00
|
|
|
search: queryString,
|
2016-08-10 07:15:04 +08:00
|
|
|
hash: uriFragment,
|
|
|
|
toString: function() { return this.search + this.hash; },
|
|
|
|
};
|
|
|
|
|
|
|
|
function onNewScreen(screen) {
|
2017-01-24 19:26:09 +08:00
|
|
|
console.log(Date.now() + " newscreen "+screen);
|
2018-11-23 02:25:55 +08:00
|
|
|
const hash = '#/' + screen;
|
2017-06-15 01:00:02 +08:00
|
|
|
windowLocation.hash = hash;
|
|
|
|
console.log(Date.now() + " browser URI now "+ windowLocation);
|
2016-08-10 07:15:04 +08:00
|
|
|
}
|
|
|
|
|
2017-03-29 23:07:11 +08:00
|
|
|
// Parse the given window.location and return parameters that can be used when calling
|
|
|
|
// MatrixChat.showScreen(screen, params)
|
|
|
|
function getScreenFromLocation(location) {
|
|
|
|
const fragparts = parseQsFromFragment(location);
|
|
|
|
return {
|
|
|
|
screen: fragparts.location.substring(1),
|
|
|
|
params: fragparts.params,
|
2018-11-23 02:25:55 +08:00
|
|
|
};
|
2017-03-29 23:07:11 +08:00
|
|
|
}
|
|
|
|
|
2016-08-10 07:15:04 +08:00
|
|
|
const MatrixChat = sdk.getComponent('structures.MatrixChat');
|
|
|
|
const fragParts = parseQsFromFragment(windowLocation);
|
2017-06-15 09:17:24 +08:00
|
|
|
|
|
|
|
const config = Object.assign({
|
|
|
|
default_hs_url: DEFAULT_HS_URL,
|
|
|
|
default_is_url: DEFAULT_IS_URL,
|
2019-05-04 06:27:41 +08:00
|
|
|
validated_server_config: makeType(ValidatedServerConfig, {
|
2019-05-03 14:11:51 +08:00
|
|
|
hsUrl: DEFAULT_HS_URL,
|
|
|
|
hsName: "TEST_ENVIRONMENT",
|
|
|
|
hsNameIsDifferent: false, // yes, we lie
|
|
|
|
isUrl: DEFAULT_IS_URL,
|
2019-05-04 06:27:41 +08:00
|
|
|
}),
|
2019-02-14 21:29:57 +08:00
|
|
|
embeddedPages: {
|
|
|
|
homeUrl: 'data:text/html;charset=utf-8;base64,PGh0bWw+PC9odG1sPg==',
|
|
|
|
},
|
2017-06-15 09:17:24 +08:00
|
|
|
}, opts.config || {});
|
|
|
|
|
2018-12-19 02:13:51 +08:00
|
|
|
PlatformPeg.set(new WebPlatform());
|
2017-11-20 04:46:40 +08:00
|
|
|
|
2018-11-23 02:25:55 +08:00
|
|
|
const params = parseQs(windowLocation);
|
2019-03-26 20:46:26 +08:00
|
|
|
|
|
|
|
tokenLoginCompletePromise = new Promise(resolve => {
|
|
|
|
matrixChat = ReactDOM.render(
|
|
|
|
<MatrixChat
|
|
|
|
onNewScreen={onNewScreen}
|
|
|
|
config={config}
|
2019-05-04 06:27:41 +08:00
|
|
|
serverConfig={config.validated_server_config}
|
2019-03-26 20:46:26 +08:00
|
|
|
realQueryParams={params}
|
|
|
|
startingFragmentQueryParams={fragParts.params}
|
|
|
|
enableGuest={true}
|
|
|
|
onTokenLoginCompleted={resolve}
|
|
|
|
initialScreenAfterLogin={getScreenFromLocation(windowLocation)}
|
|
|
|
makeRegistrationUrl={() => {throw new Error('Not implemented');}}
|
|
|
|
/>, parentDiv,
|
|
|
|
);
|
|
|
|
});
|
2016-08-10 07:15:04 +08:00
|
|
|
}
|
|
|
|
|
2017-05-19 20:33:50 +08:00
|
|
|
// set an expectation that we will get a call to /sync, then flush
|
|
|
|
// http requests until we do.
|
|
|
|
//
|
|
|
|
// returns a promise resolving to the received request
|
2021-10-01 21:41:22 +08:00
|
|
|
async function expectAndAwaitSync(opts) {
|
2017-05-19 20:33:50 +08:00
|
|
|
let syncRequest = null;
|
2019-02-08 19:48:06 +08:00
|
|
|
const isGuest = opts && opts.isGuest;
|
|
|
|
if (!isGuest) {
|
|
|
|
httpBackend.when('GET', '/_matrix/client/versions')
|
|
|
|
.respond(200, {
|
|
|
|
"versions": ["r0.3.0"],
|
|
|
|
"unstable_features": {
|
|
|
|
"m.lazy_load_members": true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// the call to create the LL filter
|
|
|
|
httpBackend.when('POST', '/filter').respond(200, { filter_id: 'llfid' });
|
|
|
|
}
|
2017-05-19 20:33:50 +08:00
|
|
|
httpBackend.when('GET', '/sync')
|
|
|
|
.check((r) => {syncRequest = r;})
|
2019-02-08 19:48:06 +08:00
|
|
|
.respond(200, {});
|
2017-05-19 20:33:50 +08:00
|
|
|
|
|
|
|
for (let attempts = 10; attempts > 0; attempts--) {
|
2017-06-13 21:45:05 +08:00
|
|
|
console.log(Date.now() + " waiting for /sync");
|
2017-05-19 20:33:50 +08:00
|
|
|
if (syncRequest) {
|
|
|
|
return syncRequest;
|
|
|
|
}
|
|
|
|
await httpBackend.flush();
|
|
|
|
}
|
|
|
|
throw new Error("Gave up waiting for /sync");
|
|
|
|
}
|
|
|
|
|
2016-08-10 07:15:04 +08:00
|
|
|
describe("Clean load with no stored credentials:", function() {
|
2019-11-22 22:08:45 +08:00
|
|
|
it('gives a welcome page by default', function() {
|
2016-08-11 09:00:27 +08:00
|
|
|
loadApp();
|
2016-08-10 07:15:04 +08:00
|
|
|
|
2019-11-22 22:08:45 +08:00
|
|
|
return sleep(1).then(() => {
|
2016-08-10 07:15:04 +08:00
|
|
|
// at this point, we're trying to do a guest registration;
|
|
|
|
// we expect a spinner
|
2016-08-10 21:37:30 +08:00
|
|
|
assertAtLoadingSpinner(matrixChat);
|
2016-08-10 07:15:04 +08:00
|
|
|
|
|
|
|
httpBackend.when('POST', '/register').check(function(req) {
|
|
|
|
expect(req.queryParams.kind).toEqual('guest');
|
|
|
|
}).respond(403, "Guest access is disabled");
|
|
|
|
|
|
|
|
return httpBackend.flush();
|
2017-06-06 22:54:45 +08:00
|
|
|
}).then(() => {
|
|
|
|
// Wait for another trip around the event loop for the UI to update
|
2019-02-09 00:35:39 +08:00
|
|
|
return awaitWelcomeComponent(matrixChat);
|
2016-12-09 22:27:41 +08:00
|
|
|
}).then(() => {
|
2019-02-09 00:35:39 +08:00
|
|
|
expect(windowLocation.hash).toEqual("#/welcome");
|
2019-11-22 22:08:45 +08:00
|
|
|
});
|
2016-08-10 07:15:04 +08:00
|
|
|
});
|
|
|
|
|
2019-11-22 22:08:45 +08:00
|
|
|
it('should follow the original link after successful login', function() {
|
2016-08-11 09:00:27 +08:00
|
|
|
loadApp({
|
|
|
|
uriFragment: "#/room/!room:id",
|
|
|
|
});
|
2016-08-10 07:15:04 +08:00
|
|
|
|
2019-06-05 23:53:22 +08:00
|
|
|
// Pass the liveliness checks
|
|
|
|
httpBackend.when("GET", "/versions").respond(200, {versions: ["r0.4.0"]});
|
|
|
|
httpBackend.when("GET", "/api/v1").respond(200, {});
|
|
|
|
|
2019-11-22 22:08:45 +08:00
|
|
|
return sleep(1).then(() => {
|
2016-08-10 07:15:04 +08:00
|
|
|
// at this point, we're trying to do a guest registration;
|
|
|
|
// we expect a spinner
|
2016-08-10 21:37:30 +08:00
|
|
|
assertAtLoadingSpinner(matrixChat);
|
2016-08-10 07:15:04 +08:00
|
|
|
|
|
|
|
httpBackend.when('POST', '/register').check(function(req) {
|
|
|
|
expect(req.queryParams.kind).toEqual('guest');
|
|
|
|
}).respond(403, "Guest access is disabled");
|
|
|
|
|
|
|
|
return httpBackend.flush();
|
2016-12-09 22:27:41 +08:00
|
|
|
}).then(() => {
|
|
|
|
// Wait for another trip around the event loop for the UI to update
|
2019-11-04 20:46:28 +08:00
|
|
|
return sleep(10);
|
2019-02-09 00:35:39 +08:00
|
|
|
}).then(() => {
|
|
|
|
return moveFromWelcomeToLogin(matrixChat);
|
2016-08-10 07:15:04 +08:00
|
|
|
}).then(() => {
|
2017-06-13 19:52:35 +08:00
|
|
|
return completeLogin(matrixChat);
|
2016-08-10 07:15:04 +08:00
|
|
|
}).then(() => {
|
|
|
|
// once the sync completes, we should have a room view
|
2017-01-24 21:35:41 +08:00
|
|
|
return awaitRoomView(matrixChat);
|
|
|
|
}).then(() => {
|
2016-08-10 07:15:04 +08:00
|
|
|
httpBackend.verifyNoOutstandingExpectation();
|
|
|
|
expect(windowLocation.hash).toEqual("#/room/!room:id");
|
2016-08-11 09:00:27 +08:00
|
|
|
|
|
|
|
// and the localstorage should have been updated
|
|
|
|
expect(localStorage.getItem('mx_user_id')).toEqual('@user:id');
|
|
|
|
expect(localStorage.getItem('mx_access_token')).toEqual('access_token');
|
|
|
|
expect(localStorage.getItem('mx_hs_url')).toEqual(DEFAULT_HS_URL);
|
|
|
|
expect(localStorage.getItem('mx_is_url')).toEqual(DEFAULT_IS_URL);
|
2019-11-22 22:08:45 +08:00
|
|
|
});
|
2019-02-11 18:06:44 +08:00
|
|
|
});
|
2017-06-14 23:59:00 +08:00
|
|
|
|
2019-02-11 18:06:44 +08:00
|
|
|
it('should not register as a guest when using a #/login link', function() {
|
2017-06-14 23:59:00 +08:00
|
|
|
loadApp({
|
|
|
|
uriFragment: "#/login",
|
|
|
|
});
|
|
|
|
|
2019-06-05 23:53:22 +08:00
|
|
|
// Pass the liveliness checks
|
|
|
|
httpBackend.when("GET", "/versions").respond(200, {versions: ["r0.4.0"]});
|
|
|
|
httpBackend.when("GET", "/api/v1").respond(200, {});
|
|
|
|
|
2017-07-13 07:18:49 +08:00
|
|
|
return awaitLoginComponent(matrixChat).then(() => {
|
2017-06-14 23:59:00 +08:00
|
|
|
// we expect a single <Login> component
|
|
|
|
ReactTestUtils.findRenderedComponentWithType(
|
2019-01-22 06:12:36 +08:00
|
|
|
matrixChat, sdk.getComponent('structures.auth.Login'));
|
2017-06-14 23:59:00 +08:00
|
|
|
|
|
|
|
// the only outstanding request should be a GET /login
|
|
|
|
// (in particular there should be no /register request for
|
|
|
|
// guest registration).
|
2019-06-05 23:53:22 +08:00
|
|
|
const allowedRequests = [
|
|
|
|
"/_matrix/client/r0/login",
|
|
|
|
"/versions",
|
|
|
|
"/api/v1",
|
|
|
|
];
|
2017-06-14 23:59:00 +08:00
|
|
|
for (const req of httpBackend.requests) {
|
2019-06-05 23:53:22 +08:00
|
|
|
if (req.method === 'GET' && allowedRequests.find(p => req.path.endsWith(p))) {
|
2017-06-14 23:59:00 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error(`Unexpected HTTP request to ${req}`);
|
|
|
|
}
|
|
|
|
return completeLogin(matrixChat);
|
|
|
|
}).then(() => {
|
|
|
|
// once the sync completes, we should have a room view
|
|
|
|
ReactTestUtils.findRenderedComponentWithType(
|
2019-02-09 00:35:39 +08:00
|
|
|
matrixChat, sdk.getComponent('structures.EmbeddedPage'));
|
2017-06-14 23:59:00 +08:00
|
|
|
expect(windowLocation.hash).toEqual("#/home");
|
|
|
|
});
|
2019-02-11 18:06:44 +08:00
|
|
|
});
|
2016-08-10 07:15:04 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("MatrixClient rehydrated from stored credentials:", function() {
|
2019-03-30 02:01:04 +08:00
|
|
|
beforeEach(async function() {
|
2016-08-10 21:37:30 +08:00
|
|
|
localStorage.setItem("mx_hs_url", "http://localhost" );
|
|
|
|
localStorage.setItem("mx_is_url", "http://localhost" );
|
|
|
|
localStorage.setItem("mx_access_token", "access_token");
|
|
|
|
localStorage.setItem("mx_user_id", "@me:localhost");
|
2017-06-13 19:52:35 +08:00
|
|
|
localStorage.setItem("mx_last_room_id", "!last_room:id");
|
2019-03-30 02:01:04 +08:00
|
|
|
|
|
|
|
// Create a crypto store as well to satisfy storage consistency checks
|
2020-01-16 05:06:44 +08:00
|
|
|
const cryptoStore = new IndexedDBCryptoStore(
|
2019-03-30 02:01:04 +08:00
|
|
|
indexedDB,
|
|
|
|
"matrix-js-sdk:crypto",
|
|
|
|
);
|
2020-02-27 22:57:52 +08:00
|
|
|
await cryptoStore.startup();
|
2017-06-13 19:52:35 +08:00
|
|
|
});
|
|
|
|
|
2019-02-11 18:06:44 +08:00
|
|
|
it('shows the last known room by default', function() {
|
2017-06-13 19:52:35 +08:00
|
|
|
httpBackend.when('GET', '/pushrules').respond(200, {});
|
|
|
|
|
|
|
|
loadApp();
|
|
|
|
|
2019-03-26 23:18:40 +08:00
|
|
|
return awaitLoggedIn(matrixChat).then(() => {
|
|
|
|
// we are logged in - let the sync complete
|
2017-06-13 19:52:35 +08:00
|
|
|
return expectAndAwaitSync();
|
|
|
|
}).then(() => {
|
|
|
|
// once the sync completes, we should have a room view
|
|
|
|
return awaitRoomView(matrixChat);
|
|
|
|
}).then(() => {
|
|
|
|
httpBackend.verifyNoOutstandingExpectation();
|
|
|
|
expect(windowLocation.hash).toEqual("#/room/!last_room:id");
|
|
|
|
});
|
2016-08-10 07:15:04 +08:00
|
|
|
});
|
|
|
|
|
2019-11-22 22:08:45 +08:00
|
|
|
it('shows a home page by default if we have no joined rooms', function() {
|
2017-06-13 19:52:35 +08:00
|
|
|
localStorage.removeItem("mx_last_room_id");
|
|
|
|
|
2016-08-10 07:15:04 +08:00
|
|
|
httpBackend.when('GET', '/pushrules').respond(200, {});
|
|
|
|
|
2016-08-11 09:00:27 +08:00
|
|
|
loadApp();
|
2016-08-10 07:15:04 +08:00
|
|
|
|
2019-11-22 22:08:45 +08:00
|
|
|
return awaitLoggedIn(matrixChat).then(() => {
|
2019-03-26 23:18:40 +08:00
|
|
|
// we are logged in - let the sync complete
|
2017-05-19 20:33:50 +08:00
|
|
|
return expectAndAwaitSync();
|
2016-08-10 07:15:04 +08:00
|
|
|
}).then(() => {
|
2017-05-30 19:55:50 +08:00
|
|
|
// once the sync completes, we should have a home page
|
2016-08-10 07:15:04 +08:00
|
|
|
httpBackend.verifyNoOutstandingExpectation();
|
|
|
|
ReactTestUtils.findRenderedComponentWithType(
|
2019-02-09 00:35:39 +08:00
|
|
|
matrixChat, sdk.getComponent('structures.EmbeddedPage'));
|
2017-05-30 19:55:50 +08:00
|
|
|
expect(windowLocation.hash).toEqual("#/home");
|
2019-11-22 22:08:45 +08:00
|
|
|
});
|
2016-08-10 07:15:04 +08:00
|
|
|
});
|
|
|
|
|
2019-11-22 22:08:45 +08:00
|
|
|
it('shows a room view if we followed a room link', function() {
|
2016-08-10 07:15:04 +08:00
|
|
|
httpBackend.when('GET', '/pushrules').respond(200, {});
|
|
|
|
|
2016-08-11 09:00:27 +08:00
|
|
|
loadApp({
|
|
|
|
uriFragment: "#/room/!room:id",
|
|
|
|
});
|
2016-08-10 07:15:04 +08:00
|
|
|
|
2019-11-22 22:08:45 +08:00
|
|
|
return awaitLoggedIn(matrixChat).then(() => {
|
2019-03-26 23:18:40 +08:00
|
|
|
// we are logged in - let the sync complete
|
2017-05-19 20:33:50 +08:00
|
|
|
return expectAndAwaitSync();
|
2016-08-10 07:15:04 +08:00
|
|
|
}).then(() => {
|
|
|
|
// once the sync completes, we should have a room view
|
2017-01-24 21:35:41 +08:00
|
|
|
return awaitRoomView(matrixChat);
|
|
|
|
}).then(() => {
|
2016-08-10 07:15:04 +08:00
|
|
|
httpBackend.verifyNoOutstandingExpectation();
|
|
|
|
expect(windowLocation.hash).toEqual("#/room/!room:id");
|
2019-11-22 22:08:45 +08:00
|
|
|
});
|
2019-02-11 18:06:44 +08:00
|
|
|
});
|
2016-08-10 07:15:04 +08:00
|
|
|
|
2017-06-13 19:52:35 +08:00
|
|
|
describe('/#/login link:', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
loadApp({
|
|
|
|
uriFragment: "#/login",
|
|
|
|
});
|
2017-06-16 22:05:14 +08:00
|
|
|
|
2017-06-13 21:45:05 +08:00
|
|
|
// give the UI a chance to display
|
2017-07-13 07:18:49 +08:00
|
|
|
return awaitLoginComponent(matrixChat);
|
2017-06-13 19:52:35 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('shows a login view', function() {
|
2019-06-05 23:53:22 +08:00
|
|
|
// Pass the liveliness checks
|
|
|
|
httpBackend.when("GET", "/versions").respond(200, {versions: ["r0.4.0"]});
|
|
|
|
httpBackend.when("GET", "/api/v1").respond(200, {});
|
|
|
|
|
2017-06-13 19:52:35 +08:00
|
|
|
// we expect a single <Login> component
|
2017-06-14 23:59:00 +08:00
|
|
|
ReactTestUtils.findRenderedComponentWithType(
|
2019-01-22 06:12:36 +08:00
|
|
|
matrixChat, sdk.getComponent('structures.auth.Login'),
|
2017-06-13 19:52:35 +08:00
|
|
|
);
|
2017-06-14 23:59:00 +08:00
|
|
|
|
|
|
|
// the only outstanding request should be a GET /login
|
|
|
|
// (in particular there should be no /register request for
|
|
|
|
// guest registration, nor /sync, etc).
|
2019-06-05 23:53:22 +08:00
|
|
|
const allowedRequests = [
|
|
|
|
"/_matrix/client/r0/login",
|
|
|
|
"/versions",
|
|
|
|
"/api/v1",
|
|
|
|
];
|
2017-06-14 23:59:00 +08:00
|
|
|
for (const req of httpBackend.requests) {
|
2019-06-05 23:53:22 +08:00
|
|
|
if (req.method === 'GET' && allowedRequests.find(p => req.path.endsWith(p))) {
|
2017-06-14 23:59:00 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error(`Unexpected HTTP request to ${req}`);
|
|
|
|
}
|
2017-06-13 19:52:35 +08:00
|
|
|
});
|
|
|
|
|
2019-02-11 18:06:44 +08:00
|
|
|
it('shows the homepage after login', function() {
|
2019-06-05 23:53:22 +08:00
|
|
|
// Pass the liveliness checks
|
|
|
|
httpBackend.when("GET", "/versions").respond(200, {versions: ["r0.4.0"]});
|
|
|
|
httpBackend.when("GET", "/api/v1").respond(200, {});
|
|
|
|
|
2017-06-13 19:52:35 +08:00
|
|
|
return completeLogin(matrixChat).then(() => {
|
2017-06-14 23:59:00 +08:00
|
|
|
// we should see a home page, even though we previously had
|
|
|
|
// a stored mx_last_room_id
|
2017-06-13 19:52:35 +08:00
|
|
|
ReactTestUtils.findRenderedComponentWithType(
|
2019-02-09 00:35:39 +08:00
|
|
|
matrixChat, sdk.getComponent('structures.EmbeddedPage'));
|
2017-06-13 19:52:35 +08:00
|
|
|
expect(windowLocation.hash).toEqual("#/home");
|
|
|
|
});
|
2019-02-11 18:06:44 +08:00
|
|
|
});
|
2016-08-10 07:15:04 +08:00
|
|
|
});
|
|
|
|
});
|
2016-08-10 21:37:30 +08:00
|
|
|
|
|
|
|
describe('Guest auto-registration:', function() {
|
2019-11-22 22:08:45 +08:00
|
|
|
it('shows a welcome page by default', function() {
|
2016-08-11 09:00:27 +08:00
|
|
|
loadApp();
|
2016-08-10 21:37:30 +08:00
|
|
|
|
2019-11-22 22:08:45 +08:00
|
|
|
return sleep(1).then(() => {
|
2016-08-10 21:37:30 +08:00
|
|
|
// at this point, we're trying to do a guest registration;
|
|
|
|
// we expect a spinner
|
|
|
|
assertAtLoadingSpinner(matrixChat);
|
|
|
|
|
|
|
|
httpBackend.when('POST', '/register').check(function(req) {
|
|
|
|
expect(req.queryParams.kind).toEqual('guest');
|
|
|
|
}).respond(200, {
|
|
|
|
user_id: "@guest:localhost",
|
|
|
|
access_token: "secret_token",
|
|
|
|
});
|
|
|
|
|
|
|
|
return httpBackend.flush();
|
2016-12-09 22:27:41 +08:00
|
|
|
}).then(() => {
|
2019-03-26 23:18:40 +08:00
|
|
|
return awaitLoggedIn(matrixChat);
|
2016-08-10 21:37:30 +08:00
|
|
|
}).then(() => {
|
2019-03-26 23:18:40 +08:00
|
|
|
// we are logged in - let the sync complete
|
2019-02-08 19:48:06 +08:00
|
|
|
return expectAndAwaitSync({isGuest: true});
|
2016-08-10 21:37:30 +08:00
|
|
|
}).then(() => {
|
2019-02-09 00:35:39 +08:00
|
|
|
// once the sync completes, we should have a welcome page
|
2016-08-10 21:37:30 +08:00
|
|
|
httpBackend.verifyNoOutstandingExpectation();
|
|
|
|
ReactTestUtils.findRenderedComponentWithType(
|
2019-02-09 00:35:39 +08:00
|
|
|
matrixChat, sdk.getComponent('auth.Welcome'));
|
|
|
|
expect(windowLocation.hash).toEqual("#/welcome");
|
2019-11-22 22:08:45 +08:00
|
|
|
});
|
2019-02-11 23:18:29 +08:00
|
|
|
});
|
2016-08-10 21:37:30 +08:00
|
|
|
|
2019-11-22 22:08:45 +08:00
|
|
|
it('uses the default homeserver to register with', function() {
|
2016-08-11 09:00:27 +08:00
|
|
|
loadApp();
|
|
|
|
|
2019-11-22 22:08:45 +08:00
|
|
|
return sleep(1).then(() => {
|
2016-08-11 09:00:27 +08:00
|
|
|
// at this point, we're trying to do a guest registration;
|
|
|
|
// we expect a spinner
|
|
|
|
assertAtLoadingSpinner(matrixChat);
|
|
|
|
|
|
|
|
httpBackend.when('POST', '/register').check(function(req) {
|
2020-01-16 05:44:46 +08:00
|
|
|
expect(req.path.startsWith(DEFAULT_HS_URL)).toBe(true);
|
2016-08-11 09:00:27 +08:00
|
|
|
expect(req.queryParams.kind).toEqual('guest');
|
|
|
|
}).respond(200, {
|
|
|
|
user_id: "@guest:localhost",
|
|
|
|
access_token: "secret_token",
|
|
|
|
});
|
|
|
|
|
|
|
|
return httpBackend.flush();
|
2016-12-09 22:27:41 +08:00
|
|
|
}).then(() => {
|
2019-03-26 23:18:40 +08:00
|
|
|
return awaitLoggedIn(matrixChat);
|
2016-08-11 09:00:27 +08:00
|
|
|
}).then(() => {
|
2019-02-08 19:48:06 +08:00
|
|
|
return expectAndAwaitSync({isGuest: true});
|
2017-05-19 20:33:50 +08:00
|
|
|
}).then((req) => {
|
2020-01-16 05:44:46 +08:00
|
|
|
expect(req.path.startsWith(DEFAULT_HS_URL)).toBe(true);
|
2017-05-19 20:33:50 +08:00
|
|
|
|
2019-02-11 23:18:29 +08:00
|
|
|
// once the sync completes, we should have a welcome page
|
2016-08-11 09:00:27 +08:00
|
|
|
httpBackend.verifyNoOutstandingExpectation();
|
|
|
|
ReactTestUtils.findRenderedComponentWithType(
|
2019-02-11 23:18:29 +08:00
|
|
|
matrixChat, sdk.getComponent('auth.Welcome'));
|
|
|
|
expect(windowLocation.hash).toEqual("#/welcome");
|
2018-12-12 00:13:46 +08:00
|
|
|
expect(MatrixClientPeg.get().baseUrl).toEqual(DEFAULT_HS_URL);
|
|
|
|
expect(MatrixClientPeg.get().idBaseUrl).toEqual(DEFAULT_IS_URL);
|
2019-11-22 22:08:45 +08:00
|
|
|
});
|
2019-02-11 23:18:29 +08:00
|
|
|
});
|
2016-08-11 09:00:27 +08:00
|
|
|
|
2019-11-22 22:08:45 +08:00
|
|
|
it('shows a room view if we followed a room link', function() {
|
2016-08-11 09:00:27 +08:00
|
|
|
loadApp({
|
2018-11-23 02:25:55 +08:00
|
|
|
uriFragment: "#/room/!room:id",
|
2016-08-11 09:00:27 +08:00
|
|
|
});
|
2019-11-22 22:08:45 +08:00
|
|
|
return sleep(1).then(() => {
|
2016-08-10 21:37:30 +08:00
|
|
|
// at this point, we're trying to do a guest registration;
|
|
|
|
// we expect a spinner
|
|
|
|
assertAtLoadingSpinner(matrixChat);
|
|
|
|
|
|
|
|
httpBackend.when('POST', '/register').check(function(req) {
|
|
|
|
expect(req.queryParams.kind).toEqual('guest');
|
|
|
|
}).respond(200, {
|
|
|
|
user_id: "@guest:localhost",
|
|
|
|
access_token: "secret_token",
|
|
|
|
});
|
|
|
|
|
|
|
|
return httpBackend.flush();
|
2016-12-09 22:27:41 +08:00
|
|
|
}).then(() => {
|
2019-03-26 23:18:40 +08:00
|
|
|
return awaitLoggedIn(matrixChat);
|
2016-08-10 21:37:30 +08:00
|
|
|
}).then(() => {
|
2019-02-08 19:48:06 +08:00
|
|
|
return expectAndAwaitSync({isGuest: true});
|
2016-08-10 21:37:30 +08:00
|
|
|
}).then(() => {
|
|
|
|
// once the sync completes, we should have a room view
|
2017-01-24 21:35:41 +08:00
|
|
|
return awaitRoomView(matrixChat);
|
|
|
|
}).then(() => {
|
2016-08-10 21:37:30 +08:00
|
|
|
httpBackend.verifyNoOutstandingExpectation();
|
|
|
|
expect(windowLocation.hash).toEqual("#/room/!room:id");
|
2019-11-22 22:08:45 +08:00
|
|
|
});
|
2016-08-10 21:37:30 +08:00
|
|
|
});
|
2017-06-15 03:27:02 +08:00
|
|
|
|
|
|
|
describe('Login as user', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
// first we have to load the homepage
|
|
|
|
loadApp();
|
|
|
|
|
|
|
|
httpBackend.when('POST', '/register').check(function(req) {
|
|
|
|
expect(req.queryParams.kind).toEqual('guest');
|
|
|
|
}).respond(200, {
|
|
|
|
user_id: "@guest:localhost",
|
|
|
|
access_token: "secret_token",
|
|
|
|
});
|
|
|
|
|
|
|
|
return httpBackend.flush().then(() => {
|
2019-03-26 23:18:40 +08:00
|
|
|
return awaitLoggedIn(matrixChat);
|
2017-06-15 03:27:02 +08:00
|
|
|
}).then(() => {
|
|
|
|
// we got a sync spinner - let the sync complete
|
|
|
|
return expectAndAwaitSync();
|
|
|
|
}).then(() => {
|
|
|
|
// once the sync completes, we should have a home page
|
|
|
|
ReactTestUtils.findRenderedComponentWithType(
|
2019-02-09 00:35:39 +08:00
|
|
|
matrixChat, sdk.getComponent('structures.EmbeddedPage'));
|
2017-06-15 03:27:02 +08:00
|
|
|
|
|
|
|
// we simulate a click on the 'login' button by firing off
|
|
|
|
// the relevant dispatch.
|
|
|
|
//
|
|
|
|
// XXX: is it an anti-pattern to access the react-sdk's
|
|
|
|
// dispatcher in this way? Is it better to find the login
|
|
|
|
// button and simulate a click? (we might have to arrange
|
|
|
|
// for it to be shown - it's not always, due to the
|
|
|
|
// collapsing left panel
|
|
|
|
|
|
|
|
dis.dispatch({ action: 'start_login' });
|
|
|
|
|
2017-07-13 07:18:49 +08:00
|
|
|
return awaitLoginComponent(matrixChat);
|
2017-06-15 03:27:02 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-11 23:18:29 +08:00
|
|
|
it('should give us a login page', function() {
|
2017-06-15 03:27:02 +08:00
|
|
|
expect(windowLocation.hash).toEqual("#/login");
|
|
|
|
|
|
|
|
// we expect a single <Login> component
|
|
|
|
ReactTestUtils.findRenderedComponentWithType(
|
2019-01-22 06:12:36 +08:00
|
|
|
matrixChat, sdk.getComponent('structures.auth.Login'),
|
2017-06-15 03:27:02 +08:00
|
|
|
);
|
2019-02-11 23:18:29 +08:00
|
|
|
});
|
2017-06-15 03:27:02 +08:00
|
|
|
|
2017-10-27 01:08:42 +08:00
|
|
|
/*
|
|
|
|
// ILAG renders this obsolete. I think.
|
2017-06-15 03:27:02 +08:00
|
|
|
it('should allow us to return to the app', function() {
|
|
|
|
const login = ReactTestUtils.findRenderedComponentWithType(
|
2019-01-22 06:12:36 +08:00
|
|
|
matrixChat, sdk.getComponent('structures.auth.Login')
|
2017-06-15 03:27:02 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
const linkText = 'Return to app';
|
|
|
|
|
|
|
|
const returnToApp = ReactTestUtils.scryRenderedDOMComponentsWithTag(
|
|
|
|
login, 'a').find((e) => e.innerText === linkText);
|
|
|
|
|
|
|
|
if (!returnToApp) {
|
|
|
|
throw new Error(`Couldn't find '${linkText}' link`);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReactTestUtils.Simulate.click(returnToApp);
|
|
|
|
|
2019-11-04 20:46:28 +08:00
|
|
|
return sleep(1).then(() => {
|
2017-06-15 03:27:02 +08:00
|
|
|
// we should be straight back into the home page
|
|
|
|
ReactTestUtils.findRenderedComponentWithType(
|
2019-02-09 00:35:39 +08:00
|
|
|
matrixChat, sdk.getComponent('structures.EmbeddedPage'));
|
2017-06-15 03:27:02 +08:00
|
|
|
});
|
|
|
|
});
|
2017-10-27 01:08:42 +08:00
|
|
|
*/
|
2017-06-15 03:27:02 +08:00
|
|
|
});
|
2016-08-10 21:37:30 +08:00
|
|
|
});
|
2016-08-11 09:00:27 +08:00
|
|
|
|
|
|
|
describe('Token login:', function() {
|
2019-11-22 22:08:45 +08:00
|
|
|
it('logs in successfully', function() {
|
2020-06-26 06:59:08 +08:00
|
|
|
localStorage.setItem("mx_sso_hs_url", "https://homeserver");
|
|
|
|
localStorage.setItem("mx_sso_is_url", "https://idserver");
|
2016-08-11 09:00:27 +08:00
|
|
|
loadApp({
|
2020-06-04 03:34:20 +08:00
|
|
|
queryString: "?loginToken=secretToken",
|
2016-08-11 09:00:27 +08:00
|
|
|
});
|
|
|
|
|
2019-11-22 22:08:45 +08:00
|
|
|
return sleep(1).then(() => {
|
2016-08-11 09:00:27 +08:00
|
|
|
// we expect a spinner while we're logging in
|
|
|
|
assertAtLoadingSpinner(matrixChat);
|
|
|
|
|
|
|
|
httpBackend.when('POST', '/login').check(function(req) {
|
|
|
|
expect(req.path).toMatch(new RegExp("^https://homeserver/"));
|
|
|
|
expect(req.data.type).toEqual("m.login.token");
|
|
|
|
expect(req.data.token).toEqual("secretToken");
|
|
|
|
}).respond(200, {
|
|
|
|
user_id: "@user:localhost",
|
2017-02-03 07:41:49 +08:00
|
|
|
device_id: 'DEVICE_ID',
|
2016-08-11 09:00:27 +08:00
|
|
|
access_token: "access_token",
|
|
|
|
});
|
|
|
|
|
|
|
|
return httpBackend.flush();
|
|
|
|
}).then(() => {
|
2017-06-16 22:05:14 +08:00
|
|
|
// at this point, MatrixChat should fire onTokenLoginCompleted, which
|
2016-08-11 09:00:27 +08:00
|
|
|
// makes index.js reload the app. We're not going to attempt to
|
|
|
|
// simulate the reload - just check that things are left in the
|
|
|
|
// right state for the reloaded app.
|
|
|
|
|
2017-06-19 16:04:24 +08:00
|
|
|
return tokenLoginCompletePromise;
|
2016-08-11 09:00:27 +08:00
|
|
|
}).then(() => {
|
|
|
|
// check that the localstorage has been set up in such a way that
|
|
|
|
// the reloaded app can pick up where we leave off.
|
|
|
|
expect(localStorage.getItem('mx_user_id')).toEqual('@user:localhost');
|
|
|
|
expect(localStorage.getItem('mx_access_token')).toEqual('access_token');
|
|
|
|
expect(localStorage.getItem('mx_hs_url')).toEqual('https://homeserver');
|
|
|
|
expect(localStorage.getItem('mx_is_url')).toEqual('https://idserver');
|
2019-11-22 22:08:45 +08:00
|
|
|
});
|
2016-08-11 09:00:27 +08:00
|
|
|
});
|
|
|
|
});
|
2017-06-13 19:52:35 +08:00
|
|
|
|
|
|
|
// check that we have a Login component, send a 'user:pass' login,
|
|
|
|
// and await the HTTP requests.
|
2019-05-04 06:27:41 +08:00
|
|
|
async function completeLogin(matrixChat) {
|
2017-06-13 19:52:35 +08:00
|
|
|
// we expect a single <Login> component
|
|
|
|
const login = ReactTestUtils.findRenderedComponentWithType(
|
2021-10-01 21:41:22 +08:00
|
|
|
matrixChat, sdk.getComponent('structures.auth.Login'));
|
2017-06-13 19:52:35 +08:00
|
|
|
|
2019-05-04 06:27:41 +08:00
|
|
|
// When we switch to the login component, it'll hit the login endpoint
|
|
|
|
// for proof of life and to get flows. We'll only give it one option.
|
|
|
|
httpBackend.when('GET', '/login')
|
|
|
|
.respond(200, {"flows": [{"type": "m.login.password"}]});
|
|
|
|
httpBackend.flush(); // We already would have tried the GET /login request
|
|
|
|
|
|
|
|
// Give the component some time to finish processing the login flows before
|
|
|
|
// continuing.
|
2019-11-04 20:46:28 +08:00
|
|
|
await sleep(100);
|
2019-05-04 06:27:41 +08:00
|
|
|
|
2017-06-13 19:52:35 +08:00
|
|
|
httpBackend.when('POST', '/login').check(function(req) {
|
|
|
|
expect(req.data.type).toEqual('m.login.password');
|
|
|
|
expect(req.data.identifier.type).toEqual('m.id.user');
|
|
|
|
expect(req.data.identifier.user).toEqual('user');
|
|
|
|
expect(req.data.password).toEqual('pass');
|
|
|
|
}).respond(200, {
|
|
|
|
user_id: '@user:id',
|
|
|
|
device_id: 'DEVICE_ID',
|
|
|
|
access_token: 'access_token',
|
|
|
|
});
|
|
|
|
login.onPasswordLogin("user", undefined, undefined, "pass");
|
|
|
|
|
|
|
|
return httpBackend.flush().then(() => {
|
|
|
|
// Wait for another trip around the event loop for the UI to update
|
2019-11-04 20:46:28 +08:00
|
|
|
return sleep(1);
|
2017-06-13 19:52:35 +08:00
|
|
|
}).then(() => {
|
|
|
|
httpBackend.when('GET', '/pushrules').respond(200, {});
|
|
|
|
return expectAndAwaitSync().catch((e) => {
|
|
|
|
throw new Error("Never got /sync after login: did the client start?");
|
|
|
|
});
|
|
|
|
}).then(() => {
|
|
|
|
httpBackend.verifyNoOutstandingExpectation();
|
|
|
|
});
|
|
|
|
}
|
2016-08-10 07:15:04 +08:00
|
|
|
});
|
2016-08-10 21:37:30 +08:00
|
|
|
|
|
|
|
// assert that we are on the loading page
|
|
|
|
function assertAtLoadingSpinner(matrixChat) {
|
2021-10-01 21:41:22 +08:00
|
|
|
const domComponent = ReactDOM.findDOMNode(matrixChat);
|
2016-08-10 21:37:30 +08:00
|
|
|
expect(domComponent.className).toEqual("mx_MatrixChat_splash");
|
|
|
|
|
|
|
|
// just the spinner
|
|
|
|
expect(domComponent.children.length).toEqual(1);
|
|
|
|
}
|
|
|
|
|
2019-03-26 23:18:40 +08:00
|
|
|
function awaitLoggedIn(matrixChat) {
|
2020-04-23 17:19:06 +08:00
|
|
|
if (matrixChat.state.view === Views.LOGGED_IN) {
|
2019-03-26 23:18:40 +08:00
|
|
|
return Promise.resolve();
|
2017-01-24 19:26:09 +08:00
|
|
|
}
|
2019-03-26 23:18:40 +08:00
|
|
|
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);
|
2021-10-01 21:41:22 +08:00
|
|
|
resolve();
|
2019-03-26 23:18:40 +08:00
|
|
|
};
|
|
|
|
const dispatcherRef = dis.register(onAction);
|
|
|
|
console.log(Date.now() + ": Waiting for on_logged_in action");
|
|
|
|
});
|
2017-01-24 19:26:09 +08:00
|
|
|
}
|
|
|
|
|
2021-10-01 21:41:22 +08:00
|
|
|
function awaitRoomView(matrixChat, retryLimit, retryCount) {
|
2017-01-24 21:35:41 +08:00
|
|
|
if (retryLimit === undefined) {
|
|
|
|
retryLimit = 5;
|
|
|
|
}
|
|
|
|
if (retryCount === undefined) {
|
|
|
|
retryCount = 0;
|
|
|
|
}
|
|
|
|
|
2020-04-23 17:19:06 +08:00
|
|
|
if (matrixChat.state.view !== Views.LOGGED_IN || !matrixChat.state.ready) {
|
2017-01-24 21:35:41 +08:00
|
|
|
console.log(Date.now() + " Awaiting room view: not ready yet.");
|
|
|
|
if (retryCount >= retryLimit) {
|
|
|
|
throw new Error("MatrixChat still not ready after " +
|
|
|
|
retryCount + " tries");
|
|
|
|
}
|
2019-11-04 20:46:28 +08:00
|
|
|
return sleep(0).then(() => {
|
2017-01-24 21:35:41 +08:00
|
|
|
return awaitRoomView(matrixChat, retryLimit, retryCount + 1);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(Date.now() + " Awaiting room view: now ready.");
|
|
|
|
|
|
|
|
// state looks good, check the rendered output
|
|
|
|
ReactTestUtils.findRenderedComponentWithType(
|
2021-10-01 21:41:25 +08:00
|
|
|
matrixChat, sdk.getComponent('structures.RoomView'));
|
2017-07-13 07:32:07 +08:00
|
|
|
return Promise.resolve();
|
2017-01-24 21:35:41 +08:00
|
|
|
}
|
2017-07-13 07:18:49 +08:00
|
|
|
|
2021-10-01 21:41:22 +08:00
|
|
|
function awaitLoginComponent(matrixChat, attempts) {
|
2017-07-13 07:18:49 +08:00
|
|
|
return MatrixReactTestUtils.waitForRenderedComponentWithType(
|
2019-01-22 06:12:36 +08:00
|
|
|
matrixChat, sdk.getComponent('structures.auth.Login'), attempts,
|
2017-07-13 07:18:49 +08:00
|
|
|
);
|
|
|
|
}
|
2019-02-09 00:35:39 +08:00
|
|
|
|
2021-10-01 21:41:22 +08:00
|
|
|
function awaitWelcomeComponent(matrixChat, attempts) {
|
2019-02-09 00:35:39 +08:00
|
|
|
return MatrixReactTestUtils.waitForRenderedComponentWithType(
|
|
|
|
matrixChat, sdk.getComponent('auth.Welcome'), attempts,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function moveFromWelcomeToLogin(matrixChat) {
|
|
|
|
ReactTestUtils.findRenderedComponentWithType(
|
|
|
|
matrixChat, sdk.getComponent('auth.Welcome'));
|
|
|
|
dis.dispatch({ action: 'start_login' });
|
|
|
|
return awaitLoginComponent(matrixChat);
|
|
|
|
}
|