-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathLoggingScreen.test.tsx
More file actions
105 lines (96 loc) · 3.8 KB
/
LoggingScreen.test.tsx
File metadata and controls
105 lines (96 loc) · 3.8 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { describe, it, expect, vi } from "vitest";
import userEvent from "@testing-library/user-event";
import { renderWithMantine, screen } from "../../../test/renderWithMantine";
import { LoggingScreen } from "./LoggingScreen";
const baseProps = {
entries: [],
currentLevel: "info" as const,
onSetLevel: vi.fn(),
onClear: vi.fn(),
onExport: vi.fn(),
autoScroll: true,
onToggleAutoScroll: vi.fn(),
};
describe("LoggingScreen", () => {
it("renders the log stream panel", () => {
renderWithMantine(<LoggingScreen {...baseProps} />);
expect(screen.getByText("Log Stream")).toBeInTheDocument();
expect(screen.getByText("No log entries")).toBeInTheDocument();
});
it("renders log entries", () => {
const entries = [
{
receivedAt: new Date(),
params: { level: "info" as const, data: "hello" },
},
];
renderWithMantine(<LoggingScreen {...baseProps} entries={entries} />);
expect(screen.getByText("hello")).toBeInTheDocument();
});
it("invokes onClear when clear is clicked", async () => {
const user = userEvent.setup();
const onClear = vi.fn();
const entries = [
{ receivedAt: new Date(), params: { level: "info" as const, data: "x" } },
];
renderWithMantine(
<LoggingScreen {...baseProps} entries={entries} onClear={onClear} />,
);
await user.click(screen.getByRole("button", { name: "Clear" }));
expect(onClear).toHaveBeenCalledTimes(1);
});
it("disables Clear / Export when there are no entries", () => {
renderWithMantine(<LoggingScreen {...baseProps} />);
expect(screen.getByRole("button", { name: "Clear" })).toBeDisabled();
expect(screen.getByRole("button", { name: "Export" })).toBeDisabled();
expect(
screen.queryByRole("button", { name: "Copy All" }),
).not.toBeInTheDocument();
});
it("toggles a single level on level button click", async () => {
const user = userEvent.setup();
const entries = [
{ receivedAt: new Date(), params: { level: "info" as const, data: "x" } },
];
renderWithMantine(<LoggingScreen {...baseProps} entries={entries} />);
expect(screen.getByText("x")).toBeInTheDocument();
const debugButton = screen.getByRole("button", { name: "info" });
await user.click(debugButton);
expect(screen.queryByText("x")).not.toBeInTheDocument();
});
it("Deselect All hides all entries; Select All restores them", async () => {
const user = userEvent.setup();
const entries = [
{ receivedAt: new Date(), params: { level: "info" as const, data: "x" } },
];
renderWithMantine(<LoggingScreen {...baseProps} entries={entries} />);
await user.click(screen.getByRole("button", { name: "Deselect All" }));
expect(screen.queryByText("x")).not.toBeInTheDocument();
await user.click(screen.getByRole("button", { name: "Select All" }));
expect(screen.getByText("x")).toBeInTheDocument();
});
it("filters log text via the search input", async () => {
const user = userEvent.setup();
const entries = [
{
receivedAt: new Date(),
params: { level: "info" as const, data: "alpha" },
},
{
receivedAt: new Date(),
params: { level: "info" as const, data: "beta" },
},
];
renderWithMantine(<LoggingScreen {...baseProps} entries={entries} />);
await user.type(screen.getByPlaceholderText("Search..."), "alpha");
expect(screen.getByText("alpha")).toBeInTheDocument();
expect(screen.queryByText("beta")).not.toBeInTheDocument();
});
it("invokes onSetLevel via the Set button", async () => {
const user = userEvent.setup();
const onSetLevel = vi.fn();
renderWithMantine(<LoggingScreen {...baseProps} onSetLevel={onSetLevel} />);
await user.click(screen.getByRole("button", { name: "Set" }));
expect(onSetLevel).toHaveBeenCalledWith("info");
});
});