|
1 | 1 | import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing'; |
2 | 2 | import {Component, ViewChild} from '@angular/core'; |
3 | 3 | import {By} from '@angular/platform-browser'; |
4 | | -import {dispatchFakeEvent, dispatchMouseEvent} from '@angular/cdk/testing'; |
| 4 | +import {dispatchFakeEvent, dispatchMouseEvent, createMouseEvent} from '@angular/cdk/testing'; |
5 | 5 | import {Direction, Directionality} from '@angular/cdk/bidi'; |
6 | 6 | import {Subject} from 'rxjs/Subject'; |
7 | 7 | import {MatTabLink, MatTabNav, MatTabsModule} from '../index'; |
@@ -125,6 +125,23 @@ describe('MatTabNavBar', () => { |
125 | 125 | .toBe(true, 'Expected element to no longer be keyboard focusable if disabled.'); |
126 | 126 | }); |
127 | 127 |
|
| 128 | + it('should prevent default action for clicks if links are disabled', () => { |
| 129 | + const tabLinkElement = fixture.debugElement.query(By.css('a')).nativeElement; |
| 130 | + |
| 131 | + const mouseEvent = createMouseEvent('click'); |
| 132 | + spyOn(mouseEvent, 'preventDefault'); |
| 133 | + tabLinkElement.dispatchEvent(mouseEvent); |
| 134 | + expect(mouseEvent.preventDefault).not.toHaveBeenCalled(); |
| 135 | + |
| 136 | + fixture.componentInstance.disabled = true; |
| 137 | + fixture.detectChanges(); |
| 138 | + |
| 139 | + const mouseEventWhileDisabled = createMouseEvent('click'); |
| 140 | + spyOn(mouseEventWhileDisabled, 'preventDefault'); |
| 141 | + tabLinkElement.dispatchEvent(mouseEventWhileDisabled); |
| 142 | + expect(mouseEventWhileDisabled.preventDefault).toHaveBeenCalled(); |
| 143 | + }); |
| 144 | + |
128 | 145 | it('should show ripples for tab links', () => { |
129 | 146 | const tabLink = fixture.debugElement.nativeElement.querySelector('.mat-tab-link'); |
130 | 147 |
|
|
0 commit comments