Skip to content
This repository has been archived by the owner on Jun 19, 2018. It is now read-only.

Commit

Permalink
feat: show deprecation warning when event type is set
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Lewis committed Jul 27, 2016
1 parent 93d1a35 commit 08bbf74
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/directives/mwlCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
14 changes: 14 additions & 0 deletions test/unit/directives/mwlCalendar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down

0 comments on commit 08bbf74

Please sign in to comment.