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

fix(warnings): dont log a warning that the event ends at is missing i…

…f it is a falsey value

Closes #348
  • Loading branch information...
Matt Lewis
Matt Lewis committed Jun 4, 2016
1 parent c0efc02 commit da101ab97a319c3318a5df35d9e7e9924eac1b4b
Showing with 40 additions and 5 deletions.
  1. +2 −4 src/directives/mwlCalendar.js
  2. +38 −1 test/unit/directives/mwlCalendar.spec.js
@@ -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);
}
@@ -9,6 +9,7 @@ describe('mwlCalendar directive', function() {
scope,
$rootScope,
$q,
$log,
$timeout,
calendarHelper,
directiveScope,
@@ -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());
@@ -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();
});

0 comments on commit da101ab

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