mirror of
https://github.com/dec0dOS/zero-ui.git
synced 2025-08-20 05:13:57 -07:00
test(HomeLoggedIn): add test for 100% coverage
This commit is contained in:
parent
8e3113d388
commit
514a86831f
1 changed files with 43 additions and 1 deletions
|
@ -1,9 +1,11 @@
|
||||||
import { render, screen } from "@testing-library/react";
|
import { render, screen } from "@testing-library/react";
|
||||||
import HomeLoggedIn from "components/HomeLoggedIn";
|
import HomeLoggedIn from "components/HomeLoggedIn";
|
||||||
import { Router } from "react-router-dom";
|
import { MemoryRouter, Route, Router } from "react-router-dom";
|
||||||
import { createMemoryHistory } from "history";
|
import { createMemoryHistory } from "history";
|
||||||
import { testNetwork } from "../../data/network";
|
import { testNetwork } from "../../data/network";
|
||||||
|
import userEvent from "@testing-library/user-event";
|
||||||
import API from "utils/API";
|
import API from "utils/API";
|
||||||
|
import { act } from "react-dom/test-utils";
|
||||||
import MockAdapter from "axios-mock-adapter";
|
import MockAdapter from "axios-mock-adapter";
|
||||||
|
|
||||||
describe("HomeLoggedIn", () => {
|
describe("HomeLoggedIn", () => {
|
||||||
|
@ -43,4 +45,44 @@ describe("HomeLoggedIn", () => {
|
||||||
|
|
||||||
expect(container).toMatchSnapshot();
|
expect(container).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("creates a new network when the 'Create A Network' button is clicked", async () => {
|
||||||
|
jest.spyOn(Math, "random").mockReturnValue(0.5);
|
||||||
|
jest.spyOn(Date, "now").mockImplementation(() => 1487076708000);
|
||||||
|
|
||||||
|
let mock = new MockAdapter(API);
|
||||||
|
const user = userEvent.setup();
|
||||||
|
let testLocation;
|
||||||
|
const networkId = "testid";
|
||||||
|
|
||||||
|
// For the API call with the initial render
|
||||||
|
mock.onGet("network").reply(200, []);
|
||||||
|
|
||||||
|
// For the API call after the 'Create A Network' button is clicked
|
||||||
|
mock.onPost("/network").reply(200, { config: { id: "testid" } });
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
render(
|
||||||
|
<MemoryRouter initialEntries={["/"]}>
|
||||||
|
<Route path="/">
|
||||||
|
<HomeLoggedIn />
|
||||||
|
</Route>
|
||||||
|
<Route
|
||||||
|
path="*"
|
||||||
|
render={({ location }) => {
|
||||||
|
testLocation = location;
|
||||||
|
return null;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</MemoryRouter>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const createANetworkButton = screen.getByRole("button", {
|
||||||
|
name: "Create A Network",
|
||||||
|
});
|
||||||
|
|
||||||
|
await user.click(createANetworkButton);
|
||||||
|
expect(testLocation.pathname).toBe("/network/testid");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue