@@ -2,7 +2,6 @@ import { AfterViewInit, ChangeDetectorRef, Component, Injectable, OnInit, ViewCh
22import { async , TestBed , ComponentFixture , tick , fakeAsync } from '@angular/core/testing' ;
33import { By } from '@angular/platform-browser' ;
44import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
5- import { SortingDirection } from '../data-operations/sorting-expression.interface' ;
65import { IgxToggleModule } from '../directives/toggle/toggle.directive' ;
76import { IgxComboItemComponent } from './combo-item.component' ;
87import { IgxComboComponent , IgxComboModule , IComboSelectionChangeEventArgs , IgxComboState } from './combo.component' ;
@@ -12,13 +11,13 @@ import { IForOfState } from '../directives/for-of/for_of.directive';
1211import { BehaviorSubject , Observable } from 'rxjs' ;
1312import { take } from 'rxjs/operators' ;
1413import { UIInteractions , wait } from '../test-utils/ui-interactions.spec' ;
15- import { DefaultSortingStrategy } from '../data-operations/sorting-strategy' ;
1614import { configureTestSuite } from '../test-utils/configure-suite' ;
1715import { IgxDropDownItemBaseDirective } from '../drop-down/drop-down-item.base' ;
1816import { DisplayDensity , DisplayDensityToken } from '../core/density' ;
1917import { AbsoluteScrollStrategy , ConnectedPositioningStrategy } from '../services/index' ;
2018import { IgxInputState } from '../directives/input/input.directive' ;
2119import { IgxComboFilteringPipe } from './combo.pipes' ;
20+ import { IgxComboAddItemComponent } from './combo-add-item.component' ;
2221
2322const CSS_CLASS_COMBO = 'igx-combo' ;
2423const CSS_CLASS_COMBO_DROPDOWN = 'igx-combo__drop-down' ;
@@ -323,7 +322,7 @@ describe('igxCombo', () => {
323322 expect ( dropdown . navigatePrev ) . toHaveBeenCalledTimes ( 1 ) ;
324323 } ) ) ;
325324
326- it ( 'Should properly call dropdown navigateNext with virutal items' , ( async ( ) => {
325+ it ( 'Should properly call dropdown navigateNext with virtual items' , ( async ( ) => {
327326 const fix = TestBed . createComponent ( IgxComboSampleComponent ) ;
328327 fix . detectChanges ( ) ;
329328 const combo = fix . componentInstance . combo ;
@@ -335,18 +334,17 @@ describe('igxCombo', () => {
335334 const mockClick = jasmine . createSpyObj ( 'event' , [ 'preventDefault' , 'stopPropagation' ] ) ;
336335 const virtualMockUP = spyOn < any > ( dropdown , 'navigatePrev' ) . and . callThrough ( ) ;
337336 const virtualMockDOWN = spyOn < any > ( dropdown , 'navigateNext' ) . and . callThrough ( ) ;
338- // expect(mockFn).toThrow();
339337 expect ( dropdown . focusedItem ) . toEqual ( null ) ;
340338 expect ( combo . collapsed ) . toBeTruthy ( ) ;
341339 combo . toggle ( ) ;
342340 await wait ( 30 ) ;
343341 fix . detectChanges ( ) ;
344- // expect(mockObj.focus).toHaveBeenCalledTimes(1);
345342 expect ( combo . collapsed ) . toBeFalsy ( ) ;
346343 ( combo as any ) . virtDir . scrollTo ( 51 ) ;
347344 await wait ( 30 ) ;
348345 fix . detectChanges ( ) ;
349- const lastItem = fix . debugElement . queryAll ( By . css ( '.' + CSS_CLASS_DROPDOWNLISTITEM ) ) [ 8 ] . componentInstance ;
346+ let items = fix . debugElement . queryAll ( By . css ( '.' + CSS_CLASS_DROPDOWNLISTITEM ) ) ;
347+ let lastItem = items [ items . length - 1 ] . componentInstance ;
350348 expect ( lastItem ) . toBeDefined ( ) ;
351349 lastItem . clicked ( mockClick ) ;
352350 await wait ( 30 ) ;
@@ -365,22 +363,18 @@ describe('igxCombo', () => {
365363 fix . detectChanges ( ) ;
366364 expect ( virtualMockDOWN ) . toHaveBeenCalledTimes ( 1 ) ;
367365 combo . searchValue = 'New' ;
368- await wait ( 30 ) ;
369- lastItem . clicked ( mockClick ) ;
370- fix . detectChanges ( ) ;
371- expect ( dropdown . focusedItem ) . toEqual ( lastItem ) ;
366+ combo . handleInputChange ( ) ;
372367 fix . detectChanges ( ) ;
373- expect ( combo . customValueFlag && combo . searchValue !== '' ) . toBeTruthy ( ) ;
374- dropdown . navigateNext ( ) ;
375- await wait ( 30 ) ;
376- expect ( virtualMockDOWN ) . toHaveBeenCalledTimes ( 2 ) ;
377- lastItem . value = ( combo as any ) . virtDir . igxForOf [ ( combo as any ) . virtDir . igxForOf . length - 1 ] ;
378- lastItem . clicked ( mockClick ) ;
379368 await wait ( 30 ) ;
369+ items = fix . debugElement . queryAll ( By . css ( '.' + CSS_CLASS_DROPDOWNLISTITEM ) ) ;
370+ lastItem = items [ items . length - 1 ] . componentInstance ;
371+ ( lastItem as IgxComboAddItemComponent ) . handleClick ( ) ;
380372 fix . detectChanges ( ) ;
381- expect ( dropdown . focusedItem ) . toEqual ( lastItem ) ;
382- dropdown . navigateNext ( ) ;
383- expect ( virtualMockDOWN ) . toHaveBeenCalledTimes ( 3 ) ;
373+ // After `Add Item` is clicked, the input is focused and the item is added to the list
374+ expect ( dropdown . focusedItem ) . toEqual ( null ) ;
375+ expect ( document . activeElement ) . toEqual ( combo . searchInput . nativeElement ) ;
376+ expect ( combo . customValueFlag ) . toBeFalsy ( ) ;
377+ expect ( combo . searchInput . nativeElement . value ) . toBeTruthy ( ) ;
384378
385379 // TEST move from first item
386380 ( combo as any ) . virtDir . scrollTo ( 0 ) ;
@@ -396,13 +390,11 @@ describe('igxCombo', () => {
396390 dropdown . navigateFirst ( ) ;
397391 await wait ( 30 ) ;
398392 fix . detectChanges ( ) ;
399- expect ( virtualMockDOWN ) . toHaveBeenCalledTimes ( 3 ) ;
400393 dropdown . navigatePrev ( ) ;
401394 await wait ( 30 ) ;
402395 fix . detectChanges ( ) ;
403396 // Called once before the `await` and called once more, because item @ index 0 is a header
404397 expect ( virtualMockUP ) . toHaveBeenCalledTimes ( 2 ) ;
405- expect ( virtualMockDOWN ) . toHaveBeenCalledTimes ( 3 ) ;
406398 } ) ) ;
407399 it ( 'Should call toggle properly' , fakeAsync ( ( ) => {
408400 const fixture = TestBed . createComponent ( IgxComboSampleComponent ) ;
@@ -2360,12 +2352,12 @@ describe('igxCombo', () => {
23602352 fix . detectChanges ( ) ;
23612353 expect ( combo . groupKey ) . toEqual ( 'region' ) ;
23622354 expect ( combo . dropdown . items [ 0 ] . value . field === combo . data [ 0 ] . field ) . toBeFalsy ( ) ;
2363- expect ( combo . sortingExpressions [ 0 ] ) . toEqual ( {
2364- fieldName : 'region' ,
2365- dir : SortingDirection . Asc ,
2366- ignoreCase : true ,
2367- strategy : DefaultSortingStrategy . instance ( )
2368- } ) ;
2355+ // expect(combo.sortingExpressions[0]).toEqual({
2356+ // fieldName: 'region',
2357+ // dir: SortingDirection.Asc,
2358+ // ignoreCase: true,
2359+ // strategy: DefaultSortingStrategy.instance()
2360+ // });
23692361 const listItems = fix . debugElement . queryAll ( By . css ( '.' + CSS_CLASS_DROPDOWNLISTITEM ) ) ;
23702362 const listHeaders = fix . debugElement . queryAll ( By . css ( '.' + CSS_CLASS_HEADERITEM ) ) ;
23712363 expect ( listItems . length ) . toBeGreaterThan ( 0 ) ;
@@ -2381,19 +2373,8 @@ describe('igxCombo', () => {
23812373 fix . detectChanges ( ) ;
23822374 expect ( combo . groupKey ) . toEqual ( 'region' ) ;
23832375 expect ( combo . dropdown . items [ 0 ] . value . field === combo . data [ 0 ] . field ) . toBeFalsy ( ) ;
2384- expect ( combo . sortingExpressions . length ) . toEqual ( 1 ) ;
2385- expect ( combo . sortingExpressions [ 0 ] ) . toEqual ( {
2386- fieldName : 'region' ,
2387- dir : SortingDirection . Asc ,
2388- ignoreCase : true ,
2389- strategy : DefaultSortingStrategy . instance ( )
2390- } ) ;
23912376 combo . groupKey = '' ;
23922377
2393- fix . detectChanges ( ) ;
2394- expect ( combo . groupKey ) . toEqual ( '' ) ;
2395- expect ( combo . sortingExpressions . length ) . toEqual ( 0 ) ;
2396- expect ( combo . sortingExpressions [ 0 ] ) . toBeUndefined ( ) ;
23972378 fix . detectChanges ( ) ;
23982379 expect ( combo . dropdown . items [ 0 ] . value ) . toEqual ( combo . data [ 0 ] ) ;
23992380 } ) ) ;
@@ -2487,7 +2468,6 @@ describe('igxCombo', () => {
24872468 expect ( combo . filteredData . length ) . toEqual ( initialData . length ) ;
24882469 expect ( combo . filteredData . length ) . toBeGreaterThan ( firstFilter . length ) ;
24892470 expect ( filterSpy ) . toHaveBeenCalledTimes ( 3 ) ;
2490- combo . filteringExpressions = [ ] ;
24912471 tick ( ) ;
24922472 fix . detectChanges ( ) ;
24932473 expect ( combo . filteredData . length ) . toEqual ( initialData . length ) ;
@@ -2528,70 +2508,38 @@ describe('igxCombo', () => {
25282508 fix . detectChanges ( ) ;
25292509 expect ( combo . selectedItems ( ) . length ) . toEqual ( 0 ) ;
25302510 } ) ) ;
2531- it ( 'Should properly sort filteredData' , fakeAsync ( ( ) => {
2532- const fix = TestBed . createComponent ( IgxComboSampleComponent ) ;
2533- fix . detectChanges ( ) ;
2534- const combo = fix . componentInstance . combo ;
2535- spyOn ( combo , 'sort' ) . and . callThrough ( ) ;
2536- const clearSpy = spyOn < any > ( combo , 'clearSorting' ) . and . callThrough ( ) ;
2537- combo . toggle ( ) ;
2538- tick ( ) ;
2539- fix . detectChanges ( ) ;
2540- expect ( combo . sort ) . toHaveBeenCalledTimes ( 0 ) ;
2541- expect ( combo . sortingExpressions . length ) . toEqual ( 1 ) ;
2542- expect ( combo . sortingExpressions [ 0 ] . fieldName ) . toEqual ( 'region' ) ;
2543- expect ( combo . groupKey ) . toEqual ( 'region' ) ;
2544- const initialFirstItem = '' + combo . filteredData [ 0 ] . field ;
2545- combo . groupKey = '' ;
2546- tick ( ) ;
2547- fix . detectChanges ( ) ;
2548- expect ( combo . sort ) . toHaveBeenCalledTimes ( 1 ) ;
2549- expect ( combo . groupKey ) . toEqual ( '' ) ;
2550- expect ( combo . sortingExpressions . length ) . toEqual ( 0 ) ;
2551- expect ( combo . sortingExpressions [ 0 ] ) . toBeUndefined ( ) ;
2552- expect ( combo . filteredData [ 0 ] . field !== initialFirstItem ) . toBeTruthy ( ) ;
2553- expect ( clearSpy ) . toHaveBeenCalledTimes ( 1 ) ;
2554- combo . groupKey = null ;
2555- tick ( ) ;
2556- fix . detectChanges ( ) ;
2557- expect ( combo . sort ) . toHaveBeenCalledTimes ( 2 ) ;
2558- expect ( combo . groupKey ) . toEqual ( null ) ;
2559- expect ( combo . sortingExpressions . length ) . toEqual ( 0 ) ;
2560- expect ( combo . sortingExpressions [ 0 ] ) . toBeUndefined ( ) ;
2561- expect ( combo . filteredData [ 0 ] . field !== initialFirstItem ) . toBeTruthy ( ) ;
2562- expect ( clearSpy ) . toHaveBeenCalledTimes ( 2 ) ;
2563- } ) ) ;
2511+
25642512 it ( 'Should properly handleInputChange' , ( ) => {
25652513 const fix = TestBed . createComponent ( IgxComboSampleComponent ) ;
25662514 fix . detectChanges ( ) ;
25672515 const combo = fix . componentInstance . combo ;
2568- const filterSpy = spyOn ( IgxComboFilteringPipe . prototype , 'transform ' ) . and . callThrough ( ) ;
2516+ const matchSpy = spyOn < any > ( combo , 'checkMatch ' ) . and . callThrough ( ) ;
25692517 spyOn ( combo . onSearchInput , 'emit' ) ;
25702518
25712519 combo . handleInputChange ( ) ;
25722520
25732521 fix . detectChanges ( ) ;
2574- expect ( filterSpy ) . toHaveBeenCalledTimes ( 1 ) ;
2522+ expect ( matchSpy ) . toHaveBeenCalledTimes ( 1 ) ;
25752523 expect ( combo . onSearchInput . emit ) . toHaveBeenCalledTimes ( 0 ) ;
25762524
25772525 combo . handleInputChange ( 'Fake' ) ;
25782526
25792527 fix . detectChanges ( ) ;
2580- expect ( filterSpy ) . toHaveBeenCalledTimes ( 2 ) ;
2528+ expect ( matchSpy ) . toHaveBeenCalledTimes ( 2 ) ;
25812529 expect ( combo . onSearchInput . emit ) . toHaveBeenCalledTimes ( 1 ) ;
25822530 expect ( combo . onSearchInput . emit ) . toHaveBeenCalledWith ( 'Fake' ) ;
25832531
25842532 combo . handleInputChange ( '' ) ;
25852533 fix . detectChanges ( ) ;
2586- expect ( filterSpy ) . toHaveBeenCalledTimes ( 3 ) ;
2534+ expect ( matchSpy ) . toHaveBeenCalledTimes ( 3 ) ;
25872535 expect ( combo . onSearchInput . emit ) . toHaveBeenCalledTimes ( 2 ) ;
25882536 expect ( combo . onSearchInput . emit ) . toHaveBeenCalledWith ( '' ) ;
25892537
25902538 combo . filterable = false ;
25912539 fix . detectChanges ( ) ;
25922540
25932541 combo . handleInputChange ( ) ;
2594- expect ( filterSpy ) . toHaveBeenCalledTimes ( 3 ) ;
2542+ expect ( matchSpy ) . toHaveBeenCalledTimes ( 4 ) ;
25952543 expect ( combo . onSearchInput . emit ) . toHaveBeenCalledTimes ( 2 ) ;
25962544 } ) ;
25972545 it ( 'Should properly handle addItemToCollection calls (Complex data)' , fakeAsync ( ( ) => {
0 commit comments