Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Fix date range Angular form control statuses #44

Merged
merged 5 commits into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export class SkyDatepickerInputDirective
.distinctUntilChanged()
.takeUntil(this.ngUnsubscribe)
.subscribe((value: Date) => {
this.isFirstChange = false;
Blackbaud-TrevorBurch marked this conversation as resolved.
Show resolved Hide resolved
this.value = value;
this.onTouched();
});
Expand Down
60 changes: 60 additions & 0 deletions src/app/public/modules/datepicker/datepicker.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Blackbaud-TrevorBurch marked this conversation as resolved.
Show resolved Hide resolved
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',
Expand Down