@@ -30,8 +30,9 @@ function runBaseListFunctionalityTests<
30
30
BaseListItemHarnessFilters
31
31
> ,
32
32
I extends MatListItemHarnessBase ,
33
+ F extends { disableThirdItem : boolean } ,
33
34
> (
34
- testComponent : Type < { } > ,
35
+ testComponent : Type < F > ,
35
36
listModule : typeof MatListModule ,
36
37
listHarness : ComponentHarnessConstructor < L > & {
37
38
with : ( config ?: BaseHarnessFilters ) => HarnessPredicate < L > ;
@@ -44,7 +45,7 @@ function runBaseListFunctionalityTests<
44
45
describe ( 'base list functionality' , ( ) => {
45
46
let simpleListHarness : L ;
46
47
let emptyListHarness : L ;
47
- let fixture : ComponentFixture < { } > ;
48
+ let fixture : ComponentFixture < F > ;
48
49
49
50
beforeEach ( async ( ) => {
50
51
await TestBed . configureTestingModule ( {
@@ -223,6 +224,14 @@ function runBaseListFunctionalityTests<
223
224
const loader = await items [ 1 ] . getChildLoader ( selectors . content as MatListItemSection ) ;
224
225
await expectAsync ( loader . getHarness ( TestItemContentHarness ) ) . toBeResolved ( ) ;
225
226
} ) ;
227
+
228
+ it ( 'should check disabled state of items' , async ( ) => {
229
+ fixture . componentInstance . disableThirdItem = true ;
230
+ const items = await simpleListHarness . getItems ( ) ;
231
+ expect ( items . length ) . toBe ( 3 ) ;
232
+ expect ( await items [ 0 ] . isDisabled ( ) ) . toBe ( false ) ;
233
+ expect ( await items [ 2 ] . isDisabled ( ) ) . toBe ( true ) ;
234
+ } ) ;
226
235
} ) ;
227
236
}
228
237
@@ -242,7 +251,7 @@ export function runHarnessTests(
242
251
selectors : { content : string } ,
243
252
) {
244
253
describe ( 'MatListHarness' , ( ) => {
245
- runBaseListFunctionalityTests < MatListHarness , MatListItemHarness > (
254
+ runBaseListFunctionalityTests < MatListHarness , MatListItemHarness , ListHarnessTest > (
246
255
ListHarnessTest ,
247
256
listModule ,
248
257
listHarness ,
@@ -254,7 +263,11 @@ export function runHarnessTests(
254
263
} ) ;
255
264
256
265
describe ( 'MatActionListHarness' , ( ) => {
257
- runBaseListFunctionalityTests < MatActionListHarness , MatActionListItemHarness > (
266
+ runBaseListFunctionalityTests <
267
+ MatActionListHarness ,
268
+ MatActionListItemHarness ,
269
+ ActionListHarnessTest
270
+ > (
258
271
ActionListHarnessTest ,
259
272
listModule ,
260
273
actionListHarness ,
@@ -296,7 +309,7 @@ export function runHarnessTests(
296
309
} ) ;
297
310
298
311
describe ( 'MatNavListHarness' , ( ) => {
299
- runBaseListFunctionalityTests < MatNavListHarness , MatNavListItemHarness > (
312
+ runBaseListFunctionalityTests < MatNavListHarness , MatNavListItemHarness , NavListHarnessTest > (
300
313
NavListHarnessTest ,
301
314
listModule ,
302
315
navListHarness ,
@@ -349,7 +362,11 @@ export function runHarnessTests(
349
362
} ) ;
350
363
351
364
describe ( 'MatSelectionListHarness' , ( ) => {
352
- runBaseListFunctionalityTests < MatSelectionListHarness , MatListOptionHarness > (
365
+ runBaseListFunctionalityTests <
366
+ MatSelectionListHarness ,
367
+ MatListOptionHarness ,
368
+ SelectionListHarnessTest
369
+ > (
353
370
SelectionListHarnessTest ,
354
371
listModule ,
355
372
selectionListHarness ,
@@ -448,14 +465,6 @@ export function runHarnessTests(
448
465
await items [ 0 ] . deselect ( ) ;
449
466
expect ( await items [ 0 ] . isSelected ( ) ) . toBe ( false ) ;
450
467
} ) ;
451
-
452
- it ( 'should check disabled state of options' , async ( ) => {
453
- fixture . componentInstance . disableItem3 = true ;
454
- const items = await harness . getItems ( ) ;
455
- expect ( items . length ) . toBe ( 3 ) ;
456
- expect ( await items [ 0 ] . isDisabled ( ) ) . toBe ( false ) ;
457
- expect ( await items [ 2 ] . isDisabled ( ) ) . toBe ( true ) ;
458
- } ) ;
459
468
} ) ;
460
469
} ) ;
461
470
}
@@ -474,15 +483,17 @@ export function runHarnessTests(
474
483
<a mat-list-item>
475
484
<span class="test-item-content">Item 2</span>
476
485
</a>
477
- <button mat-list-item>Item 3</button>
486
+ <button mat-list-item [disabled]="disableThirdItem" >Item 3</button>
478
487
<div matSubheader>Section 2</div>
479
488
<mat-divider></mat-divider>
480
489
</mat-list>
481
490
482
491
<mat-list class="test-empty"></mat-list>
483
492
` ,
484
493
} )
485
- class ListHarnessTest { }
494
+ class ListHarnessTest {
495
+ disableThirdItem = false ;
496
+ }
486
497
487
498
@Component ( {
488
499
template : `
@@ -498,7 +509,10 @@ class ListHarnessTest {}
498
509
<a mat-list-item (click)="lastClicked = 'Item 2'">
499
510
<span class="test-item-content">Item 2</span>
500
511
</a>
501
- <button mat-list-item (click)="lastClicked = 'Item 3'">Item 3</button>
512
+ <button
513
+ mat-list-item
514
+ [disabled]="disableThirdItem"
515
+ (click)="lastClicked = 'Item 3'">Item 3</button>
502
516
<div matSubheader>Section 2</div>
503
517
<mat-divider></mat-divider>
504
518
</mat-action-list>
@@ -508,6 +522,7 @@ class ListHarnessTest {}
508
522
} )
509
523
class ActionListHarnessTest {
510
524
lastClicked : string ;
525
+ disableThirdItem = false ;
511
526
}
512
527
513
528
@Component ( {
@@ -524,7 +539,11 @@ class ActionListHarnessTest {
524
539
<a mat-list-item href (click)="onClick($event, 'Item 2')">
525
540
<span class="test-item-content">Item 2</span>
526
541
</a>
527
- <a mat-list-item href="/somestuff" (click)="onClick($event, 'Item 3')">Item 3</a>
542
+ <a
543
+ mat-list-item
544
+ href="/somestuff"
545
+ (click)="onClick($event, 'Item 3')"
546
+ [disabled]="disableThirdItem">Item 3</a>
528
547
<div matSubheader>Section 2</div>
529
548
<mat-divider></mat-divider>
530
549
</mat-nav-list>
@@ -534,6 +553,7 @@ class ActionListHarnessTest {
534
553
} )
535
554
class NavListHarnessTest {
536
555
lastClicked : string ;
556
+ disableThirdItem = false ;
537
557
538
558
onClick ( event : Event , value : string ) {
539
559
event . preventDefault ( ) ;
@@ -555,7 +575,7 @@ class NavListHarnessTest {
555
575
<mat-list-option>
556
576
<span class="test-item-content">Item 2</span>
557
577
</mat-list-option>
558
- <mat-list-option [disabled]="disableItem3 ">Item 3</mat-list-option>
578
+ <mat-list-option [disabled]="disableThirdItem ">Item 3</mat-list-option>
559
579
<div matSubheader>Section 2</div>
560
580
<mat-divider></mat-divider>
561
581
</mat-selection-list>
@@ -564,7 +584,7 @@ class NavListHarnessTest {
564
584
` ,
565
585
} )
566
586
class SelectionListHarnessTest {
567
- disableItem3 = false ;
587
+ disableThirdItem = false ;
568
588
}
569
589
570
590
class TestItemContentHarness extends ComponentHarness {
0 commit comments