From 7057ceb36d021dad0c3a6cbee1173af25cc7407c Mon Sep 17 00:00:00 2001 From: Les Kleuver Date: Mon, 8 Apr 2024 13:44:24 +0200 Subject: [PATCH] merged fe-testing fix eslint errors add slightly more lenient template expression lint rules --- frontend/.eslintrc.cjs | 33 +- .../VotersAndVotesForm.test.tsx | 11 +- frontend/app/main.tsx | 6 +- .../module/input/page/PollingStationPage.tsx | 2 +- frontend/app/test/unit/server.ts | 2 +- frontend/lib/ui/Button/Button.tsx | 2 +- frontend/lib/ui/tag/Tag.tsx | 4 +- frontend/lib/util/hook/useInputMask.ts | 4 +- frontend/mockServiceWorker.js | 19 +- frontend/package-lock.json | 1159 +++++++---------- frontend/package.json | 40 +- 11 files changed, 543 insertions(+), 739 deletions(-) diff --git a/frontend/.eslintrc.cjs b/frontend/.eslintrc.cjs index 1b7669f6f..c211d3675 100644 --- a/frontend/.eslintrc.cjs +++ b/frontend/.eslintrc.cjs @@ -12,23 +12,30 @@ module.exports = { parser: "@typescript-eslint/parser", plugins: ["react-refresh", "jsx-a11y", "prettier", "@typescript-eslint"], rules: { - "react-refresh/only-export-components": ["warn", { allowConstantExport: true }] + "react-refresh/only-export-components": ["warn", { allowConstantExport: true }], + "@typescript-eslint/restrict-template-expressions": [ + "error", + { + allowNumber: true, + allowBoolean: true + } + ] }, parserOptions: { project: "./tsconfig.json" }, overrides: [ - { - files: "*.e2e.ts", - extends: [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended-type-checked", - "plugin:playwright/recommended", - ], - plugins: ["@typescript-eslint"], - rules: { - "@typescript-eslint/no-floating-promises": "error", - } + { + files: "*.e2e.ts", + extends: [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended-type-checked", + "plugin:playwright/recommended" + ], + plugins: ["@typescript-eslint"], + rules: { + "@typescript-eslint/no-floating-promises": "error" } - ] + } + ] }; diff --git a/frontend/app/component/form/voters_and_votes/VotersAndVotesForm.test.tsx b/frontend/app/component/form/voters_and_votes/VotersAndVotesForm.test.tsx index 996eb3879..961714047 100644 --- a/frontend/app/component/form/voters_and_votes/VotersAndVotesForm.test.tsx +++ b/frontend/app/component/form/voters_and_votes/VotersAndVotesForm.test.tsx @@ -1,20 +1,19 @@ import { render, screen } from "@testing-library/react"; -import userEvent from '@testing-library/user-event'; +import { userEvent } from "@testing-library/user-event"; import { expect, test } from "vitest"; -import {VotersAndVotesForm} from "./VotersAndVotesForm"; - +import { VotersAndVotesForm } from "./VotersAndVotesForm"; test("Enter pollCards count", async () => { const user = userEvent.setup(); render(); - const pollCards = screen.getByTestId("pollCards") + const pollCards = screen.getByTestId("pollCards"); expect(pollCards).toBeVisible(); - await user.clear(pollCards) - await user.type(pollCards, "12345") + await user.clear(pollCards); + await user.type(pollCards, "12345"); expect(pollCards).toHaveValue("12.345"); // ToDo: assert the call to the mocked API once that's been implemented diff --git a/frontend/app/main.tsx b/frontend/app/main.tsx index c6dde0bf8..a7ce5bc6e 100644 --- a/frontend/app/main.tsx +++ b/frontend/app/main.tsx @@ -26,7 +26,11 @@ function render() { } if (process.env.MSW) { - startMockAPI().then(render).catch(console.error); + startMockAPI() + .then(render) + .catch((e: unknown) => { + console.error(e); + }); } else { render(); } diff --git a/frontend/app/module/input/page/PollingStationPage.tsx b/frontend/app/module/input/page/PollingStationPage.tsx index 952fa5c6e..40cdc2e49 100644 --- a/frontend/app/module/input/page/PollingStationPage.tsx +++ b/frontend/app/module/input/page/PollingStationPage.tsx @@ -38,7 +38,7 @@ export function PollingStationPage() { {lijsten.map((lijst, index) => ( - + {lijst} ))} diff --git a/frontend/app/test/unit/server.ts b/frontend/app/test/unit/server.ts index b881b5a27..adf2231a0 100644 --- a/frontend/app/test/unit/server.ts +++ b/frontend/app/test/unit/server.ts @@ -13,7 +13,7 @@ import { handlers } from "@kiesraad/api-mocks"; export const server = setupServer( ...handlers.map((h) => { // Node's Fetch implementation does not accept URLs with a protocol and host - h.info.path = "http://testhost" + h.info.path; + h.info.path = "http://testhost" + h.info.path.toString(); return h; }) ); diff --git a/frontend/lib/ui/Button/Button.tsx b/frontend/lib/ui/Button/Button.tsx index 1ca773749..75a89feda 100644 --- a/frontend/lib/ui/Button/Button.tsx +++ b/frontend/lib/ui/Button/Button.tsx @@ -21,7 +21,7 @@ export function Button({ }: ButtonProps) { return (