Handle IDB closed event by showing modal with prompt to reload app (#10395

* Handle IDB `closed` event by showing modal with prompt to reload app

* Iterate

* Skip the modal for guests, e.g. during registration

* Iterate

* Add tests
This commit is contained in:
Michael Telatynski 2023-03-31 10:08:45 +01:00 committed by GitHub
parent f152613f83
commit 404c412bcb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 4 deletions

View file

@ -16,15 +16,25 @@ limitations under the License.
import { logger } from "matrix-js-sdk/src/logger";
import fetchMockJest from "fetch-mock-jest";
import EventEmitter from "events";
import { advanceDateAndTime, stubClient } from "./test-utils";
import { IMatrixClientPeg, MatrixClientPeg as peg } from "../src/MatrixClientPeg";
import SettingsStore from "../src/settings/SettingsStore";
import Modal from "../src/Modal";
import PlatformPeg from "../src/PlatformPeg";
import { SettingLevel } from "../src/settings/SettingLevel";
jest.useFakeTimers();
const PegClass = Object.getPrototypeOf(peg).constructor;
describe("MatrixClientPeg", () => {
beforeEach(() => {
// stub out Logger.log which gets called a lot and clutters up the test output
jest.spyOn(logger, "log").mockImplementation(() => {});
});
afterEach(() => {
localStorage.clear();
jest.restoreAllMocks();
@ -68,7 +78,6 @@ describe("MatrixClientPeg", () => {
beforeEach(() => {
// instantiate a MatrixClientPegClass instance, with a new MatrixClient
const PegClass = Object.getPrototypeOf(peg).constructor;
testPeg = new PegClass();
fetchMockJest.get("http://example.com/_matrix/client/versions", {});
testPeg.replaceUsingCreds({
@ -77,9 +86,6 @@ describe("MatrixClientPeg", () => {
userId: "@user:example.com",
deviceId: "TEST_DEVICE_ID",
});
// stub out Logger.log which gets called a lot and clutters up the test output
jest.spyOn(logger, "log").mockImplementation(() => {});
});
it("should initialise client crypto", async () => {
@ -134,5 +140,26 @@ describe("MatrixClientPeg", () => {
// we should have stashed the setting in the settings store
expect(mockSetValue).toHaveBeenCalledWith("feature_rust_crypto", null, SettingLevel.DEVICE, true);
});
it("should reload when store database closes for a guest user", async () => {
testPeg.get().isGuest = () => true;
const emitter = new EventEmitter();
testPeg.get().store.on = emitter.on.bind(emitter);
const platform: any = { reload: jest.fn() };
PlatformPeg.set(platform);
await testPeg.assign();
emitter.emit("closed" as any);
expect(platform.reload).toHaveBeenCalled();
});
it("should show error modal when store database closes", async () => {
testPeg.get().isGuest = () => false;
const emitter = new EventEmitter();
testPeg.get().store.on = emitter.on.bind(emitter);
const spy = jest.spyOn(Modal, "createDialog");
await testPeg.assign();
emitter.emit("closed" as any);
expect(spy).toHaveBeenCalled();
});
});
});