@@ -2667,37 +2667,6 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
26672667 expect ( dropdownList ) . toBeNull ( ) ;
26682668 } ) ) ;
26692669
2670- it ( 'Should commit the input and new chip after picking date from calendar for filtering.' , fakeAsync ( ( ) => {
2671- // Click date filter chip to show filter row.
2672- const filterCells = fix . debugElement . queryAll ( By . directive ( IgxGridFilteringCellComponent ) ) ;
2673- const dateFilterCell = filterCells . find ( ( fc ) => fc . componentInstance . column . field === 'ReleaseDate' ) ;
2674- const dateFilterCellChip = dateFilterCell . query ( By . directive ( IgxChipComponent ) ) ;
2675- dateFilterCellChip . nativeElement . click ( ) ;
2676- tick ( 100 ) ;
2677- fix . detectChanges ( ) ;
2678-
2679- // Click input to open calendar.
2680- const filteringRow = fix . debugElement . query ( By . directive ( IgxGridFilteringRowComponent ) ) ;
2681- const input = filteringRow . query ( By . directive ( IgxInputDirective ) ) ;
2682- input . nativeElement . click ( ) ;
2683- tick ( 100 ) ;
2684- fix . detectChanges ( ) ;
2685-
2686- // Click the today date.
2687- const outlet = document . getElementsByClassName ( 'igx-grid__outlet' ) [ 0 ] ;
2688- const calendar = outlet . getElementsByClassName ( 'igx-calendar' ) [ 0 ] ;
2689- const todayDayItem = calendar . querySelector ( '.igx-calendar__date--current' ) ;
2690- ( < HTMLElement > todayDayItem ) . click ( ) ;
2691- tick ( 100 ) ;
2692- fix . detectChanges ( ) ;
2693-
2694- // Verify the chip and input are committed.
2695- const activeFiltersArea = filteringRow . query ( By . css ( '.igx-grid__filtering-row-main' ) ) ;
2696- const activeFilterChip = activeFiltersArea . query ( By . directive ( IgxChipComponent ) ) ;
2697- expect ( ( < IgxChipComponent > activeFilterChip . componentInstance ) . selected ) . toBe ( false , 'chip is not committed' ) ;
2698- expect ( ( < IgxInputDirective > input . componentInstance ) . value ) . toBeNull ( 'input value is present and not committed' ) ;
2699- } ) ) ;
2700-
27012670 it ( 'Should correctly change resource strings for filter row.' , fakeAsync ( ( ) => {
27022671 fix = TestBed . createComponent ( IgxGridFilteringComponent ) ;
27032672 grid = fix . componentInstance . grid ;
@@ -3474,6 +3443,88 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
34743443 const headerChip = GridFunctions . getFilterChipsForColumn ( 'ProductName' , fix ) ;
34753444 expect ( headerChip . length ) . toBe ( 1 ) ;
34763445 } ) ) ;
3446+
3447+ it ( 'Should commit the input and new chip after focus out and should edit chip without creating new one.' , fakeAsync ( ( ) => {
3448+ // Click date filter chip to show filter row.
3449+ const dateFilterCellChip = GridFunctions . getFilterChipsForColumn ( 'ReleaseDate' , fix ) [ 0 ] ;
3450+ dateFilterCellChip . nativeElement . click ( ) ;
3451+ tick ( 100 ) ;
3452+ fix . detectChanges ( ) ;
3453+
3454+ // Click input to open calendar.
3455+ const filteringRow = fix . debugElement . query ( By . directive ( IgxGridFilteringRowComponent ) ) ;
3456+ const inputDebugElement = filteringRow . query ( By . directive ( IgxInputDirective ) ) ;
3457+ const input = inputDebugElement . nativeElement ;
3458+ input . click ( ) ;
3459+ tick ( 100 ) ;
3460+ fix . detectChanges ( ) ;
3461+
3462+ // Click the today date.
3463+ const outlet = document . getElementsByClassName ( 'igx-grid__outlet' ) [ 0 ] ;
3464+ let calendar = outlet . getElementsByClassName ( 'igx-calendar' ) [ 0 ] ;
3465+ const todayDayItem : HTMLElement = calendar . querySelector ( '.igx-calendar__date--current' ) ;
3466+ clickHtmlElemAndBlur ( todayDayItem , inputDebugElement ) ;
3467+ tick ( 100 ) ;
3468+ fix . detectChanges ( ) ;
3469+
3470+ // Verify the newly added chip is selected.
3471+ const chip = GridFunctions . getFilterConditionChip ( fix , 0 ) ;
3472+ const chipDiv = chip . querySelector ( '.igx-chip__item' ) ;
3473+
3474+ expect ( chipDiv . classList . contains ( 'igx-chip__item--selected' ) ) . toBe ( true , 'initial chip is committed' ) ;
3475+
3476+ // Focus out
3477+ clickHtmlElemAndBlur ( chip , inputDebugElement ) ;
3478+ tick ( 200 ) ;
3479+ fix . detectChanges ( ) ;
3480+
3481+ expect ( chipDiv . classList . contains ( 'igx-chip__item--selected' ) ) . toBe ( false , 'initial chip is not committed' ) ;
3482+ expect ( input . value ) . toBe ( '' , 'initial input value is present and not committed' ) ;
3483+
3484+ chip . click ( ) ;
3485+ tick ( 200 ) ;
3486+ fix . detectChanges ( ) ;
3487+
3488+ // Open calendar
3489+ input . click ( ) ;
3490+ tick ( 100 ) ;
3491+ fix . detectChanges ( ) ;
3492+
3493+ calendar = outlet . getElementsByClassName ( 'igx-calendar' ) [ 0 ] ;
3494+
3495+ // View years
3496+ const yearView : HTMLElement = calendar . querySelectorAll ( '.igx-calendar-picker__date' ) [ 1 ] as HTMLElement ;
3497+ yearView . click ( ) ;
3498+ tick ( 100 ) ;
3499+ fix . detectChanges ( ) ;
3500+
3501+ // Select the first year
3502+ const firstYear : HTMLElement = calendar . querySelectorAll ( '.igx-calendar__year' ) [ 0 ] as HTMLElement ;
3503+ firstYear . click ( ) ;
3504+ tick ( 100 ) ;
3505+ fix . detectChanges ( ) ;
3506+
3507+ // Select the first day
3508+ const firstDayItem : HTMLElement = calendar . querySelector ( '.igx-calendar__date' ) ;
3509+ clickHtmlElemAndBlur ( firstDayItem , inputDebugElement ) ;
3510+ tick ( 100 ) ;
3511+ fix . detectChanges ( ) ;
3512+
3513+ expect ( chipDiv . classList . contains ( 'igx-chip__item--selected' ) ) . toBe ( true , 'chip is committed' ) ;
3514+
3515+ // Focus out
3516+ clickHtmlElemAndBlur ( chip , inputDebugElement ) ;
3517+ tick ( 200 ) ;
3518+ fix . detectChanges ( ) ;
3519+ expect ( chipDiv . classList . contains ( 'igx-chip__item--selected' ) ) . toBe ( false , 'chip is selected' ) ;
3520+
3521+ // Check if we still have only one committed chip
3522+ const chipsLength = GridFunctions . getAllFilterConditionChips ( fix ) . length ;
3523+
3524+ expect ( chipsLength ) . toBe ( 1 , 'there is more than one chip' ) ;
3525+ expect ( chipDiv . classList . contains ( 'igx-chip__item--selected' ) ) . toBe ( false , 'chip is not committed' ) ;
3526+ expect ( input . value ) . toBe ( '' , 'input value is present and not committed' ) ;
3527+ } ) ) ;
34773528 } ) ;
34783529 describe ( null , ( ) => {
34793530 let fix , grid ;
@@ -6491,12 +6542,18 @@ function verifyChipVisibility(fix, index: number, shouldBeFullyVisible: boolean)
64916542 . toBe ( shouldBeFullyVisible , 'chip[' + index + '] visibility is incorrect' ) ;
64926543}
64936544
6494- function clickElemAndBlur ( clickElem , blurElem ) {
6495- const elementRect = clickElem . nativeElement . getBoundingClientRect ( ) ;
6496- UIInteractions . simulatePointerEvent ( 'pointerdown' , clickElem . nativeElement , elementRect . left , elementRect . top ) ;
6545+ function clickElemAndBlur ( clickElem : DebugElement , blurElem : DebugElement ) {
6546+ const clickHtmlElem = clickElem . nativeElement ;
6547+
6548+ clickHtmlElemAndBlur ( clickHtmlElem , blurElem ) ;
6549+ }
6550+
6551+ function clickHtmlElemAndBlur ( clickElem : HTMLElement , blurElem : DebugElement ) {
6552+ const elementRect = clickElem . getBoundingClientRect ( ) ;
6553+ UIInteractions . simulatePointerEvent ( 'pointerdown' , clickElem , elementRect . left , elementRect . top ) ;
64976554 blurElem . nativeElement . blur ( ) ;
6498- ( clickElem as DebugElement ) . nativeElement . focus ( ) ;
6555+ clickElem . focus ( ) ;
64996556 blurElem . nativeElement . dispatchEvent ( new FocusEvent ( 'focusout' , { bubbles : true } ) ) ;
6500- UIInteractions . simulatePointerEvent ( 'pointerup' , clickElem . nativeElement , elementRect . left , elementRect . top ) ;
6501- UIInteractions . simulateMouseEvent ( 'click' , clickElem . nativeElement , 10 , 10 ) ;
6557+ UIInteractions . simulatePointerEvent ( 'pointerup' , clickElem , elementRect . left , elementRect . top ) ;
6558+ UIInteractions . simulateMouseEvent ( 'click' , clickElem , 10 , 10 ) ;
65026559}
0 commit comments