<commit_before>'use strict';

var angular = require('angular');
var moment = require('moment');
beforeEach(angular.mock.module('mwl.calendar'));

describe('calendarHelper', function() {

  var calendarHelper, events, clock, calendarDay, calendarConfig, $templateCache, $rootScope;

  beforeEach(inject(function(_calendarHelper_, _calendarConfig_, _$templateCache_, _$rootScope_) {
    calendarHelper = _calendarHelper_;
    calendarConfig = _calendarConfig_;
    $templateCache = _$templateCache_;
    $rootScope = _$rootScope_;

    events = [{
      title: 'Event 1',
      type: 'info',
      startsAt: new Date('October 20, 2015 02:00:00'),
      endsAt: new Date('October 20, 2015 15:00:00'),
      incrementsBadgeTotal: true
    }, {
      title: 'Event 2',
      type: 'info',
      startsAt: new Date('October 20, 2015 01:00:00'),
      endsAt: new Date('October 20, 2015 15:00:00'),
      incrementsBadgeTotal: false
    }];

    clock = sinon.useFakeTimers(new Date('October 20, 2015 11:10:00').getTime());

    calendarDay = new Date();

  }));

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

  describe('eventIsInPeriod', function() {

    var periodStart, periodEnd;

    beforeEach(function() {
      periodStart = new Date('January 1, 2015 00:00:00');
      periodEnd = new Date('January 31, 2015 00:00:00');
    });

    it('should be true when the event starts within the period', function() {

      var isInPeriod = calendarHelper.eventIsInPeriod({
        startsAt: new Date('January 2, 2015 00:00:00'),
        endsAt: new Date('January 3, 2016 00:00:00')
      }, periodStart, periodEnd);

      expect(isInPeriod).to.be.true;

    });

    it('should be true when the event ends within the period', function() {
      var isInPeriod = calendarHelper.eventIsInPeriod({
        startsAt: new Date('January 2, 2014 00:00:00'),
        endsAt: new Date('January 3, 2015 00:00:00')
      }, periodStart, periodEnd);

      expect(isInPeriod).to.be.true;
    });

    it('should be true when the event starts before the period and ends after it', function() {
      var isInPeriod = calendarHelper.eventIsInPeriod({
        startsAt: new Date('January 2, 2014 00:00:00'),
        endsAt: new Date('January 3, 2016 00:00:00')
      }, periodStart, periodEnd);

      expect(isInPeriod).to.be.true;
    });

    it('should be true when the event starts at the same time as the period start', function() {
      var isInPeriod = calendarHelper.eventIsInPeriod({
        startsAt: new Date('January 1, 2015 00:00:00'),
        endsAt: new Date('January 3, 2015 00:00:00')
      }, periodStart, periodEnd);

      expect(isInPeriod).to.be.true;
    });

    it('should be true when the event ends at the same time as the period end', function() {
      var isInPeriod = calendarHelper.eventIsInPeriod({
        startsAt: new Date('January 3, 2015 00:00:00'),
        endsAt: new Date('January 31, 2015 00:00:00')
      }, periodStart, periodEnd);

      expect(isInPeriod).to.be.true;
    });

    it('should be false when the event doesn\'t overlap the period', function() {
      var isInPeriod = calendarHelper.eventIsInPeriod({
        startsAt: new Date('January 3, 2014 00:00:00'),
        endsAt: new Date('January 31, 2014 00:00:00')
      }, periodStart, periodEnd);

      expect(isInPeriod).to.be.false;
    });

    it('should be true when the event occurs yearly and the event start and end times don\'t overlap', function() {
      var isInPeriod = calendarHelper.eventIsInPeriod({
        startsAt: new Date('January 3, 2014 00:00:00'),
        endsAt: new Date('January 31, 2014 00:00:00'),
        recursOn: 'year'
      }, periodStart, periodEnd);

      expect(isInPeriod).to.be.true;
    });

    it('should be true when the event occurs monthly and the event start and end times don\'t overlap', function() {
      var isInPeriod = calendarHelper.eventIsInPeriod({
        startsAt: new Date('March 3, 2014 00:00:00'),
        endsAt: new Date('March 31, 2014 00:00:00'),
        recursOn: 'month'
      }, periodStart, periodEnd);

      expect(isInPeriod).to.be.true;
    });

    it('should throw an error when recursOn is an invalid value', function() {

      expect(function() {
        calendarHelper.eventIsInPeriod({
          startsAt: new Date(),
          endsAt: new Date(),
          recursOn: 'invalid'
        }, periodStart, periodEnd);
      }).to.throw();

    });

    it('should not throw an error when recursOn is an empty string', function() {

      expect(function() {
        calendarHelper.eventIsInPeriod({
          startsAt: new Date(),
          endsAt: new Date(),
          recursOn: ''
        }, periodStart, periodEnd);
      }).not.to.throw();

    });

    it('should use the event start time as the end time when no end time is passed', function() {

      var isInPeriod = calendarHelper.eventIsInPeriod({
        startsAt: new Date('January 3, 2015 00:00:00')
      }, periodStart, periodEnd);

      expect(isInPeriod).to.be.true;

    });

  });

  describe('getWeekDayNames', function() {

    it('should get the days of the week starting at sunday', function() {
      var weekdays = calendarHelper.getWeekDayNames();
      expect(weekdays).to.eql(['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']);
    });

    it('should get the days of the week starting at monday', inject(function() {
      moment.locale('en', {
        week: {
          dow: 1 // Monday is the first day of the week
        }
      });

      var weekdays = calendarHelper.getWeekDayNames();
      expect(weekdays).to.eql(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']);

      moment.locale('en', {
        week: {
          dow: 0 // Sunday is the first day of the week
        }
      });
    }));

  });

  describe('getYearView', function() {

    var yearView;

    beforeEach(function() {
      yearView = calendarHelper.getYearView(events, calendarDay, angular.noop);
    });

    it('should give back 12 months', function() {<commit_msg>test: fix moment deprecation warning in tests<commit_after>'use strict';

var angular = require('angular');
var moment = require('moment');
beforeEach(angular.mock.module('mwl.calendar'));

describe('calendarHelper', function() {

  var calendarHelper, events, clock, calendarDay, calendarConfig, $templateCache, $rootScope;

  beforeEach(inject(function(_calendarHelper_, _calendarConfig_, _$templateCache_, _$rootScope_) {
    calendarHelper = _calendarHelper_;
    calendarConfig = _calendarConfig_;
    $templateCache = _$templateCache_;
    $rootScope = _$rootScope_;

    events = [{
      title: 'Event 1',
      type: 'info',
      startsAt: new Date('October 20, 2015 02:00:00'),
      endsAt: new Date('October 20, 2015 15:00:00'),
      incrementsBadgeTotal: true
    }, {
      title: 'Event 2',
      type: 'info',
      startsAt: new Date('October 20, 2015 01:00:00'),
      endsAt: new Date('October 20, 2015 15:00:00'),
      incrementsBadgeTotal: false
    }];

    clock = sinon.useFakeTimers(new Date('October 20, 2015 11:10:00').getTime());

    calendarDay = new Date();

  }));

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

  describe('eventIsInPeriod', function() {

    var periodStart, periodEnd;

    beforeEach(function() {
      periodStart = new Date('January 1, 2015 00:00:00');
      periodEnd = new Date('January 31, 2015 00:00:00');
    });

    it('should be true when the event starts within the period', function() {

      var isInPeriod = calendarHelper.eventIsInPeriod({
        startsAt: new Date('January 2, 2015 00:00:00'),
        endsAt: new Date('January 3, 2016 00:00:00')
      }, periodStart, periodEnd);

      expect(isInPeriod).to.be.true;

    });

    it('should be true when the event ends within the period', function() {
      var isInPeriod = calendarHelper.eventIsInPeriod({
        startsAt: new Date('January 2, 2014 00:00:00'),
        endsAt: new Date('January 3, 2015 00:00:00')
      }, periodStart, periodEnd);

      expect(isInPeriod).to.be.true;
    });

    it('should be true when the event starts before the period and ends after it', function() {
      var isInPeriod = calendarHelper.eventIsInPeriod({
        startsAt: new Date('January 2, 2014 00:00:00'),
        endsAt: new Date('January 3, 2016 00:00:00')
      }, periodStart, periodEnd);

      expect(isInPeriod).to.be.true;
    });

    it('should be true when the event starts at the same time as the period start', function() {
      var isInPeriod = calendarHelper.eventIsInPeriod({
        startsAt: new Date('January 1, 2015 00:00:00'),
        endsAt: new Date('January 3, 2015 00:00:00')
      }, periodStart, periodEnd);

      expect(isInPeriod).to.be.true;
    });

    it('should be true when the event ends at the same time as the period end', function() {
      var isInPeriod = calendarHelper.eventIsInPeriod({
        startsAt: new Date('January 3, 2015 00:00:00'),
        endsAt: new Date('January 31, 2015 00:00:00')
      }, periodStart, periodEnd);

      expect(isInPeriod).to.be.true;
    });

    it('should be false when the event doesn\'t overlap the period', function() {
      var isInPeriod = calendarHelper.eventIsInPeriod({
        startsAt: new Date('January 3, 2014 00:00:00'),
        endsAt: new Date('January 31, 2014 00:00:00')
      }, periodStart, periodEnd);

      expect(isInPeriod).to.be.false;
    });

    it('should be true when the event occurs yearly and the event start and end times don\'t overlap', function() {
      var isInPeriod = calendarHelper.eventIsInPeriod({
        startsAt: new Date('January 3, 2014 00:00:00'),
        endsAt: new Date('January 31, 2014 00:00:00'),
        recursOn: 'year'
      }, periodStart, periodEnd);

      expect(isInPeriod).to.be.true;
    });

    it('should be true when the event occurs monthly and the event start and end times don\'t overlap', function() {
      var isInPeriod = calendarHelper.eventIsInPeriod({
        startsAt: new Date('March 3, 2014 00:00:00'),
        endsAt: new Date('March 31, 2014 00:00:00'),
        recursOn: 'month'
      }, periodStart, periodEnd);

      expect(isInPeriod).to.be.true;
    });

    it('should throw an error when recursOn is an invalid value', function() {

      expect(function() {
        calendarHelper.eventIsInPeriod({
          startsAt: new Date(),
          endsAt: new Date(),
          recursOn: 'invalid'
        }, periodStart, periodEnd);
      }).to.throw();

    });

    it('should not throw an error when recursOn is an empty string', function() {

      expect(function() {
        calendarHelper.eventIsInPeriod({
          startsAt: new Date(),
          endsAt: new Date(),
          recursOn: ''
        }, periodStart, periodEnd);
      }).not.to.throw();

    });

    it('should use the event start time as the end time when no end time is passed', function() {

      var isInPeriod = calendarHelper.eventIsInPeriod({
        startsAt: new Date('January 3, 2015 00:00:00')
      }, periodStart, periodEnd);

      expect(isInPeriod).to.be.true;

    });

  });

  describe('getWeekDayNames', function() {

    it('should get the days of the week starting at sunday', function() {
      var weekdays = calendarHelper.getWeekDayNames();
      expect(weekdays).to.eql(['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']);
    });

    it('should get the days of the week starting at monday', inject(function() {
      moment.locale('en_gb', {
        week: {
          dow: 1 // Monday is the first day of the week
        }
      });

      var weekdays = calendarHelper.getWeekDayNames();
      expect(weekdays).to.eql(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']);

      moment.locale('en');
    }));

  });

  describe('getYearView', function() {

    var yearView;

    beforeEach(function() {
      yearView = calendarHelper.getYearView(events, calendarDay, angular.noop);
    });

    it('should give back 12 months', function() {
{'fraction_non_alphanumeric': 0.1358515573227303, 'fraction_numerical': 0.04630550033134526, 'mean_word_length': 2.9990062934746606, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3942094', 'n_tokens_mistral': 4121, 'n_tokens_neox': 3495, 'n_words': 1041}