@@ -77,9 +77,25 @@ Object.defineProperty(window, "location", {
77
77
} ) ;
78
78
79
79
describe ( "AuthDebugger" , ( ) => {
80
+ const defaultAuthState = {
81
+ isInitiatingAuth : false ,
82
+ oauthTokens : null ,
83
+ loading : false ,
84
+ oauthStep : "not_started" as const ,
85
+ oauthMetadata : null ,
86
+ oauthClientInfo : null ,
87
+ authorizationUrl : null ,
88
+ authorizationCode : "" ,
89
+ latestError : null ,
90
+ statusMessage : null ,
91
+ validationError : null ,
92
+ } ;
93
+
80
94
const defaultProps = {
81
95
sseUrl : "https://example.com" ,
82
96
onBack : jest . fn ( ) ,
97
+ authState : defaultAuthState ,
98
+ updateAuthState : jest . fn ( ) ,
83
99
} ;
84
100
85
101
beforeEach ( ( ) => {
@@ -97,9 +113,14 @@ describe("AuthDebugger", () => {
97
113
} ) ;
98
114
99
115
const renderAuthDebugger = ( props = { } ) => {
116
+ const mergedProps = {
117
+ ...defaultProps ,
118
+ ...props ,
119
+ authState : { ...defaultAuthState , ...props . authState } ,
120
+ } ;
100
121
return render (
101
122
< TooltipProvider >
102
- < AuthDebugger { ...defaultProps } { ... props } />
123
+ < AuthDebugger { ...mergedProps } />
103
124
</ TooltipProvider > ,
104
125
) ;
105
126
} ;
@@ -136,19 +157,21 @@ describe("AuthDebugger", () => {
136
157
} ) ;
137
158
138
159
it ( "should show error when OAuth flow is started without sseUrl" , async ( ) => {
160
+ const updateAuthState = jest . fn ( ) ;
139
161
await act ( async ( ) => {
140
- renderAuthDebugger ( { sseUrl : "" } ) ;
162
+ renderAuthDebugger ( { sseUrl : "" , updateAuthState } ) ;
141
163
} ) ;
142
164
143
165
await act ( async ( ) => {
144
166
fireEvent . click ( screen . getByText ( "Guided OAuth Flow" ) ) ;
145
167
} ) ;
146
168
147
- expect ( mockToast ) . toHaveBeenCalledWith ( {
148
- title : "Error" ,
149
- description :
150
- "Please enter a server URL in the sidebar before authenticating" ,
151
- variant : "destructive" ,
169
+ expect ( updateAuthState ) . toHaveBeenCalledWith ( {
170
+ statusMessage : {
171
+ type : "error" ,
172
+ message :
173
+ "Please enter a server URL in the sidebar before authenticating" ,
174
+ } ,
152
175
} ) ;
153
176
} ) ;
154
177
} ) ;
@@ -164,7 +187,12 @@ describe("AuthDebugger", () => {
164
187
} ) ;
165
188
166
189
await act ( async ( ) => {
167
- renderAuthDebugger ( ) ;
190
+ renderAuthDebugger ( {
191
+ authState : {
192
+ ...defaultAuthState ,
193
+ oauthTokens : mockOAuthTokens
194
+ }
195
+ } ) ;
168
196
} ) ;
169
197
170
198
await waitFor ( ( ) => {
@@ -199,6 +227,7 @@ describe("AuthDebugger", () => {
199
227
200
228
describe ( "OAuth State Management" , ( ) => {
201
229
it ( "should clear OAuth state when Clear button is clicked" , async ( ) => {
230
+ const updateAuthState = jest . fn ( ) ;
202
231
// Mock the session storage to return tokens for the specific key
203
232
sessionStorageMock . getItem . mockImplementation ( ( key ) => {
204
233
if ( key === "[https://example.com] mcp_tokens" ) {
@@ -208,16 +237,30 @@ describe("AuthDebugger", () => {
208
237
} ) ;
209
238
210
239
await act ( async ( ) => {
211
- renderAuthDebugger ( ) ;
240
+ renderAuthDebugger ( {
241
+ authState : {
242
+ ...defaultAuthState ,
243
+ oauthTokens : mockOAuthTokens
244
+ } ,
245
+ updateAuthState
246
+ } ) ;
212
247
} ) ;
213
248
214
249
await act ( async ( ) => {
215
250
fireEvent . click ( screen . getByText ( "Clear OAuth State" ) ) ;
216
251
} ) ;
217
252
218
- expect ( mockToast ) . toHaveBeenCalledWith ( {
219
- title : "Success" ,
220
- description : "OAuth tokens cleared successfully" ,
253
+ expect ( updateAuthState ) . toHaveBeenCalledWith ( {
254
+ oauthTokens : null ,
255
+ oauthStep : "not_started" ,
256
+ latestError : null ,
257
+ oauthClientInfo : null ,
258
+ authorizationCode : "" ,
259
+ validationError : null ,
260
+ statusMessage : {
261
+ type : "success" ,
262
+ message : "OAuth tokens cleared successfully" ,
263
+ } ,
221
264
} ) ;
222
265
223
266
// Verify session storage was cleared
@@ -227,13 +270,16 @@ describe("AuthDebugger", () => {
227
270
228
271
describe ( "OAuth Flow Steps" , ( ) => {
229
272
it ( "should handle OAuth flow step progression" , async ( ) => {
273
+ const updateAuthState = jest . fn ( ) ;
230
274
await act ( async ( ) => {
231
- renderAuthDebugger ( ) ;
232
- } ) ;
233
-
234
- // Start guided flow
235
- await act ( async ( ) => {
236
- fireEvent . click ( screen . getByText ( "Guided OAuth Flow" ) ) ;
275
+ renderAuthDebugger ( {
276
+ updateAuthState,
277
+ authState : {
278
+ ...defaultAuthState ,
279
+ isInitiatingAuth : false , // Changed to false so button is enabled
280
+ oauthStep : "metadata_discovery"
281
+ }
282
+ } ) ;
237
283
} ) ;
238
284
239
285
// Verify metadata discovery step
0 commit comments