@@ -39,6 +39,7 @@ import {
3939 TOOLTIP_PANEL_CLASS ,
4040 MAT_TOOLTIP_DEFAULT_OPTIONS ,
4141 TooltipTouchGestures ,
42+ TooltipPosition ,
4243} from './index' ;
4344
4445
@@ -732,6 +733,80 @@ describe('MatTooltip', () => {
732733 expect ( overlayRef . detach ) . not . toHaveBeenCalled ( ) ;
733734 } ) ) ;
734735
736+ it ( 'should set a class on the overlay panel that reflects the position' , fakeAsync ( ( ) => {
737+ // Move the element so that the primary position is always used.
738+ buttonElement . style . position = 'fixed' ;
739+ buttonElement . style . top = buttonElement . style . left = '200px' ;
740+
741+ fixture . componentInstance . message = 'hi' ;
742+ fixture . detectChanges ( ) ;
743+ setPositionAndShow ( 'below' ) ;
744+
745+ const classList = tooltipDirective . _overlayRef ! . overlayElement . classList ;
746+ expect ( classList ) . toContain ( 'mat-tooltip-panel-below' ) ;
747+
748+ setPositionAndShow ( 'above' ) ;
749+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-below' ) ;
750+ expect ( classList ) . toContain ( 'mat-tooltip-panel-above' ) ;
751+
752+ setPositionAndShow ( 'left' ) ;
753+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-above' ) ;
754+ expect ( classList ) . toContain ( 'mat-tooltip-panel-left' ) ;
755+
756+ setPositionAndShow ( 'right' ) ;
757+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-left' ) ;
758+ expect ( classList ) . toContain ( 'mat-tooltip-panel-right' ) ;
759+
760+ function setPositionAndShow ( position : TooltipPosition ) {
761+ tooltipDirective . hide ( 0 ) ;
762+ fixture . detectChanges ( ) ;
763+ tick ( 0 ) ;
764+ tooltipDirective . position = position ;
765+ tooltipDirective . show ( 0 ) ;
766+ fixture . detectChanges ( ) ;
767+ tick ( 0 ) ;
768+ fixture . detectChanges ( ) ;
769+ tick ( 500 ) ;
770+ }
771+ } ) ) ;
772+
773+ it ( 'should account for RTL when setting the tooltip position class' , fakeAsync ( ( ) => {
774+ // Move the element so that the primary position is always used.
775+ buttonElement . style . position = 'fixed' ;
776+ buttonElement . style . top = buttonElement . style . left = '200px' ;
777+ fixture . componentInstance . message = 'hi' ;
778+ fixture . detectChanges ( ) ;
779+
780+ dir . value = 'ltr' ;
781+ tooltipDirective . position = 'after' ;
782+ tooltipDirective . show ( 0 ) ;
783+ fixture . detectChanges ( ) ;
784+ tick ( 0 ) ;
785+ fixture . detectChanges ( ) ;
786+ tick ( 500 ) ;
787+
788+ const classList = tooltipDirective . _overlayRef ! . overlayElement . classList ;
789+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-after' ) ;
790+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-before' ) ;
791+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-left' ) ;
792+ expect ( classList ) . toContain ( 'mat-tooltip-panel-right' ) ;
793+
794+ tooltipDirective . hide ( 0 ) ;
795+ fixture . detectChanges ( ) ;
796+ tick ( 0 ) ;
797+ dir . value = 'rtl' ;
798+ tooltipDirective . show ( 0 ) ;
799+ fixture . detectChanges ( ) ;
800+ tick ( 0 ) ;
801+ fixture . detectChanges ( ) ;
802+ tick ( 500 ) ;
803+
804+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-after' ) ;
805+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-before' ) ;
806+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-right' ) ;
807+ expect ( classList ) . toContain ( 'mat-tooltip-panel-left' ) ;
808+ } ) ) ;
809+
735810 } ) ;
736811
737812 describe ( 'fallback positions' , ( ) => {
0 commit comments