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,27 +15,27 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import getLevelFields from './getLevelFields';
|
||||
import getLevelFields from "./getLevelFields";
|
||||
import {
|
||||
getAddForm,
|
||||
level1,
|
||||
level2,
|
||||
fillAddLevel,
|
||||
addLevel,
|
||||
} from '../setupTests';
|
||||
} from "../setupTests";
|
||||
|
||||
document.body.innerHTML = getAddForm();
|
||||
|
||||
const visNumErr = 'visitor can contain nubers only';
|
||||
const diffNumErr = 'difficulty can contain nubers only';
|
||||
const visNumErr = "visitor can contain nubers only";
|
||||
const diffNumErr = "difficulty can contain nubers only";
|
||||
|
||||
it('get levels fields works', () => {
|
||||
it("get levels fields works", () => {
|
||||
addLevel(level1.visitor_threshold, level1.difficulty_factor);
|
||||
expect(getLevelFields(1)).toEqual(level1);
|
||||
|
||||
// NaN visitor
|
||||
try {
|
||||
fillAddLevel('test', level2.difficulty_factor);
|
||||
fillAddLevel("test", level2.difficulty_factor);
|
||||
getLevelFields(2);
|
||||
} catch (e) {
|
||||
expect(e.message).toBe(visNumErr);
|
||||
@@ -43,7 +43,7 @@ it('get levels fields works', () => {
|
||||
|
||||
// Nan difficulty_factor
|
||||
try {
|
||||
fillAddLevel(level2.visitor_threshold, 'fooasdads');
|
||||
fillAddLevel(level2.visitor_threshold, "fooasdads");
|
||||
getLevelFields(2);
|
||||
} catch (e) {
|
||||
expect(e.message).toBe(diffNumErr);
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {Level} from './index';
|
||||
import CONST from '../const';
|
||||
import { Level } from "./index";
|
||||
import CONST from "../const";
|
||||
|
||||
import log from '../../../../../logger';
|
||||
import log from "../../../../../logger";
|
||||
|
||||
/** Fetches level from DOM using the ID passesd and validates */
|
||||
const getLevelFields = (id: number) => {
|
||||
const getLevelFields = (id: number): Level => {
|
||||
log.debug(`[getLevelFields]: id: ${id}`);
|
||||
const visitorID = CONST.VISITOR_WITHOUT_LEVEL + id.toString();
|
||||
const difficultyID = CONST.DIFFICULTY_WITHOUT_LEVEL + id.toString();
|
||||
@@ -35,11 +35,11 @@ const getLevelFields = (id: number) => {
|
||||
const difficulty_factor = parseInt(difficultyElement.value);
|
||||
|
||||
if (Number.isNaN(visitor_threshold)) {
|
||||
throw new Error('visitor can contain nubers only');
|
||||
throw new Error("visitor can contain nubers only");
|
||||
}
|
||||
|
||||
if (Number.isNaN(difficulty_factor)) {
|
||||
throw new Error('difficulty can contain nubers only');
|
||||
throw new Error("difficulty can contain nubers only");
|
||||
}
|
||||
|
||||
const level: Level = {
|
||||
@@ -48,7 +48,7 @@ const getLevelFields = (id: number) => {
|
||||
};
|
||||
|
||||
log.debug(
|
||||
`[getLevelFields.ts] visitor: ${visitor_threshold} difficulty: ${difficulty_factor}`,
|
||||
`[getLevelFields.ts] visitor: ${visitor_threshold} difficulty: ${difficulty_factor}`
|
||||
);
|
||||
|
||||
return level;
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import getNumLevels from './getNumLevels';
|
||||
import {getAddForm, addLevel} from '../setupTests';
|
||||
import getNumLevels from "./getNumLevels";
|
||||
import {getAddForm, addLevel} from "../setupTests";
|
||||
|
||||
document.body.innerHTML = getAddForm();
|
||||
|
||||
it('get num levels works', () => {
|
||||
it("get num levels works", () => {
|
||||
expect(getNumLevels()).toBe(1);
|
||||
addLevel(2, 4);
|
||||
expect(getNumLevels()).toBe(2);
|
||||
|
||||
@@ -15,16 +15,16 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import CONST from '../const';
|
||||
import CONST from "../const";
|
||||
|
||||
import log from '../../../../../logger';
|
||||
import log from "../../../../../logger";
|
||||
|
||||
/** returns number of level input fields currently in DOM */
|
||||
const getNumLevels = () => {
|
||||
const getNumLevels = (): number => {
|
||||
let numLevels = 0;
|
||||
document
|
||||
.querySelectorAll(`.${CONST.LEVEL_CONTAINER_CLASS}`)
|
||||
.forEach(_ => numLevels++);
|
||||
.forEach(() => numLevels++);
|
||||
log.debug(`[getNumLevels]: numLevels: ${numLevels}`);
|
||||
return numLevels;
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import log from '../../../../../logger';
|
||||
import log from "../../../../../logger";
|
||||
|
||||
/** Datatype represenging an mCaptcha level */
|
||||
export type Level = {
|
||||
@@ -95,7 +95,7 @@ export const LEVELS = (function() {
|
||||
}
|
||||
}
|
||||
levels.levels = tmpLevel.levels;
|
||||
log.debug(`post update:`);
|
||||
log.debug("post update:");
|
||||
LEVELS.print();
|
||||
return true;
|
||||
} catch (e) {
|
||||
@@ -133,7 +133,7 @@ export const LEVELS = (function() {
|
||||
}
|
||||
}
|
||||
levels.levels = tmpLevel.levels;
|
||||
log.debug('Post remove:');
|
||||
log.debug("Post remove:");
|
||||
LEVELS.print();
|
||||
return true;
|
||||
} catch (e) {
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {LEVELS, Level} from './index';
|
||||
import {level1, level1visErr, level1diffErr, level2} from '../setupTests';
|
||||
import {LEVELS, Level} from "./index";
|
||||
import {level1, level1visErr, level1diffErr, level2} from "../setupTests";
|
||||
|
||||
const visitorErr = 'visitor count should be greater than previous levels';
|
||||
const difficultyErr = 'difficulty should be greater than previous levels';
|
||||
const visitorErr = "visitor count should be greater than previous levels";
|
||||
const difficultyErr = "difficulty should be greater than previous levels";
|
||||
|
||||
const zeroVisError = 'visitors must be greater than zero';
|
||||
const zeroDiffError = 'difficulty must be greater than zero';
|
||||
const zeroVisError = "visitors must be greater than zero";
|
||||
const zeroDiffError = "difficulty must be greater than zero";
|
||||
|
||||
const zeroVis: Level = {
|
||||
difficulty_factor: 10,
|
||||
@@ -34,7 +34,7 @@ const zeroDiff: Level = {
|
||||
visitor_threshold: 10,
|
||||
};
|
||||
|
||||
it('LEVELS works', () => {
|
||||
it("LEVELS works", () => {
|
||||
// add level
|
||||
LEVELS.add(level1);
|
||||
expect(LEVELS.getLevels()).toEqual([level1]);
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import CONST from '../const';
|
||||
import getLevelFields from './getLevelFields';
|
||||
import {LEVELS} from './index';
|
||||
import CONST from "../const";
|
||||
import getLevelFields from "./getLevelFields";
|
||||
import { LEVELS } from "./index";
|
||||
|
||||
import createError from '../../../../../components/error';
|
||||
import createError from "../../../../../components/error";
|
||||
|
||||
/** on-change event handler to update level */
|
||||
const updateLevel = (e: Event) => {
|
||||
const updateLevel = (e: Event): void => {
|
||||
const target = <HTMLInputElement>e.target;
|
||||
|
||||
const id = target.id;
|
||||
@@ -36,7 +36,7 @@ const updateLevel = (e: Event) => {
|
||||
}
|
||||
|
||||
if (Number.isNaN(level)) {
|
||||
console.error(`[updateLevel.ts] level # computed is not correct, got NaN`);
|
||||
console.error("[updateLevel.ts] level # computed is not correct, got NaN");
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -48,7 +48,7 @@ const updateLevel = (e: Event) => {
|
||||
};
|
||||
|
||||
/** registers on-change event handlers to update levels */
|
||||
export const register = (id: number) => {
|
||||
export const register = (id: number): void => {
|
||||
const visitorID = CONST.VISITOR_WITHOUT_LEVEL + id.toString();
|
||||
const difficultyID = CONST.DIFFICULTY_WITHOUT_LEVEL + id.toString();
|
||||
|
||||
@@ -57,6 +57,6 @@ export const register = (id: number) => {
|
||||
document.getElementById(difficultyID)
|
||||
);
|
||||
|
||||
visitorElement.addEventListener('input', updateLevel, false);
|
||||
difficultyElement.addEventListener('input', updateLevel, false);
|
||||
visitorElement.addEventListener("input", updateLevel, false);
|
||||
difficultyElement.addEventListener("input", updateLevel, false);
|
||||
};
|
||||
|
||||
@@ -15,15 +15,15 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import validateLevel from './validateLevel';
|
||||
import {getAddForm, level1, fillAddLevel} from '../setupTests';
|
||||
import setup from '../../../../../components/error/setUpTests';
|
||||
import validateLevel from "./validateLevel";
|
||||
import {getAddForm, level1, fillAddLevel} from "../setupTests";
|
||||
import setup from "../../../../../components/error/setUpTests";
|
||||
|
||||
document.body.innerHTML = getAddForm();
|
||||
|
||||
document.body.appendChild(setup());
|
||||
|
||||
it('validate levels fields works', () => {
|
||||
it("validate levels fields works", () => {
|
||||
// null error
|
||||
expect(validateLevel(1)).toEqual(false);
|
||||
|
||||
|
||||
@@ -15,15 +15,15 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {LEVELS} from './index';
|
||||
import getLevelFields from './getLevelFields';
|
||||
import createError from '../../../../../components/error/';
|
||||
import {LEVELS} from "./index";
|
||||
import getLevelFields from "./getLevelFields";
|
||||
import createError from "../../../../../components/error/";
|
||||
|
||||
/**
|
||||
* Fetches level from DOM using the ID passesd and validates
|
||||
* its contents
|
||||
* */
|
||||
const validateLevel = (id: number) => {
|
||||
const validateLevel = (id: number): boolean => {
|
||||
try {
|
||||
const level = getLevelFields(id);
|
||||
LEVELS.add(level);
|
||||
|
||||
Reference in New Issue
Block a user