@@ -1556,6 +1556,136 @@ describe('IgxSimpleCombo', () => {
15561556
15571557 expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
15581558 } ) ) ;
1559+
1560+ it ( 'should emit selectionChanging event when input value changes' , ( ) => {
1561+ spyOn ( combo . selectionChanging , 'emit' ) . and . callThrough ( ) ;
1562+ fixture . detectChanges ( ) ;
1563+
1564+ combo . select ( 'Connecticut' ) ;
1565+ fixture . detectChanges ( ) ;
1566+
1567+ expect ( combo . selectionChanging . emit ) . toHaveBeenCalledTimes ( 1 ) ;
1568+ expect ( combo . selectionChanging . emit ) . toHaveBeenCalledWith ( {
1569+ newValue : "Connecticut" ,
1570+ oldValue : undefined ,
1571+ newSelection : {
1572+ field : "Connecticut" ,
1573+ region : "New England"
1574+ } ,
1575+ oldSelection : undefined ,
1576+ displayText : 'Connecticut' ,
1577+ owner : combo ,
1578+ cancel : false
1579+ } ) ;
1580+
1581+ combo . handleInputChange ( 'z' ) ;
1582+ fixture . detectChanges ( ) ;
1583+
1584+ expect ( combo . selectionChanging . emit ) . toHaveBeenCalledTimes ( 2 ) ;
1585+ expect ( combo . selectionChanging . emit ) . toHaveBeenCalledWith ( {
1586+ oldValue : "Connecticut" ,
1587+ newValue : undefined ,
1588+ oldSelection : {
1589+ field : "Connecticut" ,
1590+ region : "New England"
1591+ } ,
1592+ newSelection : undefined ,
1593+ owner : combo ,
1594+ displayText : "z" ,
1595+ cancel : false
1596+ } ) ;
1597+ } ) ;
1598+
1599+ it ( 'should not change selection when selectionChanging event is canceled' , ( ) => {
1600+ spyOn ( combo . selectionChanging , 'emit' ) . and . callThrough ( ) ;
1601+
1602+ fixture . detectChanges ( ) ;
1603+
1604+ combo . select ( 'Connecticut' ) ;
1605+ fixture . detectChanges ( ) ;
1606+
1607+ expect ( combo . selection ) . toEqual ( {
1608+ field : 'Connecticut' ,
1609+ region : 'New England'
1610+ } ) ;
1611+
1612+ const cancelEventSpy = spyOn ( combo . selectionChanging , 'emit' ) . and . callFake ( ( args : ISimpleComboSelectionChangingEventArgs ) => {
1613+ args . cancel = true ;
1614+ } ) ;
1615+
1616+ combo . handleInputChange ( 'z' ) ;
1617+ fixture . detectChanges ( ) ;
1618+
1619+ expect ( cancelEventSpy ) . toHaveBeenCalled ( ) ;
1620+ expect ( combo . selection ) . toEqual ( {
1621+ field : 'Connecticut' ,
1622+ region : 'New England'
1623+ } ) ;
1624+
1625+ combo . handleInputChange ( ' ' ) ;
1626+ fixture . detectChanges ( ) ;
1627+
1628+ expect ( cancelEventSpy ) . toHaveBeenCalled ( ) ;
1629+ expect ( combo . selection ) . toEqual ( {
1630+ field : 'Connecticut' ,
1631+ region : 'New England'
1632+ } ) ;
1633+ } ) ;
1634+
1635+
1636+ it ( 'should preserved the input value of the combo when selectionChanging event is canceled' , ( ) => {
1637+ spyOn ( combo . selectionChanging , 'emit' ) . and . callThrough ( ) ;
1638+ fixture . detectChanges ( ) ;
1639+
1640+ const comboInput = fixture . debugElement . query ( By . css ( `.igx-input-group__input` ) ) ;
1641+ fixture . detectChanges ( ) ;
1642+
1643+ combo . select ( 'Connecticut' ) ;
1644+ fixture . detectChanges ( ) ;
1645+
1646+ expect ( combo . selection ) . toEqual ( {
1647+ field : 'Connecticut' ,
1648+ region : 'New England'
1649+ } ) ;
1650+
1651+ const cancelEventSpy = spyOn ( combo . selectionChanging , 'emit' ) . and . callFake ( ( args : ISimpleComboSelectionChangingEventArgs ) => {
1652+ args . cancel = true ;
1653+ } ) ;
1654+
1655+ const clearButton = fixture . debugElement . query ( By . css ( `.${ CSS_CLASS_CLEARBUTTON } ` ) ) ;
1656+ clearButton . triggerEventHandler ( 'click' , UIInteractions . getMouseEvent ( 'click' ) ) ;
1657+ fixture . detectChanges ( ) ;
1658+
1659+ expect ( cancelEventSpy ) . toHaveBeenCalled ( ) ;
1660+ expect ( combo . selection ) . toEqual ( {
1661+ field : 'Connecticut' ,
1662+ region : 'New England'
1663+ } ) ;
1664+
1665+ expect ( comboInput . nativeElement . value ) . toEqual ( 'Connecticut' ) ;
1666+
1667+ combo . handleInputChange ( 'z' ) ;
1668+ fixture . detectChanges ( ) ;
1669+
1670+ expect ( cancelEventSpy ) . toHaveBeenCalled ( ) ;
1671+ expect ( combo . selection ) . toEqual ( {
1672+ field : 'Connecticut' ,
1673+ region : 'New England'
1674+ } ) ;
1675+
1676+ expect ( comboInput . nativeElement . value ) . toEqual ( 'Connecticut' ) ;
1677+
1678+ combo . handleInputChange ( ' ' ) ;
1679+ fixture . detectChanges ( ) ;
1680+
1681+ expect ( cancelEventSpy ) . toHaveBeenCalled ( ) ;
1682+ expect ( combo . selection ) . toEqual ( {
1683+ field : 'Connecticut' ,
1684+ region : 'New England'
1685+ } ) ;
1686+
1687+ expect ( comboInput . nativeElement . value ) . toEqual ( 'Connecticut' ) ;
1688+ } ) ;
15591689 } ) ;
15601690
15611691 describe ( 'Display density' , ( ) => {
0 commit comments