Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

fix: onDateRangeSelect callback dates should be dates and not moment …

…objects

Closes #518
  • Loading branch information...
Matt Lewis
Matt Lewis committed Jan 9, 2017
1 parent d4a4d1f commit 65710b43e1374b63cea166f1e0687e355abd52ec
Showing with 12 additions and 9 deletions.
  1. +4 −1 src/directives/mwlCalendarHourList.js
  2. +8 −8 test/unit/directives/mwlCalendarHourList.spec.js
@@ -107,7 +107,10 @@ angular
if (vm.dateRangeSelect) {
vm.dateRangeSelect.endDate = date;
if (vm.dateRangeSelect.endDate > vm.dateRangeSelect.startDate) {
vm.onDateRangeSelect({calendarRangeStartDate: vm.dateRangeSelect.startDate, calendarRangeEndDate: vm.dateRangeSelect.endDate});
vm.onDateRangeSelect({
calendarRangeStartDate: vm.dateRangeSelect.startDate.toDate(),
calendarRangeEndDate: vm.dateRangeSelect.endDate.toDate()
});
}
delete vm.dateRangeSelect;
}
@@ -123,27 +123,27 @@ describe('mwlCalendarHourList directive', function() {

it('should call the onDateRangeSelect callback if there is a valid date range', function() {
MwlCalendarCtrl.onDateRangeSelect = sinon.spy();
var date1 = new Date();
var date2 = new Date(Date.now() + 100000);
var date1 = moment();
var date2 = moment(Date.now() + 100000);
MwlCalendarCtrl.dateRangeSelect = {
startDate: date1,
endDate: new Date(Date.now() + 10)
endDate: moment(Date.now() + 10)
};
MwlCalendarCtrl.onDragSelectEnd(date2);
expect(MwlCalendarCtrl.onDateRangeSelect).to.have.been.calledWith({
calendarRangeStartDate: date1,
calendarRangeEndDate: date2
calendarRangeStartDate: date1.toDate(),
calendarRangeEndDate: date2.toDate()
});
expect(MwlCalendarCtrl.dateRangeSelect).to.be.undefined;
});

it('should not call the onDateRangeSelect callback if there is an invalid date range', function() {
MwlCalendarCtrl.onDateRangeSelect = sinon.spy();
var date1 = new Date();
var date2 = new Date(Date.now() - 100000);
var date1 = moment();
var date2 = moment(Date.now() - 100000);
MwlCalendarCtrl.dateRangeSelect = {
startDate: date1,
endDate: new Date(Date.now() - 10)
endDate: moment(Date.now() - 10)
};
MwlCalendarCtrl.onDragSelectEnd(date2);
expect(MwlCalendarCtrl.onDateRangeSelect).not.to.have.been.called;

0 comments on commit 65710b4

Please sign in to comment.
You can’t perform that action at this time.