@@ -4,7 +4,11 @@ import {
44 CheckableListItemUtils ,
55} from "draft-js-checkable-list-item" ;
66
7- import { defaultInlineWhitelist , defaultBlockWhitelist } from "../constants" ;
7+ import {
8+ defaultInlineWhitelist ,
9+ defaultBlockWhitelist ,
10+ ENTITY_TYPE ,
11+ } from "../constants" ;
812
913import { Map , List } from "immutable" ;
1014import createMarkdownPlugin from "../" ;
@@ -224,37 +228,6 @@ describe("draft-js-markdown-plugin", () => {
224228 expect ( store . setEditorState ) . toHaveBeenCalledWith ( newEditorState ) ;
225229 } ) ;
226230
227- it ( "adds list item and transforms markdown" , ( ) => {
228- // createMarkdownPlugin.__Rewire__("leaveList", modifierSpy); // eslint-disable-line no-underscore-dangle
229- currentRawContentState = {
230- entityMap : { } ,
231- blocks : [
232- {
233- key : "item1" ,
234- text : "**some bold text**" ,
235- type : "unordered-list-item" ,
236- depth : 0 ,
237- inlineStyleRanges : [ ] ,
238- entityRanges : [ ] ,
239- data : { } ,
240- } ,
241- ] ,
242- } ;
243- currentSelectionState = currentSelectionState . merge ( {
244- focusOffset : 18 ,
245- anchorOffset : 18 ,
246- } ) ;
247- expect ( subject ( ) ) . toBe ( "handled" ) ;
248- // expect(modifierSpy).toHaveBeenCalledTimes(1);
249- expect ( store . setEditorState ) . toHaveBeenCalledTimes ( 1 ) ;
250- newEditorState = store . setEditorState . mock . calls [ 0 ] [ 0 ] ;
251- const newRawContentState = Draft . convertToRaw (
252- newEditorState . getCurrentContent ( )
253- ) ;
254- expect ( newRawContentState . blocks . length ) . toBe ( 2 ) ;
255- expect ( newEditorState . getCurrentInlineStyle ( ) . size ) . toBe ( 0 ) ;
256- } ) ;
257-
258231 const emptyBlockTypes = [
259232 "blockquote" ,
260233 "header-one" ,
@@ -333,7 +306,6 @@ describe("draft-js-markdown-plugin", () => {
333306 event = new window . KeyboardEvent ( "keydown" , props ) ;
334307 } ) ;
335308 it ( "inserts new empty block" , ( ) => {
336- createMarkdownPlugin . __Rewire__ ( "insertEmptyBlock" , modifierSpy ) ; // eslint-disable-line no-underscore-dangle
337309 const text = "Hello" ;
338310 currentRawContentState = {
339311 entityMap : { } ,
@@ -349,9 +321,8 @@ describe("draft-js-markdown-plugin", () => {
349321 } ,
350322 ] ,
351323 } ;
352- expect ( subject ( ) ) . toBe ( "handled" ) ;
353- expect ( modifierSpy ) . toHaveBeenCalledTimes ( 1 ) ;
354- expect ( store . setEditorState ) . toHaveBeenCalledWith ( newEditorState ) ;
324+ expect ( subject ( ) ) . toBe ( "not-handled" ) ;
325+ expect ( store . setEditorState ) . not . toHaveBeenCalled ( ) ;
355326 } ) ;
356327 } ) ;
357328 } ) ;
@@ -516,14 +487,33 @@ describe("draft-js-markdown-plugin", () => {
516487 ] ,
517488 } ;
518489 } ) ;
519- [ "handleImage" , "handleLink" ] . forEach ( modifier => {
490+ [ "handleImage" ] . forEach ( modifier => {
520491 describe ( modifier , ( ) => {
521492 beforeEach ( ( ) => {
522493 createMarkdownPlugin . __Rewire__ ( modifier , modifierSpy ) ; // eslint-disable-line no-underscore-dangle
523494 } ) ;
524495 it ( "returns handled" , ( ) => {
525496 expect ( subject ( ) ) . toBe ( "handled" ) ;
526- expect ( modifierSpy ) . toHaveBeenCalledWith ( currentEditorState , " " ) ;
497+ expect ( modifierSpy ) . toHaveBeenCalledWith (
498+ currentEditorState ,
499+ " " ,
500+ ENTITY_TYPE . IMAGE
501+ ) ;
502+ } ) ;
503+ } ) ;
504+ } ) ;
505+ [ "handleLink" ] . forEach ( modifier => {
506+ describe ( modifier , ( ) => {
507+ beforeEach ( ( ) => {
508+ createMarkdownPlugin . __Rewire__ ( modifier , modifierSpy ) ; // eslint-disable-line no-underscore-dangle
509+ } ) ;
510+ it ( "returns handled" , ( ) => {
511+ expect ( subject ( ) ) . toBe ( "handled" ) ;
512+ expect ( modifierSpy ) . toHaveBeenCalledWith (
513+ currentEditorState ,
514+ " " ,
515+ ENTITY_TYPE . LINK
516+ ) ;
527517 } ) ;
528518 } ) ;
529519 } ) ;
@@ -615,6 +605,27 @@ describe("draft-js-markdown-plugin", () => {
615605 expect ( subject ( ) ) . toBe ( "not-handled" ) ;
616606 } ) ;
617607 } ) ;
608+ it ( "handles new code block on space" , ( ) => {
609+ createMarkdownPlugin . __Rewire__ ( "handleNewCodeBlock" , modifierSpy ) ; // eslint-disable-line no-underscore-dangle
610+ currentRawContentState = {
611+ entityMap : { } ,
612+ blocks : [
613+ {
614+ key : "item1" ,
615+ text : "```" ,
616+ type : "unstyled" ,
617+ depth : 0 ,
618+ inlineStyleRanges : [ ] ,
619+ entityRanges : [ ] ,
620+ data : { } ,
621+ } ,
622+ ] ,
623+ } ;
624+ character = " " ;
625+ expect ( subject ( ) ) . toBe ( "handled" ) ;
626+ expect ( modifierSpy ) . toHaveBeenCalledTimes ( 1 ) ;
627+ expect ( store . setEditorState ) . toHaveBeenCalledWith ( newEditorState ) ;
628+ } ) ;
618629 } ) ;
619630 describe ( "handlePastedText" , ( ) => {
620631 let pastedText ;
0 commit comments