2022-01-24 11:33:27 +00:00
|
|
|
/*
|
|
|
|
Copyright 2022 Šimon Brandner <simon.bra.ag@gmail.com>
|
2022-07-11 07:56:20 +00:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
2022-01-24 11:33:27 +00: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.
|
|
|
|
*/
|
|
|
|
|
2022-03-23 10:27:28 +00:00
|
|
|
import { mockPlatformPeg, unmockPlatformPeg } from "../test-utils";
|
2022-01-24 11:33:27 +00:00
|
|
|
|
2022-07-11 07:56:20 +00:00
|
|
|
const PATH_TO_KEYBOARD_SHORTCUTS = "../../src/accessibility/KeyboardShortcuts";
|
|
|
|
const PATH_TO_KEYBOARD_SHORTCUT_UTILS = "../../src/accessibility/KeyboardShortcutUtils";
|
|
|
|
|
|
|
|
const mockKeyboardShortcuts = (override) => {
|
|
|
|
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 13:25:51 +00:00
|
|
|
describe("KeyboardShortcutUtils", () => {
|
2022-07-11 07:56:20 +00:00
|
|
|
beforeEach(() => {
|
2022-03-23 10:27:28 +00:00
|
|
|
unmockPlatformPeg();
|
2022-07-11 07:56:20 +00:00
|
|
|
jest.resetModules();
|
2022-03-23 10:27:28 +00:00
|
|
|
});
|
|
|
|
|
2022-02-23 09:12:04 +00:00
|
|
|
it("doesn't change KEYBOARD_SHORTCUTS when getting shortcuts", async () => {
|
2022-07-11 07:56:20 +00:00
|
|
|
mockKeyboardShortcuts({
|
|
|
|
KEYBOARD_SHORTCUTS: {
|
2022-12-12 11:24:14 +00:00
|
|
|
Keybind1: {},
|
|
|
|
Keybind2: {},
|
2022-02-23 09:12:04 +00:00
|
|
|
},
|
2022-07-11 07:56:20 +00:00
|
|
|
MAC_ONLY_SHORTCUTS: ["Keybind1"],
|
|
|
|
DESKTOP_SHORTCUTS: ["Keybind2"],
|
2022-02-23 09:12:04 +00:00
|
|
|
});
|
2022-03-23 10:27:28 +00:00
|
|
|
mockPlatformPeg({ overrideBrowserShortcuts: jest.fn().mockReturnValue(false) });
|
2022-07-11 07:56:20 +00:00
|
|
|
const utils = await getUtils();
|
|
|
|
const file = await getFile();
|
|
|
|
const copyKeyboardShortcuts = Object.assign({}, file.KEYBOARD_SHORTCUTS);
|
2022-02-16 15:24:00 +00:00
|
|
|
|
2022-07-11 07:56:20 +00:00
|
|
|
utils.getKeyboardShortcuts();
|
|
|
|
expect(file.KEYBOARD_SHORTCUTS).toEqual(copyKeyboardShortcuts);
|
|
|
|
utils.getKeyboardShortcutsForUI();
|
|
|
|
expect(file.KEYBOARD_SHORTCUTS).toEqual(copyKeyboardShortcuts);
|
2022-02-16 15:24:00 +00:00
|
|
|
});
|
|
|
|
|
2022-07-11 07:56:20 +00:00
|
|
|
describe("correctly filters shortcuts", () => {
|
|
|
|
it("when on web and not on macOS ", async () => {
|
|
|
|
mockKeyboardShortcuts({
|
|
|
|
KEYBOARD_SHORTCUTS: {
|
2022-12-12 11:24:14 +00:00
|
|
|
Keybind1: {},
|
|
|
|
Keybind2: {},
|
|
|
|
Keybind3: { controller: { settingDisabled: true } },
|
|
|
|
Keybind4: {},
|
2022-07-11 07:56:20 +00:00
|
|
|
},
|
|
|
|
MAC_ONLY_SHORTCUTS: ["Keybind1"],
|
|
|
|
DESKTOP_SHORTCUTS: ["Keybind2"],
|
|
|
|
});
|
|
|
|
mockPlatformPeg({ overrideBrowserShortcuts: jest.fn().mockReturnValue(false) });
|
2022-12-12 11:24:14 +00:00
|
|
|
expect((await getUtils()).getKeyboardShortcuts()).toEqual({ Keybind4: {} });
|
2022-02-23 09:12:04 +00:00
|
|
|
});
|
|
|
|
|
2022-07-11 07:56:20 +00:00
|
|
|
it("when on desktop", async () => {
|
|
|
|
mockKeyboardShortcuts({
|
|
|
|
KEYBOARD_SHORTCUTS: {
|
2022-12-12 11:24:14 +00:00
|
|
|
Keybind1: {},
|
|
|
|
Keybind2: {},
|
2022-07-11 07:56:20 +00:00
|
|
|
},
|
|
|
|
MAC_ONLY_SHORTCUTS: [],
|
|
|
|
DESKTOP_SHORTCUTS: ["Keybind2"],
|
|
|
|
});
|
|
|
|
mockPlatformPeg({ overrideBrowserShortcuts: jest.fn().mockReturnValue(true) });
|
2022-12-12 11:24:14 +00:00
|
|
|
expect((await getUtils()).getKeyboardShortcuts()).toEqual({ Keybind1: {}, Keybind2: {} });
|
2022-01-24 11:33:27 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|