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

feat: show deprecation warning when event type is set

  • Loading branch information...
Matt Lewis
Matt Lewis committed Jul 27, 2016
1 parent 93d1a35 commit 08bbf74bce5a53ab88fc34eeac543e7dbf9f120c
Showing with 24 additions and 4 deletions.
  1. +10 −4 src/directives/mwlCalendar.js
  2. +14 −0 test/unit/directives/mwlCalendar.spec.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;
}

@@ -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();
});

0 comments on commit 08bbf74

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