login: Add show password feature to login page.

The show password feature is a functionality to
toggle the visibility of the password fields in forms
so that one can check if they have entered the correct
password or not. We implement this using an eye icon
toggling which converts input field type from password
to text and vice-versa.
Fixes part of #17301.
This commit is contained in:
Gaurav Pandey
2021-04-05 13:12:29 +05:30
committed by Tim Abbott
parent 2ceda13e31
commit fa235e60ff
6 changed files with 87 additions and 2 deletions

View File

@@ -128,3 +128,33 @@ run_test("adjust_mac_shortcuts mac", (override) => {
assert.equal(test_item.stub.text(), test_item.mac_key);
}
});
run_test("show password", () => {
const password_selector = ".password_visibility_toggle";
function set_attribute(type) {
$("#id_password").attr("type", type);
}
function check_assertion(type, present_class, absent_class) {
assert.equal($("#id_password").attr("type"), type);
assert($(password_selector).hasClass(present_class));
assert(!$(password_selector).hasClass(absent_class));
}
const ev = {
preventDefault: () => {},
stopPropagation: () => {},
};
set_attribute("password");
common.setup_password_visibility_toggle("#id_password", password_selector);
const handler = $(password_selector).get_on_handler("click");
handler(ev);
check_assertion("text", "fa-eye", "fa-eye-slash");
handler(ev);
check_assertion("password", "fa-eye-slash", "fa-eye");
});