@@ -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,75 @@ 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 = '100px' ;
699+
700+ setPositionAndShow ( 'below' ) ;
701+
702+ const classList = tooltipDirective . _overlayRef ! . overlayElement . classList ;
703+ expect ( classList ) . toContain ( 'mat-tooltip-panel-below' ) ;
704+
705+ setPositionAndShow ( 'above' ) ;
706+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-below' ) ;
707+ expect ( classList ) . toContain ( 'mat-tooltip-panel-above' ) ;
708+
709+ setPositionAndShow ( 'left' ) ;
710+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-above' ) ;
711+ expect ( classList ) . toContain ( 'mat-tooltip-panel-left' ) ;
712+
713+ setPositionAndShow ( 'right' ) ;
714+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-left' ) ;
715+ expect ( classList ) . toContain ( 'mat-tooltip-panel-right' ) ;
716+
717+ function setPositionAndShow ( position : TooltipPosition ) {
718+ tooltipDirective . hide ( 0 ) ;
719+ fixture . detectChanges ( ) ;
720+ tick ( 0 ) ;
721+ tooltipDirective . position = position ;
722+ tooltipDirective . show ( 0 ) ;
723+ fixture . detectChanges ( ) ;
724+ tick ( 0 ) ;
725+ fixture . detectChanges ( ) ;
726+ tick ( 500 ) ;
727+ }
728+ } ) ) ;
729+
730+ it ( 'should account for RTL when setting the tooltip position class' , fakeAsync ( ( ) => {
731+ // Move the element so that the primary position is always used.
732+ buttonElement . style . position = 'fixed' ;
733+ buttonElement . style . top = buttonElement . style . left = '100px' ;
734+ dir . value = 'ltr' ;
735+ tooltipDirective . position = 'after' ;
736+ tooltipDirective . show ( 0 ) ;
737+ fixture . detectChanges ( ) ;
738+ tick ( 0 ) ;
739+ fixture . detectChanges ( ) ;
740+ tick ( 500 ) ;
741+
742+ const classList = tooltipDirective . _overlayRef ! . overlayElement . classList ;
743+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-after' ) ;
744+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-before' ) ;
745+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-left' ) ;
746+ expect ( classList ) . toContain ( 'mat-tooltip-panel-right' ) ;
747+
748+ tooltipDirective . hide ( 0 ) ;
749+ fixture . detectChanges ( ) ;
750+ tick ( 0 ) ;
751+ dir . value = 'rtl' ;
752+ tooltipDirective . show ( 0 ) ;
753+ fixture . detectChanges ( ) ;
754+ tick ( 0 ) ;
755+ fixture . detectChanges ( ) ;
756+ tick ( 500 ) ;
757+
758+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-after' ) ;
759+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-before' ) ;
760+ expect ( classList ) . not . toContain ( 'mat-tooltip-panel-right' ) ;
761+ expect ( classList ) . toContain ( 'mat-tooltip-panel-left' ) ;
762+ } ) ) ;
763+
694764 } ) ;
695765
696766 describe ( 'fallback positions' , ( ) => {
0 commit comments