@@ -212,25 +212,23 @@ describe("ElicitationRequest", () => {
212212 } ,
213213 } ) ;
214214
215- it ( "should render URL mode request with link and message " , ( ) => {
215+ it ( "should render URL mode request with message but no clickable link " , ( ) => {
216216 renderElicitationRequest ( createUrlRequest ( ) ) ;
217217 expect ( screen . getByTestId ( "elicitation-request" ) ) . toBeInTheDocument ( ) ;
218218 expect (
219219 screen . getByText ( "Please complete authentication" ) ,
220220 ) . toBeInTheDocument ( ) ;
221- const link = screen . getByRole ( "link" , {
222- name : "https://example.com/auth" ,
223- } ) ;
224- expect ( link ) . toHaveAttribute ( "href" , "https://example.com/auth" ) ;
225- expect ( link ) . toHaveAttribute ( "target" , "_blank" ) ;
226- expect ( link ) . toHaveAttribute ( "rel" , "noopener noreferrer" ) ;
221+ expect ( screen . queryByRole ( "link" ) ) . not . toBeInTheDocument ( ) ;
227222 } ) ;
228223
229- it ( "should render Open URL, Decline, and Cancel buttons" , ( ) => {
224+ it ( "should render Open URL, Accept, Decline, and Cancel buttons" , ( ) => {
230225 renderElicitationRequest ( createUrlRequest ( ) ) ;
231226 expect (
232227 screen . getByRole ( "button" , { name : / o p e n u r l / i } ) ,
233228 ) . toBeInTheDocument ( ) ;
229+ expect (
230+ screen . getByRole ( "button" , { name : / a c c e p t / i } ) ,
231+ ) . toBeInTheDocument ( ) ;
234232 expect (
235233 screen . getByRole ( "button" , { name : / d e c l i n e / i } ) ,
236234 ) . toBeInTheDocument ( ) ;
@@ -244,7 +242,20 @@ describe("ElicitationRequest", () => {
244242 expect ( screen . queryByTestId ( "dynamic-json-form" ) ) . not . toBeInTheDocument ( ) ;
245243 } ) ;
246244
247- it ( "should call window.open and resolve with accept when Open URL is clicked" , async ( ) => {
245+ it ( "should show consent dialog with URL as text when Open URL is clicked" , async ( ) => {
246+ renderElicitationRequest ( createUrlRequest ( ) ) ;
247+
248+ await act ( async ( ) => {
249+ fireEvent . click ( screen . getByRole ( "button" , { name : / o p e n u r l / i } ) ) ;
250+ } ) ;
251+
252+ expect ( screen . getByTestId ( "url-confirm-text" ) ) . toHaveTextContent (
253+ "https://example.com/auth" ,
254+ ) ;
255+ expect ( screen . getByText ( "Open External URL" ) ) . toBeInTheDocument ( ) ;
256+ } ) ;
257+
258+ it ( "should open URL when confirmed in consent dialog" , async ( ) => {
248259 const windowOpenSpy = jest
249260 . spyOn ( window , "open" )
250261 . mockImplementation ( ( ) => null ) ;
@@ -254,15 +265,55 @@ describe("ElicitationRequest", () => {
254265 fireEvent . click ( screen . getByRole ( "button" , { name : / o p e n u r l / i } ) ) ;
255266 } ) ;
256267
268+ await act ( async ( ) => {
269+ fireEvent . click ( screen . getByRole ( "button" , { name : / ^ o p e n $ / i } ) ) ;
270+ } ) ;
271+
257272 expect ( windowOpenSpy ) . toHaveBeenCalledWith (
258273 "https://example.com/auth" ,
259274 "_blank" ,
260275 "noopener,noreferrer" ,
261276 ) ;
262- expect ( mockOnResolve ) . toHaveBeenCalledWith ( 2 , { action : "accept" } ) ;
277+ expect ( mockOnResolve ) . not . toHaveBeenCalled ( ) ;
278+ windowOpenSpy . mockRestore ( ) ;
279+ } ) ;
280+
281+ it ( "should close consent dialog without opening URL when cancelled" , async ( ) => {
282+ const windowOpenSpy = jest
283+ . spyOn ( window , "open" )
284+ . mockImplementation ( ( ) => null ) ;
285+ renderElicitationRequest ( createUrlRequest ( ) ) ;
286+
287+ await act ( async ( ) => {
288+ fireEvent . click ( screen . getByRole ( "button" , { name : / o p e n u r l / i } ) ) ;
289+ } ) ;
290+
291+ expect ( screen . getByTestId ( "url-confirm-text" ) ) . toBeInTheDocument ( ) ;
292+
293+ await act ( async ( ) => {
294+ // The Cancel button inside the dialog
295+ const dialogButtons = screen . getAllByRole ( "button" , {
296+ name : / c a n c e l / i,
297+ } ) ;
298+ fireEvent . click ( dialogButtons [ dialogButtons . length - 1 ] ) ;
299+ } ) ;
300+
301+ expect ( windowOpenSpy ) . not . toHaveBeenCalled ( ) ;
302+ expect ( mockOnResolve ) . not . toHaveBeenCalled ( ) ;
263303 windowOpenSpy . mockRestore ( ) ;
264304 } ) ;
265305
306+ it ( "should resolve with accept and no content when Accept is clicked" , async ( ) => {
307+ renderElicitationRequest ( createUrlRequest ( ) ) ;
308+
309+ await act ( async ( ) => {
310+ fireEvent . click ( screen . getByRole ( "button" , { name : / a c c e p t / i } ) ) ;
311+ } ) ;
312+
313+ expect ( mockOnResolve ) . toHaveBeenCalledWith ( 2 , { action : "accept" } ) ;
314+ expect ( mockOnResolve . mock . calls [ 0 ] [ 1 ] ) . not . toHaveProperty ( "content" ) ;
315+ } ) ;
316+
266317 it ( "should resolve with decline when Decline is clicked" , async ( ) => {
267318 renderElicitationRequest ( createUrlRequest ( ) ) ;
268319
0 commit comments