Fix closing all modals (#12728)

* Fix closing all modals

We used `Modal.closeCurrentModal()` in a bunch of places, in all cases
(as far as I can see: it wasn't commented) we meant to close all open
modals. This swaps that function for one that closes all open modals.

Also types the close reason which claimed to be something in a comment,
of course, was wrong because a load of places passed their own random
string which was never used.

* Force close modals

* Try with minimal changes

* Already had a method for this

* Add test

* More tests

* Unused importsd
This commit is contained in:
David Baker 2024-07-05 14:39:13 +01:00 committed by GitHub
parent a7542dc0ac
commit dcf7643d4a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 95 additions and 17 deletions

View file

@ -31,6 +31,7 @@ import defaultDispatcher from "../../../src/dispatcher/dispatcher";
import SettingsStore from "../../../src/settings/SettingsStore";
import { SettingLevel } from "../../../src/settings/SettingLevel";
import { Action } from "../../../src/dispatcher/actions";
import Modal from "../../../src/Modal";
describe("<LoggedInView />", () => {
const userId = "@alice:domain.org";
@ -398,4 +399,22 @@ describe("<LoggedInView />", () => {
await userEvent.keyboard("{Control>}f{/Control}");
expect(defaultDispatcher.fire).toHaveBeenCalledWith(Action.FocusMessageSearch);
});
it("should go home on home shortcut", async () => {
jest.spyOn(defaultDispatcher, "dispatch");
getComponent();
await userEvent.keyboard("{Control>}{Alt>}h</Alt>{/Control}");
expect(defaultDispatcher.dispatch).toHaveBeenCalledWith({ action: Action.ViewHomePage });
});
it("should ignore home shortcut if dialogs are open", async () => {
jest.spyOn(defaultDispatcher, "dispatch");
jest.spyOn(Modal, "hasDialogs").mockReturnValue(true);
getComponent();
await userEvent.keyboard("{Control>}{Alt>}h</Alt>{/Control}");
expect(defaultDispatcher.dispatch).not.toHaveBeenCalledWith({ action: Action.ViewHomePage });
});
});