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,30 +15,31 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {LEVELS} from '../levels';
|
||||
import { LEVELS } from "../levels";
|
||||
|
||||
import getFormUrl from '../../../../../utils/getFormUrl';
|
||||
import genJsonPayload from '../../../../../utils/genJsonPayload';
|
||||
import getFormUrl from "../../../../../utils/getFormUrl";
|
||||
import genJsonPayload from "../../../../../utils/genJsonPayload";
|
||||
|
||||
import VIEWS from '../../../../../views/v1/routes';
|
||||
import VIEWS from "../../../../../views/v1/routes";
|
||||
|
||||
import validateDescription from './validateDescription';
|
||||
import validateDuration from './validateDuration';
|
||||
import validateDescription from "./validateDescription";
|
||||
import validateDuration from "./validateDuration";
|
||||
|
||||
import createError from '../../../../../components/error';
|
||||
import createError from "../../../../../components/error";
|
||||
|
||||
export const SITE_KEY_FORM_CLASS = 'sitekey-form';
|
||||
export const FORM = <HTMLFormElement>document.querySelector(`.${SITE_KEY_FORM_CLASS}`);
|
||||
export const SITE_KEY_FORM_CLASS = "sitekey-form";
|
||||
export const FORM = <HTMLFormElement>(
|
||||
document.querySelector(`.${SITE_KEY_FORM_CLASS}`)
|
||||
);
|
||||
|
||||
export const addSubmitEventListener = () => {
|
||||
FORM.addEventListener('submit', submit, true);
|
||||
};
|
||||
export const addSubmitEventListener = (): void =>
|
||||
FORM.addEventListener("submit", submit, true);
|
||||
|
||||
const submit = async (e: Event) => {
|
||||
e.preventDefault();
|
||||
|
||||
const description = validateDescription(e);
|
||||
const duration = validateDuration(e);
|
||||
const duration = validateDuration();
|
||||
|
||||
const formUrl = getFormUrl(FORM);
|
||||
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import validateDescription from './validateDescription';
|
||||
import {getAddForm, fillDescription} from '../setupTests';
|
||||
import {mockAlert} from '../../../../../setUpTests';
|
||||
import validateDescription from "./validateDescription";
|
||||
import {getAddForm, fillDescription} from "../setupTests";
|
||||
import {mockAlert} from "../../../../../setUpTests";
|
||||
|
||||
import setup from '../../../../../components/error/setUpTests';
|
||||
import setup from "../../../../../components/error/setUpTests";
|
||||
|
||||
mockAlert();
|
||||
|
||||
@@ -27,17 +27,17 @@ document.body.innerHTML = getAddForm();
|
||||
|
||||
const emptyErr = "can't be empty";
|
||||
|
||||
it('validateDescription workds', () => {
|
||||
document.querySelector('body').appendChild(setup());
|
||||
it("validateDescription workds", () => {
|
||||
document.querySelector("body").appendChild(setup());
|
||||
try {
|
||||
const event = new Event('submit');
|
||||
const event = new Event("submit");
|
||||
validateDescription(event);
|
||||
} catch (e) {
|
||||
expect(e.message).toContain(emptyErr);
|
||||
}
|
||||
|
||||
// fill and validate
|
||||
fillDescription('testing');
|
||||
const event = new Event('submit');
|
||||
fillDescription("testing");
|
||||
const event = new Event("submit");
|
||||
validateDescription(event);
|
||||
});
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import isBlankString from '../../../../../utils/isBlankString';
|
||||
import isBlankString from "../../../../../utils/isBlankString";
|
||||
|
||||
const validateDescription = (e: Event) => {
|
||||
const inputElement = <HTMLInputElement>document.getElementById('description');
|
||||
const validateDescription = (e: Event): string => {
|
||||
const inputElement = <HTMLInputElement>document.getElementById("description");
|
||||
const val = inputElement.value;
|
||||
const filed = 'Description';
|
||||
const filed = "Description";
|
||||
isBlankString(val, filed, e);
|
||||
return val;
|
||||
};
|
||||
|
||||
@@ -14,8 +14,6 @@
|
||||
* 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 isNumber from '../../../../../utils/isNumber';
|
||||
|
||||
//const validateDuration = (e: Event) => {
|
||||
// const duartionElement = <HTMLInputElement>document.getElementById('duration');
|
||||
// const duration = parseInt(duartionElement.value);
|
||||
@@ -31,30 +29,28 @@ import isNumber from '../../../../../utils/isNumber';
|
||||
//
|
||||
//export default validateDuration;
|
||||
|
||||
import validateDuration from './validateDuration';
|
||||
import {getAddForm, fillDuration} from '../setupTests';
|
||||
import validateDuration from "./validateDuration";
|
||||
import {getAddForm, fillDuration} from "../setupTests";
|
||||
|
||||
document.body.innerHTML = getAddForm();
|
||||
|
||||
const emptyErr = "can't be empty";
|
||||
const NaNErr = 'duration can contain nubers only';
|
||||
const zeroErr = 'duration must be greater than zero';
|
||||
const NaNErr = "duration can contain nubers only";
|
||||
const zeroErr = "duration must be greater than zero";
|
||||
|
||||
const duration = 30;
|
||||
|
||||
it('validateDuration workds', () => {
|
||||
it("validateDuration workds", () => {
|
||||
try {
|
||||
const event = new Event('submit');
|
||||
validateDuration(event);
|
||||
validateDuration();
|
||||
} catch (e) {
|
||||
expect(e.message).toContain(emptyErr);
|
||||
}
|
||||
|
||||
// fill string error
|
||||
try {
|
||||
fillDuration('testing');
|
||||
const event = new Event('submit');
|
||||
validateDuration(event);
|
||||
fillDuration("testing");
|
||||
validateDuration();
|
||||
} catch (e) {
|
||||
expect(e.message).toContain(NaNErr);
|
||||
}
|
||||
@@ -62,13 +58,11 @@ it('validateDuration workds', () => {
|
||||
// zero err
|
||||
try {
|
||||
fillDuration(0);
|
||||
const event = new Event('submit');
|
||||
validateDuration(event);
|
||||
validateDuration();
|
||||
} catch (e) {
|
||||
expect(e.message).toContain(zeroErr);
|
||||
}
|
||||
|
||||
fillDuration(duration);
|
||||
const event = new Event('submit');
|
||||
expect(validateDuration(event)).toBe(duration);
|
||||
expect(validateDuration()).toBe(duration);
|
||||
});
|
||||
|
||||
@@ -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 isNumber from '../../../../../utils/isNumber';
|
||||
import isNumber from "../../../../../utils/isNumber";
|
||||
|
||||
const validateDuration = (e: Event) => {
|
||||
const duartionElement = <HTMLInputElement>document.getElementById('duration');
|
||||
const validateDuration = (): number => {
|
||||
const duartionElement = <HTMLInputElement>document.getElementById("duration");
|
||||
const duration = parseInt(duartionElement.value);
|
||||
if (!isNumber(duration) || Number.isNaN(duration)) {
|
||||
throw new Error('duration can contain nubers only');
|
||||
throw new Error("duration can contain nubers only");
|
||||
}
|
||||
|
||||
if (duration <= 0) {
|
||||
throw new Error('duration must be greater than zero');
|
||||
throw new Error("duration must be greater than zero");
|
||||
}
|
||||
return duration;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user