Skip to content

Commit

Permalink
Migrate test hooks to React 18 render pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorbg committed Jul 2, 2022
1 parent 7d2d9eb commit b65a4f8
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 55 deletions.
22 changes: 6 additions & 16 deletions tnoodle-ui/src/test/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import { configureStore } from "@reduxjs/toolkit";
import { fireEvent } from "@testing-library/react";
import { render, act, fireEvent } from "@testing-library/react";
import { shuffle } from "lodash";
import React from "react";
import { render, unmountComponentAtNode } from "react-dom";
import { act } from "react-dom/test-utils";
import { Provider } from "react-redux";
import App from "../App";
import tnoodleApi from "../main/api/tnoodle.api";
import wcaApi from "../main/api/wca.api";
import Translation from "../main/model/Translation";
import Wcif from "../main/model/Wcif";
import { competitionSlice } from "../main/redux/slice/CompetitionSlice";
import { fmcSlice } from "../main/redux/slice/FmcSlice";
import { informationSlice } from "../main/redux/slice/InformationSlice";
import { mbldSlice } from "../main/redux/slice/MbldSlice";
import { scramblingSlice } from "../main/redux/slice/ScramblingSlice";
import { wcifSlice } from "../main/redux/slice/WcifSlice";
import { defaultWcif } from "../main/util/wcif.util";
import {
bestMbldAttempt,
Expand Down Expand Up @@ -94,7 +85,6 @@ beforeEach(() => {

afterEach(() => {
// cleanup on exiting
unmountComponentAtNode(container);
container.remove();
container = document.createElement("div");

Expand Down Expand Up @@ -126,7 +116,7 @@ it("Just generate scrambles", async () => {
<App />
</Provider>
</React.StrictMode>,
container
{ container }
);
});
const scrambleButton = container.querySelector("form button")!;
Expand Down Expand Up @@ -154,7 +144,7 @@ it("Changes on 333, scramble", async () => {
<App />
</Provider>
</React.StrictMode>,
container
{ container }
);
});

Expand Down Expand Up @@ -227,7 +217,7 @@ it("Remove 333, add FMC and MBLD", async () => {
<App />
</Provider>
</React.StrictMode>,
container
{ container }
);
});

Expand Down Expand Up @@ -361,7 +351,7 @@ it("Logged user", async () => {
<App />
</Provider>
</React.StrictMode>,
container
{ container }
);
});

Expand Down Expand Up @@ -489,7 +479,7 @@ it("Comfort features should not block zip generation", async () => {
<App />
</Provider>
</React.StrictMode>,
container
{ container }
);
});

Expand Down
9 changes: 3 additions & 6 deletions tnoodle-ui/src/test/EntryInterface.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { fireEvent } from "@testing-library/react";
import { render, act, fireEvent } from "@testing-library/react";
import React from "react";
import { render, unmountComponentAtNode } from "react-dom";
import { act } from "react-dom/test-utils";
import { Provider } from "react-redux";
import EntryInterface from "../main/components/EntryInterface";
import store from "../main/redux/Store";
Expand All @@ -15,7 +13,6 @@ beforeEach(() => {

afterEach(() => {
// cleanup on exiting
unmountComponentAtNode(container);
container.remove();
container = document.createElement("div");
});
Expand All @@ -29,7 +26,7 @@ it("Competition name should be already filled with current date and changes shou
<EntryInterface />
</Provider>
</React.StrictMode>,
container
{ container }
);
});

Expand Down Expand Up @@ -58,7 +55,7 @@ it("Password should toggle and changes to it should go to the store", async () =
<EntryInterface />
</Provider>
</React.StrictMode>,
container
{ container }
);
});

Expand Down
11 changes: 4 additions & 7 deletions tnoodle-ui/src/test/EventPicker.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { fireEvent } from "@testing-library/react";
import { render, act, fireEvent } from "@testing-library/react";
import React from "react";
import { render, unmountComponentAtNode } from "react-dom";
import { act } from "react-dom/test-utils";
import { Provider } from "react-redux";
import EventPicker from "../main/components/EventPicker";
import {
Expand All @@ -23,7 +21,6 @@ beforeEach(() => {

afterEach(() => {
// cleanup on exiting
unmountComponentAtNode(container);
container.remove();
container = document.createElement("div");
});
Expand All @@ -43,7 +40,7 @@ it("Changing values from event", async () => {
<EventPicker wcaEvent={event} wcifEvent={wcifEvent} />
</Provider>
</React.StrictMode>,
container
{ container }
);
});

Expand Down Expand Up @@ -127,7 +124,7 @@ it("Editing disabled", async () => {
<EventPicker wcaEvent={event} wcifEvent={wcifEvent} />
</Provider>
</React.StrictMode>,
container
{ container }
);
});

Expand Down Expand Up @@ -157,7 +154,7 @@ it("Progress Bar showing/hiding", async () => {
<EventPicker wcaEvent={event} wcifEvent={wcifEvent} />
</Provider>
</React.StrictMode>,
container
{ container }
);
});

