@@ -266,9 +266,11 @@ describe('MDC-based MatTabHeader', () => {
266266 // Focus on the last tab, expect this to be the maximum scroll distance.
267267 appComponent . tabHeader . focusIndex = appComponent . tabs . length - 1 ;
268268 fixture . detectChanges ( ) ;
269- expect ( appComponent . tabHeader . scrollDistance ) . toBe (
270- appComponent . tabHeader . _getMaxScrollDistance ( ) ,
269+ const { offsetLeft , offsetWidth } = appComponent . getSelectedLabel (
270+ appComponent . tabHeader . focusIndex ,
271271 ) ;
272+ const viewLength = appComponent . getViewLength ( ) ;
273+ expect ( appComponent . tabHeader . scrollDistance ) . toBe ( offsetLeft + offsetWidth - viewLength ) ;
272274
273275 // Focus on the first tab, expect this to be the maximum scroll distance.
274276 appComponent . tabHeader . focusIndex = 0 ;
@@ -329,9 +331,11 @@ describe('MDC-based MatTabHeader', () => {
329331 // Focus the last tab so the header scrolls to the end.
330332 appComponent . tabHeader . focusIndex = appComponent . tabs . length - 1 ;
331333 fixture . detectChanges ( ) ;
332- expect ( appComponent . tabHeader . scrollDistance ) . toBe (
333- appComponent . tabHeader . _getMaxScrollDistance ( ) ,
334+ const { offsetLeft , offsetWidth } = appComponent . getSelectedLabel (
335+ appComponent . tabHeader . focusIndex ,
334336 ) ;
337+ const viewLength = appComponent . getViewLength ( ) ;
338+ expect ( appComponent . tabHeader . scrollDistance ) . toBe ( offsetLeft + offsetWidth - viewLength ) ;
335339
336340 // Remove the first two tabs which includes the selected tab.
337341 appComponent . tabs = appComponent . tabs . slice ( 2 ) ;
@@ -360,9 +364,8 @@ describe('MDC-based MatTabHeader', () => {
360364 // Focus on the last tab, expect this to be the maximum scroll distance.
361365 appComponent . tabHeader . focusIndex = appComponent . tabs . length - 1 ;
362366 fixture . detectChanges ( ) ;
363- expect ( appComponent . tabHeader . scrollDistance ) . toBe (
364- appComponent . tabHeader . _getMaxScrollDistance ( ) ,
365- ) ;
367+ const { offsetLeft} = appComponent . getSelectedLabel ( appComponent . tabHeader . focusIndex ) ;
368+ expect ( offsetLeft ) . toBe ( 0 ) ;
366369
367370 // Focus on the first tab, expect this to be the maximum scroll distance.
368371 appComponent . tabHeader . focusIndex = 0 ;
@@ -757,4 +760,12 @@ class SimpleTabHeaderApp {
757760 this . tabs . push ( { label : 'new' } ) ;
758761 }
759762 }
763+
764+ getViewLength ( ) {
765+ return this . tabHeader . _tabListContainer . nativeElement . offsetWidth ;
766+ }
767+
768+ getSelectedLabel ( index : number ) {
769+ return this . tabHeader . _items . toArray ( ) [ this . tabHeader . focusIndex ] . elementRef . nativeElement ;
770+ }
760771}
0 commit comments