DEV: Refactor and test plugin addKeyboardShortcut (#9381)

Refactor plugin-api `addKeyboardShortcut` to point to `KeyboardShortcuts`.
* Do not add shortcuts to the default object directly.
* Create an addShortcut function in keyboard-shortcuts to add shortcuts safely and call to bindKey to be able to use opts.
* Refactor controllers/bookmark.js to use new addShortcut func and emove unnecessary addBindings.
* No longer export keyboard shortcut bindings, rename to DEFAULT_BINDINGS and remove export, these do not need to be accessed by anything else.
This commit is contained in:
Martin Brennan
2020-04-09 10:30:26 +10:00
committed by GitHub
parent f062ebf274
commit befaf39aca
5 changed files with 99 additions and 36 deletions
@@ -74,7 +74,7 @@ Object.keys(pathBindings).forEach(path => {
var testName = binding + " goes to " + path;
test(testName, function(assert) {
KeyboardShortcuts.bindEvents(testMouseTrap, Discourse.__container__);
KeyboardShortcuts.bindEvents();
testMouseTrap.trigger(binding);
assert.ok(DiscourseURL.routeTo.calledWith(path));
@@ -89,7 +89,7 @@ Object.keys(clickBindings).forEach(selector => {
var testName = binding + " clicks on " + selector;
test(testName, function(assert) {
KeyboardShortcuts.bindEvents(testMouseTrap, Discourse.__container__);
KeyboardShortcuts.bindEvents();
$(selector).on("click", function() {
assert.ok(true, selector + " was clicked");
});
@@ -109,7 +109,7 @@ Object.keys(functionBindings).forEach(func => {
sandbox.stub(KeyboardShortcuts, func, function() {
assert.ok(true, func + " is called when " + binding + " is triggered");
});
KeyboardShortcuts.bindEvents(testMouseTrap, Discourse.__container__);
KeyboardShortcuts.bindEvents();
testMouseTrap.trigger(binding);
});