@@ -36,6 +36,7 @@ import {
3636 SCROLL_THROTTLE_MS ,
3737 TOOLTIP_PANEL_CLASS ,
3838 MAT_TOOLTIP_DEFAULT_OPTIONS ,
39+ TooltipPosition ,
3940} from './index' ;
4041
4142
@@ -691,6 +692,80 @@ describe('MatTooltip', () => {
691692 expect ( overlayRef . detach ) . not . toHaveBeenCalled ( ) ;
692693 } ) ) ;
693694
695+ it ( 'should set a class on the overlay panel that reflects the position' , fakeAsync ( ( ) => {
696+ // Move the element so that the primary position is always used.
697+ buttonElement . style . position = 'fixed' ;
698+ buttonElement . style . top = buttonElement . style . left = '200px' ;
699+
700+ fixture . componentInstance . message = 'hi' ;
701+ fixture . detectChanges ( ) ;
702+ setPositionAndShow ( 'below' ) ;
703+
704+ const classList = tooltipDirective . _overlayRef ! . overlayElement . classList ;
705+ expect ( classList ) . toContain ( 'mat-tooltip-panel-below' ) ;
706+
707+ setPositionAndShow ( 'above' ) ;
708+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-below' ) ;
709+ expect ( classList ) . toContain ( 'mat-tooltip-panel-above' ) ;
710+
711+ setPositionAndShow ( 'left' ) ;
712+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-above' ) ;
713+ expect ( classList ) . toContain ( 'mat-tooltip-panel-left' ) ;
714+
715+ setPositionAndShow ( 'right' ) ;
716+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-left' ) ;
717+ expect ( classList ) . toContain ( 'mat-tooltip-panel-right' ) ;
718+
719+ function setPositionAndShow ( position : TooltipPosition ) {
720+ tooltipDirective . hide ( 0 ) ;
721+ fixture . detectChanges ( ) ;
722+ tick ( 0 ) ;
723+ tooltipDirective . position = position ;
724+ tooltipDirective . show ( 0 ) ;
725+ fixture . detectChanges ( ) ;
726+ tick ( 0 ) ;
727+ fixture . detectChanges ( ) ;
728+ tick ( 500 ) ;
729+ }
730+ } ) ) ;
731+
732+ it ( 'should account for RTL when setting the tooltip position class' , fakeAsync ( ( ) => {
733+ // Move the element so that the primary position is always used.
734+ buttonElement . style . position = 'fixed' ;
735+ buttonElement . style . top = buttonElement . style . left = '200px' ;
736+ fixture . componentInstance . message = 'hi' ;
737+ fixture . detectChanges ( ) ;
738+
739+ dir . value = 'ltr' ;
740+ tooltipDirective . position = 'after' ;
741+ tooltipDirective . show ( 0 ) ;
742+ fixture . detectChanges ( ) ;
743+ tick ( 0 ) ;
744+ fixture . detectChanges ( ) ;
745+ tick ( 500 ) ;
746+
747+ const classList = tooltipDirective . _overlayRef ! . overlayElement . classList ;
748+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-after' ) ;
749+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-before' ) ;
750+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-left' ) ;
751+ expect ( classList ) . toContain ( 'mat-tooltip-panel-right' ) ;
752+
753+ tooltipDirective . hide ( 0 ) ;
754+ fixture . detectChanges ( ) ;
755+ tick ( 0 ) ;
756+ dir . value = 'rtl' ;
757+ tooltipDirective . show ( 0 ) ;
758+ fixture . detectChanges ( ) ;
759+ tick ( 0 ) ;
760+ fixture . detectChanges ( ) ;
761+ tick ( 500 ) ;
762+
763+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-after' ) ;
764+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-before' ) ;
765+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-right' ) ;
766+ expect ( classList ) . toContain ( 'mat-tooltip-panel-left' ) ;
767+ } ) ) ;
768+
694769 } ) ;
695770
696771 describe ( 'fallback positions' , ( ) => {
0 commit comments