@@ -50,6 +50,8 @@ function expectShowToBeCalled(
5050 if ( foundation . getIsRich ( ) ) {
5151 expect ( mockAdapter . setAnchorAttribute )
5252 . toHaveBeenCalledWith ( 'aria-expanded' , 'true' ) ;
53+ expect ( mockAdapter . registerEventHandler )
54+ . toHaveBeenCalledWith ( 'focusout' , jasmine . any ( Function ) ) ;
5355 if ( ! foundation . getIsPersistent ( ) ) {
5456 expect ( mockAdapter . registerEventHandler )
5557 . toHaveBeenCalledWith ( 'mouseenter' , jasmine . any ( Function ) ) ;
@@ -87,6 +89,8 @@ function expectHideToBeCalled(
8789 if ( foundation . getIsRich ( ) ) {
8890 expect ( mockAdapter . setAnchorAttribute )
8991 . toHaveBeenCalledWith ( 'aria-expanded' , 'false' ) ;
92+ expect ( mockAdapter . deregisterEventHandler )
93+ . toHaveBeenCalledWith ( 'focusout' , jasmine . any ( Function ) ) ;
9094 if ( ! foundation . getIsPersistent ( ) ) {
9195 expect ( mockAdapter . deregisterEventHandler )
9296 . toHaveBeenCalledWith ( 'mouseenter' , jasmine . any ( Function ) ) ;
@@ -116,6 +120,8 @@ function expectHideNotToBeCalled(
116120 if ( foundation . getIsRich ( ) ) {
117121 expect ( mockAdapter . setAnchorAttribute )
118122 . not . toHaveBeenCalledWith ( 'aria-expanded' , 'false' ) ;
123+ expect ( mockAdapter . deregisterEventHandler )
124+ . not . toHaveBeenCalledWith ( 'focusout' , jasmine . any ( Function ) ) ;
119125 if ( ! foundation . getIsPersistent ( ) ) {
120126 expect ( mockAdapter . deregisterEventHandler )
121127 . not . toHaveBeenCalledWith ( 'mouseenter' , jasmine . any ( Function ) ) ;
@@ -810,6 +816,59 @@ describe('MDCTooltipFoundation', () => {
810816 expect ( mockAdapter . addClass ) . not . toHaveBeenCalledWith ( CssClasses . SHOWING ) ;
811817 } ) ;
812818
819+ it ( '#handleRichTooltipFocusOut hides the tooltip immediately if there is no related target' ,
820+ ( ) => {
821+ const { foundation, mockAdapter} =
822+ setUpFoundationTestForRichTooltip ( MDCTooltipFoundation ) ;
823+
824+ foundation . show ( ) ;
825+ foundation . handleRichTooltipFocusOut ( { } ) ;
826+
827+ expectHideToBeCalled ( foundation , mockAdapter ) ;
828+ } ) ;
829+
830+ it ( '#handleRichTooltipFocusOut hides the tooltip immediately if related target is not within the anchor or the tooltip' ,
831+ ( ) => {
832+ const { foundation, mockAdapter} =
833+ setUpFoundationTestForRichTooltip ( MDCTooltipFoundation ) ;
834+
835+ foundation . show ( ) ;
836+ mockAdapter . anchorContainsElement . and . returnValue ( false ) ;
837+ mockAdapter . tooltipContainsElement . and . returnValue ( false ) ;
838+ foundation . handleRichTooltipFocusOut (
839+ { relatedTarget : document . createElement ( 'div' ) } ) ;
840+
841+ expectHideToBeCalled ( foundation , mockAdapter ) ;
842+ } ) ;
843+
844+ it ( '#handleRichTooltipFocusOut does not hide the tooltip if related target is within the anchor' ,
845+ ( ) => {
846+ const { foundation, mockAdapter} =
847+ setUpFoundationTestForRichTooltip ( MDCTooltipFoundation ) ;
848+
849+ foundation . show ( ) ;
850+ mockAdapter . anchorContainsElement . and . returnValue ( true ) ;
851+ mockAdapter . tooltipContainsElement . and . returnValue ( false ) ;
852+ foundation . handleRichTooltipFocusOut (
853+ { relatedTarget : document . createElement ( 'div' ) } ) ;
854+
855+ expectHideNotToBeCalled ( foundation , mockAdapter ) ;
856+ } ) ;
857+
858+ it ( '#handleRichTooltipFocusOut does not hide the tooltip if related target is within the tooltip' ,
859+ ( ) => {
860+ const { foundation, mockAdapter} =
861+ setUpFoundationTestForRichTooltip ( MDCTooltipFoundation ) ;
862+
863+ foundation . show ( ) ;
864+ mockAdapter . anchorContainsElement . and . returnValue ( false ) ;
865+ mockAdapter . tooltipContainsElement . and . returnValue ( true ) ;
866+ foundation . handleRichTooltipFocusOut (
867+ { relatedTarget : document . createElement ( 'div' ) } ) ;
868+
869+ expectHideNotToBeCalled ( foundation , mockAdapter ) ;
870+ } ) ;
871+
813872 it ( `does not re-animate a tooltip already shown in the dom (from focus)` ,
814873 ( ) => {
815874 const { foundation, mockAdapter} =
@@ -1298,6 +1357,8 @@ describe('MDCTooltipFoundation', () => {
12981357
12991358 foundation . destroy ( ) ;
13001359
1360+ expect ( mockAdapter . deregisterEventHandler )
1361+ . not . toHaveBeenCalledWith ( 'focusout' , jasmine . any ( Function ) ) ;
13011362 expect ( mockAdapter . deregisterEventHandler )
13021363 . not . toHaveBeenCalledWith ( 'mouseenter' , jasmine . any ( Function ) ) ;
13031364 expect ( mockAdapter . deregisterEventHandler )
@@ -1319,6 +1380,8 @@ describe('MDCTooltipFoundation', () => {
13191380
13201381 foundation . destroy ( ) ;
13211382
1383+ expect ( mockAdapter . deregisterEventHandler )
1384+ . toHaveBeenCalledWith ( 'focusout' , jasmine . any ( Function ) ) ;
13221385 expect ( mockAdapter . deregisterEventHandler )
13231386 . toHaveBeenCalledWith ( 'mouseenter' , jasmine . any ( Function ) ) ;
13241387 expect ( mockAdapter . deregisterEventHandler )
@@ -1340,6 +1403,8 @@ describe('MDCTooltipFoundation', () => {
13401403
13411404 foundation . destroy ( ) ;
13421405
1406+ expect ( mockAdapter . deregisterEventHandler )
1407+ . toHaveBeenCalledWith ( 'focusout' , jasmine . any ( Function ) ) ;
13431408 expect ( mockAdapter . deregisterEventHandler )
13441409 . not . toHaveBeenCalledWith ( 'mouseenter' , jasmine . any ( Function ) ) ;
13451410 expect ( mockAdapter . deregisterEventHandler )
0 commit comments