@@ -10,53 +10,60 @@ describe('insertEmptyBlock', () => {
1010 after ( ( ) => {
1111 Draft . genKey . restore ( ) ;
1212 } ) ;
13- const firstBlock = {
14- key : 'item1' ,
15- text : 'asdf' ,
16- type : 'unstyled' ,
17- depth : 0 ,
18- inlineStyleRanges : [ {
19- length : 2 ,
20- offset : 1 ,
21- style : 'ITALIC'
22- } ] ,
23- entityRanges : [ ] ,
24- data : { foo : 'bar' }
25- } ;
26- const beforeRawContentState = {
27- entityMap : { } ,
28- blocks : [ firstBlock ]
29- } ;
30- const afterRawContentState = {
31- entityMap : { } ,
32- blocks : [ firstBlock , {
33- key : 'item2' ,
34- text : '' ,
35- type : 'header-one' ,
13+ const testInsertEmptyBlock = ( ...args ) => ( ) => {
14+ const [ type = 'unstyled' , data = { } ] = args ;
15+ const firstBlock = {
16+ key : 'item1' ,
17+ text : 'asdf' ,
18+ type : 'unstyled' ,
3619 depth : 0 ,
37- inlineStyleRanges : [ ] ,
20+ inlineStyleRanges : [ {
21+ length : 2 ,
22+ offset : 1 ,
23+ style : 'ITALIC'
24+ } ] ,
3825 entityRanges : [ ] ,
39- data : { bar : 'baz' }
40- } ]
26+ data : { foo : 'bar' }
27+ } ;
28+ const beforeRawContentState = {
29+ entityMap : { } ,
30+ blocks : [ firstBlock ]
31+ } ;
32+ const afterRawContentState = {
33+ entityMap : { } ,
34+ blocks : [ firstBlock , {
35+ key : 'item2' ,
36+ text : '' ,
37+ type,
38+ depth : 0 ,
39+ inlineStyleRanges : [ ] ,
40+ entityRanges : [ ] ,
41+ data
42+ } ]
43+ } ;
44+ const contentState = Draft . convertFromRaw ( beforeRawContentState ) ;
45+ const selection = new SelectionState ( {
46+ anchorKey : 'item1' ,
47+ anchorOffset : 4 ,
48+ focusKey : 'item1' ,
49+ focusOffset : 4 ,
50+ isBackward : false ,
51+ hasFocus : true
52+ } ) ;
53+ const editorState = EditorState . forceSelection (
54+ EditorState . createWithContent ( contentState ) , selection ) ;
55+
56+ it ( 'creates new code block' , ( ) => {
57+ const newEditorState = insertEmptyBlock ( editorState , ...args ) ;
58+ expect ( newEditorState ) . not . to . equal ( editorState ) ;
59+ expect (
60+ Draft . convertToRaw ( newEditorState . getCurrentContent ( ) )
61+ ) . to . deep . equal (
62+ afterRawContentState
63+ ) ;
64+ } ) ;
4165 } ;
42- const contentState = Draft . convertFromRaw ( beforeRawContentState ) ;
43- const selection = new SelectionState ( {
44- anchorKey : 'item1' ,
45- anchorOffset : 4 ,
46- focusKey : 'item1' ,
47- focusOffset : 4 ,
48- isBackward : false ,
49- hasFocus : true
50- } ) ;
51- const editorState = EditorState . forceSelection (
52- EditorState . createWithContent ( contentState ) , selection ) ;
53- it ( 'creates new code block' , ( ) => {
54- const newEditorState = insertEmptyBlock ( editorState , 'header-one' , { bar : 'baz' } ) ;
55- expect ( newEditorState ) . not . to . equal ( editorState ) ;
56- expect (
57- Draft . convertToRaw ( newEditorState . getCurrentContent ( ) )
58- ) . to . deep . equal (
59- afterRawContentState
60- ) ;
61- } ) ;
66+
67+ describe ( 'with arguments' , testInsertEmptyBlock ( 'header-one' , { bar : 'baz' } ) ) ;
68+ describe ( 'without arguments' , testInsertEmptyBlock ( ) ) ;
6269} ) ;
0 commit comments