Keybinding code unification #3 (#7850)

This commit is contained in:
Šimon Brandner 2022-02-23 10:12:04 +01:00 committed by GitHub
parent b0737b6e31
commit 93a9af7b3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 214 additions and 81 deletions

View file

@ -15,18 +15,24 @@ limitations under the License.
*/
import {
CATEGORIES,
CategoryName,
getCustomizableShortcuts,
getKeyboardShortcuts,
KEYBOARD_SHORTCUTS,
registerShortcut,
mock,
} from "../../src/accessibility/KeyboardShortcuts";
import { Key } from "../../src/Keyboard";
import { ISetting } from "../../src/settings/Settings";
import PlatformPeg from "../../src/PlatformPeg";
describe("KeyboardShortcuts", () => {
it("doesn't change KEYBOARD_SHORTCUTS when getting shortcuts", () => {
it("doesn't change KEYBOARD_SHORTCUTS when getting shortcuts", async () => {
mock({
keyboardShortcuts: {
"Keybind1": {},
"Keybind2": {},
},
macOnlyShortcuts: ["Keybind1"],
desktopShortcuts: ["Keybind2"],
});
PlatformPeg.get = () => ({ overrideBrowserShortcuts: () => false });
const copyKeyboardShortcuts = Object.assign({}, KEYBOARD_SHORTCUTS);
getCustomizableShortcuts();
@ -35,22 +41,31 @@ describe("KeyboardShortcuts", () => {
expect(KEYBOARD_SHORTCUTS).toEqual(copyKeyboardShortcuts);
});
describe("registerShortcut()", () => {
it("correctly registers shortcut", () => {
const shortcutName = "Keybinding.definitelyARealShortcut";
const shortcutCategory = CategoryName.NAVIGATION;
const shortcut: ISetting = {
displayName: "A real shortcut",
default: {
ctrlKey: true,
key: Key.A,
},
};
it("correctly filters shortcuts", async () => {
mock({
keyboardShortcuts: {
"Keybind1": {},
"Keybind2": {},
"Keybind3": { "controller": { settingDisabled: true } },
"Keybind4": {},
},
macOnlyShortcuts: ["Keybind1"],
desktopShortcuts: ["Keybind2"],
registerShortcut(shortcutName, shortcutCategory, shortcut);
expect(getKeyboardShortcuts()[shortcutName]).toBe(shortcut);
expect(CATEGORIES[shortcutCategory].settingNames.includes(shortcutName)).toBeTruthy();
});
PlatformPeg.get = () => ({ overrideBrowserShortcuts: () => false });
expect(getCustomizableShortcuts()).toEqual({ "Keybind4": {} });
mock({
keyboardShortcuts: {
"Keybind1": {},
"Keybind2": {},
},
macOnlyShortcuts: undefined,
desktopShortcuts: ["Keybind2"],
});
PlatformPeg.get = () => ({ overrideBrowserShortcuts: () => true });
expect(getCustomizableShortcuts()).toEqual({ "Keybind1": {}, "Keybind2": {} });
jest.resetModules();
});
});

View file

@ -37,6 +37,7 @@ import MatrixToPermalinkConstructor from "../../../../src/utils/permalinks/Matri
import defaultDispatcher from "../../../../src/dispatcher/dispatcher";
import DocumentOffset from '../../../../src/editor/offset';
import { Layout } from '../../../../src/settings/enums/Layout';
import PlatformPeg from "../../../../src/PlatformPeg";
describe('<SendMessageComposer/>', () => {
const roomContext = {
@ -253,6 +254,8 @@ describe('<SendMessageComposer/>', () => {
});
it("persists to session history upon sending", async () => {
PlatformPeg.get = () => ({ overrideBrowserShortcuts: () => false });
const wrapper = mount(<MatrixClientContext.Provider value={mockClient}>
<RoomContext.Provider value={roomContext}>