@@ -286,16 +286,25 @@ describe('DateValueHandlerComponent', () => {
286286 ( startDateEditComponentDe . componentInstance as TestDatePickerComponent ) . writeValue ( new KnoraDate ( 'JULIAN' , 'CE' , 2019 , 5 , 19 ) ) ;
287287 ( startDateEditComponentDe . componentInstance as TestDatePickerComponent ) . _handleInput ( ) ;
288288
289+ testHostFixture . detectChanges ( ) ;
290+
289291 const endDateEditComponentDe = hostCompDe . query ( By . css ( '.end-date' ) ) ;
290292
291293 ( endDateEditComponentDe . componentInstance as TestDatePickerComponent ) . writeValue ( new KnoraDate ( 'JULIAN' , 'CE' , 2020 , 5 , 19 ) ) ;
292294 ( endDateEditComponentDe . componentInstance as TestDatePickerComponent ) . _handleInput ( ) ;
293295
296+ testHostFixture . detectChanges ( ) ;
297+
294298 await testHostFixture . whenStable ( ) ;
295299
296300 expect ( testHostComponent . dateValueHandlerComponent . form . valid ) . toBe ( true ) ;
297301
298302 expect ( testHostComponent . form . controls . date . value ) . toEqual ( new KnoraPeriod ( new KnoraDate ( 'JULIAN' , 'CE' , 2019 , 5 , 19 ) , new KnoraDate ( 'JULIAN' , 'CE' , 2020 , 5 , 19 ) ) ) ;
303+
304+ // access private _subscriptions property and ensure that each subscription is still open
305+ testHostComponent . dateValueHandlerComponent [ '_subscriptions' ] . forEach ( ( sub ) => {
306+ expect ( sub . closed ) . toBeFalse ( ) ;
307+ } ) ;
299308 } ) ;
300309
301310 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)', () => {
373382 expect ( testHostComponent ) . toBeTruthy ( ) ;
374383 } ) ;
375384
376- it ( 'should receive the propagated valueRequiredValidator from the parent component' , ( ) => {
385+ it ( 'should propagate changes made by the user for a period' , async ( ) => {
386+ expect ( testHostComponent . dateValueHandlerComponent . isPeriodControl . value ) . toBeFalse ( ) ;
387+
388+ testHostComponent . dateValueHandlerComponent . isPeriodControl . setValue ( true ) ;
389+
390+ expect ( testHostComponent . dateValueHandlerComponent . isPeriodControl . value ) . toBeTrue ( ) ;
391+
392+ testHostFixture . detectChanges ( ) ;
393+
394+ const hostCompDe = testHostFixture . debugElement ;
395+
396+ const startDateEditComponentDe = hostCompDe . query ( By . css ( '.start-date' ) ) ;
397+
398+ ( startDateEditComponentDe . componentInstance as TestDatePickerComponent ) . writeValue ( new KnoraDate ( 'JULIAN' , 'CE' , 2019 , 5 , 19 ) ) ;
399+ ( startDateEditComponentDe . componentInstance as TestDatePickerComponent ) . _handleInput ( ) ;
400+
401+ testHostFixture . detectChanges ( ) ;
402+
403+ const endDateEditComponentDe = hostCompDe . query ( By . css ( '.end-date' ) ) ;
404+
405+ ( endDateEditComponentDe . componentInstance as TestDatePickerComponent ) . writeValue ( new KnoraDate ( 'JULIAN' , 'CE' , 2020 , 5 , 19 ) ) ;
406+ ( endDateEditComponentDe . componentInstance as TestDatePickerComponent ) . _handleInput ( ) ;
407+
408+ testHostFixture . detectChanges ( ) ;
409+
410+ await testHostFixture . whenStable ( ) ;
411+
412+ expect ( testHostComponent . dateValueHandlerComponent . form . valid ) . toBe ( true ) ;
413+
414+ expect ( testHostComponent . form . controls . date . value ) . toEqual ( new KnoraPeriod ( new KnoraDate ( 'JULIAN' , 'CE' , 2019 , 5 , 19 ) , new KnoraDate ( 'JULIAN' , 'CE' , 2020 , 5 , 19 ) ) ) ;
415+
416+ // access private _subscriptions property and ensure that each subscription is still open
417+ testHostComponent . dateValueHandlerComponent [ '_subscriptions' ] . forEach ( ( sub ) => {
418+ expect ( sub . closed ) . toBeFalse ( ) ;
419+ } ) ;
420+ } ) ;
421+
422+ it ( 'should not receive the propagated valueRequiredValidator from the parent component' , ( ) => {
377423 expect ( testHostComponent . dateValueHandlerComponent . valueRequiredValidator ) . toBe ( false ) ;
378424 } ) ;
379425
0 commit comments