@@ -420,33 +420,48 @@ test.describe('inline code', () => {
420420} )
421421
422422test . describe ( 'links' , ( ) => {
423+ const TestRouteComponent = {
424+ template : '<div />' ,
425+ }
426+
423427 const testLink = ( key : string , { text, href = text , name = text } ) => {
424428 test ( key , async ( { mount } ) => {
425429 const component = await mount ( NcRichText , {
426430 props : {
427431 text,
428432 useExtendedMarkdown : true ,
429433 } ,
434+ hooksConfig : {
435+ routes : [ { path : '/world' , component : TestRouteComponent } ] ,
436+ } ,
430437 } )
431438 await expect ( component . getByRole ( 'link' , { name } ) )
432439 . toHaveAttribute ( 'href' , href )
433440 } )
434441 }
435442 testLink ( 'autolink' , { text : 'https://autolink.me' } )
436- testLink ( 'relative link' , { text : '[hello](world)' , href : 'world' , name : 'hello' } )
443+ testLink ( 'relative link' , { text : '[hello](/ world)' , href : '/ world' , name : 'hello' } )
437444 testLink ( 'absolute link' , { text : '[hello](https://nextcloud.com)' , href : 'https://nextcloud.com' , name : 'hello' } )
438445 testLink ( 'tel link' , { text : '[hello](tel:+49123456789)' , href : 'tel:+49123456789' , name : 'hello' } )
446+ testLink ( 'mailto link' , { text : '[hello](mailto:+49123456789)' , href : 'mailto:+49123456789' , name : 'hello' } )
439447
440- test ( 'no link to unknown protocols' , async ( { mount } ) => {
441- const component = await mount ( NcRichText , {
442- props : {
443- text : '[link](other:proto)' ,
444- useExtendedMarkdown : true ,
445- } ,
448+ const testNoLink = ( key : string , { text, name = text } ) => {
449+ test ( key , async ( { mount } ) => {
450+ const component = await mount ( NcRichText , {
451+ props : {
452+ text,
453+ useExtendedMarkdown : true ,
454+ } ,
455+ hooksConfig : {
456+ routes : [ { path : '/world' , component : TestRouteComponent } ] ,
457+ } ,
458+ } )
459+ await expect ( component ) . toContainText ( name )
460+ await expect ( component . getByText ( name ) ) . not . toHaveRole ( 'link' )
446461 } )
447- await expect ( component ) . toContainText ( 'link' )
448- await expect ( component . getByText ( ' link' ) ) . not . toHaveRole ( 'link' )
449- } )
462+ }
463+ testNoLink ( 'no link to unknown protocols' , { text : '[hello](other:proto)' , name : 'hello' } )
464+ testNoLink ( 'no link to unresolved relative link (by router)' , { text : '[hello](world)' , name : 'hello' } )
450465} )
451466
452467test . describe ( 'multiline code' , ( ) => {
0 commit comments