|
1 | 1 | import { ComponentFixture, TestBed, fakeAsync, tick, waitForAsync, flush } from '@angular/core/testing';
|
2 | 2 | import { Component, OnInit, ViewChild, DebugElement, ChangeDetectionStrategy } from '@angular/core';
|
3 |
| -import { IgxInputDirective, IgxInputState, IgxLabelDirective, IgxPrefixDirective, IgxSuffixDirective } from '../input-group/public_api'; |
| 3 | +import { IgxInputDirective, IgxInputGroupComponent, IgxInputState, IgxLabelDirective, IgxPrefixDirective, IgxSuffixDirective } from '../input-group/public_api'; |
4 | 4 | import { PickerInteractionMode } from '../date-common/types';
|
5 | 5 | import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
6 | 6 | import { FormsModule, ReactiveFormsModule, UntypedFormBuilder, UntypedFormControl, Validators } from '@angular/forms';
|
@@ -29,6 +29,7 @@ import localeBg from "@angular/common/locales/bg";
|
29 | 29 | // The number of milliseconds in one day
|
30 | 30 | const DEBOUNCE_TIME = 16;
|
31 | 31 | const DEFAULT_ICON_TEXT = 'date_range';
|
| 32 | +const CLEAR_ICON_TEXT = 'clear'; |
32 | 33 | const DEFAULT_FORMAT_OPTIONS = { day: '2-digit', month: '2-digit', year: 'numeric' };
|
33 | 34 | const CSS_CLASS_INPUT_BUNDLE = '.igx-input-group__bundle';
|
34 | 35 | const CSS_CLASS_INPUT_START = '.igx-input-group__bundle-start'
|
@@ -399,6 +400,72 @@ describe('IgxDateRangePicker', () => {
|
399 | 400 | });
|
400 | 401 | });
|
401 | 402 |
|
| 403 | + describe('Clear tests', () => { |
| 404 | + describe('Default clear icon', () => { |
| 405 | + it('should display default clear icon when value is set', () => { |
| 406 | + const inputGroup = fixture.debugElement.query(By.directive(IgxInputGroupComponent)); |
| 407 | + let suffix = inputGroup.query(By.directive(IgxSuffixDirective)); |
| 408 | + expect(suffix).toBeNull(); |
| 409 | + |
| 410 | + dateRange.value = { start: new Date(2025, 1, 1), end: new Date(2025, 1, 2) }; |
| 411 | + fixture.detectChanges(); |
| 412 | + |
| 413 | + suffix = inputGroup.query(By.directive(IgxSuffixDirective)); |
| 414 | + const icon = suffix.query(By.css(CSS_CLASS_ICON)); |
| 415 | + expect(icon).not.toBeNull(); |
| 416 | + expect(icon.nativeElement.textContent.trim()).toEqual(CLEAR_ICON_TEXT); |
| 417 | + }); |
| 418 | + |
| 419 | + it('should clear the value when clicking the default clear icon (suffix)', fakeAsync(() => { |
| 420 | + dateRange.value = { start: new Date(2025, 1, 1), end: new Date(2025, 1, 2) }; |
| 421 | + fixture.detectChanges(); |
| 422 | + |
| 423 | + const inputGroup = fixture.debugElement.query(By.directive(IgxInputGroupComponent)); |
| 424 | + let suffix = inputGroup.query(By.directive(IgxSuffixDirective)); |
| 425 | + spyOn(dateRange.valueChange, 'emit'); |
| 426 | + |
| 427 | + UIInteractions.simulateClickAndSelectEvent(suffix.nativeElement); |
| 428 | + tick(); |
| 429 | + fixture.detectChanges(); |
| 430 | + |
| 431 | + expect(dateRange.value).toBeNull(); |
| 432 | + suffix = inputGroup.query(By.directive(IgxSuffixDirective)); |
| 433 | + expect(suffix).toBeNull(); |
| 434 | + expect(dateRange.valueChange.emit).toHaveBeenCalledOnceWith(null); |
| 435 | + })); |
| 436 | + |
| 437 | + it('should not clear the value when clicking element in the suffix that is not the clear icon', fakeAsync(() => { |
| 438 | + fixture = TestBed.createComponent(DateRangeTemplatesComponent); |
| 439 | + fixture.detectChanges(); |
| 440 | + |
| 441 | + dateRange = fixture.debugElement.queryAll(By.directive(IgxDateRangePickerComponent))[0].componentInstance; |
| 442 | + const range = { start: new Date(2025, 1, 1), end: new Date(2025, 1, 2) }; |
| 443 | + dateRange.value = range; |
| 444 | + fixture.detectChanges(); |
| 445 | + |
| 446 | + const suffixIconText = 'flight_land'; |
| 447 | + const inputGroupsEnd = fixture.debugElement.queryAll(By.css(CSS_CLASS_INPUT_END)); |
| 448 | + |
| 449 | + const customSuffix = inputGroupsEnd[1]; |
| 450 | + expect(customSuffix.children[0].nativeElement.innerText).toBe(suffixIconText); |
| 451 | + expect(customSuffix.children[0].children[0].classes[CSS_CLASS_ICON]).toBeTruthy(); |
| 452 | + |
| 453 | + const suffix = inputGroupsEnd[0]; |
| 454 | + const icon = suffix.query(By.css(CSS_CLASS_ICON)); |
| 455 | + expect(icon).not.toBeNull(); |
| 456 | + expect(icon.nativeElement.textContent.trim()).toEqual(CLEAR_ICON_TEXT); |
| 457 | + |
| 458 | + UIInteractions.simulateClickAndSelectEvent(customSuffix.nativeElement); |
| 459 | + tick(); |
| 460 | + fixture.detectChanges(); |
| 461 | + |
| 462 | + expect(dateRange.value).toEqual(range); |
| 463 | + })); |
| 464 | + }); |
| 465 | + |
| 466 | + //xdescribe('Projected clear icon', () => {}); |
| 467 | + }); |
| 468 | + |
402 | 469 | describe('Properties & events tests', () => {
|
403 | 470 | it('should display placeholder', () => {
|
404 | 471 | fixture.detectChanges();
|
|
0 commit comments