Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(date-value-handler): Date value fix (DEV-392) #771

Merged
merged 1 commit into from Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion angular.json
Expand Up @@ -56,7 +56,7 @@
"configurations": {
"development": {
"optimization": false,
"sourceMap": false,
"sourceMap": true,
"namedChunks": true,
"aot": true,
"extractLicenses": false,
Expand Down
Expand Up @@ -12,8 +12,9 @@
<mat-icon *ngIf="isPeriodControl.value">remove</mat-icon>
</button>

<div *ngIf="isPeriodControl.value" class="date-form-field">
<app-date-picker class="end-date" [formControlName]="'endDate'" [disableCalendarSelector]="true" [calendar]="startDate.value.calendar">
<div *ngIf="isPeriodControl.value && startDate.value" class="date-form-field">
<app-date-picker class="end-date" [formControlName]="'endDate'" [disableCalendarSelector]="true"
[calendar]="startDate.value.calendar">
</app-date-picker>
</div>
</div>
Expand All @@ -30,4 +31,4 @@
</mat-error>
</div>

</div>
</div>
Expand Up @@ -286,16 +286,25 @@ describe('DateValueHandlerComponent', () => {
(startDateEditComponentDe.componentInstance as TestDatePickerComponent).writeValue(new KnoraDate('JULIAN', 'CE', 2019, 5, 19));
(startDateEditComponentDe.componentInstance as TestDatePickerComponent)._handleInput();

testHostFixture.detectChanges();

const endDateEditComponentDe = hostCompDe.query(By.css('.end-date'));

(endDateEditComponentDe.componentInstance as TestDatePickerComponent).writeValue(new KnoraDate('JULIAN', 'CE', 2020, 5, 19));
(endDateEditComponentDe.componentInstance as TestDatePickerComponent)._handleInput();

testHostFixture.detectChanges();

await testHostFixture.whenStable();

expect(testHostComponent.dateValueHandlerComponent.form.valid).toBe(true);

expect(testHostComponent.form.controls.date.value).toEqual(new KnoraPeriod(new KnoraDate('JULIAN', 'CE', 2019, 5, 19), new KnoraDate('JULIAN', 'CE', 2020, 5, 19)));

// access private _subscriptions property and ensure that each subscription is still open
testHostComponent.dateValueHandlerComponent['_subscriptions'].forEach((sub) => {
expect(sub.closed).toBeFalse();
});
});

it('should return "null" for an invalid user input (start date greater than end date)', async () => {
Expand Down Expand Up @@ -373,7 +382,44 @@ describe('DateValueHandlerComponent (no validator required)', () => {
expect(testHostComponent).toBeTruthy();
});

it('should receive the propagated valueRequiredValidator from the parent component', () => {
it('should propagate changes made by the user for a period', async () => {
expect(testHostComponent.dateValueHandlerComponent.isPeriodControl.value).toBeFalse();

testHostComponent.dateValueHandlerComponent.isPeriodControl.setValue(true);

expect(testHostComponent.dateValueHandlerComponent.isPeriodControl.value).toBeTrue();

testHostFixture.detectChanges();

const hostCompDe = testHostFixture.debugElement;

const startDateEditComponentDe = hostCompDe.query(By.css('.start-date'));

(startDateEditComponentDe.componentInstance as TestDatePickerComponent).writeValue(new KnoraDate('JULIAN', 'CE', 2019, 5, 19));
(startDateEditComponentDe.componentInstance as TestDatePickerComponent)._handleInput();

testHostFixture.detectChanges();

const endDateEditComponentDe = hostCompDe.query(By.css('.end-date'));

(endDateEditComponentDe.componentInstance as TestDatePickerComponent).writeValue(new KnoraDate('JULIAN', 'CE', 2020, 5, 19));
(endDateEditComponentDe.componentInstance as TestDatePickerComponent)._handleInput();

testHostFixture.detectChanges();

await testHostFixture.whenStable();

expect(testHostComponent.dateValueHandlerComponent.form.valid).toBe(true);

expect(testHostComponent.form.controls.date.value).toEqual(new KnoraPeriod(new KnoraDate('JULIAN', 'CE', 2019, 5, 19), new KnoraDate('JULIAN', 'CE', 2020, 5, 19)));

// access private _subscriptions property and ensure that each subscription is still open
testHostComponent.dateValueHandlerComponent['_subscriptions'].forEach((sub) => {
expect(sub.closed).toBeFalse();
});
});

it('should not receive the propagated valueRequiredValidator from the parent component', () => {
expect(testHostComponent.dateValueHandlerComponent.valueRequiredValidator).toBe(false);
});

Expand Down
Expand Up @@ -100,7 +100,7 @@ export class DateValueHandlerComponent extends _MatInputMixinBase implements Con
if (!this.isPeriodControl.value) {
return this.startDate.value;
} else {
if (this.startDate.value.calendar !== this.endDate.value.calendar) {
if (this.endDate.value && (this.startDate.value.calendar !== this.endDate.value.calendar)) {
this.endDate.value.calendar = this.startDate.value.calendar;
}

Expand All @@ -109,7 +109,6 @@ export class DateValueHandlerComponent extends _MatInputMixinBase implements Con
}

set value(date: KnoraDate | KnoraPeriod | null) {

if (date instanceof KnoraDate) {
// single date
this.calendarControl.setValue(date.calendar);
Expand Down