mirror of
https://github.com/dec0dOS/zero-ui.git
synced 2025-08-20 21:33:55 -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
|
@ -1,7 +0,0 @@
|
|||
import { render } from "@testing-library/react";
|
||||
import HomeLoggedOut from "components/HomeLoggedOut";
|
||||
|
||||
it("renders HomeLoggedOut unchanged", () => {
|
||||
const { container } = render(<HomeLoggedOut />);
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
|
@ -1,8 +0,0 @@
|
|||
import { render } from "@testing-library/react";
|
||||
import NetworkHeader from "components/NetworkHeader";
|
||||
import { testNetwork } from "./NetworkHeader.test";
|
||||
|
||||
it("renders HomeLoggedOut unchanged", () => {
|
||||
const { container } = render(<NetworkHeader network={testNetwork} />);
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
|
@ -1,97 +0,0 @@
|
|||
import { render, screen } from "@testing-library/react";
|
||||
import NetworkHeader from "components/NetworkHeader";
|
||||
|
||||
export const testNetwork = {
|
||||
id: "0d303702cd0f1fc6",
|
||||
clock: 1672834445703,
|
||||
description: "Test Network",
|
||||
rulesSource:
|
||||
"\n# This is a default rule set that allows IPv4 and IPv6 traffic but otherwise\n# behaves like a standard Ethernet switch.\n\n#\n# Allow only IPv4, IPv4 ARP, and IPv6 Ethernet frames.\n#\ndrop\n not ethertype ipv4\n and not ethertype arp\n and not ethertype ipv6\n;\n\n#\n# Uncomment to drop non-ZeroTier issued and managed IP addresses.\n#\n# This prevents IP spoofing but also blocks manual IP management at the OS level and\n# bridging unless special rules to exempt certain hosts or traffic are added before\n# this rule.\n#\n#drop\n# not chr ipauth\n#;\n\n# Accept anything else. This is required since default is 'drop'.\naccept;\n",
|
||||
tagsByName: {},
|
||||
capabilitiesByName: {},
|
||||
config: {
|
||||
authTokens: [null],
|
||||
authorizationEndpoint: "",
|
||||
capabilities: [],
|
||||
clientId: "",
|
||||
creationTime: 1672676611179,
|
||||
dns: [],
|
||||
enableBroadcast: true,
|
||||
id: "0d303702cd0f1fc6",
|
||||
ipAssignmentPools: [
|
||||
{
|
||||
ipRangeEnd: "172.30.101.254",
|
||||
ipRangeStart: "172.30.101.1",
|
||||
},
|
||||
],
|
||||
mtu: 2800,
|
||||
multicastLimit: 32,
|
||||
name: "new-net-11166",
|
||||
nwid: "0d303702cd0f1fc6",
|
||||
private: true,
|
||||
routes: [
|
||||
{
|
||||
target: "172.30.101.0/24",
|
||||
via: null,
|
||||
},
|
||||
],
|
||||
rules: [
|
||||
{
|
||||
etherType: 2048,
|
||||
not: true,
|
||||
or: false,
|
||||
type: "MATCH_ETHERTYPE",
|
||||
},
|
||||
{
|
||||
etherType: 2054,
|
||||
not: true,
|
||||
or: false,
|
||||
type: "MATCH_ETHERTYPE",
|
||||
},
|
||||
{
|
||||
etherType: 34525,
|
||||
not: true,
|
||||
or: false,
|
||||
type: "MATCH_ETHERTYPE",
|
||||
},
|
||||
{
|
||||
type: "ACTION_DROP",
|
||||
},
|
||||
{
|
||||
type: "ACTION_ACCEPT",
|
||||
},
|
||||
],
|
||||
ssoEnabled: false,
|
||||
tags: [],
|
||||
v4AssignMode: {
|
||||
zt: true,
|
||||
},
|
||||
v6AssignMode: {
|
||||
"6plane": false,
|
||||
rfc4193: false,
|
||||
zt: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
describe("NetworkHeader", () => {
|
||||
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();
|
||||
});
|
||||
});
|
|
@ -6,10 +6,15 @@ import { act } from "react-dom/test-utils";
|
|||
import axios from "axios";
|
||||
import MockAdapter from "axios-mock-adapter";
|
||||
|
||||
let mock = new MockAdapter(axios);
|
||||
|
||||
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");
|
||||
|
||||
|
@ -33,6 +38,8 @@ describe("HomeLoggedOut", () => {
|
|||
});
|
||||
|
||||
test("renders HomeLoggedOut when authentication is disabled", async () => {
|
||||
let mock = new MockAdapter(axios);
|
||||
|
||||
const history = createMemoryHistory();
|
||||
const goSpy = jest.spyOn(history, "go");
|
||||
|
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();
|
||||
});
|
||||
});
|
|
@ -1,6 +1,6 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`renders HomeLoggedOut unchanged 1`] = `
|
||||
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"
|
|
@ -1,6 +1,6 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`renders HomeLoggedOut unchanged 1`] = `
|
||||
exports[`NetworkHeader renders NetworkHeader unchanged 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="MuiGrid-root MuiGrid-item"
|
Loading…
Add table
Add a link
Reference in a new issue