@@ -17,6 +17,7 @@ import {
17
17
import { CalendarMonthViewComponent } from './../src/components/month/calendarMonthView.component' ;
18
18
import { Subject } from 'rxjs/Subject' ;
19
19
import { triggerDomEvent } from './util' ;
20
+ import { CalendarEventTimesChangedEvent } from '../src/interfaces/calendarEventTimesChangedEvent.interface' ;
20
21
21
22
describe ( 'calendarMonthView component' , ( ) => {
22
23
@@ -308,4 +309,53 @@ describe('calendarMonthView component', () => {
308
309
fixture . destroy ( ) ;
309
310
} ) ;
310
311
312
+ it ( 'should allow events to be dragged and dropped' , ( ) => {
313
+
314
+ const fixture : ComponentFixture < CalendarMonthViewComponent > = TestBed . createComponent ( CalendarMonthViewComponent ) ;
315
+ fixture . componentInstance . viewDate = new Date ( '2016-12-05' ) ;
316
+ fixture . componentInstance . events = [ {
317
+ start : new Date ( 2016 , 11 , 5 , 10 , 39 , 14 ) ,
318
+ end : new Date ( 2016 , 11 , 5 , 15 , 11 , 5 ) ,
319
+ title : 'draggable event' ,
320
+ color : {
321
+ primary : 'blue' ,
322
+ secondary : 'rgb(238, 238, 238)'
323
+ } ,
324
+ draggable : true
325
+ } ] ;
326
+ fixture . componentInstance . ngOnChanges ( { viewDate : { } } ) ;
327
+ let dragEvent : CalendarEventTimesChangedEvent ;
328
+ fixture . componentInstance . eventTimesChanged . subscribe ( event => {
329
+ dragEvent = event ;
330
+ } ) ;
331
+ fixture . detectChanges ( ) ;
332
+ document . body . appendChild ( fixture . nativeElement ) ;
333
+ const cells : HTMLElement [ ] = fixture . nativeElement . querySelectorAll ( '.cal-day-cell' ) ;
334
+ const event : HTMLElement = fixture . nativeElement . querySelector ( '.cal-event' ) ;
335
+ const dragToCellPosition : ClientRect = cells [ 10 ] . getBoundingClientRect ( ) ;
336
+ const eventStartPosition : ClientRect = event . getBoundingClientRect ( ) ;
337
+ event . style . width = '10px' ;
338
+ event . style . height = '10px' ;
339
+ triggerDomEvent ( 'mousedown' , event , { clientX : eventStartPosition . left , clientY : eventStartPosition . top } ) ;
340
+ fixture . detectChanges ( ) ;
341
+ triggerDomEvent ( 'mousemove' , document . body , { clientX : dragToCellPosition . left , clientY : dragToCellPosition . top } ) ;
342
+ fixture . detectChanges ( ) ;
343
+ expect ( cells [ 10 ] . classList . contains ( 'cal-drag-over' ) ) . to . be . true ;
344
+ const eventAfterDragPosition : ClientRect = event . getBoundingClientRect ( ) ;
345
+ const movedLeft : number = dragToCellPosition . left - eventStartPosition . left ;
346
+ expect ( Math . round ( eventAfterDragPosition . left ) ) . to . equal ( eventStartPosition . left + movedLeft ) ;
347
+ const movedTop : number = dragToCellPosition . top - eventStartPosition . top ;
348
+ expect ( Math . round ( eventAfterDragPosition . top ) ) . to . equal ( eventStartPosition . top + movedTop ) ;
349
+ triggerDomEvent ( 'mouseup' , document . body , { clientX : dragToCellPosition . left , clientY : dragToCellPosition . top } ) ;
350
+ fixture . detectChanges ( ) ;
351
+ expect ( cells [ 10 ] . classList . contains ( 'cal-drag-over' ) ) . to . be . false ;
352
+ fixture . destroy ( ) ;
353
+ expect ( dragEvent ) . to . deep . equal ( {
354
+ event : fixture . componentInstance . events [ 0 ] ,
355
+ newStart : new Date ( 2016 , 11 , 7 , 10 , 39 , 14 ) ,
356
+ newEnd : new Date ( 2016 , 11 , 7 , 15 , 11 , 5 )
357
+ } ) ;
358
+
359
+ } ) ;
360
+
311
361
} ) ;
0 commit comments