@@ -26,7 +26,8 @@ describe('MdSelect', () => {
2626 SelectInitWithoutOptions ,
2727 SelectWithChangeEvent ,
2828 CustomSelectAccessor ,
29- CompWithCustomSelect
29+ CompWithCustomSelect ,
30+ ViewValueSelect
3031 ] ,
3132 providers : [
3233 { provide : OverlayContainer , useFactory : ( ) => {
@@ -543,20 +544,6 @@ describe('MdSelect', () => {
543544
544545 } ) ;
545546
546- describe ( 'misc forms' , ( ) => {
547- it ( 'should support use inside a custom value accessor' , ( ) => {
548- const fixture = TestBed . createComponent ( CompWithCustomSelect ) ;
549- spyOn ( fixture . componentInstance . customAccessor , 'writeValue' ) ;
550- fixture . detectChanges ( ) ;
551-
552- expect ( fixture . componentInstance . customAccessor . select . _control )
553- . toBe ( null , 'Expected md-select NOT to inherit control from parent value accessor.' ) ;
554- expect ( fixture . componentInstance . customAccessor . writeValue ) . toHaveBeenCalled ( ) ;
555- } ) ;
556-
557- } ) ;
558-
559-
560547 describe ( 'animations' , ( ) => {
561548 let fixture : ComponentFixture < BasicSelect > ;
562549 let trigger : HTMLElement ;
@@ -1254,7 +1241,38 @@ describe('MdSelect', () => {
12541241
12551242 expect ( fixture . componentInstance . changeListener ) . toHaveBeenCalledTimes ( 1 ) ;
12561243 } ) ;
1244+
1245+ } ) ;
1246+
1247+ describe ( 'misc' , ( ) => {
1248+ it ( 'should support use inside a custom value accessor' , ( ) => {
1249+ const fixture = TestBed . createComponent ( CompWithCustomSelect ) ;
1250+ spyOn ( fixture . componentInstance . customAccessor , 'writeValue' ) ;
1251+ fixture . detectChanges ( ) ;
1252+
1253+ expect ( fixture . componentInstance . customAccessor . select . _control )
1254+ . toBe ( null , 'Expected md-select NOT to inherit control from parent value accessor.' ) ;
1255+ expect ( fixture . componentInstance . customAccessor . writeValue ) . toHaveBeenCalled ( ) ;
1256+ } ) ;
1257+
1258+ it ( 'should display the viewValue in the trigger instead of textContent if it is set' , ( ) => {
1259+ const fixture = TestBed . createComponent ( ViewValueSelect ) ;
1260+ fixture . detectChanges ( ) ;
1261+
1262+ const trigger = fixture . debugElement . query ( By . css ( '.md-select-trigger' ) ) . nativeElement ;
1263+ trigger . click ( ) ;
1264+ fixture . detectChanges ( ) ;
1265+
1266+ const option = overlayContainerElement . querySelector ( 'md-option' ) as HTMLElement ;
1267+ option . click ( ) ;
1268+ fixture . detectChanges ( ) ;
1269+
1270+ expect ( trigger . textContent ) . toContain ( 'Steak' , 'Expected trigger to contain viewValue.' ) ;
1271+ expect ( trigger . textContent ) . not . toContain ( '0' , 'Expected trigger to contain viewValue.' ) ;
1272+ } ) ;
1273+
12571274 } ) ;
1275+
12581276} ) ;
12591277
12601278@Component ( {
@@ -1289,6 +1307,25 @@ class BasicSelect {
12891307 @ViewChildren ( MdOption ) options : QueryList < MdOption > ;
12901308}
12911309
1310+ @Component ( {
1311+ selector : 'view-value-select' ,
1312+ template : `
1313+ <md-select placeholder="Food">
1314+ <md-option *ngFor="let food of foods" [value]="food.value" [viewValue]="food.name">
1315+ {{ food.id }}: {{food.name}}
1316+ </md-option>
1317+ </md-select>
1318+ `
1319+ } )
1320+ class ViewValueSelect {
1321+ foods : any [ ] = [
1322+ { value : 'steak-0' , name : 'Steak' , id : 0 } ,
1323+ { value : 'pizza-1' , name : 'Pizza' , id : 1 } ,
1324+ { value : 'tacos-2' , name : 'Tacos' , id : 2 } ,
1325+ ] ;
1326+ }
1327+
1328+
12921329@Component ( {
12931330 selector : 'ng-model-select' ,
12941331 template : `
0 commit comments