diff --git a/angular.json b/angular.json index 3dac7cb86c..bae3a62750 100644 --- a/angular.json +++ b/angular.json @@ -56,7 +56,7 @@ "configurations": { "development": { "optimization": false, - "sourceMap": false, + "sourceMap": true, "namedChunks": true, "aot": true, "extractLicenses": false, diff --git a/src/app/workspace/resource/values/date-value/date-value-handler/date-value-handler.component.html b/src/app/workspace/resource/values/date-value/date-value-handler/date-value-handler.component.html index 96dc961936..bf068454e8 100644 --- a/src/app/workspace/resource/values/date-value/date-value-handler/date-value-handler.component.html +++ b/src/app/workspace/resource/values/date-value/date-value-handler/date-value-handler.component.html @@ -12,8 +12,9 @@ remove -
- +
+
@@ -30,4 +31,4 @@ - + \ No newline at end of file diff --git a/src/app/workspace/resource/values/date-value/date-value-handler/date-value-handler.component.spec.ts b/src/app/workspace/resource/values/date-value/date-value-handler/date-value-handler.component.spec.ts index c29d3a50e5..7825a0a48d 100644 --- a/src/app/workspace/resource/values/date-value/date-value-handler/date-value-handler.component.spec.ts +++ b/src/app/workspace/resource/values/date-value/date-value-handler/date-value-handler.component.spec.ts @@ -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 () => { @@ -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); }); diff --git a/src/app/workspace/resource/values/date-value/date-value-handler/date-value-handler.component.ts b/src/app/workspace/resource/values/date-value/date-value-handler/date-value-handler.component.ts index bafe017529..e914d6958b 100644 --- a/src/app/workspace/resource/values/date-value/date-value-handler/date-value-handler.component.ts +++ b/src/app/workspace/resource/values/date-value/date-value-handler/date-value-handler.component.ts @@ -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; } @@ -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);