-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathNetworkControls.test.tsx
More file actions
90 lines (83 loc) · 2.98 KB
/
NetworkControls.test.tsx
File metadata and controls
90 lines (83 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { describe, it, expect, vi } from "vitest";
import userEvent from "@testing-library/user-event";
import { renderWithMantine, screen } from "../../../test/renderWithMantine";
import { NetworkControls } from "./NetworkControls";
const baseProps = {
filterText: "",
visibleCategories: { auth: true, transport: true } as const,
onFilterChange: vi.fn(),
onToggleCategory: vi.fn(),
onToggleAllCategories: vi.fn(),
};
describe("NetworkControls", () => {
it("renders the title and inputs", () => {
renderWithMantine(<NetworkControls {...baseProps} />);
expect(screen.getByText("Network")).toBeInTheDocument();
expect(screen.getByPlaceholderText("Search...")).toBeInTheDocument();
expect(screen.getByRole("button", { name: "auth" })).toBeInTheDocument();
expect(
screen.getByRole("button", { name: "transport" }),
).toBeInTheDocument();
});
it("fires onFilterChange when the user types", async () => {
const user = userEvent.setup();
const onFilterChange = vi.fn();
renderWithMantine(
<NetworkControls {...baseProps} onFilterChange={onFilterChange} />,
);
await user.type(screen.getByPlaceholderText("Search..."), "x");
expect(onFilterChange).toHaveBeenLastCalledWith("x");
});
it("reflects category visibility via aria-pressed", () => {
renderWithMantine(
<NetworkControls
{...baseProps}
visibleCategories={{ auth: true, transport: false }}
/>,
);
expect(screen.getByRole("button", { name: "auth" })).toHaveAttribute(
"aria-pressed",
"true",
);
expect(screen.getByRole("button", { name: "transport" })).toHaveAttribute(
"aria-pressed",
"false",
);
});
it("fires onToggleCategory with inverted visibility when clicked", async () => {
const user = userEvent.setup();
const onToggleCategory = vi.fn();
renderWithMantine(
<NetworkControls {...baseProps} onToggleCategory={onToggleCategory} />,
);
await user.click(screen.getByRole("button", { name: "auth" }));
expect(onToggleCategory).toHaveBeenCalledWith("auth", false);
});
it("toggles between Select All and Deselect All", () => {
const { rerender } = renderWithMantine(<NetworkControls {...baseProps} />);
expect(
screen.getByRole("button", { name: "Deselect All" }),
).toBeInTheDocument();
rerender(
<NetworkControls
{...baseProps}
visibleCategories={{ auth: false, transport: false }}
/>,
);
expect(
screen.getByRole("button", { name: "Select All" }),
).toBeInTheDocument();
});
it("fires onToggleAllCategories when the toggle button is clicked", async () => {
const user = userEvent.setup();
const onToggleAllCategories = vi.fn();
renderWithMantine(
<NetworkControls
{...baseProps}
onToggleAllCategories={onToggleAllCategories}
/>,
);
await user.click(screen.getByRole("button", { name: "Deselect All" }));
expect(onToggleAllCategories).toHaveBeenCalledTimes(1);
});
});