From c5d1b530b3696807dfdbb500a21276b080e7b55c Mon Sep 17 00:00:00 2001 From: Blackbaud-SteveBrush Date: Fri, 3 May 2019 10:13:47 -0400 Subject: [PATCH 1/2] Fix date range Angular form control statuses --- package.json | 2 +- .../datepicker/datepicker-input.directive.ts | 1 + .../datepicker/datepicker.component.spec.ts | 60 +++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index cca5ec89..f0c54393 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "dependencies": {}, "devDependencies": { "@blackbaud/skyux": "2.48.3", - "@blackbaud/skyux-builder": "1.34.0", + "@blackbaud/skyux-builder": "1.34.1", "@skyux-sdk/builder-plugin-skyux": "1.0.0" } } diff --git a/src/app/public/modules/datepicker/datepicker-input.directive.ts b/src/app/public/modules/datepicker/datepicker-input.directive.ts index 7280ddaa..d86544a2 100644 --- a/src/app/public/modules/datepicker/datepicker-input.directive.ts +++ b/src/app/public/modules/datepicker/datepicker-input.directive.ts @@ -245,6 +245,7 @@ export class SkyDatepickerInputDirective .distinctUntilChanged() .takeUntil(this.ngUnsubscribe) .subscribe((value: Date) => { + this.isFirstChange = false; this.value = value; this.onTouched(); }); diff --git a/src/app/public/modules/datepicker/datepicker.component.spec.ts b/src/app/public/modules/datepicker/datepicker.component.spec.ts index a92a2d64..12458dcf 100644 --- a/src/app/public/modules/datepicker/datepicker.component.spec.ts +++ b/src/app/public/modules/datepicker/datepicker.component.spec.ts @@ -863,6 +863,66 @@ describe('datepicker', () => { })); }); + describe('Angular form control statuses', function () { + it('should set correct statuses on init', fakeAsync(function () { + fixture.detectChanges(); + tick(); + + expect(component.dateControl.valid).toBe(true); + expect(component.dateControl.pristine).toBe(true); + expect(component.dateControl.touched).toBe(false); + })); + + it('should set correct statuses on init', fakeAsync(function () { + fixture.detectChanges(); + tick(); + + expect(component.dateControl.valid).toBe(true); + expect(component.dateControl.pristine).toBe(true); + expect(component.dateControl.touched).toBe(false); + })); + + it('should set correct statuses after user types within input', fakeAsync(function () { + fixture.detectChanges(); + tick(); + + expect(component.dateControl.valid).toBe(true); + expect(component.dateControl.pristine).toBe(true); + expect(component.dateControl.touched).toBe(false); + + setInput(nativeElement, '1/1/2000', fixture); + blurInput(nativeElement, fixture); + fixture.detectChanges(); + tick(); + + expect(component.dateControl.valid).toBe(true); + expect(component.dateControl.pristine).toBe(false); + expect(component.dateControl.touched).toBe(true); + })); + + it('should set correct statuses after user selects from calendar', fakeAsync(function () { + fixture.detectChanges(); + tick(); + + expect(component.dateControl.valid).toBe(true); + expect(component.dateControl.pristine).toBe(true); + expect(component.dateControl.touched).toBe(false); + + openDatepicker(fixture.nativeElement, fixture); + tick(); + fixture.detectChanges(); + tick(); + + fixture.nativeElement.querySelector('.sky-datepicker-btn-selected').click(); + fixture.detectChanges(); + tick(); + + expect(component.dateControl.valid).toBe(true); + expect(component.dateControl.pristine).toBe(false); + expect(component.dateControl.touched).toBe(true); + })); + }); + describe('validation', () => { it('should validate properly when invalid date is passed through input change', From 1696dbae7fcb4b87b74bc288c148c76900e5d919 Mon Sep 17 00:00:00 2001 From: Blackbaud-SteveBrush Date: Fri, 3 May 2019 15:08:11 -0400 Subject: [PATCH 2/2] Fix unit tests --- .../public/modules/datepicker/datepicker.component.spec.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app/public/modules/datepicker/datepicker.component.spec.ts b/src/app/public/modules/datepicker/datepicker.component.spec.ts index 12458dcf..88a96b4e 100644 --- a/src/app/public/modules/datepicker/datepicker.component.spec.ts +++ b/src/app/public/modules/datepicker/datepicker.component.spec.ts @@ -864,7 +864,8 @@ describe('datepicker', () => { }); describe('Angular form control statuses', function () { - it('should set correct statuses on init', fakeAsync(function () { + it('should set correct statuses when initialized without value', fakeAsync(function () { + fixture.componentInstance.initialValue = undefined; fixture.detectChanges(); tick(); @@ -873,7 +874,8 @@ describe('datepicker', () => { expect(component.dateControl.touched).toBe(false); })); - it('should set correct statuses on init', fakeAsync(function () { + it('should set correct statuses when initialized with value', fakeAsync(function () { + fixture.componentInstance.initialValue = '1/1/2000'; fixture.detectChanges(); tick();