Lint test files, clean TS settings

This commit is contained in:
Aarni Halinen
2021-03-04 20:00:00 +02:00
parent 931c69d500
commit 40bb7d94f0
11 changed files with 123 additions and 115 deletions
+7
View File
@@ -0,0 +1,7 @@
# don't ever lint node_modules
node_modules
# don't lint build output (make sure it's set to your correct build folder name)
.next
# don't lint nyc coverage output
coverage
next-env.d.ts
+4 -6
View File
@@ -1,6 +1,8 @@
{
"root": true,
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
@@ -12,8 +14,7 @@
"plugin:jsx-a11y/recommended",
"plugin:react-hooks/recommended",
"plugin:@typescript-eslint/recommended",
"airbnb-typescript",
"airbnb/hooks"
"airbnb-typescript"
],
"globals": {
"Atomics": "readonly",
@@ -28,10 +29,7 @@
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": [
"react",
"@typescript-eslint"
],
"plugins": [],
"settings": {
"react": {
"version": "detect"
+1 -1
View File
@@ -22,7 +22,7 @@
"scripts": {
"build": "next build",
"lint": "npm run lint:es && npm run lint:css",
"lint:es": "eslint src/ --ext .ts,.tsx",
"lint:es": "eslint . --ext .ts,.tsx",
"lint:es:fix": "eslint --fix . --ext .ts,.tsx",
"lint:css": "stylelint \"./src/**/*.{ts,tsx}\"",
"start": "next dev",
+1 -2
View File
@@ -1,10 +1,9 @@
import { Selector } from "testcafe";
import { getSiteRoot } from "./utils";
fixture`404 page renders and functions correctly`.page(`${getSiteRoot()}/404`);
test("Page contains the text 404", async t => {
test("Page contains the text 404", async (t) => {
/**
* Test if there is a favicon element on the page
*/
+10 -9
View File
@@ -1,5 +1,7 @@
import { Selector } from "testcafe";
import { getSiteRoot, getPageUrl, generateTestForm, deleteEvent, deleteForm, doLogin, generateToken, getPostRequestLogger } from "../utils";
import {
getSiteRoot, getPageUrl, generateTestForm, deleteEvent, deleteForm, doLogin, generateToken, getPostRequestLogger,
} from "../utils";
const LOGGER = getPostRequestLogger("events/");
@@ -12,11 +14,11 @@ fixture`Admin events`.page(`${getSiteRoot()}/admin/events`)
})
.after(async (ctx) => {
const token = await generateToken();
const eResp = await deleteEvent(ctx.eventId, token);
await deleteEvent(ctx.eventId, token);
await deleteForm(ctx.formId, token);
});
test("Logged in user can create event", async t => {
test("Logged in user can create event", async (t) => {
const loginForm = Selector("form.admin-login-form");
await t.expect(loginForm.exists).ok();
await doLogin(t);
@@ -37,7 +39,6 @@ test("Logged in user can create event", async t => {
const locationFi = Selector("#rjsf_location_fi");
const locationEn = Selector("#rjsf_location_en");
const tagSelect = Selector("#rjsf_tags");
const signupSelect = Selector("#rjsf_signupForm");
// const tagOption = tagSelect.find("option").withExactText("Testi");
@@ -50,7 +51,7 @@ test("Logged in user can create event", async t => {
.click(tagSelect)
.pressKey("down")
.pressKey("down")
.pressKey("space")
.pressKey("space");
// .pressKey("tab");
// .click(tagOption, { modifiers: { ctrl: true } });
@@ -58,11 +59,10 @@ test("Logged in user can create event", async t => {
.click(signupSelect)
.pressKey("down")
.pressKey("down")
.pressKey("space")
.pressKey("space");
// .pressKey("tab");
// .click(signupOption, { modifiers: { ctrl: true } });
await t
.typeText(titleFi, "title_fi")
.typeText(descFi, "desc_fi")
@@ -78,12 +78,13 @@ test("Logged in user can create event", async t => {
await t.click(submit);
const parsed = JSON.parse(LOGGER.requests[0].response.body);
// eslint-disable-next-line no-param-reassign
t.fixtureCtx.eventId = parsed.id;
const statusMessage = Selector("[data-e2e=\"admin-form-status-message\"]");
await t
.hover(statusMessage)
.expect(
statusMessage.innerText
statusMessage.innerText,
).eql("Event created successfully");
})
});
+8 -5
View File
@@ -1,5 +1,7 @@
import { Selector } from "testcafe";
import { getSiteRoot, getPageUrl, deleteForm, doLogin, generateToken, getPostRequestLogger } from "../utils";
import {
getSiteRoot, getPageUrl, deleteForm, doLogin, generateToken, getPostRequestLogger,
} from "../utils";
const LOGGER = getPostRequestLogger("signupForm/");
@@ -10,7 +12,7 @@ fixture`Admin signup form`.page(`${getSiteRoot()}/admin/signups`)
await deleteForm(ctx.formId, token);
});
test("Logged in user can create signup", async t => {
test("Logged in user can create signup", async (t) => {
const loginForm = Selector("form.admin-login-form");
await t.expect(loginForm.exists).ok();
await doLogin(t);
@@ -38,7 +40,7 @@ test("Logged in user can create signup", async t => {
let question = lastQuestion();
let questionName = question.child("input");
let questionTypeSelect = question.child("select");
let requiredBox = question.child("label")
let requiredBox = question.child("label");
await t
.selectText(questionName)
@@ -81,12 +83,13 @@ test("Logged in user can create signup", async t => {
await t.click(submit);
const parsed = JSON.parse(LOGGER.requests[0].response.body);
// eslint-disable-next-line no-param-reassign
t.fixtureCtx.formId = parsed.id;
const statusMessage = Selector("[data-e2e=\"admin-form-status-message\"]");
await t
.hover(statusMessage)
.expect(
statusMessage.innerText
statusMessage.innerText,
).eql("Sign-up created successfully");
})
});
+4 -4
View File
@@ -3,7 +3,7 @@ import { getSiteRoot, doLogin } from "../utils";
fixture`Admin login page functions correctly`.page(`${getSiteRoot()}/admin/login`);
test("Login form exists", async t => {
test("Login form exists", async (t) => {
/**
* Test if the page contains a form.
*/
@@ -11,7 +11,7 @@ test("Login form exists", async t => {
await t.expect(form.exists).ok();
});
test("User can log in with default credentials", async t => {
test("User can log in with default credentials", async (t) => {
/**
* Test if the user can log in with default credentials.
*/
@@ -21,7 +21,7 @@ test("User can log in with default credentials", async t => {
await t.expect(frontPage.exists).ok();
});
test("User can log out and is redirected to login", async t => {
test("User can log out and is redirected to login", async (t) => {
/**
* Test if the user can log out.
*/
@@ -34,7 +34,7 @@ test("User can log out and is redirected to login", async t => {
await t.expect(loginForm.exists).ok();
});
test("User is redirected to login when JWT token is invalid", async t => {
test("User is redirected to login when JWT token is invalid", async (t) => {
/**
* Test if the user is redirected to login when JWT token is invalid.
*/
+2 -2
View File
@@ -3,7 +3,7 @@ import { getSiteRoot } from "./utils";
fixture`Front page renders and functions correctly`.page(`${getSiteRoot()}`);
test("Favicon exists", async t => {
test("Favicon exists", async (t) => {
/**
* Test if there is a favicon element on the page
*/
@@ -11,7 +11,7 @@ test("Favicon exists", async t => {
await t.expect(elem.exists).ok();
});
test("Header contains text \"Aalto-yliopiston Sähköinsinöörikilta\"", async t => {
test("Header contains text \"Aalto-yliopiston Sähköinsinöörikilta\"", async (t) => {
/**
* Test if the header contains the text.
*/
+8 -4
View File
@@ -1,5 +1,7 @@
import { Selector } from "testcafe";
import { getSiteRoot, getPageUrl, generateTestEvent, generateTestForm, deleteEvent, deleteForm, generateToken } from "./utils";
import {
getSiteRoot, getPageUrl, generateTestEvent, generateTestForm, deleteEvent, deleteForm, generateToken,
} from "./utils";
fixture`Event signup`.page(getSiteRoot())
.before(async (ctx) => {
@@ -15,7 +17,7 @@ fixture`Event signup`.page(getSiteRoot())
await deleteForm(ctx.formId, token);
});
test("User signups to event from front page", async t => {
test("User signups to event from front page", async (t) => {
const CardSelector = Selector("[data-e2e=\"event-card\"]").withText("title_fi").nth(0);
await t
@@ -33,7 +35,9 @@ test("User signups to event from front page", async t => {
const nameField = Selector("input").nth(0);
const emailField = Selector("input").nth(1);
const typeField = Selector("fieldset").child(-1).child("div").child("div").child("label").nth(-1);
const typeField = Selector("fieldset").child(-1).child("div").child("div")
.child("label")
.nth(-1);
await t
.typeText(nameField, "Testi Testeri")
@@ -46,6 +50,6 @@ test("User signups to event from front page", async t => {
await t
.hover(statusMessage)
.expect(
statusMessage.innerText
statusMessage.innerText,
).eql("Sign-up submitted successfully");
});
+60 -60
View File
@@ -40,6 +40,66 @@ export async function generateToken(): Promise<string> {
}
}
const eventURL = `${API_URL}/events/`;
export async function createEvent(data, jwt: string) {
try {
const resp = await axios.post(eventURL, data, {
headers: {
Authorization: `JWT ${jwt}`,
},
});
return resp.data;
} catch (err) {
console.error(err);
throw err;
}
}
export async function deleteEvent(id: string, jwt: string) {
try {
const resp = await axios.delete(`${eventURL}${id}/`, {
headers: {
Authorization: `JWT ${jwt}`,
},
});
return resp.data;
} catch (err) {
console.error(err);
throw err;
}
}
const formURL = `${API_URL}/signupForm/`;
export async function createForm(data, jwt: string) {
try {
const resp = await axios.post(formURL, data, {
headers: {
Authorization: `JWT ${jwt}`,
},
});
return resp.data;
} catch (err) {
console.error(err);
throw err;
}
}
export async function deleteForm(id: string, jwt: string) {
try {
const resp = await axios.delete(`${formURL}${id}/`, {
headers: {
Authorization: `JWT ${jwt}`,
},
});
return resp.data;
} catch (err) {
console.error(err);
throw err;
}
}
export const generateTestForm = async (jwt: string) => (
createForm({
title_fi: "Testi Ilmo",
@@ -74,36 +134,6 @@ export const generateTestForm = async (jwt: string) => (
}, jwt)
);
const formURL = `${API_URL}/signupForm/`;
export async function createForm(data, jwt: string) {
try {
const resp = await axios.post(formURL, data, {
headers: {
Authorization: `JWT ${jwt}`,
},
});
return resp.data;
} catch (err) {
console.error(err);
throw err;
}
}
export async function deleteForm(id: string, jwt: string) {
try {
const resp = await axios.delete(`${formURL}${id}/`, {
headers: {
Authorization: `JWT ${jwt}`,
},
});
return resp.data;
} catch (err) {
console.error(err);
throw err;
}
}
export const generateTestEvent = async (formIds = [], jwt: string) => (
createEvent({
tags: [1],
@@ -124,33 +154,3 @@ export const generateTestEvent = async (formIds = [], jwt: string) => (
tag_id: [1],
}, jwt)
);
const eventURL = `${API_URL}/events/`;
export async function createEvent(data, jwt: string) {
try {
const resp = await axios.post(eventURL, data, {
headers: {
Authorization: `JWT ${jwt}`,
},
});
return resp.data;
} catch (err) {
console.error(err);
throw err;
}
}
export async function deleteEvent(id: string, jwt: string) {
try {
const resp = await axios.delete(`${eventURL}${id}/`, {
headers: {
Authorization: `JWT ${jwt}`,
},
});
return resp.data;
} catch (err) {
console.error(err);
throw err;
}
}
+15 -19
View File
@@ -1,28 +1,24 @@
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": false,
"esModuleInterop": true,
"experimentalDecorators": true,
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"alwaysStrict": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"module": "commonjs",
"target": "esnext",
"jsx": "preserve",
"lib": ["dom", "DOM.Iterable", "ESNext"],
"typeRoots": [
"./types"
],
"types": [
"node",
],
"lib": ["dom", "esnext"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": false, // TODO: switch true
"noUnusedParameters": false, // TODO: switch true
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": false, // TODO: switch true
"target": "esnext",
"typeRoots": ["types", "node_modules/@types"],
"baseUrl": "./",
"paths": {
"@components/*": [