@@ -43,6 +43,38 @@ describe('paste-markdown', function () {
4343 assert . equal ( textarea . value , 'The examples can be found [here](https://github.com).' )
4444 } )
4545
46+ it ( 'turns pasted urls on selected text into markdown links if pasteAsPlainText is false' , function ( ) {
47+ subscription = subscribeWithOptionConfig ( subscription , textarea , false )
48+
49+ // eslint-disable-next-line i18n-text/no-en
50+ textarea . value = 'The examples can be found here.'
51+ textarea . setSelectionRange ( 26 , 30 )
52+ paste ( textarea , { 'text/plain' : 'https://github.com' } )
53+ assert . equal ( textarea . value , 'The examples can be found [here](https://github.com).' )
54+ } )
55+
56+ it ( 'turns pasted urls on selected text into markdown links if pasteAsPlainText is true and skip format flag is true' , function ( ) {
57+ subscription = subscribeWithOptionConfig ( subscription , textarea , true )
58+
59+ // eslint-disable-next-line i18n-text/no-en
60+ textarea . value = 'The examples can be found here.'
61+ textarea . setSelectionRange ( 26 , 30 )
62+ dispatchSkipFormattingKeyEvent ( textarea )
63+ paste ( textarea , { 'text/plain' : 'https://github.com' } )
64+ assert . equal ( textarea . value , 'The examples can be found [here](https://github.com).' )
65+ } )
66+
67+ it ( 'pastes as plain text on selected text if pasteAsPlainText is true' , function ( ) {
68+ subscription = subscribeWithOptionConfig ( subscription , textarea , true )
69+
70+ // eslint-disable-next-line i18n-text/no-en
71+ textarea . value = 'The examples can be found here.'
72+ textarea . setSelectionRange ( 26 , 30 )
73+ paste ( textarea , { 'text/plain' : 'https://github.com' } )
74+ // The text area will be unchanged at this stage as the paste won't be handled by our listener
75+ assert . equal ( textarea . value , 'The examples can be found here.' )
76+ } )
77+
4678 it ( 'creates a markdown link when the pasted url includes a trailing slash' , function ( ) {
4779 // eslint-disable-next-line i18n-text/no-en
4880 textarea . value = 'The examples can be found here.'
@@ -353,6 +385,12 @@ function dispatchSkipFormattingKeyEvent(textarea) {
353385 )
354386}
355387
388+ function subscribeWithOptionConfig ( subscription , textarea , pasteAsPlainText ) {
389+ // Clear the before test subscription with no config and re-subscribe with config
390+ subscription . unsubscribe ( )
391+ return subscribe ( textarea , { pasteAsPlainText} )
392+ }
393+
356394function paste ( textarea , data ) {
357395 const dataTransfer = new DataTransfer ( )
358396 for ( const key in data ) {
0 commit comments