1
1
import { fakeAsync , TestBed , waitForAsync } from '@angular/core/testing' ;
2
2
import { dispatchFakeEvent , dispatchMouseEvent } from '@angular/cdk/testing/private' ;
3
- import { Component , QueryList , ViewChildren } from '@angular/core' ;
3
+ import { Component , QueryList , ViewChild , ViewChildren } from '@angular/core' ;
4
4
import { By } from '@angular/platform-browser' ;
5
5
import { MatListItem , MatListModule } from './index' ;
6
6
@@ -22,6 +22,8 @@ describe('MDC-based MatList', () => {
22
22
NavListWithActivatedItem ,
23
23
ActionListWithoutType ,
24
24
ActionListWithType ,
25
+ ActionListWithDisabledList ,
26
+ ActionListWithDisabledItem ,
25
27
ListWithDisabledItems ,
26
28
StandaloneListItem ,
27
29
] ,
@@ -377,6 +379,34 @@ describe('MDC-based MatList', () => {
377
379
fixture . detectChanges ( ) ;
378
380
} ) . not . toThrow ( ) ;
379
381
} ) ;
382
+
383
+ it ( 'should be able to disable and enable the entire action list' , ( ) => {
384
+ const fixture = TestBed . createComponent ( ActionListWithDisabledList ) ;
385
+ const listItems : HTMLElement [ ] = Array . from (
386
+ fixture . nativeElement . querySelectorAll ( '[mat-list-item]' ) ,
387
+ ) ;
388
+ fixture . detectChanges ( ) ;
389
+
390
+ expect ( listItems . every ( listItem => listItem . hasAttribute ( 'disabled' ) ) ) . toBe ( true ) ;
391
+
392
+ fixture . componentInstance . disableList = false ;
393
+ fixture . detectChanges ( ) ;
394
+
395
+ expect ( listItems . every ( listItem => ! listItem . hasAttribute ( 'disabled' ) ) ) . toBe ( true ) ;
396
+ } ) ;
397
+
398
+ it ( 'should be able to disable and enable button item' , ( ) => {
399
+ const fixture = TestBed . createComponent ( ActionListWithDisabledItem ) ;
400
+ const buttonItem : HTMLButtonElement = fixture . nativeElement . querySelector ( '[mat-list-item]' ) ;
401
+ fixture . detectChanges ( ) ;
402
+
403
+ expect ( buttonItem . hasAttribute ( 'disabled' ) ) . toBe ( true ) ;
404
+
405
+ fixture . componentInstance . buttonItem . disabled = false ;
406
+ fixture . detectChanges ( ) ;
407
+
408
+ expect ( buttonItem . hasAttribute ( 'disabled' ) ) . toBe ( false ) ;
409
+ } ) ;
380
410
} ) ;
381
411
382
412
class BaseTestList {
@@ -460,6 +490,31 @@ class ActionListWithType extends BaseTestList {
460
490
@ViewChildren ( MatListItem ) listItems : QueryList < MatListItem > ;
461
491
}
462
492
493
+ @Component ( {
494
+ template : `
495
+ <mat-action-list [disabled]="disableList">
496
+ <button mat-list-item *ngFor="let item of items">
497
+ {{item.name}}
498
+ </button>
499
+ </mat-action-list>` ,
500
+ } )
501
+ class ActionListWithDisabledList extends BaseTestList {
502
+ disableList = true ;
503
+ }
504
+
505
+ @Component ( {
506
+ template : `
507
+ <mat-action-list>
508
+ <button mat-list-item [disabled]="disableItem">
509
+ Paprika
510
+ </button>
511
+ </mat-action-list>` ,
512
+ } )
513
+ class ActionListWithDisabledItem extends BaseTestList {
514
+ @ViewChild ( MatListItem ) buttonItem : MatListItem ;
515
+ disableItem = true ;
516
+ }
517
+
463
518
@Component ( {
464
519
template : `
465
520
<mat-list>
0 commit comments