1
1
import { TestBed , async , ComponentFixture , fakeAsync , tick } from '@angular/core/testing' ;
2
2
import { By } from '@angular/platform-browser' ;
3
- import { Component , DebugElement , QueryList , ViewChild , ViewChildren } from '@angular/core' ;
3
+ import {
4
+ Component ,
5
+ DebugElement ,
6
+ QueryList ,
7
+ ViewChild ,
8
+ ViewChildren ,
9
+ ChangeDetectionStrategy ,
10
+ } from '@angular/core' ;
4
11
import { MdSelectModule } from './index' ;
5
12
import { OverlayContainer } from '../core/overlay/overlay-container' ;
6
13
import { MdSelect } from './select' ;
@@ -26,7 +33,8 @@ describe('MdSelect', () => {
26
33
SelectInitWithoutOptions ,
27
34
SelectWithChangeEvent ,
28
35
CustomSelectAccessor ,
29
- CompWithCustomSelect
36
+ CompWithCustomSelect ,
37
+ BasicSelectOnPush
30
38
] ,
31
39
providers : [
32
40
{ provide : OverlayContainer , useFactory : ( ) => {
@@ -1255,6 +1263,29 @@ describe('MdSelect', () => {
1255
1263
expect ( fixture . componentInstance . changeListener ) . toHaveBeenCalledTimes ( 1 ) ;
1256
1264
} ) ;
1257
1265
} ) ;
1266
+
1267
+ describe ( 'with OnPush change detection' , ( ) => {
1268
+ let fixture : ComponentFixture < BasicSelectOnPush > ;
1269
+ let trigger : HTMLElement ;
1270
+
1271
+ beforeEach ( ( ) => {
1272
+ fixture = TestBed . createComponent ( BasicSelectOnPush ) ;
1273
+ fixture . detectChanges ( ) ;
1274
+ trigger = fixture . debugElement . query ( By . css ( '.md-select-trigger' ) ) . nativeElement ;
1275
+ } ) ;
1276
+
1277
+ it ( 'should update the trigger based on the value' , ( ) => {
1278
+ fixture . componentInstance . control . setValue ( 'pizza-1' ) ;
1279
+ fixture . detectChanges ( ) ;
1280
+
1281
+ expect ( trigger . textContent ) . toContain ( 'Pizza' ) ;
1282
+
1283
+ fixture . componentInstance . control . reset ( ) ;
1284
+ fixture . detectChanges ( ) ;
1285
+
1286
+ expect ( trigger . textContent ) . not . toContain ( 'Pizza' ) ;
1287
+ } ) ;
1288
+ } ) ;
1258
1289
} ) ;
1259
1290
1260
1291
@Component ( {
@@ -1433,6 +1464,29 @@ class CompWithCustomSelect {
1433
1464
@ViewChild ( CustomSelectAccessor ) customAccessor : CustomSelectAccessor ;
1434
1465
}
1435
1466
1467
+ @Component ( {
1468
+ selector : 'basic-select-on-push' ,
1469
+ changeDetection : ChangeDetectionStrategy . OnPush ,
1470
+ template : `
1471
+ <md-select placeholder="Food" [formControl]="control">
1472
+ <md-option *ngFor="let food of foods" [value]="food.value">
1473
+ {{ food.viewValue }}
1474
+ </md-option>
1475
+ </md-select>
1476
+ `
1477
+ } )
1478
+ class BasicSelectOnPush {
1479
+ foods : any [ ] = [
1480
+ { value : 'steak-0' , viewValue : 'Steak' } ,
1481
+ { value : 'pizza-1' , viewValue : 'Pizza' } ,
1482
+ { value : 'tacos-2' , viewValue : 'Tacos' } ,
1483
+ ] ;
1484
+ control = new FormControl ( ) ;
1485
+
1486
+ @ViewChild ( MdSelect ) select : MdSelect ;
1487
+ @ViewChildren ( MdOption ) options : QueryList < MdOption > ;
1488
+ }
1489
+
1436
1490
1437
1491
/**
1438
1492
* TODO: Move this to core testing utility until Angular has event faking
0 commit comments