mirror of
https://github.com/dec0dOS/zero-ui.git
synced 2025-08-20 13:24:03 -07:00
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:
parent
186cacee47
commit
8931a780aa
7 changed files with 41 additions and 44 deletions
66
frontend/__tests__/unit/components/HomeLoggedOut.test.jsx
Normal file
66
frontend/__tests__/unit/components/HomeLoggedOut.test.jsx
Normal 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();
|
||||
});
|
||||
});
|
30
frontend/__tests__/unit/components/NetworkHeader.test.jsx
Normal file
30
frontend/__tests__/unit/components/NetworkHeader.test.jsx
Normal file
|
@ -0,0 +1,30 @@
|
|||
import { render, screen } from "@testing-library/react";
|
||||
import NetworkHeader from "components/NetworkHeader";
|
||||
import { testNetwork } from "../../data/network";
|
||||
|
||||
describe("NetworkHeader", () => {
|
||||
it("renders NetworkHeader unchanged", () => {
|
||||
const { container } = render(<NetworkHeader network={testNetwork} />);
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test("renders NetworkHeader with a test network", () => {
|
||||
render(<NetworkHeader network={testNetwork} />);
|
||||
|
||||
const networkId = screen.getByRole("heading", {
|
||||
name: "0d303702cd0f1fc6",
|
||||
level: 5,
|
||||
});
|
||||
|
||||
const networkName = screen.getByRole("heading", {
|
||||
name: "new-net-11166",
|
||||
level: 6,
|
||||
});
|
||||
|
||||
const networkDescription = screen.getByText(/Test Network/);
|
||||
|
||||
expect(networkId).toBeInTheDocument();
|
||||
expect(networkName).toBeInTheDocument();
|
||||
expect(networkDescription).toBeInTheDocument();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,29 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`HomeLoggedOut renders HomeLoggedOut unchanged 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="MuiGrid-root MuiGrid-container MuiGrid-direction-xs-column MuiGrid-align-items-xs-center MuiGrid-justify-content-xs-center"
|
||||
style="min-height: 50vh;"
|
||||
>
|
||||
<div
|
||||
class="MuiGrid-root MuiGrid-item MuiGrid-grid-xs-10"
|
||||
>
|
||||
<h5
|
||||
class="MuiTypography-root MuiTypography-h5"
|
||||
>
|
||||
<span>
|
||||
ZeroUI - ZeroTier Controller Web UI - is a web user interface for a self-hosted ZeroTier network controller.
|
||||
</span>
|
||||
</h5>
|
||||
<p
|
||||
class="MuiTypography-root MuiTypography-body1"
|
||||
>
|
||||
<span>
|
||||
Please Log In to continue
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
|
@ -0,0 +1,28 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`NetworkHeader renders NetworkHeader unchanged 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="MuiGrid-root MuiGrid-item"
|
||||
>
|
||||
<h5
|
||||
class="MuiTypography-root MuiTypography-h5"
|
||||
>
|
||||
<span>
|
||||
0d303702cd0f1fc6
|
||||
</span>
|
||||
</h5>
|
||||
<h6
|
||||
class="MuiTypography-root MuiTypography-h6"
|
||||
style="font-style: italic;"
|
||||
>
|
||||
<span>
|
||||
new-net-11166
|
||||
</span>
|
||||
</h6>
|
||||
<span>
|
||||
Test Network
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
Loading…
Add table
Add a link
Reference in a new issue