@@ -266,9 +266,11 @@ describe('MDC-based MatTabHeader', () => {
266
266
// Focus on the last tab, expect this to be the maximum scroll distance.
267
267
appComponent . tabHeader . focusIndex = appComponent . tabs . length - 1 ;
268
268
fixture . detectChanges ( ) ;
269
- expect ( appComponent . tabHeader . scrollDistance ) . toBe (
270
- appComponent . tabHeader . _getMaxScrollDistance ( ) ,
269
+ const { offsetLeft , offsetWidth } = appComponent . getSelectedLabel (
270
+ appComponent . tabHeader . focusIndex ,
271
271
) ;
272
+ const viewLength = appComponent . getViewLength ( ) ;
273
+ expect ( appComponent . tabHeader . scrollDistance ) . toBe ( offsetLeft + offsetWidth - viewLength ) ;
272
274
273
275
// Focus on the first tab, expect this to be the maximum scroll distance.
274
276
appComponent . tabHeader . focusIndex = 0 ;
@@ -329,9 +331,11 @@ describe('MDC-based MatTabHeader', () => {
329
331
// Focus the last tab so the header scrolls to the end.
330
332
appComponent . tabHeader . focusIndex = appComponent . tabs . length - 1 ;
331
333
fixture . detectChanges ( ) ;
332
- expect ( appComponent . tabHeader . scrollDistance ) . toBe (
333
- appComponent . tabHeader . _getMaxScrollDistance ( ) ,
334
+ const { offsetLeft , offsetWidth } = appComponent . getSelectedLabel (
335
+ appComponent . tabHeader . focusIndex ,
334
336
) ;
337
+ const viewLength = appComponent . getViewLength ( ) ;
338
+ expect ( appComponent . tabHeader . scrollDistance ) . toBe ( offsetLeft + offsetWidth - viewLength ) ;
335
339
336
340
// Remove the first two tabs which includes the selected tab.
337
341
appComponent . tabs = appComponent . tabs . slice ( 2 ) ;
@@ -360,9 +364,8 @@ describe('MDC-based MatTabHeader', () => {
360
364
// Focus on the last tab, expect this to be the maximum scroll distance.
361
365
appComponent . tabHeader . focusIndex = appComponent . tabs . length - 1 ;
362
366
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 ) ;
366
369
367
370
// Focus on the first tab, expect this to be the maximum scroll distance.
368
371
appComponent . tabHeader . focusIndex = 0 ;
@@ -757,4 +760,12 @@ class SimpleTabHeaderApp {
757
760
this . tabs . push ( { label : 'new' } ) ;
758
761
}
759
762
}
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
+ }
760
771
}
0 commit comments