Expand Down
11 changes: 4 additions & 7 deletions tnoodle-ui/src/test/EventPickerTable.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { fireEvent } from "@testing-library/react";
import { render, act, fireEvent } from "@testing-library/react";
import React from "react";
import { render, unmountComponentAtNode } from "react-dom";
import { act } from "react-dom/test-utils";
import { Provider } from "react-redux";
import tnoodleApi from "../main/api/tnoodle.api";
import EventPickerTable from "../main/components/EventPickerTable";
Expand Down Expand Up @@ -36,7 +34,6 @@ beforeEach(() => {

afterEach(() => {
// cleanup on exiting
unmountComponentAtNode(container);
container.remove();
container = document.createElement("div");

Expand Down Expand Up @@ -78,7 +75,7 @@ it("Show editing warn if case of competition selected", async () => {
<EventPickerTable />
</Provider>
</React.StrictMode>,
container
{ container }
);
});

Expand Down Expand Up @@ -116,7 +113,7 @@ it("Singular event", async () => {
<EventPickerTable />
</Provider>
</React.StrictMode>,
container
{ container }
);
});

Expand All @@ -135,7 +132,7 @@ it("Changes in MBLD should go to the store", async () => {
<EventPickerTable />
</Provider>
</React.StrictMode>,
container
{ container }
);
});
const names = ["3x3x3 Multiple Blindfolded"];
Expand Down
7 changes: 2 additions & 5 deletions tnoodle-ui/src/test/Main.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { fireEvent } from "@testing-library/react";
import { render, act, fireEvent } from "@testing-library/react";
import React from "react";
import { render, unmountComponentAtNode } from "react-dom";
import { act } from "react-dom/test-utils";
import { Provider } from "react-redux";
import tnoodleApi from "../main/api/tnoodle.api";
import wcaApi from "../main/api/wca.api";
Expand Down Expand Up @@ -36,7 +34,6 @@ beforeEach(() => {

afterEach(() => {
// cleanup on exiting
unmountComponentAtNode(container);
container.remove();
container = document.createElement("div");

Expand Down Expand Up @@ -82,7 +79,7 @@ it("There should be only 1 button of type submit, check FMC changes", async () =
<Main />
</Provider>
</React.StrictMode>,
container
{ container }
);
});

Expand Down
6 changes: 2 additions & 4 deletions tnoodle-ui/src/test/SideBar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import { act } from "react-dom/test-utils";

import { render, unmountComponentAtNode } from "react-dom";
import { render, act } from "@testing-library/react";

import { Provider } from "react-redux";
import store from "../main/redux/Store";
Expand All @@ -21,7 +20,6 @@ beforeEach(() => {

afterEach(() => {
// cleanup on exiting
unmountComponentAtNode(container);
container.remove();
container = document.createElement("div");
});
Expand All @@ -44,7 +42,7 @@ it("Each competition fetched from the website must become a button", async () =>
<Provider store={store}>
<SideBar />
</Provider>,
container
{ container }
);
});

Expand Down
17 changes: 7 additions & 10 deletions tnoodle-ui/src/test/VersionInfo.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from "react";
import { act } from "react-dom/test-utils";

import { render, unmountComponentAtNode } from "react-dom";
import { render, act } from "@testing-library/react";

import { Provider } from "react-redux";

Expand All @@ -20,7 +18,6 @@ beforeEach(() => {

afterEach(() => {
// cleanup on exiting
unmountComponentAtNode(container);
container.remove();
container = document.createElement("div");
});
Expand Down Expand Up @@ -62,7 +59,7 @@ it("Current version is the correct one", async () => {
<Provider store={store}>
<VersionInfo />
</Provider>,
container
{ container }
);
});

Expand Down Expand Up @@ -114,7 +111,7 @@ it("Current version is allowed, but it's not the latest one", async () => {
<Provider store={store}>
<VersionInfo />
</Provider>,
container
{ container }
);
});

Expand Down Expand Up @@ -170,7 +167,7 @@ it("Not signed version alert", async () => {
<Provider store={store}>
<VersionInfo />
</Provider>,
container
{ container }
);
});

Expand Down Expand Up @@ -223,7 +220,7 @@ it("Signed with different key", async () => {
<Provider store={store}>
<VersionInfo />
</Provider>,
container
{ container }
);
});

Expand Down Expand Up @@ -276,7 +273,7 @@ it("Not allowed TNoodle version, despite it's official", async () => {
<Provider store={store}>
<VersionInfo />
</Provider>,
container
{ container }
);
});

Expand Down Expand Up @@ -322,7 +319,7 @@ it("Do not bother the user if we can't be sure", async () => {
<Provider store={store}>
<VersionInfo />
</Provider>,
container
{ container }
);
});

Expand Down

0 comments on commit b65a4f8

Please sign in to comment.