diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..26a4091 --- /dev/null +++ b/.eslintignore @@ -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 \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index baf0c09..8cf105d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -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" diff --git a/package.json b/package.json index a429ea4..6d48edb 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests/testcafe/404.test.ts b/tests/testcafe/404.test.ts index 8f3853e..90e78d1 100644 --- a/tests/testcafe/404.test.ts +++ b/tests/testcafe/404.test.ts @@ -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 */ diff --git a/tests/testcafe/admin/create-event.test.ts b/tests/testcafe/admin/create-event.test.ts index 475f4da..55e52ff 100644 --- a/tests/testcafe/admin/create-event.test.ts +++ b/tests/testcafe/admin/create-event.test.ts @@ -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,19 +51,18 @@ test("Logged in user can create event", async t => { .click(tagSelect) .pressKey("down") .pressKey("down") - .pressKey("space") - // .pressKey("tab"); + .pressKey("space"); + // .pressKey("tab"); // .click(tagOption, { modifiers: { ctrl: true } }); await t .click(signupSelect) .pressKey("down") .pressKey("down") - .pressKey("space") - // .pressKey("tab"); + .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"); -}) +}); diff --git a/tests/testcafe/admin/create-signup.test.ts b/tests/testcafe/admin/create-signup.test.ts index 8c6a1bd..5bbb480 100644 --- a/tests/testcafe/admin/create-signup.test.ts +++ b/tests/testcafe/admin/create-signup.test.ts @@ -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"); -}) +}); diff --git a/tests/testcafe/admin/login.test.ts b/tests/testcafe/admin/login.test.ts index a58dfd4..13e0797 100644 --- a/tests/testcafe/admin/login.test.ts +++ b/tests/testcafe/admin/login.test.ts @@ -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. */ diff --git a/tests/testcafe/index.test.ts b/tests/testcafe/index.test.ts index 994c4ce..05e9e59 100644 --- a/tests/testcafe/index.test.ts +++ b/tests/testcafe/index.test.ts @@ -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. */ diff --git a/tests/testcafe/signupToEvent.test.ts b/tests/testcafe/signupToEvent.test.ts index 392dae1..4704e4f 100644 --- a/tests/testcafe/signupToEvent.test.ts +++ b/tests/testcafe/signupToEvent.test.ts @@ -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"); -}); \ No newline at end of file +}); diff --git a/tests/testcafe/utils.ts b/tests/testcafe/utils.ts index 71a4162..8b0a9ba 100644 --- a/tests/testcafe/utils.ts +++ b/tests/testcafe/utils.ts @@ -40,6 +40,66 @@ export async function generateToken(): Promise { } } +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; - } -} diff --git a/tsconfig.json b/tsconfig.json index 39139f3..e51222d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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/*": [