Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/lib/tabs/tab-header.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,26 @@ describe('MatTabHeader', () => {
expect(tabHeaderElement.classList).toContain(enabledClass);
});

it('scroll to last tab', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we usually start test names with "should".

fixture = TestBed.createComponent(SimpleTabHeaderApp);
appComponent = fixture.componentInstance;
appComponent.tabs = [
{label: 'tab one'},
{label: 'tab two'},
{label: 'tab three'},
{label: 'tab four'},
{label: 'tab five'},
{label: 'tab six'},
{label: 'tab seven'},
{label: 'tab eight'},
];
appComponent.tabHeader.selectedIndex = 8;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be 7? Index 8 is out of bounds of the array.


fixture.componentRef.changeDetectorRef.markForCheck();

expect(appComponent.tabHeader.scrollDistance)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that this test is verifying the correct thing. I tried pasting it into master without the fix from this PR and it still passes. This somewhat defeats the purpose of the test, because we won't know if we accidentally introduce a regression.

.toBe(appComponent.tabHeader._getMaxScrollDistance());
});
});
});

Expand Down
1 change: 1 addition & 0 deletions src/lib/tabs/tab-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export class MatTabHeader extends _MatTabHeaderMixinBase
const dirChange = this._dir ? this._dir.change : observableOf(null);
const resize = this._viewportRuler.change(150);
const realign = () => {
this._scrollToLabel(this._selectedIndex);
this.updatePagination();
this._alignInkBarToSelectedTab();
};
Expand Down