@@ -4,6 +4,7 @@ import { u } from 'unist-builder';
44import { render , screen } from '@testing-library/react' ;
55import {
66 htmlToTextPlugin ,
7+ imageToLink ,
78 keepLineBreaksPlugin ,
89 plusPlusToEmphasis ,
910} from '../remarkPlugins' ;
@@ -449,18 +450,53 @@ describe('plusPlusToEmphasis', () => {
449450 } ;
450451
451452 it ( '++…++ renders as <ins> and ignores code/links' , ( ) => {
452- renderTextPlusPlus ( 'This is ++inserted++ and `++not++` and [x](y) ++also++' ) ;
453+ renderTextPlusPlus (
454+ 'This is ++inserted++ and `++not++` and [x](https://octodex.github.com/images/minion.png) ++also++' ,
455+ ) ;
453456 expect ( screen . getByText ( 'inserted' , { selector : 'ins' } ) ) . toBeInTheDocument ( ) ;
454457 expect ( screen . getByText ( '++not++' , { selector : 'code' } ) ) . toBeInTheDocument ( ) ;
455458 // link text exists; its inner text shouldn't be transformed
456- // expect(screen.getByRole('link', { name: 'x' })).toBeInTheDocument();
459+ expect ( screen . getByRole ( 'link' , { name : 'x' } ) ) . toBeInTheDocument ( ) ;
457460 } ) ;
458461
459462 it ( 'does not render ++…++ as <ins> if not present' , ( ) => {
460- renderTextPlusPlus ( 'This is ++inserted++ and `++not++` and [x](y) ++also++' , false ) ;
463+ renderTextPlusPlus (
464+ 'This is ++inserted++ and `++not++` and [x](https://octodex.github.com/images/minion.png) ++also++' ,
465+ false ,
466+ ) ;
461467 expect ( screen . queryByText ( 'inserted' , { selector : 'ins' } ) ) . not . toBeInTheDocument ( ) ;
462468 expect ( screen . getByText ( '++not++' , { selector : 'code' } ) ) . toBeInTheDocument ( ) ;
463469 // link text exists; its inner text shouldn't be transformed
464- // expect(screen.getByRole('link', { name: 'x' })).toBeInTheDocument();
470+ expect ( screen . getByRole ( 'link' , { name : 'x' } ) ) . toBeInTheDocument ( ) ;
471+ } ) ;
472+ } ) ;
473+
474+ describe ( 'imageToLink' , ( ) => {
475+ const renderImageToLink = ( text , withPlugin = true ) => {
476+ const Markdown = renderText (
477+ text ,
478+ { } ,
479+ { getRemarkPlugins : ( ) => ( withPlugin ? [ imageToLink ] : [ ] ) } ,
480+ ) ;
481+ return render ( Markdown ) . container ;
482+ } ;
483+
484+ it ( 'converts image link to anchor link' , ( ) => {
485+ renderImageToLink ( 'Before  After' ) ;
486+ expect (
487+ screen . getByRole ( 'link' , { name : 'https://octodex.github.com/images/minion.png' } ) ,
488+ ) . toBeInTheDocument ( ) ;
489+ } ) ;
490+
491+ it ( 'does not convert image link to anchor link if plugin is missing' , ( ) => {
492+ renderImageToLink (
493+ 'Before  After' ,
494+ false ,
495+ ) ;
496+ expect (
497+ screen . queryByRole ( 'link' , {
498+ name : 'https://octodex.github.com/images/minion.png' ,
499+ } ) ,
500+ ) . not . toBeInTheDocument ( ) ;
465501 } ) ;
466502} ) ;
0 commit comments