diff --git a/frontend/src/components/bazarr/Language.test.tsx b/frontend/src/components/bazarr/Language.test.tsx index 6b2ff93a5..8d328753e 100644 --- a/frontend/src/components/bazarr/Language.test.tsx +++ b/frontend/src/components/bazarr/Language.test.tsx @@ -1,4 +1,4 @@ -import { render, screen } from "@testing-library/react"; +import { rawRender, screen } from "@/tests"; import { describe, it } from "vitest"; import { Language } from "."; @@ -9,13 +9,13 @@ describe("Language text", () => { }; it("should show short text", () => { - render(); + rawRender(); expect(screen.getByText(testLanguage.code2)).toBeDefined(); }); it("should show long text", () => { - render(); + rawRender(); expect(screen.getByText(testLanguage.name)).toBeDefined(); }); @@ -23,7 +23,7 @@ describe("Language text", () => { const testLanguageWithHi: Language.Info = { ...testLanguage, hi: true }; it("should show short text with HI", () => { - render(); + rawRender(); const expectedText = `${testLanguageWithHi.code2}:HI`; @@ -31,7 +31,7 @@ describe("Language text", () => { }); it("should show long text with HI", () => { - render(); + rawRender(); const expectedText = `${testLanguageWithHi.name} HI`; @@ -44,7 +44,7 @@ describe("Language text", () => { }; it("should show short text with Forced", () => { - render(); + rawRender(); const expectedText = `${testLanguageWithHi.code2}:Forced`; @@ -52,7 +52,9 @@ describe("Language text", () => { }); it("should show long text with Forced", () => { - render(); + rawRender( + + ); const expectedText = `${testLanguageWithHi.name} Forced`; @@ -73,7 +75,7 @@ describe("Language list", () => { ]; it("should show all languages", () => { - render(); + rawRender(); elements.forEach((value) => { expect(screen.getByText(value.name)).toBeDefined(); diff --git a/frontend/src/components/inputs/Action.test.tsx b/frontend/src/components/inputs/Action.test.tsx index 60c0bf646..05086e71c 100644 --- a/frontend/src/components/inputs/Action.test.tsx +++ b/frontend/src/components/inputs/Action.test.tsx @@ -1,5 +1,5 @@ +import { rawRender, screen } from "@/tests"; import { faStickyNote } from "@fortawesome/free-regular-svg-icons"; -import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { describe, it, vitest } from "vitest"; import Action from "./Action"; @@ -9,7 +9,7 @@ const testIcon = faStickyNote; describe("Action button", () => { it("should be a button", () => { - render(); + rawRender(); const element = screen.getByRole("button", { name: testLabel }); expect(element.getAttribute("type")).toEqual("button"); @@ -17,7 +17,7 @@ describe("Action button", () => { }); it("should show icon", () => { - render(); + rawRender(); // TODO: use getBy... const element = screen.getByRole("img", { hidden: true }); @@ -27,7 +27,7 @@ describe("Action button", () => { it("should call on-click event when clicked", async () => { const onClickFn = vitest.fn(); - render( + rawRender( ); diff --git a/frontend/src/components/inputs/ChipInput.test.tsx b/frontend/src/components/inputs/ChipInput.test.tsx index 8cb7a099e..3e30490d2 100644 --- a/frontend/src/components/inputs/ChipInput.test.tsx +++ b/frontend/src/components/inputs/ChipInput.test.tsx @@ -1,4 +1,4 @@ -import { render, screen } from "@testing-library/react"; +import { rawRender, screen } from "@/tests"; import userEvent from "@testing-library/user-event"; import { describe, it, vitest } from "vitest"; import ChipInput from "./ChipInput"; @@ -8,7 +8,7 @@ describe("ChipInput", () => { // TODO: Support default value it.skip("should works with default value", () => { - render(); + rawRender(); existedValues.forEach((value) => { expect(screen.getByText(value)).toBeDefined(); @@ -16,7 +16,7 @@ describe("ChipInput", () => { }); it("should works with value", () => { - render(); + rawRender(); existedValues.forEach((value) => { expect(screen.getByText(value)).toBeDefined(); @@ -29,7 +29,9 @@ describe("ChipInput", () => { expect(values).toContain(typedValue); }); - render(); + rawRender( + + ); const element = screen.getByRole("searchbox"); diff --git a/frontend/src/components/inputs/Selector.test.tsx b/frontend/src/components/inputs/Selector.test.tsx index 43221ccae..96382c0b2 100644 --- a/frontend/src/components/inputs/Selector.test.tsx +++ b/frontend/src/components/inputs/Selector.test.tsx @@ -1,4 +1,4 @@ -import { render, screen } from "@testing-library/react"; +import { rawRender, screen } from "@/tests"; import userEvent from "@testing-library/user-event"; import { describe, it, vitest } from "vitest"; import { Selector, SelectorOption } from "./Selector"; @@ -18,14 +18,18 @@ const testOptions: SelectorOption[] = [ describe("Selector", () => { describe("options", () => { it("should work with the SelectorOption", () => { - render(); + rawRender( + + ); // TODO: selectorName expect(screen.getByRole("searchbox")).toBeDefined(); }); it("should display when clicked", async () => { - render(); + rawRender( + + ); const element = screen.getByRole("searchbox"); @@ -40,7 +44,7 @@ describe("Selector", () => { it("shouldn't show default value", async () => { const option = testOptions[0]; - render( + rawRender( { it("shouldn't show value", async () => { const option = testOptions[0]; - render( + rawRender( { const mockedFn = vitest.fn((value: string | null) => { expect(value).toEqual(clickedOption.value); }); - render( + rawRender( { const mockedFn = vitest.fn((value: { name: string } | null) => { expect(value).toEqual(clickedOption.value); }); - render( + rawRender( { describe("placeholder", () => { it("should show when no selection", () => { const placeholder = "Empty Selection"; - render( + rawRender( { it("should render without crash", () => { - render( - - - - ); + render(); expect(screen.getByPlaceholderText("Username")).toBeDefined(); expect(screen.getByPlaceholderText("Password")).toBeDefined(); diff --git a/frontend/src/pages/Settings/components/Layout.test.tsx b/frontend/src/pages/Settings/components/Layout.test.tsx index 696b98797..0cec7c9cd 100644 --- a/frontend/src/pages/Settings/components/Layout.test.tsx +++ b/frontend/src/pages/Settings/components/Layout.test.tsx @@ -1,30 +1,23 @@ -import queryClient from "@/apis/queries"; +import { render, screen } from "@/tests"; import { Text } from "@mantine/core"; -import { render, screen } from "@testing-library/react"; -import { QueryClientProvider } from "react-query"; -import { BrowserRouter } from "react-router-dom"; import { describe, it } from "vitest"; import Layout from "./Layout"; -const renderLayout = () => { - render( - - - - Value - - - - ); -}; - describe("Settings layout", () => { it.concurrent("should be able to render without issues", () => { - renderLayout(); + render( + + Value + + ); }); it.concurrent("save button should be disabled by default", () => { - renderLayout(); + render( + + Value + + ); expect(screen.getByRole("button", { name: "Save" })).toBeDisabled(); }); diff --git a/frontend/src/pages/Settings/components/Section.test.tsx b/frontend/src/pages/Settings/components/Section.test.tsx index 2241bd40d..716b95e40 100644 --- a/frontend/src/pages/Settings/components/Section.test.tsx +++ b/frontend/src/pages/Settings/components/Section.test.tsx @@ -1,12 +1,12 @@ +import { rawRender, screen } from "@/tests"; import { Text } from "@mantine/core"; -import { render, screen } from "@testing-library/react"; import { describe, it } from "vitest"; import { Section } from "./Section"; describe("Settings section", () => { const header = "Section Header"; it("should show header", () => { - render(
); + rawRender(
); expect(screen.getByText(header)).toBeDefined(); expect(screen.getByRole("separator")).toBeDefined(); @@ -14,7 +14,7 @@ describe("Settings section", () => { it("should show children", () => { const text = "Section Child"; - render( + rawRender(
{text}
@@ -26,7 +26,7 @@ describe("Settings section", () => { it("should work with hidden", () => { const text = "Section Child"; - render( + rawRender( diff --git a/frontend/src/pages/Settings/components/forms.test.tsx b/frontend/src/pages/Settings/components/forms.test.tsx index 7ff6eefbe..711c764a9 100644 --- a/frontend/src/pages/Settings/components/forms.test.tsx +++ b/frontend/src/pages/Settings/components/forms.test.tsx @@ -1,6 +1,6 @@ +import { rawRender, RenderOptions, screen } from "@/tests"; import { useForm } from "@mantine/form"; -import { render, screen } from "@testing-library/react"; -import { FunctionComponent } from "react"; +import { FunctionComponent, ReactElement } from "react"; import { describe, it } from "vitest"; import { FormContext, FormValues } from "../utilities/FormValues"; import { Number, Text } from "./forms"; @@ -15,14 +15,15 @@ const FormSupport: FunctionComponent = ({ children }) => { return {children}; }; +const formRender = ( + ui: ReactElement, + options?: Omit +) => rawRender(ui, { wrapper: FormSupport, ...options }); + describe("Settings form", () => { describe("number component", () => { it("should be able to render", () => { - render( - - - - ); + formRender(); expect(screen.getByRole("textbox")).toBeDefined(); }); @@ -30,11 +31,7 @@ describe("Settings form", () => { describe("text component", () => { it("should be able to render", () => { - render( - - - - ); + formRender(); expect(screen.getByRole("textbox")).toBeDefined(); }); diff --git a/frontend/src/tests/index.tsx b/frontend/src/tests/index.tsx index 07f286bce..8239af064 100644 --- a/frontend/src/tests/index.tsx +++ b/frontend/src/tests/index.tsx @@ -11,3 +11,4 @@ const customRender = ( export * from "@testing-library/react"; // override render method export { customRender as render }; +export { render as rawRender };