-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathLogStreamPanel.test.tsx
More file actions
166 lines (150 loc) · 5.69 KB
/
Copy pathLogStreamPanel.test.tsx
File metadata and controls
166 lines (150 loc) · 5.69 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import { describe, it, expect, vi } from "vitest";
import userEvent from "@testing-library/user-event";
import type { LoggingLevel } from "@modelcontextprotocol/sdk/types.js";
import { renderWithMantine, screen } from "../../../test/renderWithMantine";
import { LogStreamPanel } from "./LogStreamPanel";
import type { LogEntryData } from "../../elements/LogEntry/LogEntry";
const allVisible: Record<LoggingLevel, boolean> = {
debug: true,
info: true,
notice: true,
warning: true,
error: true,
critical: true,
alert: true,
emergency: true,
};
const entries: LogEntryData[] = [
{
receivedAt: new Date("2026-03-17T10:00:00Z"),
params: { level: "info", data: "Server started", logger: "main" },
},
{
receivedAt: new Date("2026-03-17T10:00:01Z"),
params: { level: "error", data: "Failed to read", logger: "resources" },
},
{
receivedAt: new Date("2026-03-17T10:00:02Z"),
params: { level: "debug", data: "Loading config" },
},
{
receivedAt: new Date("2026-03-17T10:00:03Z"),
params: { level: "warning", data: { code: 42, msg: "deprecated" } },
},
{
receivedAt: new Date("2026-03-17T10:00:04Z"),
params: { level: "info", data: null },
},
];
const baseProps = {
entries,
filterText: "",
visibleLevels: allVisible,
autoScroll: true,
onToggleAutoScroll: vi.fn(),
onClear: vi.fn(),
onExport: vi.fn(),
};
describe("LogStreamPanel", () => {
it("renders the title and toolbar buttons", () => {
renderWithMantine(<LogStreamPanel {...baseProps} />);
expect(screen.getByText("Log Stream")).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Clear" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Export" })).toBeInTheDocument();
expect(
screen.queryByRole("button", { name: "Copy All" }),
).not.toBeInTheDocument();
});
it("renders log entries when provided", () => {
renderWithMantine(<LogStreamPanel {...baseProps} />);
expect(screen.getByText("Server started")).toBeInTheDocument();
expect(screen.getByText("Failed to read")).toBeInTheDocument();
expect(screen.getByText("Loading config")).toBeInTheDocument();
});
it("serializes object data as JSON", () => {
renderWithMantine(<LogStreamPanel {...baseProps} />);
expect(
screen.getByText('{"code":42,"msg":"deprecated"}'),
).toBeInTheDocument();
});
it("renders empty state when there are no entries", () => {
renderWithMantine(<LogStreamPanel {...baseProps} entries={[]} />);
expect(screen.getByText("No log entries")).toBeInTheDocument();
});
it("renders empty state when all entries are filtered out", () => {
const hideAll: Record<LoggingLevel, boolean> = {
debug: false,
info: false,
notice: false,
warning: false,
error: false,
critical: false,
alert: false,
emergency: false,
};
renderWithMantine(
<LogStreamPanel {...baseProps} visibleLevels={hideAll} />,
);
expect(screen.getByText("No log entries")).toBeInTheDocument();
});
it("filters entries by visibleLevels", () => {
const onlyError: Record<LoggingLevel, boolean> = {
debug: false,
info: false,
notice: false,
warning: false,
error: true,
critical: false,
alert: false,
emergency: false,
};
renderWithMantine(
<LogStreamPanel {...baseProps} visibleLevels={onlyError} />,
);
expect(screen.getByText("Failed to read")).toBeInTheDocument();
expect(screen.queryByText("Server started")).not.toBeInTheDocument();
expect(screen.queryByText("Loading config")).not.toBeInTheDocument();
});
it("filters entries by filterText against the data", () => {
renderWithMantine(<LogStreamPanel {...baseProps} filterText="server" />);
expect(screen.getByText("Server started")).toBeInTheDocument();
expect(screen.queryByText("Failed to read")).not.toBeInTheDocument();
});
it("filters entries by filterText against the logger name", () => {
renderWithMantine(<LogStreamPanel {...baseProps} filterText="resources" />);
expect(screen.getByText("Failed to read")).toBeInTheDocument();
expect(screen.queryByText("Server started")).not.toBeInTheDocument();
});
it("filters entries by filterText against the level", () => {
renderWithMantine(<LogStreamPanel {...baseProps} filterText="debug" />);
expect(screen.getByText("Loading config")).toBeInTheDocument();
expect(screen.queryByText("Failed to read")).not.toBeInTheDocument();
});
it("invokes onClear when Clear is clicked", async () => {
const user = userEvent.setup();
const onClear = vi.fn();
renderWithMantine(<LogStreamPanel {...baseProps} onClear={onClear} />);
await user.click(screen.getByRole("button", { name: "Clear" }));
expect(onClear).toHaveBeenCalledTimes(1);
});
it("invokes onExport when Export is clicked", async () => {
const user = userEvent.setup();
const onExport = vi.fn();
renderWithMantine(<LogStreamPanel {...baseProps} onExport={onExport} />);
await user.click(screen.getByRole("button", { name: "Export" }));
expect(onExport).toHaveBeenCalledTimes(1);
});
it("invokes onToggleAutoScroll when the auto-scroll checkbox is clicked", async () => {
const user = userEvent.setup();
const onToggleAutoScroll = vi.fn();
renderWithMantine(
<LogStreamPanel {...baseProps} onToggleAutoScroll={onToggleAutoScroll} />,
);
await user.click(screen.getByLabelText("Auto-scroll"));
expect(onToggleAutoScroll).toHaveBeenCalledTimes(1);
});
it("renders auto-scroll checkbox with correct checked state", () => {
renderWithMantine(<LogStreamPanel {...baseProps} autoScroll={false} />);
expect(screen.getByLabelText("Auto-scroll")).not.toBeChecked();
});
});