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,13 +15,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import fetchMock from 'jest-fetch-mock';
import fetchMock from "jest-fetch-mock";
import emailExists from './emailExists';
import emailExists from "./emailExists";
import {mockAlert, getRegistrationFormHtml} from '../../../setUpTests';
import {mockAlert, getRegistrationFormHtml} from "../../../setUpTests";
import setup from '../../../components/error/setUpTests';
import setup from "../../../components/error/setUpTests";
fetchMock.enableMocks();
mockAlert();
@@ -30,14 +30,14 @@ beforeEach(() => {
fetchMock.resetMocks();
});
it('finds exchange', async () => {
it("finds exchange", async () => {
fetchMock.mockResponseOnce(JSON.stringify({exists: true}));
document.body.innerHTML = getRegistrationFormHtml();
document.querySelector('body').appendChild(setup());
document.querySelector("body").appendChild(setup());
const emailField = <HTMLInputElement>document.getElementById('email');
emailField.setAttribute('value', 'test@a.com');
const emailField = <HTMLInputElement>document.getElementById("email");
emailField.setAttribute("value", "test@a.com");
expect(await emailExists()).toBe(true);

View File

@@ -15,15 +15,15 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import ROUTES from '../../../api/v1/routes';
import ROUTES from "../../../api/v1/routes";
import genJsonPayload from '../../../utils/genJsonPayload';
import createError from '../../../components/error/index';
import genJsonPayload from "../../../utils/genJsonPayload";
import createError from "../../../components/error/index";
const emailExists = async (element?: HTMLInputElement) => {
const emailExists = async (element?: HTMLInputElement): Promise<boolean> => {
let email;
if (element === undefined || element === null) {
email = <HTMLInputElement>document.getElementById('email');
email = <HTMLInputElement>document.getElementById("email");
} else {
email = element;
}
@@ -37,7 +37,7 @@ const emailExists = async (element?: HTMLInputElement) => {
if (res.ok) {
const data = await res.json();
if (data.exists) {
email.className += ' form__in-field--warn';
email.className += " form__in-field--warn";
createError(`Email "${val}" is already used`);
return data.exists;
}

View File

@@ -15,33 +15,33 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import VIEWS from '../../../views/v1/routes';
import VIEWS from "../../../views/v1/routes";
import isBlankString from '../../../utils/isBlankString';
import genJsonPayload from '../../../utils/genJsonPayload';
import isBlankString from "../../../utils/isBlankString";
import genJsonPayload from "../../../utils/genJsonPayload";
import userExists from './userExists';
import emailExists from './emailExists';
import getFormUrl from '../../../utils/getFormUrl';
import registerShowPassword from '../../../components/showPassword';
import createError from '../../../components/error/index';
import userExists from "./userExists";
import emailExists from "./emailExists";
import getFormUrl from "../../../utils/getFormUrl";
import registerShowPassword from "../../../components/showPassword";
import createError from "../../../components/error/index";
//import '../forms.scss';
const usernameElement = <HTMLInputElement>document.getElementById('username');
const emailElement = <HTMLInputElement>document.getElementById('email');
const passwordElement = <HTMLInputElement>document.getElementById('password');
const usernameElement = <HTMLInputElement>document.getElementById("username");
const emailElement = <HTMLInputElement>document.getElementById("email");
const passwordElement = <HTMLInputElement>document.getElementById("password");
const registerUser = async (e: Event) => {
const registerUser = async (e: Event): Promise<void> => {
e.preventDefault();
const username = usernameElement.value;
isBlankString(username, 'username', e);
isBlankString(username, "username", e);
//isBlankString(e);//, username, 'username');
const password = passwordElement.value;
const passwordCheckElement = <HTMLInputElement>(
document.getElementById('password-check')
document.getElementById("password-check")
);
const passwordCheck = passwordCheckElement.value;
if (password != passwordCheck) {
@@ -54,7 +54,7 @@ const registerUser = async (e: Event) => {
}
let email: string | null = emailElement.value;
if (!email.replace(/\s/g, '').length) {
if (!email.replace(/\s/g, "").length) {
email = null;
} else {
exists = await emailExists();
@@ -80,11 +80,11 @@ const registerUser = async (e: Event) => {
}
};
export const index = () => {
const form = <HTMLFontElement>document.getElementById('form');
form.addEventListener('submit', registerUser, true);
export const index = (): void => {
const form = <HTMLFontElement>document.getElementById("form");
form.addEventListener("submit", registerUser, true);
usernameElement.addEventListener(
'input',
"input",
async () => await userExists(),
false,
);

View File

@@ -14,13 +14,13 @@
* 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 fetchMock from 'jest-fetch-mock';
import fetchMock from "jest-fetch-mock";
import userExists from './userExists';
import userExists from "./userExists";
import {mockAlert, getLoginFormHtml} from '../../../setUpTests';
import {mockAlert, getLoginFormHtml} from "../../../setUpTests";
import setup from '../../../components/error/setUpTests';
import setup from "../../../components/error/setUpTests";
fetchMock.enableMocks();
mockAlert();
@@ -29,16 +29,16 @@ beforeEach(() => {
fetchMock.resetMocks();
});
it('finds exchange', async () => {
it("finds exchange", async () => {
fetchMock.mockResponseOnce(JSON.stringify({exists: true}));
document.body.innerHTML = getLoginFormHtml();
document.querySelector('body').appendChild(setup());
const usernameField = <HTMLInputElement>document.querySelector('#username');
usernameField.value = 'test';
document.querySelector("body").appendChild(setup());
const usernameField = <HTMLInputElement>document.querySelector("#username");
usernameField.value = "test";
expect(await userExists()).toBe(true);
usernameField.value = 'test';
usernameField.value = "test";
fetchMock.mockResponseOnce(JSON.stringify({exists: true}));
expect(await userExists(usernameField)).toBe(true);

View File

@@ -15,16 +15,16 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import ROUTES from '../../../api/v1/routes';
import ROUTES from "../../../api/v1/routes";
import genJsonPayload from '../../../utils/genJsonPayload';
import createError from '../../../components/error/index';
import genJsonPayload from "../../../utils/genJsonPayload";
import createError from "../../../components/error/index";
const userExists = async (element?: HTMLInputElement) => {
const userExists = async (element?: HTMLInputElement): Promise<boolean> => {
console.log(element);
let username;
if (element === undefined) {
username = <HTMLInputElement>document.getElementById('username');
username = <HTMLInputElement>document.getElementById("username");
} else {
username = element;
}
@@ -37,7 +37,7 @@ const userExists = async (element?: HTMLInputElement) => {
if (res.ok) {
const data = await res.json();
if (data.exists) {
username.className += ' form__in-field--warn';
username.className += " form__in-field--warn";
createError(`Username "${val}" taken`);
}
return data.exists;