test: reorganize folder structure and files

The specific test files used for snapshots only have been integrated in
each component's test file so that all tests, including the snapshot are
located in a single test file.

Also as more tests were added, it seems like a better idea to have test
data in a separate file on its own rather than import test data from
another test file.

FInally, with all these changes, Jest wanted to have snapshots taken
again thus why the snapshot files were updated too.
This commit is contained in:
David Laganiere 2023-01-15 10:39:35 -05:00
commit 8931a780aa
No known key found for this signature in database
GPG key ID: 18C4B80581C28747
7 changed files with 41 additions and 44 deletions

View file

@ -0,0 +1,66 @@
import { render, screen } from "@testing-library/react";
import HomeLoggedOut from "components/HomeLoggedOut";
import { Router } from "react-router-dom";
import { createMemoryHistory } from "history";
import { act } from "react-dom/test-utils";
import axios from "axios";
import MockAdapter from "axios-mock-adapter";
describe("HomeLoggedOut", () => {
it("renders HomeLoggedOut unchanged", () => {
const { container } = render(<HomeLoggedOut />);
expect(container).toMatchSnapshot();
});
test("renders HomeLoggedOut when authentication is enabled", () => {
let mock = new MockAdapter(axios);
const history = createMemoryHistory();
const goSpy = jest.spyOn(history, "go");
mock.onGet("/auth/login").reply(200, { enabled: true });
render(
<Router history={history}>
<HomeLoggedOut />
</Router>
);
const projectDescription = screen.getByRole("heading", {
name: "ZeroUI - ZeroTier Controller Web UI - is a web user interface for a self-hosted ZeroTier network controller.",
});
const loginMessage = screen.getByText(/Please Log In to continue/i);
expect(projectDescription).toBeInTheDocument();
expect(loginMessage).toBeInTheDocument();
expect(goSpy).not.toHaveBeenCalled();
});
test("renders HomeLoggedOut when authentication is disabled", async () => {
let mock = new MockAdapter(axios);
const history = createMemoryHistory();
const goSpy = jest.spyOn(history, "go");
mock.onGet("/auth/login").reply(200, { enabled: false });
await act(async () => {
render(
<Router history={history}>
<HomeLoggedOut />
</Router>
);
});
const projectDescription = screen.getByRole("heading", {
name: "ZeroUI - ZeroTier Controller Web UI - is a web user interface for a self-hosted ZeroTier network controller.",
});
const loginMessage = screen.getByText(/Please Log In to continue/i);
expect(projectDescription).toBeInTheDocument();
expect(loginMessage).toBeInTheDocument();
expect(goSpy).toHaveBeenCalled();
});
});