11import { TestBed , async , ComponentFixture , fakeAsync , tick } from '@angular/core/testing' ;
22import { 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' ;
411import { MdSelectModule } from './index' ;
512import { OverlayContainer } from '../core/overlay/overlay-container' ;
613import { MdSelect } from './select' ;
@@ -26,7 +33,8 @@ describe('MdSelect', () => {
2633 SelectInitWithoutOptions ,
2734 SelectWithChangeEvent ,
2835 CustomSelectAccessor ,
29- CompWithCustomSelect
36+ CompWithCustomSelect ,
37+ BasicSelectOnPush
3038 ] ,
3139 providers : [
3240 { provide : OverlayContainer , useFactory : ( ) => {
@@ -1255,6 +1263,29 @@ describe('MdSelect', () => {
12551263 expect ( fixture . componentInstance . changeListener ) . toHaveBeenCalledTimes ( 1 ) ;
12561264 } ) ;
12571265 } ) ;
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+ } ) ;
12581289} ) ;
12591290
12601291@Component ( {
@@ -1433,6 +1464,29 @@ class CompWithCustomSelect {
14331464 @ViewChild ( CustomSelectAccessor ) customAccessor : CustomSelectAccessor ;
14341465}
14351466
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+
14361490
14371491/**
14381492 * TODO: Move this to core testing utility until Angular has event faking
0 commit comments