@@ -17,9 +17,20 @@ describe('draft-js-markdown-shortcuts-plugin', () => {
1717 createMarkdownShortcutsPlugin . __ResetDependency__ ( 'handleLink' ) ;
1818 createMarkdownShortcutsPlugin . __ResetDependency__ ( 'handleImage' ) ;
1919 createMarkdownShortcutsPlugin . __ResetDependency__ ( 'leaveList' ) ;
20+ createMarkdownShortcutsPlugin . __ResetDependency__ ( 'changeCurrentBlockType' ) ;
21+ createMarkdownShortcutsPlugin . __ResetDependency__ ( 'replaceText' ) ;
22+ createMarkdownShortcutsPlugin . __ResetDependency__ ( 'checkReturnForState' ) ;
2023 /* eslint-enable no-underscore-dangle */
2124 } ) ;
2225
26+ const createEditorState = ( rawContent , rawSelection ) => {
27+ const contentState = Draft . convertFromRaw ( rawContent ) ;
28+ return EditorState . forceSelection (
29+ EditorState . createWithContent ( contentState ) ,
30+ rawSelection
31+ ) ;
32+ } ;
33+
2334 let plugin ;
2435 let store ;
2536 let currentEditorState ;
@@ -67,10 +78,7 @@ describe('draft-js-markdown-shortcuts-plugin', () => {
6778 store = {
6879 setEditorState : sinon . spy ( ) ,
6980 getEditorState : sinon . spy ( ( ) => {
70- const contentState = Draft . convertFromRaw ( currentRawContentState ) ;
71- currentEditorState = EditorState . forceSelection (
72- EditorState . createWithContent ( contentState ) ,
73- currentSelectionState ) ;
81+ currentEditorState = createEditorState ( currentRawContentState , currentSelectionState ) ;
7482 return currentEditorState ;
7583 } )
7684 } ;
@@ -179,6 +187,23 @@ describe('draft-js-markdown-shortcuts-plugin', () => {
179187 expect ( modifierSpy ) . to . have . been . calledOnce ( ) ;
180188 expect ( store . setEditorState ) . to . have . been . calledWith ( newEditorState ) ;
181189 } ) ;
190+ it ( 'handle code block closing' , ( ) => {
191+ createMarkdownShortcutsPlugin . __Rewire__ ( 'changeCurrentBlockType' , modifierSpy ) ; // eslint-disable-line no-underscore-dangle
192+ currentRawContentState = {
193+ entityMap : { } ,
194+ blocks : [ {
195+ key : 'item1' ,
196+ text : 'foo\n```' ,
197+ type : 'code-block' ,
198+ depth : 0 ,
199+ inlineStyleRanges : [ ] ,
200+ entityRanges : [ ] ,
201+ data : { }
202+ } ]
203+ } ;
204+ expect ( subject ( ) ) . to . equal ( 'handled' ) ;
205+ expect ( modifierSpy ) . to . have . been . calledOnce ( ) ;
206+ } ) ;
182207 it ( 'insert new line char from code-block' , ( ) => {
183208 createMarkdownShortcutsPlugin . __Rewire__ ( 'insertText' , modifierSpy ) ; // eslint-disable-line no-underscore-dangle
184209 currentRawContentState = {
@@ -311,6 +336,7 @@ describe('draft-js-markdown-shortcuts-plugin', () => {
311336 beforeEach ( ( ) => {
312337 pastedText = `_hello world_
313338 Hello` ;
339+ html = undefined ;
314340 subject = ( ) => plugin . handlePastedText ( pastedText , html , store ) ;
315341 } ) ;
316342 [
@@ -349,6 +375,42 @@ describe('draft-js-markdown-shortcuts-plugin', () => {
349375 expect ( modifierSpy ) . to . have . been . calledWith ( currentEditorState , 'hello' ) ;
350376 } ) ;
351377 } ) ;
378+ describe ( 'pasted just text with new line code' , ( ) => {
379+ beforeEach ( ( ) => {
380+ pastedText = 'hello\nworld' ;
381+ const rawContentState = {
382+ entityMap : { } ,
383+ blocks : [ {
384+ key : 'item1' ,
385+ text : '' ,
386+ type : 'unstyled' ,
387+ depth : 0 ,
388+ inlineStyleRanges : [ ] ,
389+ entityRanges : [ ] ,
390+ data : { }
391+ } ]
392+ } ;
393+ const otherRawContentState = {
394+ entityMap : { } ,
395+ blocks : [ {
396+ key : 'item2' ,
397+ text : 'H1' ,
398+ type : 'header-one' ,
399+ depth : 0 ,
400+ inlineStyleRanges : [ ] ,
401+ entityRanges : [ ] ,
402+ data : { }
403+ } ]
404+ } ;
405+ /* eslint-disable no-underscore-dangle */
406+ createMarkdownShortcutsPlugin . __Rewire__ ( 'replaceText' , ( ) => createEditorState ( rawContentState , currentSelectionState ) ) ;
407+ createMarkdownShortcutsPlugin . __Rewire__ ( 'checkReturnForState' , ( ) => createEditorState ( otherRawContentState , currentSelectionState ) ) ;
408+ /* eslint-enable no-underscore-dangle */
409+ } ) ;
410+ it ( 'return handled' , ( ) => {
411+ expect ( subject ( ) ) . to . equal ( 'handled' ) ;
412+ } ) ;
413+ } ) ;
352414 describe ( 'passed `html` argument' , ( ) => {
353415 beforeEach ( ( ) => {
354416 pastedText = '# hello' ;
0 commit comments