@@ -45,7 +45,7 @@ describe('draft-js-markdown-shortcuts-plugin', () => {
4545
4646 [
4747 [ ] ,
48- [ { } ] ,
48+ [ { insertEmptyBlockOnReturnWithModifierKey : false } ]
4949 ] . forEach ( ( args ) => {
5050 beforeEach ( ( ) => {
5151 modifierSpy = sinon . spy ( ( ) => newEditorState ) ;
@@ -85,7 +85,7 @@ describe('draft-js-markdown-shortcuts-plugin', () => {
8585 subject = null ;
8686 } ) ;
8787
88- describe ( args . length === 0 ? 'without config' : 'with config' , ( ) => {
88+ describe ( args . length === 0 ? 'without config' : 'with `insertEmptyBlockOnReturnWithModifierKey: false` config' , ( ) => {
8989 beforeEach ( ( ) => {
9090 plugin = createMarkdownShortcutsPlugin ( ...args ) ;
9191 } ) ;
@@ -98,6 +98,16 @@ describe('draft-js-markdown-shortcuts-plugin', () => {
9898 expect ( plugin . store ) . to . deep . equal ( store ) ;
9999 } ) ;
100100 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+ } ;
101111 beforeEach ( ( ) => {
102112 subject = ( ) => plugin . handleReturn ( event , store . getEditorState ( ) , store ) ;
103113 } ) ;
@@ -114,9 +124,7 @@ describe('draft-js-markdown-shortcuts-plugin', () => {
114124 data : { }
115125 } ]
116126 } ;
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 ( ) ;
120128 } ) ;
121129 it ( 'leaves from list' , ( ) => {
122130 createMarkdownShortcutsPlugin . __Rewire__ ( 'leaveList' , modifierSpy ) ; // eslint-disable-line no-underscore-dangle
@@ -132,11 +140,9 @@ describe('draft-js-markdown-shortcuts-plugin', () => {
132140 data : { }
133141 } ]
134142 } ;
135- expect ( subject ( ) ) . to . equal ( 'handled' ) ;
136- expect ( modifierSpy ) . to . have . been . calledOnce ( ) ;
137- expect ( store . setEditorState ) . to . have . been . calledWith ( newEditorState ) ;
143+ expectsHandled ( ) ;
138144 } ) ;
139- const testInsertNewBlock = ( type ) => ( ) => {
145+ const testInsertNewBlock = ( type , expects ) => ( ) => {
140146 createMarkdownShortcutsPlugin . __Rewire__ ( 'insertEmptyBlock' , modifierSpy ) ; // eslint-disable-line no-underscore-dangle
141147 currentRawContentState = {
142148 entityMap : { } ,
@@ -158,13 +164,14 @@ describe('draft-js-markdown-shortcuts-plugin', () => {
158164 isBackward : false ,
159165 hasFocus : true
160166 } ) ;
161- expect ( subject ( ) ) . to . equal ( 'handled' ) ;
162- expect ( modifierSpy ) . to . have . been . calledOnce ( ) ;
163- expect ( store . setEditorState ) . to . have . been . calledWith ( newEditorState ) ;
167+ expects ( ) ;
164168 } ;
169+ const expects = args [ 0 ] && args [ 0 ] . insertEmptyBlockOnReturnWithModifierKey === false
170+ ? expectsNotHandled
171+ : expectsHandled ;
165172 [ 'one' , 'two' , 'three' , 'four' , 'five' , 'six' ] . forEach ( ( level ) => {
166173 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 ) ) ;
168175 } ) ;
169176 } ) ;
170177 [ 'ctrlKey' , 'shiftKey' , 'metaKey' , 'altKey' ] . forEach ( ( key ) => {
@@ -174,7 +181,7 @@ describe('draft-js-markdown-shortcuts-plugin', () => {
174181 props [ key ] = true ;
175182 event = new window . KeyboardEvent ( 'keydown' , props ) ;
176183 } ) ;
177- it ( 'inserts new empty block' , testInsertNewBlock ( 'blockquote' ) ) ;
184+ it ( 'inserts new empty block' , testInsertNewBlock ( 'blockquote' , expects ) ) ;
178185 } ) ;
179186 } ) ;
180187 it ( 'handles new code block' , ( ) => {
0 commit comments