@@ -126,6 +126,7 @@ describe('MDCTooltipFoundation', () => {
126126 'setAnchorAttribute' ,
127127 'isRTL' ,
128128 'anchorContainsElement' ,
129+ 'tooltipContainsElement' ,
129130 'registerEventHandler' ,
130131 'deregisterEventHandler' ,
131132 'registerDocumentEventHandler' ,
@@ -634,13 +635,140 @@ describe('MDCTooltipFoundation', () => {
634635 expectHideToBeCalled ( foundation , mockAdapter ) ;
635636 } ) ;
636637
637- it ( `#handleAnchorBlur hides the tooltip immediately` , ( ) => {
638- const { foundation , mockAdapter } = setUpFoundationTest ( MDCTooltipFoundation ) ;
639- foundation . show ( ) ;
640- foundation . handleAnchorBlur ( ) ;
638+ it ( `#handleAnchorBlur hides the tooltip immediately for plain tooltips` ,
639+ ( ) => {
640+ const { foundation, mockAdapter } =
641+ setUpFoundationTest ( MDCTooltipFoundation ) ;
641642
642- expectHideToBeCalled ( foundation , mockAdapter ) ;
643- } ) ;
643+ foundation . show ( ) ;
644+ foundation . handleAnchorBlur ( ) ;
645+
646+ expectHideToBeCalled ( foundation , mockAdapter ) ;
647+ } ) ;
648+
649+ it ( `#handleAnchorBlur hides the tooltip immediately when focus changes to non-HTMLElement related target for default rich tooltips` ,
650+ ( ) => {
651+ const { foundation, mockAdapter} =
652+ setUpFoundationTest ( MDCTooltipFoundation ) ;
653+ mockAdapter . hasClass . withArgs ( CssClasses . RICH ) . and . returnValue ( true ) ;
654+ foundation . init ( ) ;
655+
656+ foundation . show ( ) ;
657+ foundation . handleAnchorBlur ( { } ) ;
658+
659+ expectHideToBeCalled ( foundation , mockAdapter ) ;
660+ } ) ;
661+
662+ it ( `#handleAnchorBlur hides the tooltip immediately when focus changes to related target not within tooltip for default rich tooltips` ,
663+ ( ) => {
664+ const { foundation, mockAdapter} =
665+ setUpFoundationTest ( MDCTooltipFoundation ) ;
666+ mockAdapter . hasClass . withArgs ( CssClasses . RICH ) . and . returnValue ( true ) ;
667+ mockAdapter . tooltipContainsElement . and . returnValue ( false ) ;
668+ foundation . init ( ) ;
669+
670+ const mockFocusEvent = { relatedTarget : document . createElement ( 'div' ) } ;
671+ foundation . show ( ) ;
672+ foundation . handleAnchorBlur ( mockFocusEvent ) ;
673+
674+ expectHideToBeCalled ( foundation , mockAdapter ) ;
675+ } ) ;
676+
677+ it ( `#handleAnchorBlur doesn't hide the tooltip when focus changes to related target not within tooltip for default rich tooltips` ,
678+ ( ) => {
679+ const { foundation, mockAdapter} =
680+ setUpFoundationTest ( MDCTooltipFoundation ) ;
681+ mockAdapter . hasClass . withArgs ( CssClasses . RICH ) . and . returnValue ( true ) ;
682+ mockAdapter . tooltipContainsElement . and . returnValue ( true ) ;
683+ foundation . init ( ) ;
684+
685+ const mockFocusEvent = { relatedTarget : document . createElement ( 'div' ) } ;
686+ foundation . show ( ) ;
687+ foundation . handleAnchorBlur ( mockFocusEvent ) ;
688+
689+ expect ( mockAdapter . setAnchorAttribute )
690+ . not . toHaveBeenCalledWith ( 'aria-expanded' , 'false' ) ;
691+ expect ( mockAdapter . setAttribute )
692+ . not . toHaveBeenCalledWith ( 'aria-hidden' , 'true' ) ;
693+ expect ( mockAdapter . addClass ) . not . toHaveBeenCalledWith ( CssClasses . HIDE ) ;
694+ expect ( mockAdapter . addClass )
695+ . not . toHaveBeenCalledWith ( CssClasses . HIDE_TRANSITION ) ;
696+ expect ( mockAdapter . removeClass )
697+ . not . toHaveBeenCalledWith ( CssClasses . SHOWN ) ;
698+ expect ( mockAdapter . deregisterDocumentEventHandler )
699+ . not . toHaveBeenCalledWith ( 'click' , jasmine . any ( Function ) ) ;
700+ expect ( mockAdapter . deregisterDocumentEventHandler )
701+ . not . toHaveBeenCalledWith ( 'keydown' , jasmine . any ( Function ) ) ;
702+ expect ( mockAdapter . deregisterWindowEventHandler )
703+ . not . toHaveBeenCalledWith ( 'scroll' , jasmine . any ( Function ) ) ;
704+ expect ( mockAdapter . deregisterWindowEventHandler )
705+ . not . toHaveBeenCalledWith ( 'resize' , jasmine . any ( Function ) ) ;
706+ } ) ;
707+
708+ it ( `#handleAnchorBlur hides the tooltip immediately when focus changes to non-HTMLElement related target for persistent rich tooltips` ,
709+ ( ) => {
710+ const { foundation, mockAdapter} =
711+ setUpFoundationTest ( MDCTooltipFoundation ) ;
712+ mockAdapter . hasClass . withArgs ( CssClasses . RICH ) . and . returnValue ( true ) ;
713+ mockAdapter . getAttribute . withArgs ( attributes . PERSISTENT )
714+ . and . returnValue ( 'true' ) ;
715+ foundation . init ( ) ;
716+
717+ foundation . show ( ) ;
718+ foundation . handleAnchorBlur ( { } ) ;
719+
720+ expectHideToBeCalled ( foundation , mockAdapter ) ;
721+ } ) ;
722+
723+ it ( `#handleAnchorBlur hides the tooltip immediately when focus changes to related target not within tooltip for persistent rich tooltips` ,
724+ ( ) => {
725+ const { foundation, mockAdapter} =
726+ setUpFoundationTest ( MDCTooltipFoundation ) ;
727+ mockAdapter . hasClass . withArgs ( CssClasses . RICH ) . and . returnValue ( true ) ;
728+ mockAdapter . getAttribute . withArgs ( attributes . PERSISTENT )
729+ . and . returnValue ( 'true' ) ;
730+ mockAdapter . tooltipContainsElement . and . returnValue ( false ) ;
731+ foundation . init ( ) ;
732+
733+ const mockFocusEvent = { relatedTarget : document . createElement ( 'div' ) } ;
734+ foundation . show ( ) ;
735+ foundation . handleAnchorBlur ( mockFocusEvent ) ;
736+
737+ expectHideToBeCalled ( foundation , mockAdapter ) ;
738+ } ) ;
739+
740+ it ( `#handleAnchorBlur doesn't hide the tooltip when focus changes to related target within tooltip for persistent rich tooltips` ,
741+ ( ) => {
742+ const { foundation, mockAdapter} =
743+ setUpFoundationTest ( MDCTooltipFoundation ) ;
744+ mockAdapter . hasClass . withArgs ( CssClasses . RICH ) . and . returnValue ( true ) ;
745+ mockAdapter . getAttribute . withArgs ( attributes . PERSISTENT )
746+ . and . returnValue ( 'true' ) ;
747+ mockAdapter . tooltipContainsElement . and . returnValue ( true ) ;
748+ foundation . init ( ) ;
749+
750+ const mockFocusEvent = { relatedTarget : document . createElement ( 'div' ) } ;
751+ foundation . show ( ) ;
752+ foundation . handleAnchorBlur ( mockFocusEvent ) ;
753+
754+ expect ( mockAdapter . setAnchorAttribute )
755+ . not . toHaveBeenCalledWith ( 'aria-expanded' , 'false' ) ;
756+ expect ( mockAdapter . setAttribute )
757+ . not . toHaveBeenCalledWith ( 'aria-hidden' , 'true' ) ;
758+ expect ( mockAdapter . addClass ) . not . toHaveBeenCalledWith ( CssClasses . HIDE ) ;
759+ expect ( mockAdapter . addClass )
760+ . not . toHaveBeenCalledWith ( CssClasses . HIDE_TRANSITION ) ;
761+ expect ( mockAdapter . removeClass )
762+ . not . toHaveBeenCalledWith ( CssClasses . SHOWN ) ;
763+ expect ( mockAdapter . deregisterDocumentEventHandler )
764+ . not . toHaveBeenCalledWith ( 'click' , jasmine . any ( Function ) ) ;
765+ expect ( mockAdapter . deregisterDocumentEventHandler )
766+ . not . toHaveBeenCalledWith ( 'keydown' , jasmine . any ( Function ) ) ;
767+ expect ( mockAdapter . deregisterWindowEventHandler )
768+ . not . toHaveBeenCalledWith ( 'scroll' , jasmine . any ( Function ) ) ;
769+ expect ( mockAdapter . deregisterWindowEventHandler )
770+ . not . toHaveBeenCalledWith ( 'resize' , jasmine . any ( Function ) ) ;
771+ } ) ;
644772
645773 it ( `#handleDocumentClick hides the tooltip immediately` , ( ) => {
646774 const { foundation, mockAdapter} = setUpFoundationTest ( MDCTooltipFoundation ) ;
0 commit comments