mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
frontend linting
This commit is contained in:
@@ -15,12 +15,12 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
const showPasswordButtonClassHidden = 'show-password--hide';
|
||||
const showPasswordButtonClassShowing = 'show-password--show';
|
||||
const showPasswordButtonClassHidden = "show-password--hide";
|
||||
const showPasswordButtonClassShowing = "show-password--show";
|
||||
|
||||
const container = 'show-password-container';
|
||||
const container = "show-password-container";
|
||||
|
||||
let display = 'hidden';
|
||||
let display = "hidden";
|
||||
|
||||
const showPasswordButtons = () => {
|
||||
let buttons: NodeListOf<HTMLElement>;
|
||||
@@ -49,45 +49,45 @@ const hidePasswordButtons = () => {
|
||||
};
|
||||
|
||||
// e is click event from show password container
|
||||
export const showPassword = () => {
|
||||
const inputs = document.body.querySelectorAll('input');
|
||||
export const showPassword = (): void => {
|
||||
const inputs = document.body.querySelectorAll("input");
|
||||
|
||||
if (display == 'hidden') {
|
||||
display = 'show';
|
||||
if (display == "hidden") {
|
||||
display = "show";
|
||||
inputs.forEach(element => {
|
||||
if (element.type === 'password') {
|
||||
element.type = 'text';
|
||||
if (element.type === "password") {
|
||||
element.type = "text";
|
||||
}
|
||||
});
|
||||
showPasswordButtons().forEach((button: HTMLInputElement) => {
|
||||
button.style.display = 'none';
|
||||
button.style.display = "none";
|
||||
});
|
||||
|
||||
hidePasswordButtons().forEach((button: HTMLInputElement) => {
|
||||
button.style.display = 'inline';
|
||||
button.style.display = "inline";
|
||||
});
|
||||
} else {
|
||||
display = 'hidden';
|
||||
display = "hidden";
|
||||
inputs.forEach(element => {
|
||||
if (element.type === 'text' && element.name.includes('password')) {
|
||||
element.type = 'password';
|
||||
if (element.type === "text" && element.name.includes("password")) {
|
||||
element.type = "password";
|
||||
}
|
||||
});
|
||||
showPasswordButtons().forEach((button: HTMLInputElement) => {
|
||||
button.style.display = 'inline';
|
||||
button.style.display = "inline";
|
||||
});
|
||||
|
||||
hidePasswordButtons().forEach((button: HTMLInputElement) => {
|
||||
button.style.display = 'none';
|
||||
button.style.display = "none";
|
||||
});
|
||||
}
|
||||
|
||||
// posibily clicked on something else
|
||||
};
|
||||
|
||||
export const registerShowPassword = () => {
|
||||
export const registerShowPassword = (): void => {
|
||||
document.querySelectorAll(`.${container}`).forEach(container => {
|
||||
container.addEventListener('click', showPassword);
|
||||
container.addEventListener("click", showPassword);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import registerShowPassword from './index';
|
||||
import {showPassword} from './index';
|
||||
import registerShowPassword from "./index";
|
||||
import {showPassword} from "./index";
|
||||
|
||||
const initial_content = `
|
||||
<form class="sitekey-form" method="POST" action="/api/v1/signin" id="form" data-bitwarden-watching="1">
|
||||
@@ -41,49 +41,49 @@ const initial_content = `
|
||||
</form>
|
||||
`;
|
||||
|
||||
it('show password works', () => {
|
||||
it("show password works", () => {
|
||||
document.body.innerHTML = initial_content;
|
||||
|
||||
const container = <HTMLElement>(
|
||||
document.querySelector(`.show-password-container`)
|
||||
document.querySelector(".show-password-container")
|
||||
);
|
||||
const hide = <HTMLElement>container.querySelector('.show-password--hide');
|
||||
const show = <HTMLElement>container.querySelector('.show-password--show');
|
||||
const password = <HTMLInputElement>document.getElementById('password');
|
||||
show.style.display = 'inline';
|
||||
hide.style.display = 'none';
|
||||
const hide = <HTMLElement>container.querySelector(".show-password--hide");
|
||||
const show = <HTMLElement>container.querySelector(".show-password--show");
|
||||
const password = <HTMLInputElement>document.getElementById("password");
|
||||
show.style.display = "inline";
|
||||
hide.style.display = "none";
|
||||
|
||||
showPassword();
|
||||
expect(hide.style.display).toEqual('inline');
|
||||
expect(show.style.display).toEqual('none');
|
||||
expect(password.type).toEqual('text');
|
||||
expect(hide.style.display).toEqual("inline");
|
||||
expect(show.style.display).toEqual("none");
|
||||
expect(password.type).toEqual("text");
|
||||
|
||||
showPassword();
|
||||
expect(show.style.display).toEqual('inline');
|
||||
expect(hide.style.display).toEqual('none');
|
||||
expect(password.type).toEqual('password');
|
||||
expect(show.style.display).toEqual("inline");
|
||||
expect(hide.style.display).toEqual("none");
|
||||
expect(password.type).toEqual("password");
|
||||
});
|
||||
|
||||
it('show password click works', () => {
|
||||
it("show password click works", () => {
|
||||
document.body.innerHTML = initial_content;
|
||||
|
||||
const container = <HTMLElement>(
|
||||
document.querySelector(`.show-password-container`)
|
||||
document.querySelector(".show-password-container")
|
||||
);
|
||||
const hide = <HTMLElement>container.querySelector('.show-password--hide');
|
||||
const show = <HTMLElement>container.querySelector('.show-password--show');
|
||||
const password = <HTMLInputElement>document.getElementById('password');
|
||||
show.style.display = 'inline';
|
||||
hide.style.display = 'none';
|
||||
const hide = <HTMLElement>container.querySelector(".show-password--hide");
|
||||
const show = <HTMLElement>container.querySelector(".show-password--show");
|
||||
const password = <HTMLInputElement>document.getElementById("password");
|
||||
show.style.display = "inline";
|
||||
hide.style.display = "none";
|
||||
|
||||
registerShowPassword();
|
||||
container.click();
|
||||
expect(hide.style.display).toEqual('inline');
|
||||
expect(show.style.display).toEqual('none');
|
||||
expect(password.type).toEqual('text');
|
||||
expect(hide.style.display).toEqual("inline");
|
||||
expect(show.style.display).toEqual("none");
|
||||
expect(password.type).toEqual("text");
|
||||
|
||||
container.click();
|
||||
expect(show.style.display).toEqual('inline');
|
||||
expect(hide.style.display).toEqual('none');
|
||||
expect(password.type).toEqual('password');
|
||||
expect(show.style.display).toEqual("inline");
|
||||
expect(hide.style.display).toEqual("none");
|
||||
expect(password.type).toEqual("password");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user