@@ -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
@@ -968,6 +970,39 @@ describe('MdSelect', () => {
968970
969971 } ) ;
970972
973+ describe ( 'special cases' , ( ) => {
974+
975+ it ( 'should handle nesting in an ngIf' , async ( ( ) => {
976+ const fixture = TestBed . createComponent ( NgIfSelect ) ;
977+ fixture . detectChanges ( ) ;
978+
979+ fixture . componentInstance . isShowing = true ;
980+ fixture . detectChanges ( ) ;
981+
982+ const trigger = fixture . debugElement . query ( By . css ( '.md-select-trigger' ) ) . nativeElement ;
983+ trigger . style . width = '300px' ;
984+
985+ fixture . whenStable ( ) . then ( ( ) => {
986+ fixture . detectChanges ( ) ;
987+ const value = fixture . debugElement . query ( By . css ( '.md-select-value' ) ) ;
988+ expect ( value . nativeElement . textContent )
989+ . toContain ( 'Pizza' , `Expected trigger to be populated by the control's initial value.` ) ;
990+
991+ trigger . click ( ) ;
992+ fixture . detectChanges ( ) ;
993+
994+ const pane = overlayContainerElement . children [ 0 ] as HTMLElement ;
995+ expect ( pane . style . minWidth ) . toEqual ( '300px' ) ;
996+
997+ expect ( fixture . componentInstance . select . panelOpen ) . toBe ( true ) ;
998+ expect ( overlayContainerElement . textContent ) . toContain ( 'Steak' ) ;
999+ expect ( overlayContainerElement . textContent ) . toContain ( 'Pizza' ) ;
1000+ expect ( overlayContainerElement . textContent ) . toContain ( 'Tacos' ) ;
1001+ } ) ;
1002+ } ) ) ;
1003+
1004+ } ) ;
1005+
9711006} ) ;
9721007
9731008@Component ( {
@@ -1033,6 +1068,32 @@ class NgModelSelect {
10331068} )
10341069class ManySelects { }
10351070
1071+ @Component ( {
1072+ selector : 'ng-if-select' ,
1073+ template : `
1074+ <div *ngIf="isShowing">
1075+ <md-select placeholder="Food I want to eat right now" [formControl]="control">
1076+ <md-option *ngFor="let food of foods" [value]="food.value">
1077+ {{ food.viewValue }}
1078+ </md-option>
1079+ </md-select>
1080+ </div>
1081+ `
1082+
1083+ } )
1084+ class NgIfSelect {
1085+ isShowing = false ;
1086+ foods : any [ ] = [
1087+ { value : 'steak-0' , viewValue : 'Steak' } ,
1088+ { value : 'pizza-1' , viewValue : 'Pizza' } ,
1089+ { value : 'tacos-2' , viewValue : 'Tacos' }
1090+ ] ;
1091+ control = new FormControl ( 'pizza-1' ) ;
1092+
1093+ @ViewChild ( MdSelect ) select : MdSelect ;
1094+ }
1095+
1096+
10361097
10371098/**
10381099 * TODO: Move this to core testing utility until Angular has event faking
0 commit comments