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