2022-01-24 14:33:27 +03:00
|
|
|
/*
|
|
|
|
Copyright 2022 Šimon Brandner <simon.bra.ag@gmail.com>
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {
|
2022-03-04 15:14:52 +03:00
|
|
|
getKeyboardShortcutsForUI,
|
2022-01-27 14:37:53 +03:00
|
|
|
getKeyboardShortcuts,
|
2022-02-16 18:24:00 +03:00
|
|
|
KEYBOARD_SHORTCUTS,
|
2022-02-23 12:12:04 +03:00
|
|
|
mock,
|
2022-01-24 14:33:27 +03:00
|
|
|
} from "../../src/accessibility/KeyboardShortcuts";
|
2022-02-23 12:12:04 +03:00
|
|
|
import PlatformPeg from "../../src/PlatformPeg";
|
2022-01-24 14:33:27 +03:00
|
|
|
|
|
|
|
describe("KeyboardShortcuts", () => {
|
2022-02-23 12:12:04 +03:00
|
|
|
it("doesn't change KEYBOARD_SHORTCUTS when getting shortcuts", async () => {
|
|
|
|
mock({
|
|
|
|
keyboardShortcuts: {
|
|
|
|
"Keybind1": {},
|
|
|
|
"Keybind2": {},
|
|
|
|
},
|
|
|
|
macOnlyShortcuts: ["Keybind1"],
|
|
|
|
desktopShortcuts: ["Keybind2"],
|
|
|
|
});
|
|
|
|
PlatformPeg.get = () => ({ overrideBrowserShortcuts: () => false });
|
2022-02-16 18:24:00 +03:00
|
|
|
const copyKeyboardShortcuts = Object.assign({}, KEYBOARD_SHORTCUTS);
|
|
|
|
|
|
|
|
getKeyboardShortcuts();
|
|
|
|
expect(KEYBOARD_SHORTCUTS).toEqual(copyKeyboardShortcuts);
|
2022-03-04 15:14:52 +03:00
|
|
|
getKeyboardShortcutsForUI();
|
|
|
|
expect(KEYBOARD_SHORTCUTS).toEqual(copyKeyboardShortcuts);
|
2022-02-16 18:24:00 +03:00
|
|
|
});
|
|
|
|
|
2022-02-23 12:12:04 +03:00
|
|
|
it("correctly filters shortcuts", async () => {
|
|
|
|
mock({
|
|
|
|
keyboardShortcuts: {
|
|
|
|
"Keybind1": {},
|
|
|
|
"Keybind2": {},
|
|
|
|
"Keybind3": { "controller": { settingDisabled: true } },
|
|
|
|
"Keybind4": {},
|
|
|
|
},
|
|
|
|
macOnlyShortcuts: ["Keybind1"],
|
|
|
|
desktopShortcuts: ["Keybind2"],
|
|
|
|
|
|
|
|
});
|
|
|
|
PlatformPeg.get = () => ({ overrideBrowserShortcuts: () => false });
|
2022-03-04 15:14:52 +03:00
|
|
|
expect(getKeyboardShortcuts()).toEqual({ "Keybind4": {} });
|
2022-02-23 12:12:04 +03:00
|
|
|
|
|
|
|
mock({
|
|
|
|
keyboardShortcuts: {
|
|
|
|
"Keybind1": {},
|
|
|
|
"Keybind2": {},
|
|
|
|
},
|
|
|
|
macOnlyShortcuts: undefined,
|
|
|
|
desktopShortcuts: ["Keybind2"],
|
2022-01-24 14:33:27 +03:00
|
|
|
});
|
2022-02-23 12:12:04 +03:00
|
|
|
PlatformPeg.get = () => ({ overrideBrowserShortcuts: () => true });
|
2022-03-04 15:14:52 +03:00
|
|
|
expect(getKeyboardShortcuts()).toEqual({ "Keybind1": {}, "Keybind2": {} });
|
2022-02-23 12:12:04 +03:00
|
|
|
jest.resetModules();
|
2022-01-24 14:33:27 +03:00
|
|
|
});
|
|
|
|
});
|