1
1
import { render , screen , fireEvent } from "@testing-library/react" ;
2
- import "@testing-library/jest-dom" ;
3
2
import { describe , it , expect , jest } from "@jest/globals" ;
4
- import HistoryAndNotifications from "../History " ;
3
+ import HistoryAndNotifications from "../HistoryAndNotifications " ;
5
4
import { ServerNotification } from "@modelcontextprotocol/sdk/types.js" ;
6
5
7
6
// Mock JsonView component
@@ -25,12 +24,19 @@ describe("HistoryAndNotifications", () => {
25
24
26
25
const mockNotifications : ServerNotification [ ] = [
27
26
{
28
- method : "notification/test1" ,
29
- params : { message : "First notification" } ,
27
+ method : "notifications/message" ,
28
+ params : {
29
+ level : "info" as const ,
30
+ message : "First notification" ,
31
+ } ,
30
32
} ,
31
33
{
32
- method : "notification/test2" ,
33
- params : { message : "Second notification" } ,
34
+ method : "notifications/progress" ,
35
+ params : {
36
+ progressToken : "test-token" ,
37
+ progress : 50 ,
38
+ message : "Second notification" ,
39
+ } ,
34
40
} ,
35
41
] ;
36
42
@@ -42,8 +48,8 @@ describe("HistoryAndNotifications", () => {
42
48
/> ,
43
49
) ;
44
50
45
- expect ( screen . getByText ( "History" ) ) . toBeInTheDocument ( ) ;
46
- expect ( screen . getByText ( "Server Notifications" ) ) . toBeInTheDocument ( ) ;
51
+ expect ( screen . getByText ( "History" ) ) . toBeTruthy ( ) ;
52
+ expect ( screen . getByText ( "Server Notifications" ) ) . toBeTruthy ( ) ;
47
53
} ) ;
48
54
49
55
it ( "displays request history items with correct numbering" , ( ) => {
@@ -55,8 +61,8 @@ describe("HistoryAndNotifications", () => {
55
61
) ;
56
62
57
63
// Items should be numbered in reverse order (newest first)
58
- expect ( screen . getByText ( "2. test/method2" ) ) . toBeInTheDocument ( ) ;
59
- expect ( screen . getByText ( "1. test/method1" ) ) . toBeInTheDocument ( ) ;
64
+ expect ( screen . getByText ( "2. test/method2" ) ) . toBeTruthy ( ) ;
65
+ expect ( screen . getByText ( "1. test/method1" ) ) . toBeTruthy ( ) ;
60
66
} ) ;
61
67
62
68
it ( "displays server notifications with correct numbering" , ( ) => {
@@ -68,8 +74,8 @@ describe("HistoryAndNotifications", () => {
68
74
) ;
69
75
70
76
// Items should be numbered in reverse order (newest first)
71
- expect ( screen . getByText ( "2. notification/test2 " ) ) . toBeInTheDocument ( ) ;
72
- expect ( screen . getByText ( "1. notification/test1 " ) ) . toBeInTheDocument ( ) ;
77
+ expect ( screen . getByText ( "2. notifications/progress " ) ) . toBeTruthy ( ) ;
78
+ expect ( screen . getByText ( "1. notifications/message " ) ) . toBeTruthy ( ) ;
73
79
} ) ;
74
80
75
81
it ( "expands and collapses request items when clicked" , ( ) => {
@@ -84,16 +90,16 @@ describe("HistoryAndNotifications", () => {
84
90
85
91
// Initially collapsed - should show ▶ arrows (there are multiple)
86
92
expect ( screen . getAllByText ( "▶" ) ) . toHaveLength ( 2 ) ;
87
- expect ( screen . queryByText ( "Request:" ) ) . not . toBeInTheDocument ( ) ;
93
+ expect ( screen . queryByText ( "Request:" ) ) . toBeNull ( ) ;
88
94
89
95
// Click to expand
90
96
fireEvent . click ( firstRequestHeader ) ;
91
97
92
98
// Should now be expanded - one ▼ and one ▶
93
- expect ( screen . getByText ( "▼" ) ) . toBeInTheDocument ( ) ;
99
+ expect ( screen . getByText ( "▼" ) ) . toBeTruthy ( ) ;
94
100
expect ( screen . getAllByText ( "▶" ) ) . toHaveLength ( 1 ) ;
95
- expect ( screen . getByText ( "Request:" ) ) . toBeInTheDocument ( ) ;
96
- expect ( screen . getByText ( "Response:" ) ) . toBeInTheDocument ( ) ;
101
+ expect ( screen . getByText ( "Request:" ) ) . toBeTruthy ( ) ;
102
+ expect ( screen . getByText ( "Response:" ) ) . toBeTruthy ( ) ;
97
103
} ) ;
98
104
99
105
it ( "expands and collapses notification items when clicked" , ( ) => {
@@ -104,19 +110,21 @@ describe("HistoryAndNotifications", () => {
104
110
/> ,
105
111
) ;
106
112
107
- const firstNotificationHeader = screen . getByText ( "2. notification/test2" ) ;
113
+ const firstNotificationHeader = screen . getByText (
114
+ "2. notifications/progress" ,
115
+ ) ;
108
116
109
117
// Initially collapsed
110
118
expect ( screen . getAllByText ( "▶" ) ) . toHaveLength ( 2 ) ;
111
- expect ( screen . queryByText ( "Details:" ) ) . not . toBeInTheDocument ( ) ;
119
+ expect ( screen . queryByText ( "Details:" ) ) . toBeNull ( ) ;
112
120
113
121
// Click to expand
114
122
fireEvent . click ( firstNotificationHeader ) ;
115
123
116
124
// Should now be expanded
117
- expect ( screen . getByText ( "▼" ) ) . toBeInTheDocument ( ) ;
125
+ expect ( screen . getByText ( "▼" ) ) . toBeTruthy ( ) ;
118
126
expect ( screen . getAllByText ( "▶" ) ) . toHaveLength ( 1 ) ;
119
- expect ( screen . getByText ( "Details:" ) ) . toBeInTheDocument ( ) ;
127
+ expect ( screen . getByText ( "Details:" ) ) . toBeTruthy ( ) ;
120
128
} ) ;
121
129
122
130
it ( "maintains expanded state when new notifications are added" , ( ) => {
@@ -127,18 +135,20 @@ describe("HistoryAndNotifications", () => {
127
135
/> ,
128
136
) ;
129
137
130
- // Find and expand the older notification (should be "1. notification/test1")
131
- const olderNotificationHeader = screen . getByText ( "1. notification/test1" ) ;
138
+ // Find and expand the older notification (should be "1. notifications/message")
139
+ const olderNotificationHeader = screen . getByText (
140
+ "1. notifications/message" ,
141
+ ) ;
132
142
fireEvent . click ( olderNotificationHeader ) ;
133
143
134
144
// Verify it's expanded
135
- expect ( screen . getByText ( "Details:" ) ) . toBeInTheDocument ( ) ;
145
+ expect ( screen . getByText ( "Details:" ) ) . toBeTruthy ( ) ;
136
146
137
147
// Add a new notification at the beginning (simulating real behavior)
138
148
const newNotifications : ServerNotification [ ] = [
139
149
{
140
- method : "notification/new " ,
141
- params : { message : "New notification " } ,
150
+ method : "notifications/resources/updated " ,
151
+ params : { uri : "file://test.txt " } ,
142
152
} ,
143
153
...mockNotifications ,
144
154
] ;
@@ -152,13 +162,13 @@ describe("HistoryAndNotifications", () => {
152
162
) ;
153
163
154
164
// The original notification should still be expanded
155
- // It's now numbered as "2. notification/test1 " due to the new item
156
- expect ( screen . getByText ( "3. notification/test2 " ) ) . toBeInTheDocument ( ) ;
157
- expect ( screen . getByText ( "2. notification/test1 " ) ) . toBeInTheDocument ( ) ;
158
- expect ( screen . getByText ( "1. notification/new " ) ) . toBeInTheDocument ( ) ;
165
+ // It's now numbered as "2. notifications/message " due to the new item
166
+ expect ( screen . getByText ( "3. notifications/progress " ) ) . toBeTruthy ( ) ;
167
+ expect ( screen . getByText ( "2. notifications/message " ) ) . toBeTruthy ( ) ;
168
+ expect ( screen . getByText ( "1. notifications/resources/updated " ) ) . toBeTruthy ( ) ;
159
169
160
170
// The originally expanded notification should still show its details
161
- expect ( screen . getByText ( "Details:" ) ) . toBeInTheDocument ( ) ;
171
+ expect ( screen . getByText ( "Details:" ) ) . toBeTruthy ( ) ;
162
172
} ) ;
163
173
164
174
it ( "maintains expanded state when new requests are added" , ( ) => {
@@ -174,8 +184,8 @@ describe("HistoryAndNotifications", () => {
174
184
fireEvent . click ( olderRequestHeader ) ;
175
185
176
186
// Verify it's expanded
177
- expect ( screen . getByText ( "Request:" ) ) . toBeInTheDocument ( ) ;
178
- expect ( screen . getByText ( "Response:" ) ) . toBeInTheDocument ( ) ;
187
+ expect ( screen . getByText ( "Request:" ) ) . toBeTruthy ( ) ;
188
+ expect ( screen . getByText ( "Response:" ) ) . toBeTruthy ( ) ;
179
189
180
190
// Add a new request at the beginning
181
191
const newRequestHistory = [
@@ -196,21 +206,21 @@ describe("HistoryAndNotifications", () => {
196
206
197
207
// The original request should still be expanded
198
208
// It's now numbered as "2. test/method1" due to the new item
199
- expect ( screen . getByText ( "3. test/method2" ) ) . toBeInTheDocument ( ) ;
200
- expect ( screen . getByText ( "2. test/method1" ) ) . toBeInTheDocument ( ) ;
201
- expect ( screen . getByText ( "1. test/new_method" ) ) . toBeInTheDocument ( ) ;
209
+ expect ( screen . getByText ( "3. test/method2" ) ) . toBeTruthy ( ) ;
210
+ expect ( screen . getByText ( "2. test/method1" ) ) . toBeTruthy ( ) ;
211
+ expect ( screen . getByText ( "1. test/new_method" ) ) . toBeTruthy ( ) ;
202
212
203
213
// The originally expanded request should still show its details
204
- expect ( screen . getByText ( "Request:" ) ) . toBeInTheDocument ( ) ;
205
- expect ( screen . getByText ( "Response:" ) ) . toBeInTheDocument ( ) ;
214
+ expect ( screen . getByText ( "Request:" ) ) . toBeTruthy ( ) ;
215
+ expect ( screen . getByText ( "Response:" ) ) . toBeTruthy ( ) ;
206
216
} ) ;
207
217
208
218
it ( "displays empty state messages when no data is available" , ( ) => {
209
219
render (
210
220
< HistoryAndNotifications requestHistory = { [ ] } serverNotifications = { [ ] } /> ,
211
221
) ;
212
222
213
- expect ( screen . getByText ( "No history yet" ) ) . toBeInTheDocument ( ) ;
214
- expect ( screen . getByText ( "No notifications yet" ) ) . toBeInTheDocument ( ) ;
223
+ expect ( screen . getByText ( "No history yet" ) ) . toBeTruthy ( ) ;
224
+ expect ( screen . getByText ( "No notifications yet" ) ) . toBeTruthy ( ) ;
215
225
} ) ;
216
226
} ) ;
0 commit comments