@@ -38,6 +38,7 @@ import {
3838 SCROLL_THROTTLE_MS ,
3939 TOOLTIP_PANEL_CLASS ,
4040 MAT_TOOLTIP_DEFAULT_OPTIONS ,
41+ TooltipPosition ,
4142} from './index' ;
4243
4344
@@ -719,6 +720,80 @@ describe('MatTooltip', () => {
719720 expect ( overlayRef . detach ) . not . toHaveBeenCalled ( ) ;
720721 } ) ) ;
721722
723+ it ( 'should set a class on the overlay panel that reflects the position' , fakeAsync ( ( ) => {
724+ // Move the element so that the primary position is always used.
725+ buttonElement . style . position = 'fixed' ;
726+ buttonElement . style . top = buttonElement . style . left = '200px' ;
727+
728+ fixture . componentInstance . message = 'hi' ;
729+ fixture . detectChanges ( ) ;
730+ setPositionAndShow ( 'below' ) ;
731+
732+ const classList = tooltipDirective . _overlayRef ! . overlayElement . classList ;
733+ expect ( classList ) . toContain ( 'mat-tooltip-panel-below' ) ;
734+
735+ setPositionAndShow ( 'above' ) ;
736+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-below' ) ;
737+ expect ( classList ) . toContain ( 'mat-tooltip-panel-above' ) ;
738+
739+ setPositionAndShow ( 'left' ) ;
740+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-above' ) ;
741+ expect ( classList ) . toContain ( 'mat-tooltip-panel-left' ) ;
742+
743+ setPositionAndShow ( 'right' ) ;
744+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-left' ) ;
745+ expect ( classList ) . toContain ( 'mat-tooltip-panel-right' ) ;
746+
747+ function setPositionAndShow ( position : TooltipPosition ) {
748+ tooltipDirective . hide ( 0 ) ;
749+ fixture . detectChanges ( ) ;
750+ tick ( 0 ) ;
751+ tooltipDirective . position = position ;
752+ tooltipDirective . show ( 0 ) ;
753+ fixture . detectChanges ( ) ;
754+ tick ( 0 ) ;
755+ fixture . detectChanges ( ) ;
756+ tick ( 500 ) ;
757+ }
758+ } ) ) ;
759+
760+ it ( 'should account for RTL when setting the tooltip position class' , fakeAsync ( ( ) => {
761+ // Move the element so that the primary position is always used.
762+ buttonElement . style . position = 'fixed' ;
763+ buttonElement . style . top = buttonElement . style . left = '200px' ;
764+ fixture . componentInstance . message = 'hi' ;
765+ fixture . detectChanges ( ) ;
766+
767+ dir . value = 'ltr' ;
768+ tooltipDirective . position = 'after' ;
769+ tooltipDirective . show ( 0 ) ;
770+ fixture . detectChanges ( ) ;
771+ tick ( 0 ) ;
772+ fixture . detectChanges ( ) ;
773+ tick ( 500 ) ;
774+
775+ const classList = tooltipDirective . _overlayRef ! . overlayElement . classList ;
776+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-after' ) ;
777+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-before' ) ;
778+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-left' ) ;
779+ expect ( classList ) . toContain ( 'mat-tooltip-panel-right' ) ;
780+
781+ tooltipDirective . hide ( 0 ) ;
782+ fixture . detectChanges ( ) ;
783+ tick ( 0 ) ;
784+ dir . value = 'rtl' ;
785+ tooltipDirective . show ( 0 ) ;
786+ fixture . detectChanges ( ) ;
787+ tick ( 0 ) ;
788+ fixture . detectChanges ( ) ;
789+ tick ( 500 ) ;
790+
791+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-after' ) ;
792+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-before' ) ;
793+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-right' ) ;
794+ expect ( classList ) . toContain ( 'mat-tooltip-panel-left' ) ;
795+ } ) ) ;
796+
722797 } ) ;
723798
724799 describe ( 'fallback positions' , ( ) => {
0 commit comments