mirror of
https://github.com/dec0dOS/zero-ui.git
synced 2025-08-14 10:37:31 -07:00
test: tests for HomeLoggedOut component
This commit is contained in:
parent
23be268630
commit
f69d82e4dc
3 changed files with 95 additions and 0 deletions
7
frontend/__tests__/unit/HomeLoggedOut.snapshot.jsx
Normal file
7
frontend/__tests__/unit/HomeLoggedOut.snapshot.jsx
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { render } from "@testing-library/react";
|
||||
import HomeLoggedOut from "../../src/components/HomeLoggedOut";
|
||||
|
||||
it("renders HomeLoggedOut unchanged", () => {
|
||||
const { container } = render(<HomeLoggedOut />);
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
59
frontend/__tests__/unit/HomeLoggedOut.test.jsx
Normal file
59
frontend/__tests__/unit/HomeLoggedOut.test.jsx
Normal file
|
@ -0,0 +1,59 @@
|
|||
import { render, screen } from "@testing-library/react";
|
||||
import HomeLoggedOut from "../../src/components/HomeLoggedOut";
|
||||
import { Router } from "react-router-dom";
|
||||
import { createMemoryHistory } from "history";
|
||||
import { act } from "react-dom/test-utils";
|
||||
|
||||
var axios = require("axios");
|
||||
var MockAdapter = require("axios-mock-adapter");
|
||||
var mock = new MockAdapter(axios);
|
||||
|
||||
describe("HomeLoggedOut", () => {
|
||||
test("renders HomeLoggedOut when authentication is enabled", () => {
|
||||
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 () => {
|
||||
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();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,29 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`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>
|
||||
`;
|
Loading…
Add table
Add a link
Reference in a new issue