@@ -20,7 +20,7 @@ import {
20
20
MdAutocomplete ,
21
21
MdAutocompleteModule ,
22
22
MdAutocompleteTrigger ,
23
- MdAutocompleteSelect ,
23
+ MdAutocompleteSelectedEvent ,
24
24
} from './index' ;
25
25
import { MdInputModule } from '../input/index' ;
26
26
import { Subscription } from 'rxjs/Subscription' ;
@@ -1466,7 +1466,7 @@ describe('MdAutocomplete', () => {
1466
1466
} ) ;
1467
1467
} ) ) ;
1468
1468
1469
- it ( 'should call emit an event when an option is selected' , fakeAsync ( ( ) => {
1469
+ it ( 'should emit an event when an option is selected' , fakeAsync ( ( ) => {
1470
1470
let fixture = TestBed . createComponent ( AutocompleteWithSelectEvent ) ;
1471
1471
1472
1472
fixture . detectChanges ( ) ;
@@ -1475,19 +1475,45 @@ describe('MdAutocomplete', () => {
1475
1475
fixture . detectChanges ( ) ;
1476
1476
1477
1477
let options = overlayContainerElement . querySelectorAll ( 'md-option' ) as NodeListOf < HTMLElement > ;
1478
- let spy = fixture . componentInstance . select ;
1478
+ let spy = fixture . componentInstance . optionSelected ;
1479
1479
1480
1480
options [ 1 ] . click ( ) ;
1481
1481
tick ( ) ;
1482
1482
fixture . detectChanges ( ) ;
1483
1483
1484
1484
expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
1485
1485
1486
- let event = spy . calls . mostRecent ( ) . args [ 0 ] as MdAutocompleteSelect ;
1486
+ let event = spy . calls . mostRecent ( ) . args [ 0 ] as MdAutocompleteSelectedEvent ;
1487
1487
1488
1488
expect ( event . source ) . toBe ( fixture . componentInstance . autocomplete ) ;
1489
1489
expect ( event . option . value ) . toBe ( 'Washington' ) ;
1490
1490
} ) ) ;
1491
+
1492
+ it ( 'should emit an event when a newly-added option is selected' , fakeAsync ( ( ) => {
1493
+ let fixture = TestBed . createComponent ( AutocompleteWithSelectEvent ) ;
1494
+
1495
+ fixture . detectChanges ( ) ;
1496
+ fixture . componentInstance . trigger . openPanel ( ) ;
1497
+ tick ( ) ;
1498
+ fixture . detectChanges ( ) ;
1499
+
1500
+ fixture . componentInstance . states . push ( 'Puerto Rico' ) ;
1501
+ fixture . detectChanges ( ) ;
1502
+
1503
+ let options = overlayContainerElement . querySelectorAll ( 'md-option' ) as NodeListOf < HTMLElement > ;
1504
+ let spy = fixture . componentInstance . optionSelected ;
1505
+
1506
+ options [ 3 ] . click ( ) ;
1507
+ tick ( ) ;
1508
+ fixture . detectChanges ( ) ;
1509
+
1510
+ expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
1511
+
1512
+ let event = spy . calls . mostRecent ( ) . args [ 0 ] as MdAutocompleteSelectedEvent ;
1513
+
1514
+ expect ( event . source ) . toBe ( fixture . componentInstance . autocomplete ) ;
1515
+ expect ( event . option . value ) . toBe ( 'Puerto Rico' ) ;
1516
+ } ) ) ;
1491
1517
} ) ;
1492
1518
1493
1519
@Component ( {
@@ -1738,7 +1764,7 @@ class AutocompleteWithFormsAndNonfloatingPlaceholder {
1738
1764
<input mdInput placeholder="State" [mdAutocomplete]="auto" [(ngModel)]="selectedState">
1739
1765
</md-input-container>
1740
1766
1741
- <md-autocomplete #auto="mdAutocomplete" (select )="select ($event)">
1767
+ <md-autocomplete #auto="mdAutocomplete" (optionSelected )="optionSelected ($event)">
1742
1768
<md-option *ngFor="let state of states" [value]="state">
1743
1769
<span>{{ state }}</span>
1744
1770
</md-option>
@@ -1748,7 +1774,7 @@ class AutocompleteWithFormsAndNonfloatingPlaceholder {
1748
1774
class AutocompleteWithSelectEvent {
1749
1775
selectedState : string ;
1750
1776
states = [ 'New York' , 'Washington' , 'Oregon' ] ;
1751
- select = jasmine . createSpy ( 'select callback' ) ;
1777
+ optionSelected = jasmine . createSpy ( 'optionSelected callback' ) ;
1752
1778
1753
1779
@ViewChild ( MdAutocompleteTrigger ) trigger : MdAutocompleteTrigger ;
1754
1780
@ViewChild ( MdAutocomplete ) autocomplete : MdAutocomplete ;
0 commit comments