2022-01-24 14:33:27 +03:00
|
|
|
/*
|
2024-09-09 16:57:16 +03:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-01-24 14:33:27 +03:00
|
|
|
Copyright 2022 Šimon Brandner <simon.bra.ag@gmail.com>
|
2022-07-11 10:56:20 +03:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
2022-01-24 14:33:27 +03:00
|
|
|
|
2024-09-09 16:57:16 +03:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2022-01-24 14:33:27 +03:00
|
|
|
*/
|
|
|
|
|
2024-10-15 16:57:26 +03:00
|
|
|
import { mockPlatformPeg, unmockPlatformPeg } from "../../test-utils";
|
2022-01-24 14:33:27 +03:00
|
|
|
|
2024-10-15 16:57:26 +03:00
|
|
|
const PATH_TO_KEYBOARD_SHORTCUTS = "../../../src/accessibility/KeyboardShortcuts";
|
|
|
|
const PATH_TO_KEYBOARD_SHORTCUT_UTILS = "../../../src/accessibility/KeyboardShortcutUtils";
|
2022-07-11 10:56:20 +03:00
|
|
|
|
2023-02-13 14:39:16 +03:00
|
|
|
const mockKeyboardShortcuts = (override: Record<string, any>) => {
|
2022-07-11 10:56:20 +03:00
|
|
|
jest.doMock(PATH_TO_KEYBOARD_SHORTCUTS, () => {
|
|
|
|
const original = jest.requireActual(PATH_TO_KEYBOARD_SHORTCUTS);
|
|
|
|
return {
|
|
|
|
...original,
|
|
|
|
...override,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
const getFile = async () => await import(PATH_TO_KEYBOARD_SHORTCUTS);
|
|
|
|
const getUtils = async () => await import(PATH_TO_KEYBOARD_SHORTCUT_UTILS);
|
|
|
|
|
2022-03-14 16:25:51 +03:00
|
|
|
describe("KeyboardShortcutUtils", () => {
|
2022-07-11 10:56:20 +03:00
|
|
|
beforeEach(() => {
|
2022-03-23 13:27:28 +03:00
|
|
|
unmockPlatformPeg();
|
2022-07-11 10:56:20 +03:00
|
|
|
jest.resetModules();
|
2022-03-23 13:27:28 +03:00
|
|
|
});
|
|
|
|
|
2022-02-23 12:12:04 +03:00
|
|
|
it("doesn't change KEYBOARD_SHORTCUTS when getting shortcuts", async () => {
|
2022-07-11 10:56:20 +03:00
|
|
|
mockKeyboardShortcuts({
|
|
|
|
KEYBOARD_SHORTCUTS: {
|
2022-02-23 12:12:04 +03:00
|
|
|
Keybind1: {},
|
|
|
|
Keybind2: {},
|
|
|
|
},
|
2022-07-11 10:56:20 +03:00
|
|
|
MAC_ONLY_SHORTCUTS: ["Keybind1"],
|
|
|
|
DESKTOP_SHORTCUTS: ["Keybind2"],
|
2022-02-23 12:12:04 +03:00
|
|
|
});
|
2022-03-23 13:27:28 +03:00
|
|
|
mockPlatformPeg({ overrideBrowserShortcuts: jest.fn().mockReturnValue(false) });
|
2022-07-11 10:56:20 +03:00
|
|
|
const utils = await getUtils();
|
|
|
|
const file = await getFile();
|
|
|
|
const copyKeyboardShortcuts = Object.assign({}, file.KEYBOARD_SHORTCUTS);
|
2022-02-16 18:24:00 +03:00
|
|
|
|
2022-07-11 10:56:20 +03:00
|
|
|
utils.getKeyboardShortcuts();
|
|
|
|
expect(file.KEYBOARD_SHORTCUTS).toEqual(copyKeyboardShortcuts);
|
|
|
|
utils.getKeyboardShortcutsForUI();
|
|
|
|
expect(file.KEYBOARD_SHORTCUTS).toEqual(copyKeyboardShortcuts);
|
2022-02-16 18:24:00 +03:00
|
|
|
});
|
|
|
|
|
2022-07-11 10:56:20 +03:00
|
|
|
describe("correctly filters shortcuts", () => {
|
2023-03-01 18:23:35 +03:00
|
|
|
it("when on web and not on macOS", async () => {
|
2022-07-11 10:56:20 +03:00
|
|
|
mockKeyboardShortcuts({
|
|
|
|
KEYBOARD_SHORTCUTS: {
|
|
|
|
Keybind1: {},
|
|
|
|
Keybind2: {},
|
|
|
|
Keybind3: { controller: { settingDisabled: true } },
|
|
|
|
Keybind4: {},
|
|
|
|
},
|
|
|
|
MAC_ONLY_SHORTCUTS: ["Keybind1"],
|
|
|
|
DESKTOP_SHORTCUTS: ["Keybind2"],
|
|
|
|
});
|
|
|
|
mockPlatformPeg({ overrideBrowserShortcuts: jest.fn().mockReturnValue(false) });
|
|
|
|
expect((await getUtils()).getKeyboardShortcuts()).toEqual({ Keybind4: {} });
|
2022-02-23 12:12:04 +03:00
|
|
|
});
|
|
|
|
|
2022-07-11 10:56:20 +03:00
|
|
|
it("when on desktop", async () => {
|
|
|
|
mockKeyboardShortcuts({
|
|
|
|
KEYBOARD_SHORTCUTS: {
|
|
|
|
Keybind1: {},
|
|
|
|
Keybind2: {},
|
|
|
|
},
|
|
|
|
MAC_ONLY_SHORTCUTS: [],
|
|
|
|
DESKTOP_SHORTCUTS: ["Keybind2"],
|
|
|
|
});
|
|
|
|
mockPlatformPeg({ overrideBrowserShortcuts: jest.fn().mockReturnValue(true) });
|
|
|
|
expect((await getUtils()).getKeyboardShortcuts()).toEqual({ Keybind1: {}, Keybind2: {} });
|
2022-01-24 14:33:27 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|