@@ -490,6 +490,122 @@ describe('CalendarDayViewComponent component', () => {
490
490
} ) ;
491
491
} ) ;
492
492
493
+ it . only ( 'should resize events with no end date' , ( ) => {
494
+ const fixture : ComponentFixture <
495
+ CalendarDayViewComponent
496
+ > = TestBed . createComponent ( CalendarDayViewComponent ) ;
497
+ fixture . componentInstance . viewDate = new Date ( '2016-06-27' ) ;
498
+ fixture . componentInstance . events = [
499
+ {
500
+ title : 'foo' ,
501
+ color : { primary : '' , secondary : '' } ,
502
+ start : moment ( '2016-06-27' )
503
+ . add ( 4 , 'hours' )
504
+ . toDate ( ) ,
505
+ resizable : {
506
+ afterEnd : true
507
+ }
508
+ }
509
+ ] ;
510
+ fixture . componentInstance . ngOnChanges ( { viewDate : { } , events : { } } ) ;
511
+ fixture . detectChanges ( ) ;
512
+ document . body . appendChild ( fixture . nativeElement ) ;
513
+ const event : HTMLElement = fixture . nativeElement . querySelector (
514
+ '.cal-event-container'
515
+ ) ;
516
+ const rect : ClientRect = event . getBoundingClientRect ( ) ;
517
+ let resizeEvent : CalendarEventTimesChangedEvent ;
518
+ fixture . componentInstance . eventTimesChanged . subscribe ( e => {
519
+ resizeEvent = e ;
520
+ } ) ;
521
+ triggerDomEvent ( 'mousedown' , document . body , {
522
+ clientY : rect . bottom ,
523
+ clientX : rect . left + 10
524
+ } ) ;
525
+ fixture . detectChanges ( ) ;
526
+ triggerDomEvent ( 'mousemove' , document . body , {
527
+ clientY : rect . bottom + 30 ,
528
+ clientX : rect . left + 10
529
+ } ) ;
530
+ fixture . detectChanges ( ) ;
531
+ expect ( event . getBoundingClientRect ( ) . bottom ) . to . equal ( rect . bottom + 30 ) ;
532
+ expect ( event . getBoundingClientRect ( ) . height ) . to . equal ( 60 ) ;
533
+ triggerDomEvent ( 'mouseup' , document . body , {
534
+ clientY : rect . top + 30 ,
535
+ clientX : rect . left + 10
536
+ } ) ;
537
+ fixture . detectChanges ( ) ;
538
+ fixture . destroy ( ) ;
539
+ expect ( resizeEvent ) . to . deep . equal ( {
540
+ event : fixture . componentInstance . events [ 0 ] ,
541
+ newStart : moment ( '2016-06-27' )
542
+ . add ( 4 , 'hours' )
543
+ . toDate ( ) ,
544
+ newEnd : moment ( '2016-06-27' )
545
+ . add ( 5 , 'hours' )
546
+ . toDate ( )
547
+ } ) ;
548
+ } ) ;
549
+
550
+ it . only ( 'should resize events with no end date with a custom amount of segments' , ( ) => {
551
+ const fixture : ComponentFixture <
552
+ CalendarDayViewComponent
553
+ > = TestBed . createComponent ( CalendarDayViewComponent ) ;
554
+ fixture . componentInstance . viewDate = new Date ( '2016-06-27' ) ;
555
+ fixture . componentInstance . hourSegments = 4 ;
556
+ fixture . componentInstance . events = [
557
+ {
558
+ title : 'foo' ,
559
+ color : { primary : '' , secondary : '' } ,
560
+ start : moment ( '2016-06-27' )
561
+ . add ( 4 , 'hours' )
562
+ . toDate ( ) ,
563
+ resizable : {
564
+ afterEnd : true
565
+ }
566
+ }
567
+ ] ;
568
+ fixture . componentInstance . ngOnChanges ( { viewDate : { } , events : { } } ) ;
569
+ fixture . detectChanges ( ) ;
570
+ document . body . appendChild ( fixture . nativeElement ) ;
571
+ const event : HTMLElement = fixture . nativeElement . querySelector (
572
+ '.cal-event-container'
573
+ ) ;
574
+ const rect : ClientRect = event . getBoundingClientRect ( ) ;
575
+ let resizeEvent : CalendarEventTimesChangedEvent ;
576
+ fixture . componentInstance . eventTimesChanged . subscribe ( e => {
577
+ resizeEvent = e ;
578
+ } ) ;
579
+ triggerDomEvent ( 'mousedown' , document . body , {
580
+ clientY : rect . bottom ,
581
+ clientX : rect . left + 10
582
+ } ) ;
583
+ fixture . detectChanges ( ) ;
584
+ triggerDomEvent ( 'mousemove' , document . body , {
585
+ clientY : rect . bottom + 30 ,
586
+ clientX : rect . left + 10
587
+ } ) ;
588
+ fixture . detectChanges ( ) ;
589
+ expect ( event . getBoundingClientRect ( ) . bottom ) . to . equal ( rect . bottom + 30 ) ;
590
+ expect ( event . getBoundingClientRect ( ) . height ) . to . equal ( 60 ) ;
591
+ triggerDomEvent ( 'mouseup' , document . body , {
592
+ clientY : rect . top + 30 ,
593
+ clientX : rect . left + 10
594
+ } ) ;
595
+ fixture . detectChanges ( ) ;
596
+ fixture . destroy ( ) ;
597
+ expect ( resizeEvent ) . to . deep . equal ( {
598
+ event : fixture . componentInstance . events [ 0 ] ,
599
+ newStart : moment ( '2016-06-27' )
600
+ . add ( 4 , 'hours' )
601
+ . toDate ( ) ,
602
+ newEnd : moment ( '2016-06-27' )
603
+ . add ( 4 , 'hours' )
604
+ . add ( 30 , 'minutes' )
605
+ . toDate ( )
606
+ } ) ;
607
+ } ) ;
608
+
493
609
it ( 'should resize the event and respect the event snap size' , ( ) => {
494
610
const fixture : ComponentFixture <
495
611
CalendarDayViewComponent
0 commit comments