1
1
import { async , ComponentFixture , fakeAsync , TestBed , tick } from '@angular/core/testing' ;
2
2
import { Component , ViewChild , ViewChildren , QueryList } from '@angular/core' ;
3
+ import { MAT_RIPPLE_GLOBAL_OPTIONS , RippleGlobalOptions } from '@angular/material/core' ;
3
4
import { By } from '@angular/platform-browser' ;
4
5
import { dispatchFakeEvent , dispatchMouseEvent } from '@angular/cdk/testing' ;
5
6
import { Direction , Directionality } from '@angular/cdk/bidi' ;
@@ -10,8 +11,11 @@ import {MatTabLink, MatTabNav, MatTabsModule} from '../index';
10
11
describe ( 'MatTabNavBar' , ( ) => {
11
12
let dir : Direction = 'ltr' ;
12
13
let dirChange = new Subject ( ) ;
14
+ let globalRippleOptions : RippleGlobalOptions ;
13
15
14
16
beforeEach ( async ( ( ) => {
17
+ globalRippleOptions = { } ;
18
+
15
19
TestBed . configureTestingModule ( {
16
20
imports : [ MatTabsModule ] ,
17
21
declarations : [
@@ -21,10 +25,9 @@ describe('MatTabNavBar', () => {
21
25
TabLinkWithNativeTabindexAttr ,
22
26
] ,
23
27
providers : [
24
- { provide : Directionality , useFactory : ( ) => ( {
25
- value : dir ,
26
- change : dirChange . asObservable ( )
27
- } ) } ,
28
+ { provide : MAT_RIPPLE_GLOBAL_OPTIONS , useFactory : ( ) => globalRippleOptions } ,
29
+ { provide : Directionality , useFactory : ( ) =>
30
+ ( { value : dir , change : dirChange . asObservable ( ) } ) } ,
28
31
]
29
32
} ) ;
30
33
@@ -113,29 +116,6 @@ describe('MatTabNavBar', () => {
113
116
. toBe ( true , 'Expected aria-disabled to be set to "true" if link is disabled.' ) ;
114
117
} ) ;
115
118
116
- it ( 'should disable the ripples on all tabs when they are disabled on the nav bar' , ( ) => {
117
- expect ( fixture . componentInstance . tabLinks . toArray ( ) . every ( tabLink => ! tabLink . rippleDisabled ) )
118
- . toBe ( true , 'Expected every tab link to have ripples enabled' ) ;
119
-
120
- fixture . componentInstance . disableRippleOnBar = true ;
121
- fixture . detectChanges ( ) ;
122
-
123
- expect ( fixture . componentInstance . tabLinks . toArray ( ) . every ( tabLink => tabLink . rippleDisabled ) )
124
- . toBe ( true , 'Expected every tab link to have ripples disabled' ) ;
125
- } ) ;
126
-
127
- it ( 'should have the `disableRipple` from the tab take precendence over the nav bar' , ( ) => {
128
- const firstTab = fixture . componentInstance . tabLinks . first ;
129
-
130
- expect ( firstTab . rippleDisabled ) . toBe ( false , 'Expected ripples to be enabled on first tab' ) ;
131
-
132
- firstTab . disableRipple = true ;
133
- fixture . componentInstance . disableRippleOnBar = false ;
134
- fixture . detectChanges ( ) ;
135
-
136
- expect ( firstTab . rippleDisabled ) . toBe ( true , 'Expected ripples to be disabled on first tab' ) ;
137
- } ) ;
138
-
139
119
it ( 'should update the tabindex if links are disabled' , ( ) => {
140
120
const tabLinkElements = fixture . debugElement . queryAll ( By . css ( 'a' ) )
141
121
. map ( tabLinkDebugEl => tabLinkDebugEl . nativeElement ) ;
@@ -161,30 +141,6 @@ describe('MatTabNavBar', () => {
161
141
expect ( getComputedStyle ( tabLinkElement ) . pointerEvents ) . toBe ( 'none' ) ;
162
142
} ) ;
163
143
164
- it ( 'should show ripples for tab links' , ( ) => {
165
- const tabLink = fixture . debugElement . nativeElement . querySelector ( '.mat-tab-link' ) ;
166
-
167
- dispatchMouseEvent ( tabLink , 'mousedown' ) ;
168
- dispatchMouseEvent ( tabLink , 'mouseup' ) ;
169
-
170
- expect ( tabLink . querySelectorAll ( '.mat-ripple-element' ) . length )
171
- . toBe ( 1 , 'Expected one ripple to show up if user clicks on tab link.' ) ;
172
- } ) ;
173
-
174
- it ( 'should be able to disable ripples on a tab link' , ( ) => {
175
- const tabLinkDebug = fixture . debugElement . query ( By . css ( 'a' ) ) ;
176
- const tabLinkElement = tabLinkDebug . nativeElement ;
177
- const tabLinkInstance = tabLinkDebug . injector . get < MatTabLink > ( MatTabLink ) ;
178
-
179
- tabLinkInstance . disableRipple = true ;
180
-
181
- dispatchMouseEvent ( tabLinkElement , 'mousedown' ) ;
182
- dispatchMouseEvent ( tabLinkElement , 'mouseup' ) ;
183
-
184
- expect ( tabLinkElement . querySelectorAll ( '.mat-ripple-element' ) . length )
185
- . toBe ( 0 , 'Expected no ripple to show up if ripples are disabled.' ) ;
186
- } ) ;
187
-
188
144
it ( 'should re-align the ink bar when the direction changes' , ( ) => {
189
145
const inkBar = fixture . componentInstance . tabNavBar . _inkBar ;
190
146
@@ -285,6 +241,72 @@ describe('MatTabNavBar', () => {
285
241
286
242
expect ( tabLink . tabIndex ) . toBe ( 3 , 'Expected the tabIndex to be have been set to 3.' ) ;
287
243
} ) ;
244
+
245
+ describe ( 'ripples' , ( ) => {
246
+ let fixture : ComponentFixture < SimpleTabNavBarTestApp > ;
247
+
248
+ beforeEach ( ( ) => {
249
+ fixture = TestBed . createComponent ( SimpleTabNavBarTestApp ) ;
250
+ fixture . detectChanges ( ) ;
251
+ } ) ;
252
+
253
+ it ( 'should be disabled on all tab links when they are disabled on the nav bar' , ( ) => {
254
+ expect ( fixture . componentInstance . tabLinks . toArray ( ) . every ( tabLink => ! tabLink . rippleDisabled ) )
255
+ . toBe ( true , 'Expected every tab link to have ripples enabled' ) ;
256
+
257
+ fixture . componentInstance . disableRippleOnBar = true ;
258
+ fixture . detectChanges ( ) ;
259
+
260
+ expect ( fixture . componentInstance . tabLinks . toArray ( ) . every ( tabLink => tabLink . rippleDisabled ) )
261
+ . toBe ( true , 'Expected every tab link to have ripples disabled' ) ;
262
+ } ) ;
263
+
264
+ it ( 'should have the `disableRipple` from the tab take precedence over the nav bar' , ( ) => {
265
+ const firstTab = fixture . componentInstance . tabLinks . first ;
266
+
267
+ expect ( firstTab . rippleDisabled ) . toBe ( false , 'Expected ripples to be enabled on first tab' ) ;
268
+
269
+ firstTab . disableRipple = true ;
270
+ fixture . componentInstance . disableRippleOnBar = false ;
271
+ fixture . detectChanges ( ) ;
272
+
273
+ expect ( firstTab . rippleDisabled ) . toBe ( true , 'Expected ripples to be disabled on first tab' ) ;
274
+ } ) ;
275
+
276
+ it ( 'should show up for tab link elements on mousedown' , ( ) => {
277
+ const tabLink = fixture . debugElement . nativeElement . querySelector ( '.mat-tab-link' ) ;
278
+
279
+ dispatchMouseEvent ( tabLink , 'mousedown' ) ;
280
+ dispatchMouseEvent ( tabLink , 'mouseup' ) ;
281
+
282
+ expect ( tabLink . querySelectorAll ( '.mat-ripple-element' ) . length )
283
+ . toBe ( 1 , 'Expected one ripple to show up if user clicks on tab link.' ) ;
284
+ } ) ;
285
+
286
+ it ( 'should be able to disable ripples on an individual tab link' , ( ) => {
287
+ const tabLinkDebug = fixture . debugElement . query ( By . css ( 'a' ) ) ;
288
+ const tabLinkElement = tabLinkDebug . nativeElement ;
289
+ const tabLinkInstance = tabLinkDebug . injector . get < MatTabLink > ( MatTabLink ) ;
290
+
291
+ tabLinkInstance . disableRipple = true ;
292
+
293
+ dispatchMouseEvent ( tabLinkElement , 'mousedown' ) ;
294
+ dispatchMouseEvent ( tabLinkElement , 'mouseup' ) ;
295
+
296
+ expect ( tabLinkElement . querySelectorAll ( '.mat-ripple-element' ) . length )
297
+ . toBe ( 0 , 'Expected no ripple to show up if ripples are disabled.' ) ;
298
+ } ) ;
299
+
300
+ it ( 'should be able to disable ripples through global options at runtime' , ( ) => {
301
+ expect ( fixture . componentInstance . tabLinks . toArray ( ) . every ( tabLink => ! tabLink . rippleDisabled ) )
302
+ . toBe ( true , 'Expected every tab link to have ripples enabled' ) ;
303
+
304
+ globalRippleOptions . disabled = true ;
305
+
306
+ expect ( fixture . componentInstance . tabLinks . toArray ( ) . every ( tabLink => tabLink . rippleDisabled ) )
307
+ . toBe ( true , 'Expected every tab link to have ripples disabled' ) ;
308
+ } ) ;
309
+ } ) ;
288
310
} ) ;
289
311
290
312
@Component ( {
0 commit comments