UX: Submit security key edit form on Enter (#24532)

Co-authored-by: Jarek Radosz <jradosz@gmail.com>
This commit is contained in:
Penar Musaraj 2023-11-27 16:11:12 -05:00 committed by GitHub
parent cda86e63bb
commit 633deb5af8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 14 deletions

View File

@ -1,27 +1,28 @@
<DModal <DModal
@title={{i18n "user.second_factor.security_key.edit"}} @title={{i18n "user.second_factor.security_key.edit"}}
@closeModal={{@closeModal}} @closeModal={{@closeModal}}
@tagName="form"
> >
<:body> <:body>
<form class="form-horizontal"> <div class="input-group">
<div class="input-group"> <label for="security-key-name">{{i18n
<label for="security-key-name">{{i18n "user.second_factor.security_key.edit_description"
"user.second_factor.security_key.edit_description" }}</label>
}}</label> <Input
<Input name="security-key-name"
name="security-key-name" id="security-key-name"
maxlength={{this.maxSecondFactorNameLength}} maxlength={{this.maxSecondFactorNameLength}}
@type="text" @type="text"
@value={{@model.securityKey.name}} @value={{@model.securityKey.name}}
/> />
</div> </div>
</form>
</:body> </:body>
<:footer> <:footer>
<DButton <DButton
@action={{this.editSecurityKey}} @action={{this.editSecurityKey}}
class="btn-primary" class="btn-primary"
@label="user.second_factor.security_key.save" @label="user.second_factor.security_key.save"
@type="submit"
/> />
</:footer> </:footer>
</DModal> </DModal>

View File

@ -1,4 +1,10 @@
import { click, currentRouteName, fillIn, visit } from "@ember/test-helpers"; import {
click,
currentRouteName,
fillIn,
triggerKeyEvent,
visit,
} from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { import {
acceptance, acceptance,
@ -133,6 +139,25 @@ acceptance("User Preferences - Second Factor", function (needs) {
"Are you sure you want to disable two-factor authentication?" "Are you sure you want to disable two-factor authentication?"
); );
}); });
test("rename second factor security method", async function (assert) {
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
await visit("/u/eviltrout/preferences/second-factor");
assert
.dom(".security-key .second-factor-item")
.exists("User has a physical security key");
await click(".security-key-dropdown .select-kit-header");
await click(".security-key-dropdown li[data-name='Edit']");
await fillIn("input[name='security-key-name']", "keyname changed");
await triggerKeyEvent(".d-modal .btn-primary", "keydown", "Enter");
assert
.dom(".d-modal__container")
.doesNotExist("modal is closed when form is submitted via keyboard");
});
}); });
acceptance( acceptance(