Skip to content

Commit 6f53e7b

Browse files
committed
chore(*): fix unit test #6594
1 parent 7351dea commit 6f53e7b

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

projects/igniteui-angular/src/lib/grids/grid/grid-filtering-ui.spec.ts

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3446,80 +3446,85 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
34463446

34473447
it('Should commit the input and new chip after focus out and should edit chip without creating new one.', fakeAsync(() => {
34483448
// Click date filter chip to show filter row.
3449-
const filterCells = fix.debugElement.queryAll(By.directive(IgxGridFilteringCellComponent));
3450-
const dateFilterCell = filterCells.find((fc) => fc.componentInstance.column.field === 'ReleaseDate');
3451-
const dateFilterCellChip = dateFilterCell.query(By.directive(IgxChipComponent));
3449+
const dateFilterCellChip = GridFunctions.getFilterChipsForColumn('ReleaseDate', fix)[0];
34523450
dateFilterCellChip.nativeElement.click();
34533451
tick(100);
34543452
fix.detectChanges();
34553453

34563454
// Click input to open calendar.
34573455
const filteringRow = fix.debugElement.query(By.directive(IgxGridFilteringRowComponent));
3458-
const input = filteringRow.query(By.directive(IgxInputDirective));
3459-
input.nativeElement.click();
3456+
const inputDebugElement = filteringRow.query(By.directive(IgxInputDirective));
3457+
const input = inputDebugElement.nativeElement;
3458+
input.click();
34603459
tick(100);
34613460
fix.detectChanges();
34623461

34633462
// Click the today date.
34643463
const outlet = document.getElementsByClassName('igx-grid__outlet')[0];
34653464
let calendar = outlet.getElementsByClassName('igx-calendar')[0];
3466-
const todayDayItem = calendar.querySelector('.igx-calendar__date--current');
3467-
(<HTMLElement>todayDayItem).click();
3465+
const todayDayItem: HTMLElement = calendar.querySelector('.igx-calendar__date--current');
3466+
todayDayItem.click();
34683467
tick(100);
34693468
fix.detectChanges();
34703469

3470+
// Select our newly added chip
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')).toBeTruthy('initial chip is committed');
3475+
34713476
// Focus out
3472-
clickElemAndBlur(dateFilterCellChip, input);
3477+
clickElemAndBlur(dateFilterCellChip, inputDebugElement);
34733478
tick(200);
34743479
fix.detectChanges();
3475-
expect(dateFilterCellChip.componentInstance.selected).toBeFalsy('initial chip is not committed');
3476-
expect((<IgxInputDirective>input.componentInstance).value).toBeNull('initial input value is present and not committed');
3480+
expect(chipDiv.classList.contains('igx-chip__item--selected')).toBeFalsy('initial chip is not committed');
3481+
expect(input.value).toBeFalsy('initial input value is present and not committed');
34773482

3478-
// Select our newly added chip to edit it
3479-
const chip = GridFunctions.getFilterConditionChip(fix, 0);
34803483
chip.click();
34813484
tick(200);
34823485
fix.detectChanges();
34833486

34843487
// Open calendar
3485-
input.nativeElement.click();
3488+
input.click();
34863489
tick(100);
34873490
fix.detectChanges();
34883491

34893492
calendar = outlet.getElementsByClassName('igx-calendar')[0];
34903493

34913494
// View years
3492-
const yearView = calendar.querySelectorAll('.igx-calendar-picker__date')[1];
3493-
(<HTMLElement>yearView).click();
3495+
const yearView: HTMLElement = calendar.querySelectorAll('.igx-calendar-picker__date')[1] as HTMLElement;
3496+
yearView.click();
34943497
tick(100);
34953498
fix.detectChanges();
34963499

34973500
// Select the first year
3498-
const firstYear = calendar.querySelectorAll('.igx-calendar__year')[0];
3499-
(<HTMLElement>firstYear).click();
3501+
const firstYear: HTMLElement = calendar.querySelectorAll('.igx-calendar__year')[0] as HTMLElement;
3502+
firstYear.click();
35003503
tick(100);
35013504
fix.detectChanges();
35023505

35033506
// Select the first day
3504-
const firstDayItem = calendar.querySelector('.igx-calendar__date');
3505-
(<HTMLElement>firstDayItem).click();
3507+
const firstDayItem: HTMLElement = calendar.querySelector('.igx-calendar__date');
3508+
firstDayItem.click();
35063509
tick(100);
35073510
fix.detectChanges();
35083511

3512+
expect(chipDiv.classList.contains('igx-chip__item--selected')).toBeTruthy('chip is committed');
3513+
35093514
// Focus out
3510-
clickElemAndBlur(dateFilterCellChip, input);
3515+
clickElemAndBlur(dateFilterCellChip, inputDebugElement);
35113516
tick(200);
35123517
fix.detectChanges();
3513-
expect(dateFilterCellChip.componentInstance.selected).toBeFalsy();
3518+
expect(chipDiv.classList.contains('igx-chip__item--selected')).toBe(false, 'chip is selected');
35143519

35153520
// Check if we still have only one committed chip
35163521
const activeFiltersArea = filteringRow.query(By.css('.igx-grid__filtering-row-main'));
3517-
const activeFilterChip = activeFiltersArea.query(By.directive(IgxChipComponent));
3522+
const activeFilterChip: IgxChipComponent = activeFiltersArea.query(By.directive(IgxChipComponent)).componentInstance;
35183523
const chipsLength = GridFunctions.getAllFilterConditionChips(fix).length;
35193524

35203525
expect(chipsLength).toBe(1, 'there is more than one chip');
3521-
expect((<IgxChipComponent>activeFilterChip.componentInstance).selected).toBe(false, 'chip is not committed');
3522-
expect((<IgxInputDirective>input.componentInstance).value).toBeNull('input value is present and not committed');
3526+
expect(activeFilterChip.selected).toBe(false, 'chip is not committed');
3527+
expect(input.value).toBeFalsy('input value is present and not committed');
35233528
}));
35243529
});
35253530
describe(null, () => {

0 commit comments

Comments
 (0)