@@ -204,6 +204,33 @@ describe('MatTooltip', () => {
204
204
expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( false ) ;
205
205
} ) ) ;
206
206
207
+ it ( 'should be able to override the default position' , fakeAsync ( ( ) => {
208
+ TestBed
209
+ . resetTestingModule ( )
210
+ . configureTestingModule ( {
211
+ imports : [ MatTooltipModule , OverlayModule , NoopAnimationsModule ] ,
212
+ declarations : [ TooltipDemoWithoutPositionBinding ] ,
213
+ providers : [ {
214
+ provide : MAT_TOOLTIP_DEFAULT_OPTIONS ,
215
+ useValue : { position : 'right' }
216
+ } ]
217
+ } )
218
+ . compileComponents ( ) ;
219
+
220
+ const newFixture = TestBed . createComponent ( TooltipDemoWithoutPositionBinding ) ;
221
+ newFixture . detectChanges ( ) ;
222
+ tooltipDirective = newFixture . debugElement . query ( By . css ( 'button' ) )
223
+ . injector . get < MatTooltip > ( MatTooltip ) ;
224
+
225
+ tooltipDirective . show ( ) ;
226
+ newFixture . detectChanges ( ) ;
227
+ tick ( ) ;
228
+
229
+ expect ( tooltipDirective . position ) . toBe ( 'right' ) ;
230
+ expect ( tooltipDirective . _getOverlayPosition ( ) . main . overlayX ) . toBe ( 'start' ) ;
231
+ expect ( tooltipDirective . _getOverlayPosition ( ) . fallback . overlayX ) . toBe ( 'end' ) ;
232
+ } ) ) ;
233
+
207
234
it ( 'should set a css class on the overlay panel element' , fakeAsync ( ( ) => {
208
235
tooltipDirective . show ( ) ;
209
236
fixture . detectChanges ( ) ;
@@ -995,6 +1022,15 @@ class TooltipOnDraggableElement {
995
1022
@ViewChild ( 'button' ) button : ElementRef ;
996
1023
}
997
1024
1025
+ @Component ( {
1026
+ selector : 'app' ,
1027
+ template : `<button #button [matTooltip]="message">Button</button>`
1028
+ } )
1029
+ class TooltipDemoWithoutPositionBinding {
1030
+ message : any = initialTooltipMessage ;
1031
+ @ViewChild ( MatTooltip ) tooltip : MatTooltip ;
1032
+ @ViewChild ( 'button' ) button : ElementRef < HTMLButtonElement > ;
1033
+ }
998
1034
999
1035
/** Asserts whether a tooltip directive has a tooltip instance. */
1000
1036
function assertTooltipInstance ( tooltip : MatTooltip , shouldExist : boolean ) : void {
0 commit comments