@@ -329,4 +329,66 @@ describe('calendarWeekView component', () => {
329
329
} ) ;
330
330
} ) ;
331
331
332
+ it ( 'should not allow events to be resized smaller than 1 day' , ( ) => {
333
+ const fixture : ComponentFixture < CalendarWeekViewComponent > = TestBed . createComponent ( CalendarWeekViewComponent ) ;
334
+ fixture . componentInstance . viewDate = new Date ( '2016-06-27' ) ;
335
+ fixture . componentInstance . events = [ {
336
+ title : 'foo' ,
337
+ color : { primary : '' , secondary : '' } ,
338
+ start : moment ( '2016-06-27' ) . add ( 4 , 'hours' ) . toDate ( ) ,
339
+ end : moment ( '2016-06-27' ) . add ( 6 , 'hours' ) . toDate ( ) ,
340
+ resizable : {
341
+ beforeStart : true
342
+ }
343
+ } ] ;
344
+ fixture . componentInstance . ngOnChanges ( { viewDate : { } , events : { } } ) ;
345
+ fixture . detectChanges ( ) ;
346
+ document . body . appendChild ( fixture . nativeElement ) ;
347
+ const event : HTMLElement = fixture . nativeElement . querySelector ( '.cal-event-container' ) ;
348
+ const dayWidth : number = event . parentElement . offsetWidth / 7 ;
349
+ const rect : ClientRect = event . getBoundingClientRect ( ) ;
350
+ triggerDomEvent ( 'mousedown' , document . body , { clientX : rect . left , clientY : rect . top } ) ;
351
+ fixture . detectChanges ( ) ;
352
+ triggerDomEvent ( 'mousemove' , document . body , { clientX : rect . left + dayWidth , clientY : rect . top } ) ;
353
+ fixture . detectChanges ( ) ;
354
+ expect ( Math . round ( event . getBoundingClientRect ( ) . left ) ) . to . equal ( Math . round ( rect . left ) ) ;
355
+ expect ( Math . round ( event . getBoundingClientRect ( ) . width ) ) . to . equal ( Math . round ( rect . width ) ) ;
356
+ triggerDomEvent ( 'mouseup' , document . body , { clientX : rect . left - dayWidth , clientY : rect . top } ) ;
357
+ fixture . detectChanges ( ) ;
358
+ fixture . destroy ( ) ;
359
+ } ) ;
360
+
361
+ it ( 'should not allow events to be resized outside of the current view' , ( ) => {
362
+ const fixture : ComponentFixture < CalendarWeekViewComponent > = TestBed . createComponent ( CalendarWeekViewComponent ) ;
363
+ fixture . componentInstance . viewDate = new Date ( '2016-06-27' ) ;
364
+ fixture . componentInstance . events = [ {
365
+ title : 'foo' ,
366
+ color : { primary : '' , secondary : '' } ,
367
+ start : moment ( '2016-06-27' ) . add ( 4 , 'hours' ) . toDate ( ) ,
368
+ end : moment ( '2016-06-27' ) . add ( 6 , 'hours' ) . toDate ( ) ,
369
+ resizable : {
370
+ beforeStart : true
371
+ }
372
+ } ] ;
373
+ fixture . componentInstance . ngOnChanges ( { viewDate : { } , events : { } } ) ;
374
+ fixture . detectChanges ( ) ;
375
+ document . body . appendChild ( fixture . nativeElement ) ;
376
+ const event : HTMLElement = fixture . nativeElement . querySelector ( '.cal-event-container' ) ;
377
+ const dayWidth : number = event . parentElement . offsetWidth / 7 ;
378
+ const rect : ClientRect = event . getBoundingClientRect ( ) ;
379
+ triggerDomEvent ( 'mousedown' , document . body , { clientX : rect . left , clientY : rect . top } ) ;
380
+ fixture . detectChanges ( ) ;
381
+ triggerDomEvent ( 'mousemove' , document . body , { clientX : rect . left - dayWidth , clientY : rect . top } ) ;
382
+ fixture . detectChanges ( ) ;
383
+ expect ( Math . round ( event . getBoundingClientRect ( ) . left ) ) . to . equal ( Math . round ( rect . left - dayWidth ) ) ;
384
+ expect ( Math . round ( event . getBoundingClientRect ( ) . width ) ) . to . equal ( Math . round ( rect . width + dayWidth ) ) ;
385
+ triggerDomEvent ( 'mousemove' , document . body , { clientX : rect . left - ( dayWidth * 2 ) , clientY : rect . top } ) ;
386
+ fixture . detectChanges ( ) ;
387
+ expect ( Math . round ( event . getBoundingClientRect ( ) . left ) ) . to . equal ( Math . round ( rect . left - dayWidth ) ) ;
388
+ expect ( Math . round ( event . getBoundingClientRect ( ) . width ) ) . to . equal ( Math . round ( rect . width + dayWidth ) ) ;
389
+ triggerDomEvent ( 'mouseup' , document . body , { clientX : rect . left - ( dayWidth * 2 ) , clientY : rect . top } ) ;
390
+ fixture . detectChanges ( ) ;
391
+ fixture . destroy ( ) ;
392
+ } ) ;
393
+
332
394
} ) ;
0 commit comments