diff --git a/src/directives/mwlCalendar.js b/src/directives/mwlCalendar.js index 4ad9ef78..50be29a8 100644 --- a/src/directives/mwlCalendar.js +++ b/src/directives/mwlCalendar.js @@ -35,21 +35,27 @@ angular var previousView = vm.view; function eventIsValid(event) { + var LOG_PREFIX = 'Bootstrap calendar:'; if (!event.startsAt) { - $log.warn('Bootstrap calendar: ', 'Event is missing the startsAt field', event); + $log.warn(LOG_PREFIX, 'Event is missing the startsAt field', event); } else if (!angular.isDate(event.startsAt)) { - $log.warn('Bootstrap calendar: ', 'Event startsAt should be a javascript date object. Do `new Date(event.startsAt)` to fix it.', event); + $log.warn(LOG_PREFIX, 'Event startsAt should be a javascript date object. Do `new Date(event.startsAt)` to fix it.', event); } if (event.endsAt) { if (!angular.isDate(event.endsAt)) { - $log.warn('Bootstrap calendar: ', 'Event endsAt should be a javascript date object. Do `new Date(event.endsAt)` to fix it.', event); + $log.warn(LOG_PREFIX, 'Event endsAt should be a javascript date object. Do `new Date(event.endsAt)` to fix it.', event); } if (moment(event.startsAt).isAfter(moment(event.endsAt))) { - $log.warn('Bootstrap calendar: ', 'Event cannot start after it finishes', event); + $log.warn(LOG_PREFIX, 'Event cannot start after it finishes', event); } } + if (event.type && !event.color) { + $log.warn(LOG_PREFIX, 'Event type is deprecated, please see the changelog on how to upgrade: ' + + 'https://github.com/mattlewis92/angular-bootstrap-calendar/blob/master/CHANGELOG.md', event); + } + return true; } diff --git a/test/unit/directives/mwlCalendar.spec.js b/test/unit/directives/mwlCalendar.spec.js index 13a2f56d..12d7cbf3 100644 --- a/test/unit/directives/mwlCalendar.spec.js +++ b/test/unit/directives/mwlCalendar.spec.js @@ -187,6 +187,20 @@ describe('mwlCalendar directive', function() { expect($log.warn).to.have.been.calledOnce; }); + it('should log a warning if the deprecated event type is used', function() { + $log.warn = sinon.spy(); + scope.vm.events = [{title: 'title', startsAt: new Date(), type: 'success'}]; + scope.$apply(); + expect($log.warn).to.have.been.calledOnce; + }); + + it('should not log a warning if the deprecated event type is not used', function() { + $log.warn = sinon.spy(); + scope.vm.events = [{title: 'title', startsAt: new Date(), color: {primary: 'blue', secondary: 'lightblue'}}]; + scope.$apply(); + expect($log.warn).not.to.have.been.called; + }); + afterEach(function() { clock.restore(); });