mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
frontend linting
This commit is contained in:
@@ -14,25 +14,25 @@
|
||||
* 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 getNumLevels from '../../levels/getNumLevels';
|
||||
import CONST from '../../const';
|
||||
import log from '../../../../../../logger';
|
||||
import getNumLevels from "../../levels/getNumLevels";
|
||||
import CONST from "../../const";
|
||||
import log from "../../../../../../logger";
|
||||
|
||||
import updateLabels from './updateLabel';
|
||||
import updateInputs from './updateInputs';
|
||||
import updateRemoveButton from './updateRemoveButton';
|
||||
import updateLevelGroup from './updateLevelGroup';
|
||||
import updateLabels from "./updateLabel";
|
||||
import updateInputs from "./updateInputs";
|
||||
import updateRemoveButton from "./updateRemoveButton";
|
||||
import updateLevelGroup from "./updateLevelGroup";
|
||||
|
||||
/**
|
||||
* update level number on fieldset legends and their ids too
|
||||
* @param {number} id - level number that was ordered to remove.
|
||||
* All updates are made relative to id
|
||||
* */
|
||||
const updateLevelNumbersOnDOM = (id: number) => {
|
||||
const updateLevelNumbersOnDOM = (id: number): void => {
|
||||
const numLevels = getNumLevels();
|
||||
if (id == numLevels) {
|
||||
throw new Error(
|
||||
"Can't remove the very fist element, it has to be first added to DOM",
|
||||
"Can't remove the very fist element, it has to be first added to DOM"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ const updateLevelNumbersOnDOM = (id: number) => {
|
||||
const newLevel = i - 1;
|
||||
|
||||
const levelGroup = document.querySelector(
|
||||
`#${CONST.LEVEL_FIELDSET_ID_WITHOUT_LEVEL}${i}`,
|
||||
`#${CONST.LEVEL_FIELDSET_ID_WITHOUT_LEVEL}${i}`
|
||||
);
|
||||
|
||||
if (levelGroup === null) {
|
||||
@@ -53,9 +53,9 @@ const updateLevelNumbersOnDOM = (id: number) => {
|
||||
}
|
||||
|
||||
// rename legend
|
||||
const legend = levelGroup.getElementsByTagName('legend')[0];
|
||||
const legend = levelGroup.getElementsByTagName("legend")[0];
|
||||
const legendText = document.createTextNode(`Level ${newLevel}`);
|
||||
const newLegend = document.createElement('legend');
|
||||
const newLegend = document.createElement("legend");
|
||||
newLegend.className = legend.className;
|
||||
newLegend.appendChild(legendText);
|
||||
legend.replaceWith(newLegend);
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import getNumLevels from '../../levels/getNumLevels';
|
||||
import {getAddForm, addLevel} from '../../setupTests';
|
||||
import getNumLevels from "../../levels/getNumLevels";
|
||||
import { getAddForm, addLevel } from "../../setupTests";
|
||||
|
||||
document.body.innerHTML = getAddForm();
|
||||
|
||||
export const setupAddlevels = () => {
|
||||
export const setupAddlevels = (): void => {
|
||||
expect(getNumLevels()).toBe(1);
|
||||
// add a level
|
||||
addLevel(2, 2);
|
||||
|
||||
@@ -15,20 +15,20 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {getAddForm, trim} from '../../setupTests';
|
||||
import updateInputs from './updateInputs';
|
||||
import CONST from '../../const';
|
||||
import {getAddForm, trim} from "../../setupTests";
|
||||
import updateInputs from "./updateInputs";
|
||||
import CONST from "../../const";
|
||||
|
||||
import log from '../../../../../../logger';
|
||||
import {MODE} from '../../../../../../logger';
|
||||
import log from "../../../../../../logger";
|
||||
import {MODE} from "../../../../../../logger";
|
||||
|
||||
import {setupAddlevels} from './setupTests';
|
||||
import {setupAddlevels} from "./setupTests";
|
||||
|
||||
document.body.innerHTML = getAddForm();
|
||||
|
||||
log.setMode(MODE.none);
|
||||
|
||||
it('updateInputs works', () => {
|
||||
it("updateInputs works", () => {
|
||||
setupAddlevels();
|
||||
// removing level 2
|
||||
const level = 2;
|
||||
@@ -58,7 +58,7 @@ it('updateInputs works', () => {
|
||||
});
|
||||
|
||||
/** get initial form to test remove button functionality */
|
||||
export const update = () => {
|
||||
export const update = (): string => {
|
||||
return `
|
||||
<form class="sitekey-form" action="/api/v1/mcaptcha/levels/add" method="post">
|
||||
<h1 class="form__title">
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
* 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 CONST from '../../const';
|
||||
import log from '../../../../../../logger';
|
||||
import CONST from "../../const";
|
||||
import log from "../../../../../../logger";
|
||||
|
||||
/** update input IDs with new level */
|
||||
const updateInput = (levelGroup: Element, newLevel: number) => {
|
||||
const updateInput = (levelGroup: Element, newLevel: number): void => {
|
||||
const inputs = <NodeListOf<HTMLInputElement>>(
|
||||
levelGroup.querySelectorAll(`.${CONST.LEVEL_INPUT_CLASS}`)
|
||||
);
|
||||
@@ -26,17 +26,17 @@ const updateInput = (levelGroup: Element, newLevel: number) => {
|
||||
inputs.forEach(input => {
|
||||
if (input.id.includes(CONST.VISITOR_WITHOUT_LEVEL)) {
|
||||
log.log(`${input.id}`);
|
||||
log.log('changing visitor_threshold input');
|
||||
log.log("changing visitor_threshold input");
|
||||
const id = `${CONST.VISITOR_WITHOUT_LEVEL}${newLevel}`;
|
||||
input.id = id;
|
||||
input.name = id;
|
||||
} else if (input.id.includes(CONST.DIFFICULTY_WITHOUT_LEVEL)) {
|
||||
log.log('changing difficulty input');
|
||||
log.log("changing difficulty input");
|
||||
const id = `${CONST.DIFFICULTY_WITHOUT_LEVEL}${newLevel}`;
|
||||
input.id = id;
|
||||
input.name = id;
|
||||
} else {
|
||||
if (input.id != 'add') {
|
||||
if (input.id != "add") {
|
||||
throw new Error(`Did you add an extra input to DOM? ${input.id} ${input.className} ${input.name}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,18 +15,15 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import getNumLevels from '../../levels/getNumLevels';
|
||||
import {getAddForm, trim} from '../../setupTests';
|
||||
import updateLabels from './updateLabel';
|
||||
import CONST from '../../const';
|
||||
import { trim } from "../../setupTests";
|
||||
import updateLabels from "./updateLabel";
|
||||
import CONST from "../../const";
|
||||
|
||||
import log from '../../../../../../logger';
|
||||
import {MODE} from '../../../../../../logger';
|
||||
|
||||
import {setupAddlevels} from './setupTests';
|
||||
import log from "../../../../../../logger";
|
||||
import { MODE } from "../../../../../../logger";
|
||||
|
||||
/** get initial form to test remove button functionality */
|
||||
export const labelLevel = (level: number) => {
|
||||
export const labelLevel = (level: number): string => {
|
||||
return `
|
||||
<form class="sitekey-form" action="/api/v1/mcaptcha/levels/add" method="post">
|
||||
<fieldset class="sitekey__level-container" id="level-group-2">
|
||||
@@ -85,11 +82,11 @@ document.body.innerHTML = labelLevel(2);
|
||||
|
||||
log.setMode(MODE.none);
|
||||
|
||||
it('addLevelButton works', () => {
|
||||
it("addLevelButton works", () => {
|
||||
// removing level 2
|
||||
const level = 2;
|
||||
const levelGroup = document.querySelector(
|
||||
`#${CONST.LEVEL_FIELDSET_ID_WITHOUT_LEVEL}${level}`,
|
||||
`#${CONST.LEVEL_FIELDSET_ID_WITHOUT_LEVEL}${level}`
|
||||
);
|
||||
|
||||
const newLevel = 20;
|
||||
@@ -100,22 +97,22 @@ it('addLevelButton works', () => {
|
||||
levelGroup.querySelectorAll(`.${CONST.LABEL_CLASS}`)
|
||||
);
|
||||
log.log(labels);
|
||||
labels.forEach(label => {
|
||||
labels.forEach((label) => {
|
||||
log.log(`${label.htmlFor}`);
|
||||
if (label.htmlFor.includes(CONST.VISITOR_WITHOUT_LEVEL)) {
|
||||
expect(label.htmlFor).toBe(`${CONST.VISITOR_WITHOUT_LEVEL}${newLevel}`);
|
||||
} else if (label.htmlFor.includes(CONST.DIFFICULTY_WITHOUT_LEVEL)) {
|
||||
expect(label.htmlFor).toBe(
|
||||
`${CONST.DIFFICULTY_WITHOUT_LEVEL}${newLevel}`,
|
||||
`${CONST.DIFFICULTY_WITHOUT_LEVEL}${newLevel}`
|
||||
);
|
||||
} else if (
|
||||
label.htmlFor.includes(CONST.REMOVE_LEVEL_BUTTON_ID_WITHOUT_LEVEL)
|
||||
) {
|
||||
expect(label.htmlFor).toBe(
|
||||
`${CONST.REMOVE_LEVEL_BUTTON_ID_WITHOUT_LEVEL}${newLevel}`,
|
||||
`${CONST.REMOVE_LEVEL_BUTTON_ID_WITHOUT_LEVEL}${newLevel}`
|
||||
);
|
||||
} else {
|
||||
throw new Error('Did you add an extra label to DOM?');
|
||||
throw new Error("Did you add an extra label to DOM?");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -14,17 +14,17 @@
|
||||
* 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 CONST from '../../const';
|
||||
import log from '../../../../../../logger';
|
||||
import CONST from "../../const";
|
||||
import log from "../../../../../../logger";
|
||||
|
||||
/** update level lables to match new level */
|
||||
const updateLabels = (levelGroup: Element, newLevel: number) => {
|
||||
const updateLabels = (levelGroup: Element, newLevel: number): void => {
|
||||
// rename labels
|
||||
const labels = <NodeListOf<HTMLLabelElement>>(
|
||||
levelGroup.querySelectorAll(`label`)
|
||||
levelGroup.querySelectorAll("label")
|
||||
);
|
||||
log.log(labels);
|
||||
labels.forEach(label => {
|
||||
labels.forEach((label) => {
|
||||
log.log(`${label.htmlFor}`);
|
||||
const currentFor = label.htmlFor;
|
||||
if (currentFor.includes(CONST.VISITOR_WITHOUT_LEVEL)) {
|
||||
@@ -36,9 +36,9 @@ const updateLabels = (levelGroup: Element, newLevel: number) => {
|
||||
) {
|
||||
label.htmlFor = `${CONST.REMOVE_LEVEL_BUTTON_ID_WITHOUT_LEVEL}${newLevel}`;
|
||||
} else {
|
||||
if (currentFor != 'add') {
|
||||
if (currentFor != "add") {
|
||||
throw new Error(
|
||||
`Did you add an extra label to DOM? Found label with for: ${currentFor}`,
|
||||
`Did you add an extra label to DOM? Found label with for: ${currentFor}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,18 +15,16 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import getNumLevels from '../../levels/getNumLevels';
|
||||
import {getAddForm, trim} from '../../setupTests';
|
||||
import updateLevelGroup from './updateLevelGroup';
|
||||
import CONST from '../../const';
|
||||
import { trim} from "../../setupTests";
|
||||
import updateLevelGroup from "./updateLevelGroup";
|
||||
import CONST from "../../const";
|
||||
|
||||
import log from '../../../../../../logger';
|
||||
import {MODE} from '../../../../../../logger';
|
||||
import log from "../../../../../../logger";
|
||||
import {MODE} from "../../../../../../logger";
|
||||
|
||||
import {setupAddlevels} from './setupTests';
|
||||
|
||||
/** get initial form to test remove button functionality */
|
||||
export const labelLevel = (level: number) => {
|
||||
export const labelLevel = (level: number): string => {
|
||||
return `
|
||||
<form class="sitekey-form" action="/api/v1/mcaptcha/levels/add" method="post">
|
||||
<fieldset class="sitekey__level-container" id="level-group-${level}">
|
||||
@@ -85,7 +83,7 @@ document.body.innerHTML = labelLevel(2);
|
||||
|
||||
log.setMode(MODE.none);
|
||||
|
||||
it('update levelGroup works', () => {
|
||||
it("update levelGroup works", () => {
|
||||
// removing level 2
|
||||
const level = 2;
|
||||
const levelGroup = document.querySelector(
|
||||
|
||||
@@ -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 CONST from '../../const';
|
||||
import CONST from "../../const";
|
||||
|
||||
/** update level grup to match new level */
|
||||
const updateLevelGroup = (levelGroup: Element, newLevel: number) =>
|
||||
const updateLevelGroup = (levelGroup: Element, newLevel: number): string =>
|
||||
(levelGroup.id = `${CONST.LEVEL_FIELDSET_ID_WITHOUT_LEVEL}${newLevel}`);
|
||||
|
||||
export default updateLevelGroup;
|
||||
|
||||
@@ -15,15 +15,15 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {trim} from '../../setupTests';
|
||||
import updateRemoveButton from './updateRemoveButton';
|
||||
import CONST from '../../const';
|
||||
import {trim} from "../../setupTests";
|
||||
import updateRemoveButton from "./updateRemoveButton";
|
||||
import CONST from "../../const";
|
||||
|
||||
import log from '../../../../../../logger';
|
||||
import {MODE} from '../../../../../../logger';
|
||||
import log from "../../../../../../logger";
|
||||
import {MODE} from "../../../../../../logger";
|
||||
|
||||
/** get initial form to test remove button functionality */
|
||||
export const labelLevel = (level: number) => {
|
||||
export const labelLevel = (level: number): string => {
|
||||
return `
|
||||
<form class="sitekey-form" action="/api/v1/mcaptcha/levels/add" method="post">
|
||||
<fieldset class="sitekey__level-container" id="level-group-">
|
||||
@@ -83,7 +83,7 @@ document.body.innerHTML = labelLevel(level);
|
||||
|
||||
log.setMode(MODE.none);
|
||||
|
||||
it('update remove button works', () => {
|
||||
it("update remove button works", () => {
|
||||
// removing level 2
|
||||
|
||||
const levelGroup = document.getElementById(
|
||||
|
||||
@@ -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 CONST from '../../const';
|
||||
import CONST from "../../const";
|
||||
|
||||
/** update remove level button's ID */
|
||||
const updateRemoveButton = (levelGroup: Element, newLevel: number) => {
|
||||
const updateRemoveButton = (levelGroup: Element, newLevel: number): void => {
|
||||
// rename button
|
||||
const button = <HTMLInputElement>(
|
||||
levelGroup.querySelector(`.${CONST.REMOVE_LEVEL_BUTTON_CLASS}`)
|
||||
|
||||
Reference in New Issue
Block a user