Skip to content

Commit af48ed2

Browse files
author
Matt Lewis
committed
fix(monthView): ensure events are dropped onto the correct dates
1 parent 989ab79 commit af48ed2

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/components/month/calendarMonthView.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export class CalendarMonthViewComponent implements OnChanges, OnInit, OnDestroy
252252
const year: number = getYear(day.date);
253253
const month: number = getMonth(day.date);
254254
const date: number = getDate(day.date);
255-
const newStart: Date = setYear(setMonth(setDate(event.start, date), month), year);
255+
const newStart: Date = setDate(setMonth(setYear(event.start, year), month), date);
256256
let newEnd: Date;
257257
if (event.end) {
258258
const secondsDiff: number = differenceInSeconds(newStart, event.start);

test/calendarMonthView.component.spec.ts

+41
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,47 @@ describe('calendarMonthView component', () => {
417417

418418
});
419419

420+
it('should apply the year, month and date changes in the correct order when dragging and dropping events', () => {
421+
422+
const fixture: ComponentFixture<CalendarMonthViewComponent> = TestBed.createComponent(CalendarMonthViewComponent);
423+
fixture.componentInstance.viewDate = new Date('2017-02-05');
424+
fixture.componentInstance.events = [{
425+
start: new Date('2017-02-01'),
426+
title: 'draggable event',
427+
color: {
428+
primary: 'blue',
429+
secondary: 'rgb(238, 238, 238)'
430+
},
431+
draggable: true
432+
}];
433+
fixture.componentInstance.ngOnChanges({viewDate: {}});
434+
let dragEvent: CalendarEventTimesChangedEvent;
435+
fixture.componentInstance.eventTimesChanged.subscribe(event => {
436+
dragEvent = event;
437+
});
438+
fixture.detectChanges();
439+
document.body.appendChild(fixture.nativeElement);
440+
const cells: HTMLElement[] = fixture.nativeElement.querySelectorAll('.cal-day-cell');
441+
const event: HTMLElement = fixture.nativeElement.querySelector('.cal-event');
442+
event.style.width = '10px';
443+
event.style.height = '10px';
444+
const dragToCellPosition: ClientRect = cells[2].getBoundingClientRect();
445+
const eventStartPosition: ClientRect = event.getBoundingClientRect();
446+
triggerDomEvent('mousedown', event, {clientX: eventStartPosition.left, clientY: eventStartPosition.top});
447+
fixture.detectChanges();
448+
triggerDomEvent('mousemove', document.body, {clientX: dragToCellPosition.left, clientY: dragToCellPosition.top});
449+
fixture.detectChanges();
450+
triggerDomEvent('mouseup', document.body, {clientX: dragToCellPosition.left, clientY: dragToCellPosition.top});
451+
fixture.detectChanges();
452+
fixture.destroy();
453+
expect(dragEvent).to.deep.equal({
454+
event: fixture.componentInstance.events[0],
455+
newStart: new Date('2017-01-31'),
456+
newEnd: undefined
457+
});
458+
459+
});
460+
420461
it('should update the event title', () => {
421462
const fixture: ComponentFixture<CalendarMonthViewComponent> = TestBed.createComponent(CalendarMonthViewComponent);
422463
fixture.componentInstance.viewDate = new Date('2016-06-01');

0 commit comments

Comments
 (0)