File tree Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Original file line number Diff line number Diff line change @@ -179,6 +179,24 @@ describe('draft-js-markdown-shortcuts-plugin', () => {
179179 expect ( modifierSpy ) . to . have . been . calledOnce ( ) ;
180180 expect ( store . setEditorState ) . to . have . been . calledWith ( newEditorState ) ;
181181 } ) ;
182+ it ( 'insert new line char from code-block' , ( ) => {
183+ createMarkdownShortcutsPlugin . __Rewire__ ( 'insertText' , modifierSpy ) ; // eslint-disable-line no-underscore-dangle
184+ currentRawContentState = {
185+ entityMap : { } ,
186+ blocks : [ {
187+ key : 'item1' ,
188+ text : 'const foo = a => a' ,
189+ type : 'code-block' ,
190+ depth : 0 ,
191+ inlineStyleRanges : [ ] ,
192+ entityRanges : [ ] ,
193+ data : { }
194+ } ]
195+ } ;
196+ expect ( subject ( ) ) . to . equal ( 'handled' ) ;
197+ expect ( modifierSpy ) . to . have . been . calledOnce ( ) ;
198+ expect ( store . setEditorState ) . to . have . been . calledWith ( newEditorState ) ;
199+ } ) ;
182200 } ) ;
183201 describe ( 'blockStyleFn' , ( ) => {
184202 let type ;
Original file line number Diff line number Diff line change 1+ import { expect } from 'chai' ;
2+ import Draft , { EditorState , SelectionState } from 'draft-js' ;
3+ import insertText from '../insertText' ;
4+
5+ describe ( 'insertText' , ( ) => {
6+ const beforeRawContentState = {
7+ entityMap : { } ,
8+ blocks : [ {
9+ key : 'item1' ,
10+ text : 'text0' ,
11+ type : 'unstyled' ,
12+ depth : 0 ,
13+ inlineStyleRanges : [ ] ,
14+ entityRanges : [ ] ,
15+ data : { }
16+ } ]
17+ } ;
18+ const afterRawContentState = {
19+ entityMap : { } ,
20+ blocks : [ {
21+ key : 'item1' ,
22+ text : 'text01' ,
23+ type : 'unstyled' ,
24+ depth : 0 ,
25+ inlineStyleRanges : [ ] ,
26+ entityRanges : [ ] ,
27+ data : { }
28+ } ]
29+ } ;
30+ const selection = new SelectionState ( {
31+ anchorKey : 'item1' ,
32+ anchorOffset : 5 ,
33+ focusKey : 'item1' ,
34+ focusOffset : 5 ,
35+ isBackward : false ,
36+ hasFocus : true
37+ } ) ;
38+ const contentState = Draft . convertFromRaw ( beforeRawContentState ) ;
39+ const editorState = EditorState . forceSelection (
40+ EditorState . createWithContent ( contentState ) , selection ) ;
41+ it ( 'insert text' , ( ) => {
42+ const newEditorState = insertText ( editorState , '1' ) ;
43+ expect ( newEditorState ) . not . to . equal ( editorState ) ;
44+ expect (
45+ Draft . convertToRaw ( newEditorState . getCurrentContent ( ) )
46+ ) . to . deep . equal (
47+ afterRawContentState
48+ ) ;
49+ } ) ;
50+ } ) ;
You can’t perform that action at this time.
0 commit comments