|
1 | 1 | import {TestBed, async, fakeAsync, tick, ComponentFixture} from '@angular/core/testing';
|
2 |
| -import {Component, OnDestroy, QueryList, ViewChild, ViewChildren} from '@angular/core'; |
| 2 | +import { |
| 3 | + Component, |
| 4 | + OnDestroy, |
| 5 | + QueryList, |
| 6 | + ViewChild, |
| 7 | + ViewChildren, |
| 8 | + ChangeDetectionStrategy, |
| 9 | + OnInit, |
| 10 | +} from '@angular/core'; |
3 | 11 | import {By} from '@angular/platform-browser';
|
4 | 12 | import {NoopAnimationsModule} from '@angular/platform-browser/animations';
|
5 | 13 | import {MdAutocompleteModule, MdAutocompleteTrigger} from './index';
|
@@ -38,7 +46,8 @@ describe('MdAutocomplete', () => {
|
38 | 46 | SimpleAutocomplete,
|
39 | 47 | AutocompleteWithoutForms,
|
40 | 48 | NgIfAutocomplete,
|
41 |
| - AutocompleteWithNgModel |
| 49 | + AutocompleteWithNgModel, |
| 50 | + AutocompleteWithOnPushDelay |
42 | 51 | ],
|
43 | 52 | providers: [
|
44 | 53 | {provide: OverlayContainer, useFactory: () => {
|
@@ -1090,6 +1099,24 @@ describe('MdAutocomplete', () => {
|
1090 | 1099 | expect(Math.ceil(parseFloat(overlayPane.style.width))).toEqual(500);
|
1091 | 1100 |
|
1092 | 1101 | });
|
| 1102 | + |
| 1103 | + it('should show the panel when the options are initialized later within a component with ' + |
| 1104 | + 'OnPush change detection', fakeAsync(() => { |
| 1105 | + let fixture = TestBed.createComponent(AutocompleteWithOnPushDelay); |
| 1106 | + |
| 1107 | + fixture.detectChanges(); |
| 1108 | + dispatchFakeEvent(fixture.debugElement.query(By.css('input')).nativeElement, 'focus'); |
| 1109 | + tick(1000); |
| 1110 | + fixture.detectChanges(); |
| 1111 | + |
| 1112 | + Promise.resolve().then(() => { |
| 1113 | + let panel = overlayContainerElement.querySelector('.mat-autocomplete-panel') as HTMLElement; |
| 1114 | + let visibleClass = 'mat-autocomplete-visible'; |
| 1115 | + |
| 1116 | + fixture.detectChanges(); |
| 1117 | + expect(panel.classList).toContain(visibleClass, `Expected panel to be visible.`); |
| 1118 | + }); |
| 1119 | + })); |
1093 | 1120 | });
|
1094 | 1121 |
|
1095 | 1122 | @Component({
|
@@ -1239,6 +1266,30 @@ class AutocompleteWithNgModel {
|
1239 | 1266 |
|
1240 | 1267 | }
|
1241 | 1268 |
|
| 1269 | + |
| 1270 | +@Component({ |
| 1271 | + changeDetection: ChangeDetectionStrategy.OnPush, |
| 1272 | + template: ` |
| 1273 | + <md-input-container> |
| 1274 | + <input type="text" mdInput [mdAutocomplete]="auto"> |
| 1275 | + </md-input-container> |
| 1276 | +
|
| 1277 | + <md-autocomplete #auto="mdAutocomplete"> |
| 1278 | + <md-option *ngFor="let option of options" [value]="option">{{ option }}</md-option> |
| 1279 | + </md-autocomplete> |
| 1280 | + ` |
| 1281 | +}) |
| 1282 | +class AutocompleteWithOnPushDelay implements OnInit { |
| 1283 | + options: string[]; |
| 1284 | + |
| 1285 | + ngOnInit() { |
| 1286 | + setTimeout(() => { |
| 1287 | + this.options = ['One']; |
| 1288 | + }, 1000); |
| 1289 | + } |
| 1290 | +} |
| 1291 | + |
| 1292 | + |
1242 | 1293 | /** This is a mock keyboard event to test keyboard events in the autocomplete. */
|
1243 | 1294 | class MockKeyboardEvent {
|
1244 | 1295 | constructor(public keyCode: number) {}
|
|
0 commit comments