@@ -45,7 +45,7 @@ describe('draft-js-markdown-shortcuts-plugin', () => {
45
45
46
46
[
47
47
[ ] ,
48
- [ { } ] ,
48
+ [ { insertEmptyBlockOnReturnWithModifierKey : false } ]
49
49
] . forEach ( ( args ) => {
50
50
beforeEach ( ( ) => {
51
51
modifierSpy = sinon . spy ( ( ) => newEditorState ) ;
@@ -85,7 +85,7 @@ describe('draft-js-markdown-shortcuts-plugin', () => {
85
85
subject = null ;
86
86
} ) ;
87
87
88
- describe ( args . length === 0 ? 'without config' : 'with config' , ( ) => {
88
+ describe ( args . length === 0 ? 'without config' : 'with `insertEmptyBlockOnReturnWithModifierKey: false` config' , ( ) => {
89
89
beforeEach ( ( ) => {
90
90
plugin = createMarkdownShortcutsPlugin ( ...args ) ;
91
91
} ) ;
@@ -98,6 +98,16 @@ describe('draft-js-markdown-shortcuts-plugin', () => {
98
98
expect ( plugin . store ) . to . deep . equal ( store ) ;
99
99
} ) ;
100
100
describe ( 'handleReturn' , ( ) => {
101
+ const expectsHandled = ( ) => {
102
+ expect ( subject ( ) ) . to . equal ( 'handled' ) ;
103
+ expect ( modifierSpy ) . to . have . been . calledOnce ( ) ;
104
+ expect ( store . setEditorState ) . to . have . been . calledWith ( newEditorState ) ;
105
+ } ;
106
+ const expectsNotHandled = ( ) => {
107
+ expect ( subject ( ) ) . to . equal ( 'not-handled' ) ;
108
+ expect ( modifierSpy ) . not . to . have . been . calledOnce ( ) ;
109
+ expect ( store . setEditorState ) . not . to . have . been . called ( ) ;
110
+ } ;
101
111
beforeEach ( ( ) => {
102
112
subject = ( ) => plugin . handleReturn ( event , store . getEditorState ( ) , store ) ;
103
113
} ) ;
@@ -114,9 +124,7 @@ describe('draft-js-markdown-shortcuts-plugin', () => {
114
124
data : { }
115
125
} ]
116
126
} ;
117
- expect ( subject ( ) ) . to . equal ( 'not-handled' ) ;
118
- expect ( modifierSpy ) . not . to . have . been . calledOnce ( ) ;
119
- expect ( store . setEditorState ) . not . to . have . been . called ( ) ;
127
+ expectsNotHandled ( ) ;
120
128
} ) ;
121
129
it ( 'leaves from list' , ( ) => {
122
130
createMarkdownShortcutsPlugin . __Rewire__ ( 'leaveList' , modifierSpy ) ; // eslint-disable-line no-underscore-dangle
@@ -132,11 +140,9 @@ describe('draft-js-markdown-shortcuts-plugin', () => {
132
140
data : { }
133
141
} ]
134
142
} ;
135
- expect ( subject ( ) ) . to . equal ( 'handled' ) ;
136
- expect ( modifierSpy ) . to . have . been . calledOnce ( ) ;
137
- expect ( store . setEditorState ) . to . have . been . calledWith ( newEditorState ) ;
143
+ expectsHandled ( ) ;
138
144
} ) ;
139
- const testInsertNewBlock = ( type ) => ( ) => {
145
+ const testInsertNewBlock = ( type , expects ) => ( ) => {
140
146
createMarkdownShortcutsPlugin . __Rewire__ ( 'insertEmptyBlock' , modifierSpy ) ; // eslint-disable-line no-underscore-dangle
141
147
currentRawContentState = {
142
148
entityMap : { } ,
@@ -158,13 +164,14 @@ describe('draft-js-markdown-shortcuts-plugin', () => {
158
164
isBackward : false ,
159
165
hasFocus : true
160
166
} ) ;
161
- expect ( subject ( ) ) . to . equal ( 'handled' ) ;
162
- expect ( modifierSpy ) . to . have . been . calledOnce ( ) ;
163
- expect ( store . setEditorState ) . to . have . been . calledWith ( newEditorState ) ;
167
+ expects ( ) ;
164
168
} ;
169
+ const expects = args [ 0 ] && args [ 0 ] . insertEmptyBlockOnReturnWithModifierKey === false
170
+ ? expectsNotHandled
171
+ : expectsHandled ;
165
172
[ 'one' , 'two' , 'three' , 'four' , 'five' , 'six' ] . forEach ( ( level ) => {
166
173
describe ( `on header-${ level } ` , ( ) => {
167
- it ( 'inserts new empty block on end of header return' , testInsertNewBlock ( `header-${ level } ` ) ) ;
174
+ it ( 'inserts new empty block on end of header return' , testInsertNewBlock ( `header-${ level } ` , expects ) ) ;
168
175
} ) ;
169
176
} ) ;
170
177
[ 'ctrlKey' , 'shiftKey' , 'metaKey' , 'altKey' ] . forEach ( ( key ) => {
@@ -174,7 +181,7 @@ describe('draft-js-markdown-shortcuts-plugin', () => {
174
181
props [ key ] = true ;
175
182
event = new window . KeyboardEvent ( 'keydown' , props ) ;
176
183
} ) ;
177
- it ( 'inserts new empty block' , testInsertNewBlock ( 'blockquote' ) ) ;
184
+ it ( 'inserts new empty block' , testInsertNewBlock ( 'blockquote' , expects ) ) ;
178
185
} ) ;
179
186
} ) ;
180
187
it ( 'handles new code block' , ( ) => {
0 commit comments