2016-08-10 02:15:04 +03:00
|
|
|
/*
|
|
|
|
Copyright 2016 OpenMarket Ltd
|
2020-01-16 00:05:55 +03:00
|
|
|
Copyright 2020 New Vector Ltd
|
2016-08-10 02:15:04 +03: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 */
|
|
|
|
|
2022-10-13 11:22:34 +03:00
|
|
|
import "fake-indexeddb/auto";
|
2016-08-10 02:15:04 +03:00
|
|
|
import React from "react";
|
2022-10-13 11:22:34 +03:00
|
|
|
import { render, screen, fireEvent, waitFor, RenderResult, waitForElementToBeRemoved } from "@testing-library/react";
|
|
|
|
import PlatformPeg from "matrix-react-sdk/src/PlatformPeg";
|
|
|
|
import { MatrixClientPeg } from "matrix-react-sdk/src/MatrixClientPeg";
|
|
|
|
import MatrixChat from "matrix-react-sdk/src/components/structures/MatrixChat";
|
2020-05-14 06:15:30 +03:00
|
|
|
import dis from "matrix-react-sdk/src/dispatcher/dispatcher";
|
2017-07-04 17:25:09 +03:00
|
|
|
import MockHttpBackend from "matrix-mock-request";
|
2022-07-14 16:04:32 +03:00
|
|
|
import { ValidatedServerConfig } from "matrix-react-sdk/src/utils/ValidatedServerConfig";
|
2022-10-13 11:22:34 +03:00
|
|
|
import { IndexedDBCryptoStore } from "matrix-js-sdk/src/crypto/store/indexeddb-crypto-store";
|
2022-11-23 19:24:36 +03:00
|
|
|
import { QueryDict, sleep } from "matrix-js-sdk/src/utils";
|
2023-04-25 11:36:17 +03:00
|
|
|
import { IConfigOptions } from "matrix-react-sdk/src/IConfigOptions";
|
|
|
|
import { ActionPayload } from "matrix-react-sdk/src/dispatcher/payloads";
|
2022-10-13 11:22:34 +03:00
|
|
|
|
|
|
|
import "../jest-mocks";
|
|
|
|
import WebPlatform from "../../src/vector/platform/WebPlatform";
|
|
|
|
import { parseQs, parseQsFromFragment } from "../../src/vector/url_utils";
|
2023-08-30 09:52:41 +03:00
|
|
|
import { cleanLocalstorage, deleteIndexedDB, waitForLoadingSpinner, waitForWelcomeComponent } from "../test-utils";
|
2016-08-10 02:15:04 +03:00
|
|
|
|
2022-10-13 11:22:34 +03:00
|
|
|
const DEFAULT_HS_URL = "http://my_server";
|
|
|
|
const DEFAULT_IS_URL = "http://my_is";
|
2016-08-10 02:15:04 +03:00
|
|
|
|
2024-01-02 14:14:57 +03:00
|
|
|
/** The matrix versions our mock server claims to support */
|
|
|
|
const SERVER_SUPPORTED_MATRIX_VERSIONS = ["v1.1", "v1.5", "v1.6", "v1.8", "v1.9"];
|
|
|
|
|
2018-11-22 21:25:55 +03:00
|
|
|
describe("loading:", function () {
|
2023-04-25 11:36:17 +03:00
|
|
|
let httpBackend: MockHttpBackend;
|
2016-08-10 02:15:04 +03:00
|
|
|
|
|
|
|
// an Object simulating the window.location
|
2023-04-06 15:17:51 +03:00
|
|
|
let windowLocation: Location | undefined;
|
2016-08-10 02:15:04 +03:00
|
|
|
|
2016-08-11 04:00:27 +03:00
|
|
|
// the mounted MatrixChat
|
2023-04-25 11:36:17 +03:00
|
|
|
let matrixChat: RenderResult | undefined;
|
2016-08-11 04:00:27 +03:00
|
|
|
|
2017-06-16 17:05:14 +03:00
|
|
|
// a promise which resolves when the MatrixChat calls onTokenLoginCompleted
|
2023-04-06 15:17:51 +03:00
|
|
|
let tokenLoginCompletePromise: Promise<void> | undefined;
|
2016-08-11 04:00:27 +03:00
|
|
|
|
2016-08-10 02:15:04 +03:00
|
|
|
beforeEach(function () {
|
|
|
|
httpBackend = new MockHttpBackend();
|
2023-04-25 11:36:17 +03:00
|
|
|
// @ts-ignore
|
2022-10-12 20:59:10 +03:00
|
|
|
window.fetch = httpBackend.fetchFn;
|
2016-08-10 02:15:04 +03:00
|
|
|
|
2023-04-06 15:17:51 +03:00
|
|
|
windowLocation = undefined;
|
|
|
|
matrixChat = undefined;
|
2016-08-10 02:15:04 +03:00
|
|
|
});
|
|
|
|
|
2018-11-22 21:25:55 +03:00
|
|
|
afterEach(async function () {
|
2017-06-20 19:41:21 +03:00
|
|
|
console.log(`${Date.now()}: loading: afterEach`);
|
2022-10-13 11:22:34 +03:00
|
|
|
matrixChat?.unmount();
|
|
|
|
// unmounting should have cleared the MatrixClientPeg
|
|
|
|
expect(MatrixClientPeg.get()).toBe(null);
|
|
|
|
|
|
|
|
// clear the indexeddbs so we can start from a clean slate next time.
|
|
|
|
await Promise.all([deleteIndexedDB("matrix-js-sdk:crypto"), deleteIndexedDB("matrix-js-sdk:riot-web-sync")]);
|
|
|
|
cleanLocalstorage();
|
2017-06-20 19:41:21 +03:00
|
|
|
console.log(`${Date.now()}: loading: afterEach complete`);
|
2016-08-10 02:15:04 +03: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.
|
|
|
|
*/
|
2023-04-25 11:36:17 +03:00
|
|
|
function loadApp(
|
|
|
|
opts: {
|
|
|
|
queryString?: string;
|
|
|
|
uriFragment?: string;
|
|
|
|
config?: IConfigOptions;
|
|
|
|
} = {},
|
|
|
|
): void {
|
2016-08-11 04:00:27 +03:00
|
|
|
const queryString = opts.queryString || "";
|
|
|
|
const uriFragment = opts.uriFragment || "";
|
|
|
|
|
2016-08-10 02:15:04 +03:00
|
|
|
windowLocation = {
|
2016-08-11 04:00:27 +03:00
|
|
|
search: queryString,
|
2016-08-10 02:15:04 +03:00
|
|
|
hash: uriFragment,
|
2022-11-23 19:24:36 +03:00
|
|
|
toString: function (): string {
|
|
|
|
return this.search + this.hash;
|
|
|
|
},
|
2023-04-06 15:17:51 +03:00
|
|
|
} as Location;
|
2016-08-10 02:15:04 +03:00
|
|
|
|
2023-04-25 11:36:17 +03:00
|
|
|
function onNewScreen(screen: string): void {
|
2017-01-24 14:26:09 +03:00
|
|
|
console.log(Date.now() + " newscreen " + screen);
|
2018-11-22 21:25:55 +03:00
|
|
|
const hash = "#/" + screen;
|
2023-04-06 15:17:51 +03:00
|
|
|
windowLocation!.hash = hash;
|
2017-06-14 20:00:02 +03:00
|
|
|
console.log(Date.now() + " browser URI now " + windowLocation);
|
2016-08-10 02:15:04 +03:00
|
|
|
}
|
|
|
|
|
2017-03-29 18:07:11 +03:00
|
|
|
// Parse the given window.location and return parameters that can be used when calling
|
|
|
|
// MatrixChat.showScreen(screen, params)
|
2023-04-25 11:36:17 +03:00
|
|
|
function getScreenFromLocation(location: Location): { screen: string; params: QueryDict } {
|
2017-03-29 18:07:11 +03:00
|
|
|
const fragparts = parseQsFromFragment(location);
|
|
|
|
return {
|
|
|
|
screen: fragparts.location.substring(1),
|
|
|
|
params: fragparts.params,
|
2018-11-22 21:25:55 +03:00
|
|
|
};
|
2017-03-29 18:07:11 +03:00
|
|
|
}
|
|
|
|
|
2016-08-10 02:15:04 +03:00
|
|
|
const fragParts = parseQsFromFragment(windowLocation);
|
2017-06-15 04:17:24 +03:00
|
|
|
|
2023-04-25 11:36:17 +03:00
|
|
|
const config = {
|
|
|
|
default_hs_url: DEFAULT_HS_URL,
|
|
|
|
default_is_url: DEFAULT_IS_URL,
|
|
|
|
validated_server_config: {
|
|
|
|
hsUrl: DEFAULT_HS_URL,
|
|
|
|
hsName: "TEST_ENVIRONMENT",
|
|
|
|
hsNameIsDifferent: false, // yes, we lie
|
|
|
|
isUrl: DEFAULT_IS_URL,
|
|
|
|
} as ValidatedServerConfig,
|
|
|
|
embedded_pages: {
|
|
|
|
home_url: "data:text/html;charset=utf-8;base64,PGh0bWw+PC9odG1sPg==",
|
2019-02-14 16:29:57 +03:00
|
|
|
},
|
2023-04-25 11:36:17 +03:00
|
|
|
...(opts.config ?? {}),
|
|
|
|
} as IConfigOptions;
|
2017-06-15 04:17:24 +03:00
|
|
|
|
2018-12-18 21:13:51 +03:00
|
|
|
PlatformPeg.set(new WebPlatform());
|
2017-11-19 23:46:40 +03:00
|
|
|
|
2018-11-22 21:25:55 +03:00
|
|
|
const params = parseQs(windowLocation);
|
2019-03-26 15:46:26 +03:00
|
|
|
|
2022-10-13 11:22:34 +03:00
|
|
|
tokenLoginCompletePromise = new Promise<void>((resolve) => {
|
|
|
|
matrixChat = render(
|
2019-03-26 15:46:26 +03:00
|
|
|
<MatrixChat
|
|
|
|
onNewScreen={onNewScreen}
|
2023-04-25 11:36:17 +03:00
|
|
|
config={config!}
|
2019-03-26 15:46:26 +03:00
|
|
|
realQueryParams={params}
|
|
|
|
startingFragmentQueryParams={fragParts.params}
|
|
|
|
enableGuest={true}
|
|
|
|
onTokenLoginCompleted={resolve}
|
2023-04-25 11:36:17 +03:00
|
|
|
initialScreenAfterLogin={getScreenFromLocation(windowLocation!)}
|
2019-03-26 15:46:26 +03:00
|
|
|
/>,
|
|
|
|
);
|
|
|
|
});
|
2016-08-10 02:15:04 +03:00
|
|
|
}
|
|
|
|
|
2017-05-19 15:33:50 +03: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
|
2023-04-25 11:36:17 +03:00
|
|
|
async function expectAndAwaitSync(opts?: { isGuest?: boolean }): Promise<any> {
|
|
|
|
let syncRequest: (typeof MockHttpBackend.prototype.requests)[number] | null = null;
|
2022-03-11 12:04:41 +03:00
|
|
|
httpBackend.when("GET", "/_matrix/client/versions").respond(200, {
|
2024-01-02 14:14:57 +03:00
|
|
|
versions: SERVER_SUPPORTED_MATRIX_VERSIONS,
|
2023-08-14 11:07:43 +03:00
|
|
|
unstable_features: {},
|
2022-03-11 12:04:41 +03:00
|
|
|
});
|
2023-04-25 11:36:17 +03:00
|
|
|
const isGuest = opts?.isGuest;
|
2019-02-08 14:48:06 +03:00
|
|
|
if (!isGuest) {
|
|
|
|
// the call to create the LL filter
|
|
|
|
httpBackend.when("POST", "/filter").respond(200, { filter_id: "llfid" });
|
2022-10-13 11:22:34 +03:00
|
|
|
httpBackend.when("GET", "/pushrules").respond(200, {});
|
2019-02-08 14:48:06 +03:00
|
|
|
}
|
2017-05-19 15:33:50 +03:00
|
|
|
httpBackend
|
|
|
|
.when("GET", "/sync")
|
|
|
|
.check((r) => {
|
|
|
|
syncRequest = r;
|
|
|
|
})
|
2019-02-08 14:48:06 +03:00
|
|
|
.respond(200, {});
|
2017-05-19 15:33:50 +03:00
|
|
|
|
|
|
|
for (let attempts = 10; attempts > 0; attempts--) {
|
2017-06-13 16:45:05 +03:00
|
|
|
console.log(Date.now() + " waiting for /sync");
|
2017-05-19 15:33:50 +03:00
|
|
|
if (syncRequest) {
|
|
|
|
return syncRequest;
|
|
|
|
}
|
2023-04-25 11:36:17 +03:00
|
|
|
await httpBackend.flush(undefined);
|
2017-05-19 15:33:50 +03:00
|
|
|
}
|
|
|
|
throw new Error("Gave up waiting for /sync");
|
|
|
|
}
|
|
|
|
|
2016-08-10 02:15:04 +03:00
|
|
|
describe("Clean load with no stored credentials:", function () {
|
2019-11-22 17:08:45 +03:00
|
|
|
it("gives a welcome page by default", function () {
|
2016-08-11 04:00:27 +03:00
|
|
|
loadApp();
|
2016-08-10 02:15:04 +03:00
|
|
|
|
2022-10-13 11:22:34 +03:00
|
|
|
return sleep(1)
|
|
|
|
.then(async () => {
|
2016-08-10 02:15:04 +03:00
|
|
|
// at this point, we're trying to do a guest registration;
|
|
|
|
// we expect a spinner
|
2023-08-30 09:52:41 +03:00
|
|
|
await waitForLoadingSpinner();
|
2022-12-09 15:28:29 +03:00
|
|
|
|
2016-08-10 02:15:04 +03:00
|
|
|
httpBackend
|
|
|
|
.when("POST", "/register")
|
|
|
|
.check(function (req) {
|
2023-04-25 11:36:17 +03:00
|
|
|
expect(req.queryParams?.kind).toEqual("guest");
|
2016-08-10 02:15:04 +03:00
|
|
|
})
|
|
|
|
.respond(403, "Guest access is disabled");
|
2022-12-09 15:28:29 +03:00
|
|
|
|
2023-04-25 11:36:17 +03:00
|
|
|
return httpBackend.flush(undefined);
|
2017-06-06 17:54:45 +03:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
// Wait for another trip around the event loop for the UI to update
|
2023-08-30 09:52:41 +03:00
|
|
|
return waitForWelcomeComponent(matrixChat);
|
2016-12-09 17:27:41 +03:00
|
|
|
})
|
|
|
|
.then(() => {
|
2023-04-06 15:17:51 +03:00
|
|
|
return waitFor(() => expect(windowLocation?.hash).toEqual("#/welcome"));
|
2019-11-22 17:08:45 +03:00
|
|
|
});
|
2016-08-10 02:15:04 +03:00
|
|
|
});
|
|
|
|
|
2019-11-22 17:08:45 +03:00
|
|
|
it("should follow the original link after successful login", function () {
|
2016-08-11 04:00:27 +03:00
|
|
|
loadApp({
|
|
|
|
uriFragment: "#/room/!room:id",
|
|
|
|
});
|
2016-08-10 02:15:04 +03:00
|
|
|
|
2019-06-05 18:53:22 +03:00
|
|
|
// Pass the liveliness checks
|
2024-01-02 14:14:57 +03:00
|
|
|
httpBackend.when("GET", "/versions").respond(200, { versions: SERVER_SUPPORTED_MATRIX_VERSIONS });
|
2023-01-03 10:59:00 +03:00
|
|
|
httpBackend.when("GET", "/_matrix/identity/v2").respond(200, {});
|
2019-06-05 18:53:22 +03:00
|
|
|
|
2022-10-13 11:22:34 +03:00
|
|
|
return sleep(1)
|
|
|
|
.then(async () => {
|
2016-08-10 02:15:04 +03:00
|
|
|
// at this point, we're trying to do a guest registration;
|
|
|
|
// we expect a spinner
|
2023-08-30 09:52:41 +03:00
|
|
|
await waitForLoadingSpinner();
|
2022-12-09 15:28:29 +03:00
|
|
|
|
2016-08-10 02:15:04 +03:00
|
|
|
httpBackend
|
|
|
|
.when("POST", "/register")
|
|
|
|
.check(function (req) {
|
2023-04-25 11:36:17 +03:00
|
|
|
expect(req.queryParams?.kind).toEqual("guest");
|
2016-08-10 02:15:04 +03:00
|
|
|
})
|
|
|
|
.respond(403, "Guest access is disabled");
|
2022-12-09 15:28:29 +03:00
|
|
|
|
2023-04-25 11:36:17 +03:00
|
|
|
return httpBackend.flush(undefined);
|
2016-12-09 17:27:41 +03:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
// Wait for another trip around the event loop for the UI to update
|
2019-11-04 15:46:28 +03:00
|
|
|
return sleep(10);
|
2019-02-08 19:35:39 +03:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
return moveFromWelcomeToLogin(matrixChat);
|
2016-08-10 02:15:04 +03:00
|
|
|
})
|
|
|
|
.then(() => {
|
2023-04-06 15:17:51 +03:00
|
|
|
return completeLogin(matrixChat!);
|
2016-08-10 02:15:04 +03:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
// once the sync completes, we should have a room view
|
2017-01-24 16:35:41 +03:00
|
|
|
return awaitRoomView(matrixChat);
|
|
|
|
})
|
|
|
|
.then(() => {
|
2016-08-10 02:15:04 +03:00
|
|
|
httpBackend.verifyNoOutstandingExpectation();
|
2023-04-06 15:17:51 +03:00
|
|
|
expect(windowLocation?.hash).toEqual("#/room/!room:id");
|
2022-12-09 15:28:29 +03:00
|
|
|
|
2016-08-11 04:00:27 +03: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 17:08:45 +03:00
|
|
|
});
|
2019-02-11 13:06:44 +03:00
|
|
|
});
|
2017-06-14 18:59:00 +03:00
|
|
|
|
2022-10-13 11:22:34 +03:00
|
|
|
it.skip("should not register as a guest when using a #/login link", function () {
|
2017-06-14 18:59:00 +03:00
|
|
|
loadApp({
|
|
|
|
uriFragment: "#/login",
|
|
|
|
});
|
|
|
|
|
2019-06-05 18:53:22 +03:00
|
|
|
// Pass the liveliness checks
|
2024-01-02 14:14:57 +03:00
|
|
|
httpBackend.when("GET", "/versions").respond(200, { versions: SERVER_SUPPORTED_MATRIX_VERSIONS });
|
2023-01-03 10:59:00 +03:00
|
|
|
httpBackend.when("GET", "/_matrix/identity/v2").respond(200, {});
|
2019-06-05 18:53:22 +03:00
|
|
|
|
2022-10-13 11:22:34 +03:00
|
|
|
return awaitLoginComponent(matrixChat)
|
|
|
|
.then(async () => {
|
|
|
|
await waitForElementToBeRemoved(() => screen.queryAllByLabelText("Loading..."));
|
2017-06-14 18:59:00 +03:00
|
|
|
// we expect a single <Login> component
|
2022-10-13 11:22:34 +03:00
|
|
|
await screen.findByRole("main");
|
2023-09-06 20:14:38 +03:00
|
|
|
screen.getAllByText("Sign in");
|
2022-12-09 15:28:29 +03:00
|
|
|
|
2017-06-14 18:59:00 +03:00
|
|
|
// the only outstanding request should be a GET /login
|
|
|
|
// (in particular there should be no /register request for
|
|
|
|
// guest registration).
|
2023-08-14 11:07:43 +03:00
|
|
|
const allowedRequests = ["/_matrix/client/v3/login", "/versions", "/_matrix/identity/v2"];
|
2017-06-14 18:59:00 +03:00
|
|
|
for (const req of httpBackend.requests) {
|
2019-06-05 18:53:22 +03:00
|
|
|
if (req.method === "GET" && allowedRequests.find((p) => req.path.endsWith(p))) {
|
2017-06-14 18:59:00 +03:00
|
|
|
continue;
|
2022-12-09 15:28:29 +03:00
|
|
|
}
|
|
|
|
|
2017-06-14 18:59:00 +03:00
|
|
|
throw new Error(`Unexpected HTTP request to ${req}`);
|
|
|
|
}
|
2023-04-06 15:17:51 +03:00
|
|
|
return completeLogin(matrixChat!);
|
2017-06-14 18:59:00 +03:00
|
|
|
})
|
|
|
|
.then(() => {
|
2023-04-06 15:17:51 +03:00
|
|
|
expect(matrixChat?.container.querySelector(".mx_HomePage")).toBeTruthy();
|
|
|
|
expect(windowLocation?.hash).toEqual("#/home");
|
2017-06-14 18:59:00 +03:00
|
|
|
});
|
2019-02-11 13:06:44 +03:00
|
|
|
});
|
2016-08-10 02:15:04 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("MatrixClient rehydrated from stored credentials:", function () {
|
2019-03-29 21:01:04 +03:00
|
|
|
beforeEach(async function () {
|
2022-10-13 11:22:34 +03:00
|
|
|
localStorage.setItem("mx_hs_url", "http://localhost");
|
|
|
|
localStorage.setItem("mx_is_url", "http://localhost");
|
2016-08-10 16:37:30 +03:00
|
|
|
localStorage.setItem("mx_access_token", "access_token");
|
|
|
|
localStorage.setItem("mx_user_id", "@me:localhost");
|
2024-02-01 18:36:23 +03:00
|
|
|
localStorage.setItem("mx_device_id", "QWERTYUIOP");
|
2017-06-13 14:52:35 +03:00
|
|
|
localStorage.setItem("mx_last_room_id", "!last_room:id");
|
2019-03-29 21:01:04 +03:00
|
|
|
|
|
|
|
// Create a crypto store as well to satisfy storage consistency checks
|
2020-01-16 00:06:44 +03:00
|
|
|
const cryptoStore = new IndexedDBCryptoStore(indexedDB, "matrix-js-sdk:crypto");
|
2020-02-27 17:57:52 +03:00
|
|
|
await cryptoStore.startup();
|
2017-06-13 14:52:35 +03:00
|
|
|
});
|
|
|
|
|
2019-02-11 13:06:44 +03:00
|
|
|
it("shows the last known room by default", function () {
|
2017-06-13 14:52:35 +03:00
|
|
|
loadApp();
|
|
|
|
|
2023-04-06 15:17:51 +03:00
|
|
|
return awaitLoggedIn(matrixChat!)
|
2019-03-26 18:18:40 +03:00
|
|
|
.then(() => {
|
|
|
|
// we are logged in - let the sync complete
|
2017-06-13 14:52:35 +03:00
|
|
|
return expectAndAwaitSync();
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
// once the sync completes, we should have a room view
|
|
|
|
return awaitRoomView(matrixChat);
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
httpBackend.verifyNoOutstandingExpectation();
|
2023-04-06 15:17:51 +03:00
|
|
|
expect(windowLocation?.hash).toEqual("#/room/!last_room:id");
|
2017-06-13 14:52:35 +03:00
|
|
|
});
|
2016-08-10 02:15:04 +03:00
|
|
|
});
|
|
|
|
|
2019-11-22 17:08:45 +03:00
|
|
|
it("shows a home page by default if we have no joined rooms", function () {
|
2017-06-13 14:52:35 +03:00
|
|
|
localStorage.removeItem("mx_last_room_id");
|
|
|
|
|
2016-08-11 04:00:27 +03:00
|
|
|
loadApp();
|
2016-08-10 02:15:04 +03:00
|
|
|
|
2023-04-06 15:17:51 +03:00
|
|
|
return awaitLoggedIn(matrixChat!)
|
2019-11-22 17:08:45 +03:00
|
|
|
.then(() => {
|
2019-03-26 18:18:40 +03:00
|
|
|
// we are logged in - let the sync complete
|
2017-05-19 15:33:50 +03:00
|
|
|
return expectAndAwaitSync();
|
2016-08-10 02:15:04 +03:00
|
|
|
})
|
|
|
|
.then(() => {
|
2017-05-30 14:55:50 +03:00
|
|
|
// once the sync completes, we should have a home page
|
2016-08-10 02:15:04 +03:00
|
|
|
httpBackend.verifyNoOutstandingExpectation();
|
2023-04-06 15:17:51 +03:00
|
|
|
expect(matrixChat?.container.querySelector(".mx_HomePage")).toBeTruthy();
|
|
|
|
expect(windowLocation?.hash).toEqual("#/home");
|
2019-11-22 17:08:45 +03:00
|
|
|
});
|
2016-08-10 02:15:04 +03:00
|
|
|
});
|
|
|
|
|
2019-11-22 17:08:45 +03:00
|
|
|
it("shows a room view if we followed a room link", function () {
|
2016-08-11 04:00:27 +03:00
|
|
|
loadApp({
|
|
|
|
uriFragment: "#/room/!room:id",
|
|
|
|
});
|
2016-08-10 02:15:04 +03:00
|
|
|
|
2023-04-06 15:17:51 +03:00
|
|
|
return awaitLoggedIn(matrixChat!)
|
2019-11-22 17:08:45 +03:00
|
|
|
.then(() => {
|
2019-03-26 18:18:40 +03:00
|
|
|
// we are logged in - let the sync complete
|
2017-05-19 15:33:50 +03:00
|
|
|
return expectAndAwaitSync();
|
2016-08-10 02:15:04 +03:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
// once the sync completes, we should have a room view
|
2017-01-24 16:35:41 +03:00
|
|
|
return awaitRoomView(matrixChat);
|
|
|
|
})
|
|
|
|
.then(() => {
|
2016-08-10 02:15:04 +03:00
|
|
|
httpBackend.verifyNoOutstandingExpectation();
|
2023-04-06 15:17:51 +03:00
|
|
|
expect(windowLocation?.hash).toEqual("#/room/!room:id");
|
2019-11-22 17:08:45 +03:00
|
|
|
});
|
2019-02-11 13:06:44 +03:00
|
|
|
});
|
2016-08-10 02:15:04 +03:00
|
|
|
|
2017-06-13 14:52:35 +03:00
|
|
|
describe("/#/login link:", function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
loadApp({
|
|
|
|
uriFragment: "#/login",
|
|
|
|
});
|
2017-06-16 17:05:14 +03:00
|
|
|
|
2017-06-13 16:45:05 +03:00
|
|
|
// give the UI a chance to display
|
2022-10-13 11:22:34 +03:00
|
|
|
return expectAndAwaitSync();
|
2017-06-13 14:52:35 +03:00
|
|
|
});
|
|
|
|
|
2022-10-13 11:22:34 +03:00
|
|
|
it("does not show a login view", async function () {
|
|
|
|
await awaitRoomView(matrixChat);
|
2017-06-13 14:52:35 +03:00
|
|
|
|
2023-12-20 18:32:23 +03:00
|
|
|
await screen.getByRole("tree", { name: "Spaces" });
|
2023-09-06 20:14:38 +03:00
|
|
|
expect(screen.queryAllByText("Sign in")).toHaveLength(0);
|
2019-02-11 13:06:44 +03:00
|
|
|
});
|
2016-08-10 02:15:04 +03:00
|
|
|
});
|
|
|
|
});
|
2016-08-10 16:37:30 +03:00
|
|
|
|
|
|
|
describe("Guest auto-registration:", function () {
|
2019-11-22 17:08:45 +03:00
|
|
|
it("shows a welcome page by default", function () {
|
2016-08-11 04:00:27 +03:00
|
|
|
loadApp();
|
2016-08-10 16:37:30 +03:00
|
|
|
|
2022-10-13 11:22:34 +03:00
|
|
|
return sleep(1)
|
|
|
|
.then(async () => {
|
2016-08-10 16:37:30 +03:00
|
|
|
// at this point, we're trying to do a guest registration;
|
|
|
|
// we expect a spinner
|
2023-08-30 09:52:41 +03:00
|
|
|
await waitForLoadingSpinner();
|
2022-12-09 15:28:29 +03:00
|
|
|
|
2016-08-10 16:37:30 +03:00
|
|
|
httpBackend
|
|
|
|
.when("POST", "/register")
|
|
|
|
.check(function (req) {
|
2023-04-25 11:36:17 +03:00
|
|
|
expect(req.queryParams?.kind).toEqual("guest");
|
2016-08-10 16:37:30 +03:00
|
|
|
})
|
|
|
|
.respond(200, {
|
|
|
|
user_id: "@guest:localhost",
|
2024-02-01 18:36:23 +03:00
|
|
|
device_id: "QWERTYUIOP",
|
2016-08-10 16:37:30 +03:00
|
|
|
access_token: "secret_token",
|
2022-12-09 15:28:29 +03:00
|
|
|
});
|
|
|
|
|
2023-04-25 11:36:17 +03:00
|
|
|
return httpBackend.flush(undefined);
|
2022-12-09 15:28:29 +03:00
|
|
|
})
|
2016-12-09 17:27:41 +03:00
|
|
|
.then(() => {
|
2023-04-06 15:17:51 +03:00
|
|
|
return awaitLoggedIn(matrixChat!);
|
2022-12-09 15:28:29 +03:00
|
|
|
})
|
2016-08-11 04:00:27 +03:00
|
|
|
.then(() => {
|
2019-03-26 18:18:40 +03:00
|
|
|
// we are logged in - let the sync complete
|
2022-10-13 11:22:34 +03:00
|
|
|
return expectAndAwaitSync({ isGuest: true });
|
2022-12-09 15:28:29 +03:00
|
|
|
})
|
2016-08-11 04:00:27 +03:00
|
|
|
.then(() => {
|
2019-02-11 18:18:29 +03:00
|
|
|
// once the sync completes, we should have a welcome page
|
2016-08-11 04:00:27 +03:00
|
|
|
httpBackend.verifyNoOutstandingExpectation();
|
2023-04-06 15:17:51 +03:00
|
|
|
expect(matrixChat?.container.querySelector(".mx_Welcome")).toBeTruthy();
|
|
|
|
expect(windowLocation?.hash).toEqual("#/welcome");
|
2016-08-10 16:37:30 +03:00
|
|
|
});
|
2019-02-11 18:18:29 +03:00
|
|
|
});
|
2016-08-10 16:37:30 +03:00
|
|
|
|
2019-11-22 17:08:45 +03:00
|
|
|
it("uses the default homeserver to register with", function () {
|
2016-08-11 04:00:27 +03:00
|
|
|
loadApp();
|
|
|
|
|
2022-10-13 11:22:34 +03:00
|
|
|
return sleep(1)
|
|
|
|
.then(async () => {
|
2016-08-11 04:00:27 +03:00
|
|
|
// at this point, we're trying to do a guest registration;
|
|
|
|
// we expect a spinner
|
2023-08-30 09:52:41 +03:00
|
|
|
await waitForLoadingSpinner();
|
2022-12-09 15:28:29 +03:00
|
|
|
|
2016-08-11 04:00:27 +03:00
|
|
|
httpBackend
|
|
|
|
.when("POST", "/register")
|
|
|
|
.check(function (req) {
|
|
|
|
expect(req.path.startsWith(DEFAULT_HS_URL)).toBe(true);
|
2023-04-25 11:36:17 +03:00
|
|
|
expect(req.queryParams?.kind).toEqual("guest");
|
2022-12-09 15:28:29 +03:00
|
|
|
})
|
2022-10-13 11:22:34 +03:00
|
|
|
.respond(200, {
|
2016-08-10 16:37:30 +03:00
|
|
|
user_id: "@guest:localhost",
|
|
|
|
access_token: "secret_token",
|
2022-12-09 15:28:29 +03:00
|
|
|
});
|
|
|
|
|
2023-04-25 11:36:17 +03:00
|
|
|
return httpBackend.flush(undefined);
|
2022-12-09 15:28:29 +03:00
|
|
|
})
|
2016-08-10 16:37:30 +03:00
|
|
|
.then(() => {
|
2023-04-06 15:17:51 +03:00
|
|
|
return awaitLoggedIn(matrixChat!);
|
2022-12-09 15:28:29 +03:00
|
|
|
})
|
2016-08-11 04:00:27 +03:00
|
|
|
.then(() => {
|
2022-10-13 11:22:34 +03:00
|
|
|
return expectAndAwaitSync({ isGuest: true });
|
2022-12-09 15:28:29 +03:00
|
|
|
})
|
2017-05-19 15:33:50 +03:00
|
|
|
.then((req) => {
|
2020-01-16 00:44:46 +03:00
|
|
|
expect(req.path.startsWith(DEFAULT_HS_URL)).toBe(true);
|
2017-05-19 15:33:50 +03:00
|
|
|
|
2019-02-11 18:18:29 +03:00
|
|
|
// once the sync completes, we should have a welcome page
|
2016-08-11 04:00:27 +03:00
|
|
|
httpBackend.verifyNoOutstandingExpectation();
|
2023-04-06 15:17:51 +03:00
|
|
|
expect(matrixChat?.container.querySelector(".mx_Welcome")).toBeTruthy();
|
|
|
|
expect(windowLocation?.hash).toEqual("#/welcome");
|
2023-06-28 17:09:36 +03:00
|
|
|
expect(MatrixClientPeg.safeGet().baseUrl).toEqual(DEFAULT_HS_URL);
|
|
|
|
expect(MatrixClientPeg.safeGet().idBaseUrl).toEqual(DEFAULT_IS_URL);
|
2019-11-22 17:08:45 +03:00
|
|
|
});
|
2019-02-11 18:18:29 +03:00
|
|
|
});
|
2016-08-11 04:00:27 +03:00
|
|
|
|
2019-11-22 17:08:45 +03:00
|
|
|
it("shows a room view if we followed a room link", function () {
|
2016-08-11 04:00:27 +03:00
|
|
|
loadApp({
|
2018-11-22 21:25:55 +03:00
|
|
|
uriFragment: "#/room/!room:id",
|
2016-08-11 04:00:27 +03:00
|
|
|
});
|
2022-10-13 11:22:34 +03:00
|
|
|
return sleep(1)
|
|
|
|
.then(async () => {
|
2016-08-10 16:37:30 +03:00
|
|
|
// at this point, we're trying to do a guest registration;
|
|
|
|
// we expect a spinner
|
2023-08-30 09:52:41 +03:00
|
|
|
await waitForLoadingSpinner();
|
2022-12-09 15:28:29 +03:00
|
|
|
|
2016-08-10 16:37:30 +03:00
|
|
|
httpBackend
|
|
|
|
.when("POST", "/register")
|
|
|
|
.check(function (req) {
|
2023-04-25 11:36:17 +03:00
|
|
|
expect(req.queryParams?.kind).toEqual("guest");
|
2016-08-10 16:37:30 +03:00
|
|
|
})
|
|
|
|
.respond(200, {
|
|
|
|
user_id: "@guest:localhost",
|
|
|
|
access_token: "secret_token",
|
2022-12-09 15:28:29 +03:00
|
|
|
});
|
|
|
|
|
2023-04-25 11:36:17 +03:00
|
|
|
return httpBackend.flush(undefined);
|
2022-12-09 15:28:29 +03:00
|
|
|
})
|
2017-06-14 22:27:02 +03:00
|
|
|
.then(() => {
|
2023-04-06 15:17:51 +03:00
|
|
|
return awaitLoggedIn(matrixChat!);
|
2022-12-09 15:28:29 +03:00
|
|
|
})
|
2017-06-14 22:27:02 +03:00
|
|
|
.then(() => {
|
2022-10-13 11:22:34 +03:00
|
|
|
return expectAndAwaitSync({ isGuest: true });
|
2022-12-09 15:28:29 +03:00
|
|
|
})
|
2017-06-14 22:27:02 +03:00
|
|
|
.then(() => {
|
2016-08-10 16:37:30 +03:00
|
|
|
// once the sync completes, we should have a room view
|
2017-01-24 16:35:41 +03:00
|
|
|
return awaitRoomView(matrixChat);
|
2022-12-09 15:28:29 +03:00
|
|
|
})
|
2017-06-14 22:27:02 +03:00
|
|
|
.then(() => {
|
2016-08-10 16:37:30 +03:00
|
|
|
httpBackend.verifyNoOutstandingExpectation();
|
2023-04-06 15:17:51 +03:00
|
|
|
expect(windowLocation?.hash).toEqual("#/room/!room:id");
|
2016-08-10 16:37:30 +03:00
|
|
|
});
|
|
|
|
});
|
2017-06-14 22:27:02 +03:00
|
|
|
|
|
|
|
describe("Login as user", function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
// first we have to load the homepage
|
|
|
|
loadApp();
|
|
|
|
|
|
|
|
httpBackend
|
|
|
|
.when("POST", "/register")
|
|
|
|
.check(function (req) {
|
2023-04-25 11:36:17 +03:00
|
|
|
expect(req.queryParams?.kind).toEqual("guest");
|
2017-06-14 22:27:02 +03:00
|
|
|
})
|
|
|
|
.respond(200, {
|
|
|
|
user_id: "@guest:localhost",
|
|
|
|
access_token: "secret_token",
|
|
|
|
});
|
2022-12-09 15:28:29 +03:00
|
|
|
|
2017-06-14 22:27:02 +03:00
|
|
|
return httpBackend
|
2023-04-25 11:36:17 +03:00
|
|
|
.flush(undefined)
|
2017-06-14 22:27:02 +03:00
|
|
|
.then(() => {
|
2023-04-06 15:17:51 +03:00
|
|
|
return awaitLoggedIn(matrixChat!);
|
2017-06-14 22:27:02 +03:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
// we got a sync spinner - let the sync complete
|
|
|
|
return expectAndAwaitSync();
|
2022-10-13 11:22:34 +03:00
|
|
|
})
|
|
|
|
.then(async () => {
|
2017-06-14 22:27:02 +03:00
|
|
|
// once the sync completes, we should have a home page
|
2023-04-06 15:17:51 +03:00
|
|
|
await waitFor(() => matrixChat?.container.querySelector(".mx_HomePage"));
|
2022-12-09 15:28:29 +03:00
|
|
|
|
2017-06-14 22:27:02 +03: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
|
2022-12-09 15:28:29 +03:00
|
|
|
|
2017-06-14 22:27:02 +03:00
|
|
|
dis.dispatch({ action: "start_login" });
|
2022-12-09 15:28:29 +03:00
|
|
|
|
2017-07-13 02:18:49 +03:00
|
|
|
return awaitLoginComponent(matrixChat);
|
2017-06-14 22:27:02 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-10-13 11:22:34 +03:00
|
|
|
it("should give us a login page", async function () {
|
2017-06-14 22:27:02 +03:00
|
|
|
// we expect a single <Login> component
|
2022-10-13 11:22:34 +03:00
|
|
|
await screen.findByRole("main");
|
2023-09-06 20:14:38 +03:00
|
|
|
screen.getAllByText("Sign in");
|
2017-06-14 22:27:02 +03:00
|
|
|
|
2023-04-06 15:17:51 +03:00
|
|
|
expect(windowLocation?.hash).toEqual("#/login");
|
2017-06-14 22:27:02 +03:00
|
|
|
});
|
|
|
|
});
|
2016-08-10 16:37:30 +03:00
|
|
|
});
|
2016-08-11 04:00:27 +03:00
|
|
|
|
|
|
|
describe("Token login:", function () {
|
2019-11-22 17:08:45 +03:00
|
|
|
it("logs in successfully", function () {
|
2020-06-26 01:59:08 +03:00
|
|
|
localStorage.setItem("mx_sso_hs_url", "https://homeserver");
|
|
|
|
localStorage.setItem("mx_sso_is_url", "https://idserver");
|
2016-08-11 04:00:27 +03:00
|
|
|
loadApp({
|
2020-06-03 22:34:20 +03:00
|
|
|
queryString: "?loginToken=secretToken",
|
2016-08-11 04:00:27 +03:00
|
|
|
});
|
|
|
|
|
2022-10-13 11:22:34 +03:00
|
|
|
return sleep(1)
|
|
|
|
.then(async () => {
|
2016-08-11 04:00:27 +03:00
|
|
|
// we expect a spinner while we're logging in
|
2023-08-30 09:52:41 +03:00
|
|
|
await waitForLoadingSpinner();
|
2022-12-09 15:28:29 +03:00
|
|
|
|
2016-08-11 04:00:27 +03:00
|
|
|
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 02:41:49 +03:00
|
|
|
device_id: "DEVICE_ID",
|
2016-08-11 04:00:27 +03:00
|
|
|
access_token: "access_token",
|
2022-12-09 15:28:29 +03:00
|
|
|
});
|
|
|
|
|
2023-04-25 11:36:17 +03:00
|
|
|
return httpBackend.flush(undefined);
|
2022-12-09 15:28:29 +03:00
|
|
|
})
|
2017-06-13 14:52:35 +03:00
|
|
|
.then(() => {
|
2017-06-16 17:05:14 +03:00
|
|
|
// at this point, MatrixChat should fire onTokenLoginCompleted, which
|
2016-08-11 04:00:27 +03: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.
|
2022-12-09 15:28:29 +03:00
|
|
|
|
2017-06-19 11:04:24 +03:00
|
|
|
return tokenLoginCompletePromise;
|
2022-12-09 15:28:29 +03:00
|
|
|
})
|
2023-07-16 23:50:13 +03:00
|
|
|
.then(() => {
|
|
|
|
return expectAndAwaitSync().catch((e) => {
|
|
|
|
throw new Error("Never got /sync after login: did the client start?");
|
|
|
|
});
|
|
|
|
})
|
2017-06-13 14:52:35 +03:00
|
|
|
.then(() => {
|
2016-08-11 04:00:27 +03:00
|
|
|
// 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");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-06-13 14:52:35 +03:00
|
|
|
|
|
|
|
// check that we have a Login component, send a 'user:pass' login,
|
|
|
|
// and await the HTTP requests.
|
2023-04-25 11:36:17 +03:00
|
|
|
async function completeLogin(matrixChat: RenderResult): Promise<void> {
|
2019-05-04 01:27:41 +03: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.
|
2022-10-13 11:22:34 +03:00
|
|
|
httpBackend.when("GET", "/login").respond(200, { flows: [{ type: "m.login.password" }] });
|
2023-04-25 11:36:17 +03:00
|
|
|
httpBackend.flush(undefined); // We already would have tried the GET /login request
|
2019-05-04 01:27:41 +03:00
|
|
|
|
2017-06-13 14:52:35 +03: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",
|
|
|
|
});
|
2023-05-05 13:56:35 +03:00
|
|
|
|
|
|
|
// Give the component some time to finish processing the login flows before continuing.
|
2023-05-05 14:53:12 +03:00
|
|
|
await waitFor(() => expect(matrixChat?.container.querySelector("#mx_LoginForm_username")).toBeTruthy());
|
2023-05-05 13:56:35 +03:00
|
|
|
|
|
|
|
// Enter login details
|
2023-04-06 15:17:51 +03:00
|
|
|
fireEvent.change(matrixChat.container.querySelector("#mx_LoginForm_username")!, { target: { value: "user" } });
|
|
|
|
fireEvent.change(matrixChat.container.querySelector("#mx_LoginForm_password")!, { target: { value: "pass" } });
|
2023-09-06 20:14:38 +03:00
|
|
|
fireEvent.click(screen.getByText("Sign in", { selector: ".mx_Login_submit" }));
|
2017-06-13 14:52:35 +03:00
|
|
|
|
|
|
|
return httpBackend
|
2023-04-25 11:36:17 +03:00
|
|
|
.flush(undefined)
|
2017-06-13 14:52:35 +03:00
|
|
|
.then(() => {
|
|
|
|
// Wait for another trip around the event loop for the UI to update
|
2019-11-04 15:46:28 +03:00
|
|
|
return sleep(1);
|
2017-06-13 14:52:35 +03:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
return expectAndAwaitSync().catch((e) => {
|
|
|
|
throw new Error("Never got /sync after login: did the client start?");
|
2022-12-09 15:28:29 +03:00
|
|
|
});
|
|
|
|
})
|
2017-06-13 14:52:35 +03:00
|
|
|
.then(() => {
|
|
|
|
httpBackend.verifyNoOutstandingExpectation();
|
|
|
|
});
|
|
|
|
}
|
2016-08-10 02:15:04 +03:00
|
|
|
});
|
2016-08-10 16:37:30 +03:00
|
|
|
|
2023-04-25 11:36:17 +03:00
|
|
|
async function awaitLoggedIn(matrixChat: RenderResult): Promise<void> {
|
2022-10-13 11:22:34 +03:00
|
|
|
if (matrixChat.container.querySelector(".mx_MatrixChat_wrapper")) return; // already logged in
|
|
|
|
|
2019-03-26 18:18:40 +03:00
|
|
|
return new Promise((resolve) => {
|
2023-04-25 11:36:17 +03:00
|
|
|
const onAction = ({ action }: ActionPayload): void => {
|
2019-03-26 18:18:40 +03:00
|
|
|
if (action !== "on_logged_in") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log(Date.now() + ": Received on_logged_in action");
|
|
|
|
dis.unregister(dispatcherRef);
|
2022-10-13 11:22:34 +03:00
|
|
|
resolve(sleep(1));
|
2019-03-26 18:18:40 +03:00
|
|
|
};
|
|
|
|
const dispatcherRef = dis.register(onAction);
|
|
|
|
console.log(Date.now() + ": Waiting for on_logged_in action");
|
|
|
|
});
|
2017-01-24 14:26:09 +03:00
|
|
|
}
|
|
|
|
|
2023-04-25 11:36:17 +03:00
|
|
|
async function awaitRoomView(matrixChat?: RenderResult): Promise<void> {
|
2023-04-06 15:17:51 +03:00
|
|
|
await waitFor(() => matrixChat?.container.querySelector(".mx_RoomView"));
|
2017-01-24 16:35:41 +03:00
|
|
|
}
|
2017-07-13 02:18:49 +03:00
|
|
|
|
2023-04-25 11:36:17 +03:00
|
|
|
async function awaitLoginComponent(matrixChat?: RenderResult): Promise<void> {
|
2023-04-06 15:17:51 +03:00
|
|
|
await waitFor(() => matrixChat?.container.querySelector(".mx_AuthPage"));
|
2017-07-13 02:18:49 +03:00
|
|
|
}
|
2019-02-08 19:35:39 +03:00
|
|
|
|
2023-04-25 11:36:17 +03:00
|
|
|
function moveFromWelcomeToLogin(matrixChat?: RenderResult): Promise<void> {
|
2019-02-08 19:35:39 +03:00
|
|
|
dis.dispatch({ action: "start_login" });
|
|
|
|
return awaitLoginComponent(matrixChat);
|
|
|
|
}
|