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": { "env": {
"browser": true, "browser": true,
"commonjs": true,
"es6": true, "es6": true,
"node": true "node": true
}, },
@@ -12,8 +14,7 @@
"plugin:jsx-a11y/recommended", "plugin:jsx-a11y/recommended",
"plugin:react-hooks/recommended", "plugin:react-hooks/recommended",
"plugin:@typescript-eslint/recommended", "plugin:@typescript-eslint/recommended",
"airbnb-typescript", "airbnb-typescript"
"airbnb/hooks"
], ],
"globals": { "globals": {
"Atomics": "readonly", "Atomics": "readonly",
@@ -28,10 +29,7 @@
"sourceType": "module", "sourceType": "module",
"project": "./tsconfig.json" "project": "./tsconfig.json"
}, },
"plugins": [ "plugins": [],
"react",
"@typescript-eslint"
],
"settings": { "settings": {
"react": { "react": {
"version": "detect" "version": "detect"
+1 -1
View File
@@ -22,7 +22,7 @@
"scripts": { "scripts": {
"build": "next build", "build": "next build",
"lint": "npm run lint:es && npm run lint:css", "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:es:fix": "eslint --fix . --ext .ts,.tsx",
"lint:css": "stylelint \"./src/**/*.{ts,tsx}\"", "lint:css": "stylelint \"./src/**/*.{ts,tsx}\"",
"start": "next dev", "start": "next dev",
+1 -2
View File
@@ -1,10 +1,9 @@
import { Selector } from "testcafe"; import { Selector } from "testcafe";
import { getSiteRoot } from "./utils"; import { getSiteRoot } from "./utils";
fixture`404 page renders and functions correctly`.page(`${getSiteRoot()}/404`); 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 * Test if there is a favicon element on the page
*/ */
+12 -11
View File
@@ -1,5 +1,7 @@
import { Selector } from "testcafe"; 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/"); const LOGGER = getPostRequestLogger("events/");
@@ -12,11 +14,11 @@ fixture`Admin events`.page(`${getSiteRoot()}/admin/events`)
}) })
.after(async (ctx) => { .after(async (ctx) => {
const token = await generateToken(); const token = await generateToken();
const eResp = await deleteEvent(ctx.eventId, token); await deleteEvent(ctx.eventId, token);
await deleteForm(ctx.formId, 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"); const loginForm = Selector("form.admin-login-form");
await t.expect(loginForm.exists).ok(); await t.expect(loginForm.exists).ok();
await doLogin(t); await doLogin(t);
@@ -37,7 +39,6 @@ test("Logged in user can create event", async t => {
const locationFi = Selector("#rjsf_location_fi"); const locationFi = Selector("#rjsf_location_fi");
const locationEn = Selector("#rjsf_location_en"); const locationEn = Selector("#rjsf_location_en");
const tagSelect = Selector("#rjsf_tags"); const tagSelect = Selector("#rjsf_tags");
const signupSelect = Selector("#rjsf_signupForm"); const signupSelect = Selector("#rjsf_signupForm");
// const tagOption = tagSelect.find("option").withExactText("Testi"); // const tagOption = tagSelect.find("option").withExactText("Testi");
@@ -50,19 +51,18 @@ test("Logged in user can create event", async t => {
.click(tagSelect) .click(tagSelect)
.pressKey("down") .pressKey("down")
.pressKey("down") .pressKey("down")
.pressKey("space") .pressKey("space");
// .pressKey("tab"); // .pressKey("tab");
// .click(tagOption, { modifiers: { ctrl: true } }); // .click(tagOption, { modifiers: { ctrl: true } });
await t await t
.click(signupSelect) .click(signupSelect)
.pressKey("down") .pressKey("down")
.pressKey("down") .pressKey("down")
.pressKey("space") .pressKey("space");
// .pressKey("tab"); // .pressKey("tab");
// .click(signupOption, { modifiers: { ctrl: true } }); // .click(signupOption, { modifiers: { ctrl: true } });
await t await t
.typeText(titleFi, "title_fi") .typeText(titleFi, "title_fi")
.typeText(descFi, "desc_fi") .typeText(descFi, "desc_fi")
@@ -78,12 +78,13 @@ test("Logged in user can create event", async t => {
await t.click(submit); await t.click(submit);
const parsed = JSON.parse(LOGGER.requests[0].response.body); const parsed = JSON.parse(LOGGER.requests[0].response.body);
// eslint-disable-next-line no-param-reassign
t.fixtureCtx.eventId = parsed.id; t.fixtureCtx.eventId = parsed.id;
const statusMessage = Selector("[data-e2e=\"admin-form-status-message\"]"); const statusMessage = Selector("[data-e2e=\"admin-form-status-message\"]");
await t await t
.hover(statusMessage) .hover(statusMessage)
.expect( .expect(
statusMessage.innerText statusMessage.innerText,
).eql("Event created successfully"); ).eql("Event created successfully");
}) });
+8 -5
View File
@@ -1,5 +1,7 @@
import { Selector } from "testcafe"; 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/"); const LOGGER = getPostRequestLogger("signupForm/");
@@ -10,7 +12,7 @@ fixture`Admin signup form`.page(`${getSiteRoot()}/admin/signups`)
await deleteForm(ctx.formId, token); 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"); const loginForm = Selector("form.admin-login-form");
await t.expect(loginForm.exists).ok(); await t.expect(loginForm.exists).ok();
await doLogin(t); await doLogin(t);
@@ -38,7 +40,7 @@ test("Logged in user can create signup", async t => {
let question = lastQuestion(); let question = lastQuestion();
let questionName = question.child("input"); let questionName = question.child("input");
let questionTypeSelect = question.child("select"); let questionTypeSelect = question.child("select");
let requiredBox = question.child("label") let requiredBox = question.child("label");
await t await t
.selectText(questionName) .selectText(questionName)
@@ -81,12 +83,13 @@ test("Logged in user can create signup", async t => {
await t.click(submit); await t.click(submit);
const parsed = JSON.parse(LOGGER.requests[0].response.body); const parsed = JSON.parse(LOGGER.requests[0].response.body);
// eslint-disable-next-line no-param-reassign
t.fixtureCtx.formId = parsed.id; t.fixtureCtx.formId = parsed.id;
const statusMessage = Selector("[data-e2e=\"admin-form-status-message\"]"); const statusMessage = Selector("[data-e2e=\"admin-form-status-message\"]");
await t await t
.hover(statusMessage) .hover(statusMessage)
.expect( .expect(
statusMessage.innerText statusMessage.innerText,
).eql("Sign-up created successfully"); ).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`); 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. * Test if the page contains a form.
*/ */
@@ -11,7 +11,7 @@ test("Login form exists", async t => {
await t.expect(form.exists).ok(); 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. * 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(); 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. * 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(); 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. * 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()}`); 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 * 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(); 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. * Test if the header contains the text.
*/ */
+9 -5
View File
@@ -1,5 +1,7 @@
import { Selector } from "testcafe"; 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()) fixture`Event signup`.page(getSiteRoot())
.before(async (ctx) => { .before(async (ctx) => {
@@ -15,7 +17,7 @@ fixture`Event signup`.page(getSiteRoot())
await deleteForm(ctx.formId, token); 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); const CardSelector = Selector("[data-e2e=\"event-card\"]").withText("title_fi").nth(0);
await t await t
@@ -33,7 +35,9 @@ test("User signups to event from front page", async t => {
const nameField = Selector("input").nth(0); const nameField = Selector("input").nth(0);
const emailField = Selector("input").nth(1); 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 await t
.typeText(nameField, "Testi Testeri") .typeText(nameField, "Testi Testeri")
@@ -46,6 +50,6 @@ test("User signups to event from front page", async t => {
await t await t
.hover(statusMessage) .hover(statusMessage)
.expect( .expect(
statusMessage.innerText statusMessage.innerText,
).eql("Sign-up submitted successfully"); ).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) => ( export const generateTestForm = async (jwt: string) => (
createForm({ createForm({
title_fi: "Testi Ilmo", title_fi: "Testi Ilmo",
@@ -74,36 +134,6 @@ export const generateTestForm = async (jwt: string) => (
}, jwt) }, 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) => ( export const generateTestEvent = async (formIds = [], jwt: string) => (
createEvent({ createEvent({
tags: [1], tags: [1],
@@ -124,33 +154,3 @@ export const generateTestEvent = async (formIds = [], jwt: string) => (
tag_id: [1], tag_id: [1],
}, jwt) }, 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": { "compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": false,
"esModuleInterop": true,
"experimentalDecorators": true,
"allowJs": true, "allowJs": true,
"skipLibCheck": true, "alwaysStrict": true,
"strict": false, "esModuleInterop": true,
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"noEmit": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true, "isolatedModules": true,
"module": "commonjs",
"target": "esnext",
"jsx": "preserve", "jsx": "preserve",
"lib": ["dom", "DOM.Iterable", "ESNext"], "lib": ["dom", "esnext"],
"typeRoots": [ "module": "esnext",
"./types" "moduleResolution": "node",
], "noEmit": true,
"types": [ "noFallthroughCasesInSwitch": true,
"node", "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": "./", "baseUrl": "./",
"paths": { "paths": {
"@components/*": [ "@components/*": [