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

Commit

Permalink
fix(warnings): dont log a warning that the event ends at is missing i…
Browse files Browse the repository at this point in the history
…f it is a falsey value

Closes #348
  • Loading branch information
Matt Lewis committed Jun 4, 2016
1 parent c0efc02 commit da101ab
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/directives/mwlCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ angular
function eventIsValid(event) {
if (!event.startsAt) {
$log.warn('Bootstrap calendar: ', 'Event is missing the startsAt field', event);
}

if (!angular.isDate(event.startsAt)) {
} 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);
}

if (angular.isDefined(event.endsAt)) {
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);
}
Expand Down
39 changes: 38 additions & 1 deletion test/unit/directives/mwlCalendar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('mwlCalendar directive', function() {
scope,
$rootScope,
$q,
$log,
$timeout,
calendarHelper,
directiveScope,
Expand Down Expand Up @@ -90,12 +91,13 @@ describe('mwlCalendar directive', function() {

beforeEach(angular.mock.module('mwl.calendar'));

beforeEach(angular.mock.inject(function($compile, _$rootScope_, _$timeout_, _$q_, _calendarHelper_) {
beforeEach(angular.mock.inject(function($compile, _$rootScope_, _$timeout_, _$q_, _calendarHelper_, _$log_) {
$q = _$q_;
$rootScope = _$rootScope_;
$timeout = _$timeout_;
calendarHelper = _calendarHelper_;
scope = $rootScope.$new();
$log = _$log_;
scope.vm = {};
clock = sinon.useFakeTimers(new Date(2015, 4, 1).getTime());
calendarHelper.loadTemplates = sinon.stub().returns($q.when());
Expand Down Expand Up @@ -150,6 +152,41 @@ describe('mwlCalendar directive', function() {
expect(MwlCalendarCtrl.templatesLoaded).to.be.true;
});

it('should log a warning if the event starts at is not set', function() {
$log.warn = sinon.spy();
scope.vm.events = [{title: 'title'}];
scope.$apply();
expect($log.warn).to.have.been.calledOnce;
});

it('should log a warning if the event starts at is not a valid date object', function() {
$log.warn = sinon.spy();
scope.vm.events = [{title: 'title', startsAt: '2016-06-01'}];
scope.$apply();
expect($log.warn).to.have.been.calledOnce;
});

it('should log a warning if the event ends at is not a valid date object', function() {
$log.warn = sinon.spy();
scope.vm.events = [{title: 'title', startsAt: new Date(), endsAt: '2016-01-01'}];
scope.$apply();
expect($log.warn).to.have.been.calledOnce;
});

it('should not log a warning if the event ends at is set to a falsey value', function() {
$log.warn = sinon.spy();
scope.vm.events = [{title: 'title', startsAt: new Date(), endsAt: null}];
scope.$apply();
expect($log.warn).not.to.have.been.called;
});

it('should log a warning if the event ends after it starts', function() {
$log.warn = sinon.spy();
scope.vm.events = [{title: 'title', startsAt: new Date(), endsAt: new Date(Date.now() - 1)}];
scope.$apply();
expect($log.warn).to.have.been.calledOnce;
});

afterEach(function() {
clock.restore();
});
Expand Down

0 comments on commit da101ab

Please sign in to comment.