FIX: Dismiss new keyboard shortcut not working (#13430)

The dismiss new keyboard shortcut (x,r) has been broken since
7a79bd7da3. A fix was done and JS
tests were added in 006d52f32b
and b01e4738ab but the test was not
quite correct and so the bottom dismiss new button was not clicked.

This also fixes an issue with our keyboard shortcut click handling.
If multiple elements matched the selector they were all clicked. Now
we just click the first match.
This commit is contained in:
Martin Brennan 2021-06-18 13:56:23 +10:00 committed by GitHub
parent 33c3bb261a
commit 7f916ad06d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 3 deletions

View File

@ -86,8 +86,8 @@ const DEFAULT_BINDINGS = {
t: { postAction: "replyAsNewTopic" },
u: { handler: "goBack", anonymous: true },
"x r": {
click: "#dismiss-new,#dismiss-new-top,#dismiss-posts,#dismiss-posts-top",
}, // dismiss new/posts
click: "#dismiss-new-bottom,#dismiss-new-top",
}, // dismiss new
"x t": { click: "#dismiss-topics-bottom,#dismiss-topics-top" }, // dismiss topics
};
@ -549,7 +549,11 @@ export default {
// If effective, prevent default.
e.preventDefault();
}
$sel.click();
// If there is more than one match for the selector, just click
// the first one, we don't want to click multiple things from one
// shortcut.
$sel[0].click();
});
},

View File

@ -82,6 +82,7 @@ acceptance("Keyboard Shortcuts - Authenticated Users", function (needs) {
test("dismiss unread from top and bottom button", async function (assert) {
await visit("/unread");
assert.ok(exists("#dismiss-topics-top"));
await triggerKeyEvent(document, "keypress", "x".charCodeAt(0));
await triggerKeyEvent(document, "keypress", "t".charCodeAt(0));
assert.ok(exists("#dismiss-read-confirm"));
@ -98,7 +99,10 @@ acceptance("Keyboard Shortcuts - Authenticated Users", function (needs) {
let originalTopics = [...topicList.topic_list.topics];
topicList.topic_list.topics = [topicList.topic_list.topics[0]];
// visit root first so topic list starts fresh
await visit("/");
await visit("/unread");
assert.notOk(exists("#dismiss-topics-top"));
await triggerKeyEvent(document, "keypress", "x".charCodeAt(0));
await triggerKeyEvent(document, "keypress", "t".charCodeAt(0));
assert.ok(exists("#dismiss-read-confirm"));
@ -115,6 +119,7 @@ acceptance("Keyboard Shortcuts - Authenticated Users", function (needs) {
test("dismiss new from top and bottom button", async function (assert) {
await visit("/new");
assert.ok(exists("#dismiss-new-top"));
await triggerKeyEvent(document, "keypress", "x".charCodeAt(0));
await triggerKeyEvent(document, "keypress", "r".charCodeAt(0));
assert.equal(resetNewCalled, 1);
@ -125,7 +130,10 @@ acceptance("Keyboard Shortcuts - Authenticated Users", function (needs) {
let originalTopics = [...topicList.topic_list.topics];
topicList.topic_list.topics = [topicList.topic_list.topics[0]];
// visit root first so topic list starts fresh
await visit("/");
await visit("/new");
assert.notOk(exists("#dismiss-new-top"));
await triggerKeyEvent(document, "keypress", "x".charCodeAt(0));
await triggerKeyEvent(document, "keypress", "r".charCodeAt(0));
assert.equal(resetNewCalled, 2);
@ -133,4 +141,15 @@ acceptance("Keyboard Shortcuts - Authenticated Users", function (needs) {
// restore the original topic list
topicList.topic_list.topics = originalTopics;
});
test("click event not fired twice when both dismiss buttons are present", async function (assert) {
await visit("/new");
assert.ok(exists("#dismiss-new-top"));
assert.ok(exists("#dismiss-new-bottom"));
await triggerKeyEvent(document, "keypress", "x".charCodeAt(0));
await triggerKeyEvent(document, "keypress", "r".charCodeAt(0));
assert.equal(resetNewCalled, 1);
});
});