|
5 | 5 | dispatchEvent,
|
6 | 6 | dispatchKeyboardEvent,
|
7 | 7 | } from '@angular/cdk/testing';
|
8 |
| -import {Component, DebugElement} from '@angular/core'; |
9 |
| -import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing'; |
| 8 | +import {Component, DebugElement, ChangeDetectionStrategy} from '@angular/core'; |
| 9 | +import {async, ComponentFixture, fakeAsync, TestBed, tick, flush} from '@angular/core/testing'; |
10 | 10 | import {By} from '@angular/platform-browser';
|
11 | 11 | import {
|
12 | 12 | MatListModule,
|
@@ -592,7 +592,8 @@ describe('MatSelectionList with forms', () => {
|
592 | 592 | SelectionListWithModel,
|
593 | 593 | SelectionListWithFormControl,
|
594 | 594 | SelectionListWithPreselectedOption,
|
595 |
| - SelectionListWithPreselectedOptionAndModel |
| 595 | + SelectionListWithPreselectedOptionAndModel, |
| 596 | + SelectionListWithPreselectedFormControlOnPush, |
596 | 597 | ]
|
597 | 598 | });
|
598 | 599 |
|
@@ -800,6 +801,20 @@ describe('MatSelectionList with forms', () => {
|
800 | 801 | expect(fixture.componentInstance.selectedOptions).toEqual(['opt1', 'opt2']);
|
801 | 802 | }));
|
802 | 803 |
|
| 804 | + it('should show the item as selected when preselected inside OnPush parent', fakeAsync(() => { |
| 805 | + const fixture = TestBed.createComponent(SelectionListWithPreselectedFormControlOnPush); |
| 806 | + fixture.detectChanges(); |
| 807 | + |
| 808 | + const option = fixture.debugElement.queryAll(By.directive(MatListOption))[1]; |
| 809 | + |
| 810 | + fixture.detectChanges(); |
| 811 | + flush(); |
| 812 | + fixture.detectChanges(); |
| 813 | + |
| 814 | + expect(option.componentInstance.selected).toBe(true); |
| 815 | + expect(option.nativeElement.querySelector('.mat-pseudo-checkbox-checked')).toBeTruthy(); |
| 816 | + })); |
| 817 | + |
803 | 818 | });
|
804 | 819 | });
|
805 | 820 |
|
@@ -949,3 +964,17 @@ class SelectionListWithPreselectedOption {
|
949 | 964 | class SelectionListWithPreselectedOptionAndModel {
|
950 | 965 | selectedOptions = ['opt1'];
|
951 | 966 | }
|
| 967 | + |
| 968 | + |
| 969 | +@Component({ |
| 970 | + changeDetection: ChangeDetectionStrategy.OnPush, |
| 971 | + template: ` |
| 972 | + <mat-selection-list [formControl]="formControl"> |
| 973 | + <mat-list-option *ngFor="let opt of opts" [value]="opt">{{opt}}</mat-list-option> |
| 974 | + </mat-selection-list> |
| 975 | + ` |
| 976 | +}) |
| 977 | +class SelectionListWithPreselectedFormControlOnPush { |
| 978 | + opts = ['opt1', 'opt2', 'opt3']; |
| 979 | + formControl = new FormControl(['opt2']); |
| 980 | +} |
0 commit comments