@@ -651,28 +651,62 @@ describe("DraftailEditor", () => {
651651 RichUtils . handleKeyCommand . mockRestore ( ) ;
652652 } ) ;
653653
654- it ( "entity type" , ( ) => {
655- expect (
656- shallowNoLifecycle ( < DraftailEditor /> )
657- . instance ( )
658- . handleKeyCommand ( "LINK" ) ,
659- ) . toBe ( "handled" ) ;
654+ it ( "entity type - active" , ( ) => {
655+ const wrapper = shallowNoLifecycle (
656+ < DraftailEditor entityTypes = { [ { type : "LINK" , source : ( ) => null } ] } /> ,
657+ ) . instance ( ) ;
658+ jest . spyOn ( wrapper , "onRequestSource" ) ;
659+ expect ( wrapper . handleKeyCommand ( "LINK" ) ) . toBe ( "handled" ) ;
660+ expect ( wrapper . onRequestSource ) . toHaveBeenCalled ( ) ;
660661 } ) ;
661662
662- it ( "block type" , ( ) => {
663- expect (
664- shallowNoLifecycle ( < DraftailEditor /> )
665- . instance ( )
666- . handleKeyCommand ( "header-one" ) ,
667- ) . toBe ( "handled" ) ;
663+ it ( "entity type - inactive" , ( ) => {
664+ const wrapper = shallowNoLifecycle ( < DraftailEditor /> ) . instance ( ) ;
665+ jest . spyOn ( wrapper , "onRequestSource" ) ;
666+ expect ( wrapper . handleKeyCommand ( "LINK" ) ) . toBe ( "handled" ) ;
667+ expect ( wrapper . onRequestSource ) . not . toHaveBeenCalled ( ) ;
668668 } ) ;
669669
670- it ( "inline style" , ( ) => {
671- expect (
672- shallowNoLifecycle ( < DraftailEditor /> )
673- . instance ( )
674- . handleKeyCommand ( "BOLD" ) ,
675- ) . toBe ( "handled" ) ;
670+ it ( "block type - active" , ( ) => {
671+ const wrapper = shallowNoLifecycle (
672+ < DraftailEditor blockTypes = { [ { type : "header-one" } ] } /> ,
673+ ) . instance ( ) ;
674+ jest . spyOn ( wrapper , "toggleBlockType" ) ;
675+ expect ( wrapper . handleKeyCommand ( "header-one" ) ) . toBe ( "handled" ) ;
676+ expect ( wrapper . toggleBlockType ) . toHaveBeenCalled ( ) ;
677+ } ) ;
678+
679+ it ( "block type - inactive" , ( ) => {
680+ const wrapper = shallowNoLifecycle ( < DraftailEditor /> ) . instance ( ) ;
681+ jest . spyOn ( wrapper , "toggleBlockType" ) ;
682+ expect ( wrapper . handleKeyCommand ( "header-one" ) ) . toBe ( "handled" ) ;
683+ expect ( wrapper . toggleBlockType ) . not . toHaveBeenCalled ( ) ;
684+ } ) ;
685+
686+ it ( "inline style - active" , ( ) => {
687+ const wrapper = shallowNoLifecycle (
688+ < DraftailEditor inlineStyles = { [ { type : "BOLD" } ] } /> ,
689+ ) . instance ( ) ;
690+ jest . spyOn ( wrapper , "toggleInlineStyle" ) ;
691+ expect ( wrapper . handleKeyCommand ( "BOLD" ) ) . toBe ( "handled" ) ;
692+ expect ( wrapper . toggleInlineStyle ) . toHaveBeenCalled ( ) ;
693+ } ) ;
694+
695+ it ( "inline style - inactive" , ( ) => {
696+ const wrapper = shallowNoLifecycle ( < DraftailEditor /> ) . instance ( ) ;
697+ jest . spyOn ( wrapper , "toggleInlineStyle" ) ;
698+ expect ( wrapper . handleKeyCommand ( "BOLD" ) ) . toBe ( "handled" ) ;
699+ expect ( wrapper . toggleInlineStyle ) . not . toHaveBeenCalled ( ) ;
700+ } ) ;
701+
702+ it ( "draft-js defaults" , ( ) => {
703+ const wrapper = shallowNoLifecycle ( < DraftailEditor /> ) . instance ( ) ;
704+ jest . spyOn ( wrapper , "toggleInlineStyle" ) ;
705+ expect ( wrapper . handleKeyCommand ( "bold" ) ) . toBe ( "handled" ) ;
706+ expect ( wrapper . handleKeyCommand ( "italic" ) ) . toBe ( "handled" ) ;
707+ expect ( wrapper . handleKeyCommand ( "underline" ) ) . toBe ( "handled" ) ;
708+ expect ( wrapper . handleKeyCommand ( "code" ) ) . toBe ( "handled" ) ;
709+ expect ( wrapper . toggleInlineStyle ) . not . toHaveBeenCalled ( ) ;
676710 } ) ;
677711
678712 describe ( "delete" , ( ) => {
0 commit comments