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,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}`);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user