@@ -12,11 +12,13 @@ import {
12
12
CalendarMomentDateFormatter ,
13
13
CalendarDateFormatter ,
14
14
CalendarModule ,
15
- MOMENT
15
+ MOMENT ,
16
+ CalendarEventTimesChangedEvent
16
17
} from './../src' ;
17
18
import { CalendarDayViewComponent } from './../src/components/day/calendarDayView.component' ;
18
19
import { Subject } from 'rxjs/Rx' ;
19
20
import { spy } from 'sinon' ;
21
+ import { triggerDomEvent } from './util' ;
20
22
21
23
describe ( 'CalendarDayViewComponent component' , ( ) => {
22
24
@@ -248,4 +250,77 @@ describe('CalendarDayViewComponent component', () => {
248
250
fixture . destroy ( ) ;
249
251
} ) ;
250
252
253
+ it ( 'should resize the event by dragging from the top edge' , ( ) => {
254
+ const fixture : ComponentFixture < CalendarDayViewComponent > = TestBed . createComponent ( CalendarDayViewComponent ) ;
255
+ fixture . componentInstance . viewDate = new Date ( '2016-06-27' ) ;
256
+ fixture . componentInstance . events = [ {
257
+ title : 'foo' ,
258
+ color : { primary : '' , secondary : '' } ,
259
+ start : moment ( '2016-06-27' ) . add ( 4 , 'hours' ) . toDate ( ) ,
260
+ end : moment ( '2016-06-27' ) . add ( 6 , 'hours' ) . toDate ( ) ,
261
+ resizable : {
262
+ beforeStart : true
263
+ }
264
+ } ] ;
265
+ fixture . componentInstance . ngOnChanges ( { viewDate : { } , events : { } } ) ;
266
+ fixture . detectChanges ( ) ;
267
+ document . body . appendChild ( fixture . nativeElement ) ;
268
+ const event : HTMLElement = fixture . nativeElement . querySelector ( '.cal-event' ) ;
269
+ const rect : ClientRect = event . getBoundingClientRect ( ) ;
270
+ let resizeEvent : CalendarEventTimesChangedEvent ;
271
+ fixture . componentInstance . eventTimesChanged . subscribe ( event => {
272
+ resizeEvent = event ;
273
+ } ) ;
274
+ triggerDomEvent ( 'mousedown' , document . body , { clientY : rect . top , clientX : rect . left + 10 } ) ;
275
+ fixture . detectChanges ( ) ;
276
+ triggerDomEvent ( 'mousemove' , document . body , { clientY : rect . top - 30 , clientX : rect . left + 10 } ) ;
277
+ fixture . detectChanges ( ) ;
278
+ expect ( event . getBoundingClientRect ( ) . top ) . to . equal ( rect . top - 30 ) ;
279
+ triggerDomEvent ( 'mouseup' , document . body , { clientY : rect . top - 30 , clientX : rect . left + 10 } ) ;
280
+ fixture . detectChanges ( ) ;
281
+ fixture . destroy ( ) ;
282
+ expect ( resizeEvent ) . to . deep . equal ( {
283
+ event : fixture . componentInstance . events [ 0 ] ,
284
+ newStart : moment ( '2016-06-27' ) . add ( 4 , 'hours' ) . subtract ( 30 , 'minutes' ) . toDate ( ) ,
285
+ newEnd : moment ( '2016-06-27' ) . add ( 6 , 'hours' ) . toDate ( )
286
+ } ) ;
287
+ } ) ;
288
+
289
+ it ( 'should resize the event by dragging from the bottom edge' , ( ) => {
290
+ const fixture : ComponentFixture < CalendarDayViewComponent > = TestBed . createComponent ( CalendarDayViewComponent ) ;
291
+ fixture . componentInstance . viewDate = new Date ( '2016-06-27' ) ;
292
+ fixture . componentInstance . events = [ {
293
+ title : 'foo' ,
294
+ color : { primary : '' , secondary : '' } ,
295
+ start : moment ( '2016-06-27' ) . add ( 4 , 'hours' ) . toDate ( ) ,
296
+ end : moment ( '2016-06-27' ) . add ( 6 , 'hours' ) . toDate ( ) ,
297
+ resizable : {
298
+ afterEnd : true
299
+ }
300
+ } ] ;
301
+ fixture . componentInstance . ngOnChanges ( { viewDate : { } , events : { } } ) ;
302
+ fixture . detectChanges ( ) ;
303
+ document . body . appendChild ( fixture . nativeElement ) ;
304
+ const event : HTMLElement = fixture . nativeElement . querySelector ( '.cal-event' ) ;
305
+ const rect : ClientRect = event . getBoundingClientRect ( ) ;
306
+ let resizeEvent : CalendarEventTimesChangedEvent ;
307
+ fixture . componentInstance . eventTimesChanged . subscribe ( event => {
308
+ resizeEvent = event ;
309
+ } ) ;
310
+ triggerDomEvent ( 'mousedown' , document . body , { clientY : rect . bottom , clientX : rect . left + 10 } ) ;
311
+ fixture . detectChanges ( ) ;
312
+ triggerDomEvent ( 'mousemove' , document . body , { clientY : rect . bottom + 30 , clientX : rect . left + 10 } ) ;
313
+ fixture . detectChanges ( ) ;
314
+ expect ( event . getBoundingClientRect ( ) . bottom ) . to . equal ( rect . bottom + 30 ) ;
315
+ expect ( event . getBoundingClientRect ( ) . height ) . to . equal ( 150 ) ;
316
+ triggerDomEvent ( 'mouseup' , document . body , { clientY : rect . top + 30 , clientX : rect . left + 10 } ) ;
317
+ fixture . detectChanges ( ) ;
318
+ fixture . destroy ( ) ;
319
+ expect ( resizeEvent ) . to . deep . equal ( {
320
+ event : fixture . componentInstance . events [ 0 ] ,
321
+ newStart : moment ( '2016-06-27' ) . add ( 4 , 'hours' ) . toDate ( ) ,
322
+ newEnd : moment ( '2016-06-27' ) . add ( 6 , 'hours' ) . add ( 30 , 'minutes' ) . toDate ( )
323
+ } ) ;
324
+ } ) ;
325
+
251
326
} ) ;
0 commit comments