|
1 |
| -import {SPACE} from '@angular/cdk/keycodes'; |
| 1 | +import {ENTER, SPACE} from '@angular/cdk/keycodes'; |
2 | 2 | import {waitForAsync, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
|
3 | 3 | import {Component, QueryList, ViewChild, ViewChildren} from '@angular/core';
|
4 | 4 | import {MAT_RIPPLE_GLOBAL_OPTIONS, RippleGlobalOptions} from '@angular/material/core';
|
@@ -73,31 +73,6 @@ describe('MDC-based MatTabNavBar', () => {
|
73 | 73 | expect(tabLinkElements[1].classList.contains('mdc-tab--active')).toBeTruthy();
|
74 | 74 | });
|
75 | 75 |
|
76 |
| - it('should add the disabled class if disabled', () => { |
77 |
| - const tabLinkElements = fixture.debugElement |
78 |
| - .queryAll(By.css('a')) |
79 |
| - .map(tabLinkDebugEl => tabLinkDebugEl.nativeElement); |
80 |
| - |
81 |
| - expect( |
82 |
| - tabLinkElements.every(tabLinkEl => { |
83 |
| - return !tabLinkEl.classList.contains('mat-mdc-tab-disabled'); |
84 |
| - }), |
85 |
| - ) |
86 |
| - .withContext('Expected every tab link to not have the disabled class initially') |
87 |
| - .toBe(true); |
88 |
| - |
89 |
| - fixture.componentInstance.disabled = true; |
90 |
| - fixture.detectChanges(); |
91 |
| - |
92 |
| - expect( |
93 |
| - tabLinkElements.every(tabLinkEl => { |
94 |
| - return tabLinkEl.classList.contains('mat-mdc-tab-disabled'); |
95 |
| - }), |
96 |
| - ) |
97 |
| - .withContext('Expected every tab link to have the disabled class if set through binding') |
98 |
| - .toBe(true); |
99 |
| - }); |
100 |
| - |
101 | 76 | it('should update aria-disabled if disabled', () => {
|
102 | 77 | const tabLinkElements = fixture.debugElement
|
103 | 78 | .queryAll(By.css('a'))
|
@@ -143,6 +118,20 @@ describe('MDC-based MatTabNavBar', () => {
|
143 | 118 | expect(tabLinkElement.classList).toContain('mat-mdc-tab-disabled');
|
144 | 119 | });
|
145 | 120 |
|
| 121 | + it('should prevent default keyboard actions on disabled links', () => { |
| 122 | + const link = fixture.debugElement.query(By.css('a')).nativeElement; |
| 123 | + fixture.componentInstance.disabled = true; |
| 124 | + fixture.detectChanges(); |
| 125 | + |
| 126 | + const spaceEvent = dispatchKeyboardEvent(link, 'keydown', SPACE); |
| 127 | + fixture.detectChanges(); |
| 128 | + expect(spaceEvent.defaultPrevented).toBe(true); |
| 129 | + |
| 130 | + const enterEvent = dispatchKeyboardEvent(link, 'keydown', ENTER); |
| 131 | + fixture.detectChanges(); |
| 132 | + expect(enterEvent.defaultPrevented).toBe(true); |
| 133 | + }); |
| 134 | + |
146 | 135 | it('should re-align the ink bar when the direction changes', fakeAsync(() => {
|
147 | 136 | const inkBar = fixture.componentInstance.tabNavBar._inkBar;
|
148 | 137 |
|
|
0 commit comments