@@ -16,7 +16,7 @@ describe('MdSelect', () => {
1616 beforeEach ( async ( ( ) => {
1717 TestBed . configureTestingModule ( {
1818 imports : [ MdSelectModule . forRoot ( ) , ReactiveFormsModule , FormsModule ] ,
19- declarations : [ BasicSelect , NgModelSelect , ManySelects ] ,
19+ declarations : [ BasicSelect , NgModelSelect , ManySelects , NgIfSelect ] ,
2020 providers : [
2121 { provide : OverlayContainer , useFactory : ( ) => {
2222 overlayContainerElement = document . createElement ( 'div' ) ;
@@ -96,14 +96,16 @@ describe('MdSelect', () => {
9696 } ) ;
9797 } ) ) ;
9898
99- it ( 'should set the width of the overlay based on the trigger' , ( ) => {
99+ it ( 'should set the width of the overlay based on the trigger' , async ( ( ) => {
100100 trigger . style . width = '200px' ;
101- trigger . click ( ) ;
102- fixture . detectChanges ( ) ;
103101
104- const pane = overlayContainerElement . children [ 0 ] as HTMLElement ;
105- expect ( pane . style . width ) . toBe ( '200px' ) ;
106- } ) ;
102+ fixture . whenStable ( ) . then ( ( ) => {
103+ trigger . click ( ) ;
104+ fixture . detectChanges ( ) ;
105+ const pane = overlayContainerElement . children [ 0 ] as HTMLElement ;
106+ expect ( pane . style . minWidth ) . toBe ( '200px' ) ;
107+ } ) ;
108+ } ) ) ;
107109
108110 } ) ;
109111
@@ -973,6 +975,39 @@ describe('MdSelect', () => {
973975
974976 } ) ;
975977
978+ describe ( 'special cases' , ( ) => {
979+
980+ it ( 'should handle nesting in an ngIf' , async ( ( ) => {
981+ const fixture = TestBed . createComponent ( NgIfSelect ) ;
982+ fixture . detectChanges ( ) ;
983+
984+ fixture . componentInstance . isShowing = true ;
985+ fixture . detectChanges ( ) ;
986+
987+ const trigger = fixture . debugElement . query ( By . css ( '.md-select-trigger' ) ) . nativeElement ;
988+ trigger . style . width = '300px' ;
989+
990+ fixture . whenStable ( ) . then ( ( ) => {
991+ fixture . detectChanges ( ) ;
992+ const value = fixture . debugElement . query ( By . css ( '.md-select-value' ) ) ;
993+ expect ( value . nativeElement . textContent )
994+ . toContain ( 'Pizza' , `Expected trigger to be populated by the control's initial value.` ) ;
995+
996+ trigger . click ( ) ;
997+ fixture . detectChanges ( ) ;
998+
999+ const pane = overlayContainerElement . children [ 0 ] as HTMLElement ;
1000+ expect ( pane . style . minWidth ) . toEqual ( '300px' ) ;
1001+
1002+ expect ( fixture . componentInstance . select . panelOpen ) . toBe ( true ) ;
1003+ expect ( overlayContainerElement . textContent ) . toContain ( 'Steak' ) ;
1004+ expect ( overlayContainerElement . textContent ) . toContain ( 'Pizza' ) ;
1005+ expect ( overlayContainerElement . textContent ) . toContain ( 'Tacos' ) ;
1006+ } ) ;
1007+ } ) ) ;
1008+
1009+ } ) ;
1010+
9761011} ) ;
9771012
9781013@Component ( {
@@ -1038,6 +1073,32 @@ class NgModelSelect {
10381073} )
10391074class ManySelects { }
10401075
1076+ @Component ( {
1077+ selector : 'ng-if-select' ,
1078+ template : `
1079+ <div *ngIf="isShowing">
1080+ <md-select placeholder="Food I want to eat right now" [formControl]="control">
1081+ <md-option *ngFor="let food of foods" [value]="food.value">
1082+ {{ food.viewValue }}
1083+ </md-option>
1084+ </md-select>
1085+ </div>
1086+ `
1087+
1088+ } )
1089+ class NgIfSelect {
1090+ isShowing = false ;
1091+ foods : any [ ] = [
1092+ { value : 'steak-0' , viewValue : 'Steak' } ,
1093+ { value : 'pizza-1' , viewValue : 'Pizza' } ,
1094+ { value : 'tacos-2' , viewValue : 'Tacos' }
1095+ ] ;
1096+ control = new FormControl ( 'pizza-1' ) ;
1097+
1098+ @ViewChild ( MdSelect ) select : MdSelect ;
1099+ }
1100+
1101+
10411102
10421103/**
10431104 * TODO: Move this to core testing utility until Angular has event faking
0 commit comments