FIX: In newer embers, it's triggerKeyEvent not keyEvent

This commit is contained in:
Robin Ward 2020-11-17 13:48:03 -05:00
parent 504aaad838
commit 410214e5a9
10 changed files with 39 additions and 35 deletions

View File

@ -3,7 +3,7 @@ import { exists } from "discourse/tests/helpers/qunit-helpers";
import { import {
fillIn, fillIn,
click, click,
keyEvent, triggerKeyEvent,
visit, visit,
currentURL, currentURL,
} from "@ember/test-helpers"; } from "@ember/test-helpers";
@ -98,7 +98,7 @@ acceptance("Admin - Site Settings", function (needs) {
); );
await fillIn(".input-setting-string", "Test"); await fillIn(".input-setting-string", "Test");
await keyEvent(".input-setting-string", "keydown", 13); // enter await triggerKeyEvent(".input-setting-string", "keydown", 13); // enter
assert.ok( assert.ok(
exists(".row.setting.overridden"), exists(".row.setting.overridden"),
"saving via Enter key marks setting as overriden" "saving via Enter key marks setting as overriden"

View File

@ -1,6 +1,6 @@
import { queryAll } from "discourse/tests/helpers/qunit-helpers"; import { queryAll } from "discourse/tests/helpers/qunit-helpers";
import { exists } from "discourse/tests/helpers/qunit-helpers"; import { exists } from "discourse/tests/helpers/qunit-helpers";
import { click, fillIn, keyEvent, visit } from "@ember/test-helpers"; import { click, fillIn, triggerKeyEvent, visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
@ -71,21 +71,21 @@ acceptance("Composer - Hyperlink", function (needs) {
await click(".d-editor button.link"); await click(".d-editor button.link");
await fillIn(".modal-body .link-url", "http://google.com"); await fillIn(".modal-body .link-url", "http://google.com");
await keyEvent(".modal-body .link-url", "keyup", 32); await triggerKeyEvent(".modal-body .link-url", "keyup", 32);
assert.ok( assert.ok(
!exists(".internal-link-results"), !exists(".internal-link-results"),
"does not show internal links search dropdown when inputting a url" "does not show internal links search dropdown when inputting a url"
); );
await fillIn(".modal-body .link-url", "local"); await fillIn(".modal-body .link-url", "local");
await keyEvent(".modal-body .link-url", "keyup", 32); await triggerKeyEvent(".modal-body .link-url", "keyup", 32);
assert.ok( assert.ok(
exists(".internal-link-results"), exists(".internal-link-results"),
"shows internal links search dropdown when entering keywords" "shows internal links search dropdown when entering keywords"
); );
await keyEvent(".insert-link", "keydown", 40); await triggerKeyEvent(".insert-link", "keydown", 40);
await keyEvent(".insert-link", "keydown", 13); await triggerKeyEvent(".insert-link", "keydown", 13);
assert.ok( assert.ok(
!exists(".internal-link-results"), !exists(".internal-link-results"),

View File

@ -1,4 +1,4 @@
import { keyEvent, visit, currentURL } from "@ember/test-helpers"; import { triggerKeyEvent, visit, currentURL } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
@ -25,19 +25,19 @@ acceptance("Keyboard Shortcuts", function (needs) {
test("go to first suggested topic", async function (assert) { test("go to first suggested topic", async function (assert) {
await visit("/t/this-is-a-test-topic/9"); await visit("/t/this-is-a-test-topic/9");
await keyEvent(document, "keypress", "g".charCodeAt(0)); await triggerKeyEvent(document, "keypress", "g".charCodeAt(0));
await keyEvent(document, "keypress", "s".charCodeAt(0)); await triggerKeyEvent(document, "keypress", "s".charCodeAt(0));
assert.equal(currentURL(), "/t/this-is-a-test-topic/9"); assert.equal(currentURL(), "/t/this-is-a-test-topic/9");
// Suggested topics elements exist. // Suggested topics elements exist.
await visit("/t/internationalization-localization/280"); await visit("/t/internationalization-localization/280");
await keyEvent(document, "keypress", "g".charCodeAt(0)); await triggerKeyEvent(document, "keypress", "g".charCodeAt(0));
await keyEvent(document, "keypress", "s".charCodeAt(0)); await triggerKeyEvent(document, "keypress", "s".charCodeAt(0));
assert.equal(currentURL(), "/t/polls-are-still-very-buggy/27331/4"); assert.equal(currentURL(), "/t/polls-are-still-very-buggy/27331/4");
await visit("/t/1-3-0beta9-no-rate-limit-popups/28830"); await visit("/t/1-3-0beta9-no-rate-limit-popups/28830");
await keyEvent(document, "keypress", "g".charCodeAt(0)); await triggerKeyEvent(document, "keypress", "g".charCodeAt(0));
await keyEvent(document, "keypress", "s".charCodeAt(0)); await triggerKeyEvent(document, "keypress", "s".charCodeAt(0));
assert.equal(currentURL(), "/t/keyboard-shortcuts-are-awesome/27331"); assert.equal(currentURL(), "/t/keyboard-shortcuts-are-awesome/27331");
}); });
}); });

View File

@ -1,5 +1,5 @@
import { queryAll } from "discourse/tests/helpers/qunit-helpers"; import { queryAll } from "discourse/tests/helpers/qunit-helpers";
import { click, keyEvent, visit } from "@ember/test-helpers"; import { click, triggerKeyEvent, visit } from "@ember/test-helpers";
import { skip, test } from "qunit"; import { skip, test } from "qunit";
import I18n from "I18n"; import I18n from "I18n";
import { run } from "@ember/runloop"; import { run } from "@ember/runloop";
@ -54,7 +54,7 @@ acceptance("Modal", function (needs) {
"modal should reappear" "modal should reappear"
); );
await keyEvent("#main-outlet", "keyup", 27); await triggerKeyEvent("#main-outlet", "keyup", 27);
assert.ok( assert.ok(
queryAll(".d-modal:visible").length === 0, queryAll(".d-modal:visible").length === 0,
"ESC should close the modal" "ESC should close the modal"
@ -73,7 +73,7 @@ acceptance("Modal", function (needs) {
queryAll(".d-modal:visible").length === 1, queryAll(".d-modal:visible").length === 1,
"modal should not disappear when you click outside" "modal should not disappear when you click outside"
); );
await keyEvent("#main-outlet", "keyup", 27); await triggerKeyEvent("#main-outlet", "keyup", 27);
assert.ok( assert.ok(
queryAll(".d-modal:visible").length === 1, queryAll(".d-modal:visible").length === 1,
"ESC should not close the modal" "ESC should not close the modal"
@ -139,7 +139,7 @@ acceptance("Modal Keyboard Events", function (needs) {
await click(".toggle-admin-menu"); await click(".toggle-admin-menu");
await click(".topic-admin-status-update button"); await click(".topic-admin-status-update button");
await keyEvent(".d-modal", "keyup", 13); await triggerKeyEvent(".d-modal", "keyup", 13);
assert.ok( assert.ok(
queryAll("#modal-alert:visible").length === 1, queryAll("#modal-alert:visible").length === 1,
@ -150,7 +150,7 @@ acceptance("Modal Keyboard Events", function (needs) {
"hitting Enter does not dismiss modal due to alert error" "hitting Enter does not dismiss modal due to alert error"
); );
await keyEvent("#main-outlet", "keyup", 27); await triggerKeyEvent("#main-outlet", "keyup", 27);
assert.ok( assert.ok(
queryAll(".d-modal:visible").length === 0, queryAll(".d-modal:visible").length === 0,
"ESC should close the modal" "ESC should close the modal"
@ -160,7 +160,7 @@ acceptance("Modal Keyboard Events", function (needs) {
await click(".d-editor-button-bar .btn.link"); await click(".d-editor-button-bar .btn.link");
await keyEvent(".d-modal", "keyup", 13); await triggerKeyEvent(".d-modal", "keyup", 13);
assert.ok( assert.ok(
queryAll(".d-modal:visible").length === 0, queryAll(".d-modal:visible").length === 0,
"modal should disappear on hitting Enter" "modal should disappear on hitting Enter"

View File

@ -1,4 +1,4 @@
import { keyEvent, visit } from "@ember/test-helpers"; import { triggerKeyEvent, visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { withPluginApi } from "discourse/lib/plugin-api"; import { withPluginApi } from "discourse/lib/plugin-api";
@ -21,7 +21,7 @@ acceptance("Plugin Keyboard Shortcuts - Logged In", function (needs) {
}); });
await visit("/t/this-is-a-test-topic/9"); await visit("/t/this-is-a-test-topic/9");
await keyEvent(document, "keypress", "]".charCodeAt(0)); await triggerKeyEvent(document, "keypress", "]".charCodeAt(0));
assert.equal( assert.equal(
$("#added-element").length, $("#added-element").length,
1, 1,

View File

@ -1,6 +1,6 @@
import { queryAll } from "discourse/tests/helpers/qunit-helpers"; import { queryAll } from "discourse/tests/helpers/qunit-helpers";
import { exists } from "discourse/tests/helpers/qunit-helpers"; import { exists } from "discourse/tests/helpers/qunit-helpers";
import { keyEvent, visit, fillIn, click } from "@ember/test-helpers"; import { triggerKeyEvent, visit, fillIn, click } from "@ember/test-helpers";
import { skip, test } from "qunit"; import { skip, test } from "qunit";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
import { import {
@ -128,7 +128,11 @@ acceptance("Search - Full Page", function (needs) {
await fillIn(".search-query", "none"); await fillIn(".search-query", "none");
await fillIn(".search-advanced-options .user-selector", "admin"); await fillIn(".search-advanced-options .user-selector", "admin");
await click(".search-advanced-options .user-selector"); await click(".search-advanced-options .user-selector");
await keyEvent(".search-advanced-options .user-selector", "keydown", 8); await triggerKeyEvent(
".search-advanced-options .user-selector",
"keydown",
8
);
waitFor(assert, async () => { waitFor(assert, async () => {
assert.ok( assert.ok(

View File

@ -1,6 +1,6 @@
import { queryAll } from "discourse/tests/helpers/qunit-helpers"; import { queryAll } from "discourse/tests/helpers/qunit-helpers";
import { exists } from "discourse/tests/helpers/qunit-helpers"; import { exists } from "discourse/tests/helpers/qunit-helpers";
import { click, keyEvent, fillIn, visit } from "@ember/test-helpers"; import { click, triggerKeyEvent, fillIn, visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
@ -28,7 +28,7 @@ acceptance("Search - Anonymous", function (needs) {
assert.ok(!exists(".search-menu .results ul li"), "no results by default"); assert.ok(!exists(".search-menu .results ul li"), "no results by default");
await fillIn("#search-term", "dev"); await fillIn("#search-term", "dev");
await keyEvent("#search-term", "keyup", 16); await triggerKeyEvent("#search-term", "keyup", 16);
assert.ok(exists(".search-menu .results ul li"), "it shows results"); assert.ok(exists(".search-menu .results ul li"), "it shows results");
assert.ok( assert.ok(
exists(".search-menu .results ul li .topic-title[data-topic-id]"), exists(".search-menu .results ul li .topic-title[data-topic-id]"),
@ -54,7 +54,7 @@ acceptance("Search - Anonymous", function (needs) {
await click("#search-button"); await click("#search-button");
await fillIn("#search-term", "evil"); await fillIn("#search-term", "evil");
await keyEvent("#search-term", "keyup", 16); await triggerKeyEvent("#search-term", "keyup", 16);
assert.ok(exists(".search-menu .results ul li"), "it shows results"); assert.ok(exists(".search-menu .results ul li"), "it shows results");
}); });
@ -97,7 +97,7 @@ acceptance("Search - Anonymous", function (needs) {
await click("#search-button"); await click("#search-button");
await fillIn("#search-term", "a proper"); await fillIn("#search-term", "a proper");
await click(".search-context input[type='checkbox']"); await click(".search-context input[type='checkbox']");
await keyEvent("#search-term", "keyup", 16); await triggerKeyEvent("#search-term", "keyup", 16);
assert.ok(exists(".search-menu .results ul li"), "it shows results"); assert.ok(exists(".search-menu .results ul li"), "it shows results");
@ -187,7 +187,7 @@ acceptance("Search - with tagging enabled", function (needs) {
await click("#search-button"); await click("#search-button");
await fillIn("#search-term", "dev"); await fillIn("#search-term", "dev");
await keyEvent("#search-term", "keyup", 16); await triggerKeyEvent("#search-term", "keyup", 16);
const tags = queryAll(".search-menu .results ul li:eq(0) .discourse-tags") const tags = queryAll(".search-menu .results ul li:eq(0) .discourse-tags")
.text() .text()

View File

@ -1,6 +1,6 @@
import { queryAll } from "discourse/tests/helpers/qunit-helpers"; import { queryAll } from "discourse/tests/helpers/qunit-helpers";
import { exists } from "discourse/tests/helpers/qunit-helpers"; import { exists } from "discourse/tests/helpers/qunit-helpers";
import { click, keyEvent, fillIn, visit } from "@ember/test-helpers"; import { click, triggerKeyEvent, fillIn, visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import I18n from "I18n"; import I18n from "I18n";
import { withPluginApi } from "discourse/lib/plugin-api"; import { withPluginApi } from "discourse/lib/plugin-api";
@ -394,8 +394,8 @@ acceptance("Topic featured links", function (needs) {
test("Quoting a quote with replyAsNewTopic keeps the original poster name", async function (assert) { test("Quoting a quote with replyAsNewTopic keeps the original poster name", async function (assert) {
await visit("/t/internationalization-localization/280"); await visit("/t/internationalization-localization/280");
selectText("#post_5 blockquote"); selectText("#post_5 blockquote");
await keyEvent(document, "keypress", "j".charCodeAt(0)); await triggerKeyEvent(document, "keypress", "j".charCodeAt(0));
await keyEvent(document, "keypress", "t".charCodeAt(0)); await triggerKeyEvent(document, "keypress", "t".charCodeAt(0));
assert.ok( assert.ok(
queryAll(".d-editor-input") queryAll(".d-editor-input")

View File

@ -1,7 +1,7 @@
import { queryAll } from "discourse/tests/helpers/qunit-helpers"; import { queryAll } from "discourse/tests/helpers/qunit-helpers";
import { moduleForComponent } from "ember-qunit"; import { moduleForComponent } from "ember-qunit";
import componentTest from "discourse/tests/helpers/component-test"; import componentTest from "discourse/tests/helpers/component-test";
import { click, keyEvent, fillIn } from "@ember/test-helpers"; import { click, triggerKeyEvent, fillIn } from "@ember/test-helpers";
moduleForComponent("simple-list", { integration: true }); moduleForComponent("simple-list", { integration: true });
@ -33,7 +33,7 @@ componentTest("adding a value", {
); );
await fillIn(".add-value-input", "eviltrout"); await fillIn(".add-value-input", "eviltrout");
await keyEvent(".add-value-input", "keydown", 13); // enter await triggerKeyEvent(".add-value-input", "keydown", 13); // enter
assert.ok( assert.ok(
queryAll(".values .value").length === 4, queryAll(".values .value").length === 4,

View File

@ -37,12 +37,12 @@ define("@ember/test-helpers", () => {
"currentRouteName", "currentRouteName",
"fillIn", "fillIn",
"setResolver", "setResolver",
"keyEvent",
].forEach((attr) => { ].forEach((attr) => {
helpers[attr] = function () { helpers[attr] = function () {
return window[attr](...arguments); return window[attr](...arguments);
}; };
}); });
helpers.triggerKeyEvent = window.keyEvent;
return helpers; return helpers;
}); });
define("pretender", () => { define("pretender", () => {