DEV: @bind create-account actions (#17100)

DEV: @bind create-account actions

Context: https://github.com/discourse/discourse/pull/16983#discussion_r894721403
This commit is contained in:
Isaac Janzen 2022-06-15 12:36:04 -05:00 committed by GitHub
parent 275849771f
commit bc0a37b642
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -1,5 +1,6 @@
import Component from "@ember/component";
import cookie from "discourse/lib/cookie";
import { bind } from "discourse-common/utils/decorators";
export default Component.extend({
classNames: ["create-account-body"],
@ -21,6 +22,7 @@ export default Component.extend({
}
},
@bind
actionOnEnter(event) {
if (!this.disabled && event.key === "Enter") {
event.preventDefault();
@ -30,6 +32,7 @@ export default Component.extend({
}
},
@bind
selectKitFocus(event) {
const target = document.getElementById(event.target.getAttribute("for"));
if (target?.classList.contains("select-kit")) {

View File

@ -1,9 +1,10 @@
import {
acceptance,
count,
exists,
query,
} from "discourse/tests/helpers/qunit-helpers";
import { click, fillIn, visit } from "@ember/test-helpers";
import { click, fillIn, triggerKeyEvent, visit } from "@ember/test-helpers";
import { test } from "qunit";
acceptance("Create Account - User Fields", function (needs) {
@ -65,4 +66,22 @@ acceptance("Create Account - User Fields", function (needs) {
await click(".user-field input[type=checkbox]");
await click(".modal-footer .btn-primary");
});
test("can submit with enter", async function (assert) {
await visit("/");
await click("header .sign-up-button");
await triggerKeyEvent(".modal-footer .btn-primary", "keydown", 13);
assert.strictEqual(
count("#modal-alert:visible"),
1,
"hitting Enter triggers modal action"
);
assert.strictEqual(
count(".d-modal:visible"),
1,
"hitting Enter does not dismiss modal due to alert error"
);
});
});