frontend linting

This commit is contained in:
realaravinth
2021-10-08 15:24:29 +05:30
parent f7afc72d81
commit 53720ff740
91 changed files with 2158 additions and 1677 deletions

View File

@@ -15,9 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import additionalData from './index';
import additionalData from "./index";
it('sudo form works', () => {
it("sudo form works", () => {
try {
additionalData();
} catch (e) {
@@ -26,8 +26,8 @@ it('sudo form works', () => {
);
}
const element = document.createElement('div');
element.id = 'additional-data';
const element = document.createElement("div");
element.id = "additional-data";
document.body.appendChild(element);
expect(additionalData()).toBe(element);
});

View File

@@ -15,9 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const additionalData = () => {
const additionalData = (): HTMLElement => {
let element = null;
const ID = 'additional-data';
const ID = "additional-data";
if (element === null) {
element = <HTMLElement>document.getElementById(ID);
@@ -29,7 +29,7 @@ const additionalData = () => {
return element;
}
} else {
element;
return element;
}
};

View File

@@ -23,7 +23,7 @@ class CopyIcon {
constructor(
writeText: string,
copyIcon: HTMLElement,
copyDoneIconClass: string,
copyDoneIconClass: string
) {
this.copyIcon = copyIcon;
this.copyDoneIconClass = copyDoneIconClass;
@@ -32,24 +32,24 @@ class CopyIcon {
this.__registerHandlers();
}
__registerHandlers() {
this.copyIcon.addEventListener('click', e => this.copySitekey(e));
__registerHandlers(): void {
this.copyIcon.addEventListener("click", (e) => this.copySitekey(e));
}
/*
* Copy secret to clipboard
*/
async copySitekey(e: Event) {
async copySitekey(e: Event): Promise<void> {
const image = <HTMLElement>e.target;
const copyDoneIcon = <HTMLElement>(
image.parentElement.querySelector(`.${this.copyDoneIconClass}`)
);
await navigator.clipboard.writeText(this.writeText);
image.style.display = 'none';
copyDoneIcon.style.display = 'block';
image.style.display = "none";
copyDoneIcon.style.display = "block";
setTimeout(() => {
copyDoneIcon.style.display = 'none';
image.style.display = 'block';
copyDoneIcon.style.display = "none";
image.style.display = "block";
}, 1200);
}
}

View File

@@ -15,16 +15,16 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import createError from './index';
import * as e from './index';
import createError from "./index";
import * as e from "./index";
import setup from './setUpTests';
import setup from "./setUpTests";
'use strict';
"use strict";
jest.useFakeTimers();
it('checks if error boxes work', () => {
it("checks if error boxes work", () => {
document.body.append(setup());
const getMsg = (num: number) => `message ${num}`;
@@ -32,21 +32,21 @@ it('checks if error boxes work', () => {
let msg = document.querySelector(`.${e.ERR_MSG_CONTAINER}`);
expect(msg.innerHTML).toContain(getMsg(1));
let btn = <HTMLButtonElement>msg.getElementsByClassName(e.ERR_CLOSE)[0];
const btn = <HTMLButtonElement>msg.getElementsByClassName(e.ERR_CLOSE)[0];
btn.click();
msg = document.querySelector(`.${e.ERR_MSG_CONTAINER}`);
expect(msg).toEqual(null);
const errElement = document.createElement('p');
const errElement = document.createElement("p");
errElement.appendChild(document.createTextNode(getMsg(2)));
createError(errElement);
msg = document.querySelector(`.${e.ERR_MSG_CONTAINER}`).querySelector('p');
msg = document.querySelector(`.${e.ERR_MSG_CONTAINER}`).querySelector("p");
expect(msg).toEqual(errElement);
let timeOutElement = document.createElement('p');
const timeOutElement = document.createElement("p");
timeOutElement.appendChild(document.createTextNode(getMsg(2)));
createError(timeOutElement, 200);
msg = document.querySelector(`.${e.ERR_MSG_CONTAINER}`).querySelector('p');
msg = document.querySelector(`.${e.ERR_MSG_CONTAINER}`).querySelector("p");
expect(msg).toEqual(timeOutElement);
jest.runOnlyPendingTimers();
msg = document.querySelector(`.${e.ERR_MSG_CONTAINER}`);

View File

@@ -15,9 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
export const ERR_CONTAINER_ID = 'err__container';
export const ERR_MSG_CONTAINER = 'err__msg-container'; // class
export const ERR_CLOSE = 'err__close'; // class
export const ERR_CONTAINER_ID = "err__container";
export const ERR_MSG_CONTAINER = "err__msg-container"; // class
export const ERR_CLOSE = "err__close"; // class
export const DEFAULT_LIFETIME = 5000;
@@ -41,11 +41,11 @@ const err = () => {
const createError = (
message: string | HTMLElement,
lifetime: number = DEFAULT_LIFETIME,
) => {
const box = document.createElement('div');
): void => {
const box = document.createElement("div");
const msg = () => {
if (typeof message === 'string') {
if (typeof message === "string") {
return document.createTextNode(message);
} else {
return message;
@@ -55,8 +55,8 @@ const createError = (
box.className = ERR_MSG_CONTAINER;
box.appendChild(msg());
const deleteBtn = document.createElement('button');
const deleteMsg = document.createTextNode('x');
const deleteBtn = document.createElement("button");
const deleteMsg = document.createTextNode("x");
deleteBtn.appendChild(deleteMsg);
deleteBtn.className = ERR_CLOSE;
box.appendChild(deleteBtn);
@@ -71,7 +71,7 @@ const createError = (
box.remove();
};
deleteBtn.addEventListener('click', e => deleteHandler(e));
deleteBtn.addEventListener("click", e => deleteHandler(e));
};
export default createError;

View File

@@ -14,10 +14,10 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import * as e from './index';
import * as e from "./index";
const setup = () => {
let x = document.createElement('div');
const setup = (): HTMLElement => {
const x = document.createElement("div");
x.id = e.ERR_CONTAINER_ID;
return x;
};

View File

@@ -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);
});
};

View File

@@ -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");
});