diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index f55bc0c0b2..dd81bac35f 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -30,224 +30,108 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst watchListeners = [], optionsUsed = !!$attrs.datepickerOptions; + if (!$scope.datepickerOptions) { + $scope.datepickerOptions = {}; + } + // Modes chain this.modes = ['day', 'month', 'year']; - if (optionsUsed) { - [ - 'customClass', - 'dateDisabled', - 'datepickerMode', - 'formatDay', - 'formatDayHeader', - 'formatDayTitle', - 'formatMonth', - 'formatMonthTitle', - 'formatYear', - 'initDate', - 'maxDate', - 'maxMode', - 'minDate', - 'minMode', - 'showWeeks', - 'shortcutPropagation', - 'startingDay', - 'yearColumns', - 'yearRows' - ].forEach(function(key) { - switch (key) { - case 'customClass': - case 'dateDisabled': - $scope[key] = $scope.datepickerOptions[key] || angular.noop; - break; - case 'datepickerMode': - $scope.datepickerMode = angular.isDefined($scope.datepickerOptions.datepickerMode) ? - $scope.datepickerOptions.datepickerMode : datepickerConfig.datepickerMode; - break; - case 'formatDay': - case 'formatDayHeader': - case 'formatDayTitle': - case 'formatMonth': - case 'formatMonthTitle': - case 'formatYear': - self[key] = angular.isDefined($scope.datepickerOptions[key]) ? - $interpolate($scope.datepickerOptions[key])($scope.$parent) : - datepickerConfig[key]; - break; - case 'showWeeks': - case 'shortcutPropagation': - case 'yearColumns': - case 'yearRows': - self[key] = angular.isDefined($scope.datepickerOptions[key]) ? - $scope.datepickerOptions[key] : datepickerConfig[key]; - break; - case 'startingDay': - if (angular.isDefined($scope.datepickerOptions.startingDay)) { - self.startingDay = $scope.datepickerOptions.startingDay; - } else if (angular.isNumber(datepickerConfig.startingDay)) { - self.startingDay = datepickerConfig.startingDay; - } else { - self.startingDay = ($locale.DATETIME_FORMATS.FIRSTDAYOFWEEK + 8) % 7; - } + [ + 'customClass', + 'dateDisabled', + 'datepickerMode', + 'formatDay', + 'formatDayHeader', + 'formatDayTitle', + 'formatMonth', + 'formatMonthTitle', + 'formatYear', + 'maxDate', + 'maxMode', + 'minDate', + 'minMode', + 'showWeeks', + 'shortcutPropagation', + 'startingDay', + 'yearColumns', + 'yearRows' + ].forEach(function(key) { + switch (key) { + case 'customClass': + case 'dateDisabled': + $scope[key] = $scope.datepickerOptions[key] || angular.noop; + break; + case 'datepickerMode': + $scope.datepickerMode = angular.isDefined($scope.datepickerOptions.datepickerMode) ? + $scope.datepickerOptions.datepickerMode : datepickerConfig.datepickerMode; + break; + case 'formatDay': + case 'formatDayHeader': + case 'formatDayTitle': + case 'formatMonth': + case 'formatMonthTitle': + case 'formatYear': + self[key] = angular.isDefined($scope.datepickerOptions[key]) ? + $interpolate($scope.datepickerOptions[key])($scope.$parent) : + datepickerConfig[key]; + break; + case 'showWeeks': + case 'shortcutPropagation': + case 'yearColumns': + case 'yearRows': + self[key] = angular.isDefined($scope.datepickerOptions[key]) ? + $scope.datepickerOptions[key] : datepickerConfig[key]; + break; + case 'startingDay': + if (angular.isDefined($scope.datepickerOptions.startingDay)) { + self.startingDay = $scope.datepickerOptions.startingDay; + } else if (angular.isNumber(datepickerConfig.startingDay)) { + self.startingDay = datepickerConfig.startingDay; + } else { + self.startingDay = ($locale.DATETIME_FORMATS.FIRSTDAYOFWEEK + 8) % 7; + } - break; - case 'maxDate': - case 'minDate': - if ($scope.datepickerOptions[key]) { - $scope.$watch(function() { return $scope.datepickerOptions[key]; }, function(value) { - if (value) { - if (angular.isDate(value)) { - self[key] = dateParser.fromTimezone(new Date(value), ngModelOptions.timezone); - } else { - self[key] = new Date(dateFilter(value, 'medium')); - } + break; + case 'maxDate': + case 'minDate': + if ($scope.datepickerOptions[key]) { + $scope.$watch('datepickerOptions.' + key, function(value) { + if (value) { + if (angular.isDate(value)) { + self[key] = dateParser.fromTimezone(new Date(value), ngModelOptions.timezone); } else { - self[key] = null; + self[key] = new Date(dateFilter(value, 'medium')); } - - self.refreshView(); - }); - } else { - self[key] = datepickerConfig[key] ? dateParser.fromTimezone(new Date(datepickerConfig[key]), ngModelOptions.timezone) : null; - } - - break; - case 'maxMode': - case 'minMode': - if ($scope.datepickerOptions[key]) { - $scope.$watch(function() { return $scope.datepickerOptions[key]; }, function(value) { - self[key] = $scope[key] = angular.isDefined(value) ? value : datepickerOptions[key]; - if (key === 'minMode' && self.modes.indexOf($scope.datepickerOptions.datepickerMode) < self.modes.indexOf(self[key]) || - key === 'maxMode' && self.modes.indexOf($scope.datepickerOptions.datepickerMode) > self.modes.indexOf(self[key])) { - $scope.datepickerMode = self[key]; - $scope.datepickerOptions.datepickerMode = self[key]; - } - }); - } else { - self[key] = $scope[key] = datepickerConfig[key] || null; - } - - break; - case 'initDate': - if ($scope.datepickerOptions.initDate) { - self.activeDate = dateParser.fromTimezone($scope.datepickerOptions.initDate, ngModelOptions.timezone) || new Date(); - $scope.$watch(function() { return $scope.datepickerOptions.initDate; }, function(initDate) { - if (initDate && (ngModelCtrl.$isEmpty(ngModelCtrl.$modelValue) || ngModelCtrl.$invalid)) { - self.activeDate = dateParser.fromTimezone(initDate, ngModelOptions.timezone); - self.refreshView(); - } - }); - } else { - self.activeDate = new Date(); - } - } - }); - } else { - // Interpolated configuration attributes - angular.forEach(['formatDay', 'formatMonth', 'formatYear', 'formatDayHeader', 'formatDayTitle', 'formatMonthTitle'], function(key) { - self[key] = angular.isDefined($attrs[key]) ? $interpolate($attrs[key])($scope.$parent) : datepickerConfig[key]; - - if (angular.isDefined($attrs[key]) && datepickerAttributeWarning) { - $log.warn('uib-datepicker ' + key + ' attribute usage is deprecated, use datepicker-options attribute instead'); - } - }); - - // Evaled configuration attributes - angular.forEach(['showWeeks', 'yearRows', 'yearColumns', 'shortcutPropagation'], function(key) { - self[key] = angular.isDefined($attrs[key]) ? - $scope.$parent.$eval($attrs[key]) : datepickerConfig[key]; - - if (angular.isDefined($attrs[key]) && datepickerAttributeWarning) { - $log.warn('uib-datepicker ' + key + ' attribute usage is deprecated, use datepicker-options attribute instead'); - } - }); - - angular.forEach(['dateDisabled', 'customClass'], function(key) { - if (angular.isDefined($attrs[key]) && datepickerAttributeWarning) { - $log.warn('uib-datepicker ' + key + ' attribute usage is deprecated, use datepicker-options attribute instead'); - } - }); - - if (angular.isDefined($attrs.startingDay)) { - if (datepickerAttributeWarning) { - $log.warn('uib-datepicker startingDay attribute usage is deprecated, use datepicker-options attribute instead'); - } - - self.startingDay = $scope.$parent.$eval($attrs.startingDay); - } else if (angular.isNumber(datepickerConfig.startingDay)) { - self.startingDay = datepickerConfig.startingDay; - } else { - self.startingDay = ($locale.DATETIME_FORMATS.FIRSTDAYOFWEEK + 8) % 7; - } - - // Watchable date attributes - angular.forEach(['minDate', 'maxDate'], function(key) { - if ($attrs[key]) { - if (datepickerAttributeWarning) { - $log.warn('uib-datepicker ' + key + ' attribute usage is deprecated, use datepicker-options attribute instead'); - } - - watchListeners.push($scope.$parent.$watch($attrs[key], function(value) { - if (value) { - if (angular.isDate(value)) { - self[key] = dateParser.fromTimezone(new Date(value), ngModelOptions.timezone); } else { - self[key] = new Date(dateFilter(value, 'medium')); + self[key] = null; } - } else { - self[key] = null; - } - self.refreshView(); - })); - } else { - self[key] = datepickerConfig[key] ? dateParser.fromTimezone(new Date(datepickerConfig[key]), ngModelOptions.timezone) : null; - } - }); - - angular.forEach(['minMode', 'maxMode'], function(key) { - if ($attrs[key]) { - if (datepickerAttributeWarning) { - $log.warn('uib-datepicker ' + key + ' attribute usage is deprecated, use datepicker-options attribute instead'); + self.refreshView(); + }); + } else { + self[key] = datepickerConfig[key] ? dateParser.fromTimezone(new Date(datepickerConfig[key]), ngModelOptions.timezone) : null; } - watchListeners.push($scope.$parent.$watch($attrs[key], function(value) { - self[key] = $scope[key] = angular.isDefined(value) ? value : $attrs[key]; - if (key === 'minMode' && self.modes.indexOf($scope.datepickerMode) < self.modes.indexOf(self[key]) || - key === 'maxMode' && self.modes.indexOf($scope.datepickerMode) > self.modes.indexOf(self[key])) { - $scope.datepickerMode = self[key]; - } - })); - } else { - self[key] = $scope[key] = datepickerConfig[key] || null; - } - }); - - if (angular.isDefined($attrs.initDate)) { - if (datepickerAttributeWarning) { - $log.warn('uib-datepicker initDate attribute usage is deprecated, use datepicker-options attribute instead'); - } - - var initDate = dateParser.fromTimezone($scope.$parent.$eval($attrs.initDate), ngModelOptions.timezone); - this.activeDate = !isNaN(initDate) ? initDate : new Date(); - watchListeners.push($scope.$parent.$watch($attrs.initDate, function(initDate) { - if (initDate && (ngModelCtrl.$isEmpty(ngModelCtrl.$modelValue) || ngModelCtrl.$invalid)) { - initDate = dateParser.fromTimezone(initDate, ngModelOptions.timezone); - self.activeDate = !isNaN(initDate) ? initDate : new Date(); - self.refreshView(); + break; + case 'maxMode': + case 'minMode': + if ($scope.datepickerOptions[key]) { + $scope.$watch(function() { return $scope.datepickerOptions[key]; }, function(value) { + self[key] = $scope[key] = angular.isDefined(value) ? value : datepickerOptions[key]; + if (key === 'minMode' && self.modes.indexOf($scope.datepickerOptions.datepickerMode) < self.modes.indexOf(self[key]) || + key === 'maxMode' && self.modes.indexOf($scope.datepickerOptions.datepickerMode) > self.modes.indexOf(self[key])) { + $scope.datepickerMode = self[key]; + $scope.datepickerOptions.datepickerMode = self[key]; + } + }); + } else { + self[key] = $scope[key] = datepickerConfig[key] || null; } - })); - } else { - this.activeDate = new Date(); - } - if ($attrs.datepickerMode && datepickerAttributeWarning) { - $log.warn('uib-datepicker datepickerMode attribute usage is deprecated, use datepicker-options attribute instead'); + break; } - - $scope.datepickerMode = $scope.datepickerMode || - datepickerConfig.datepickerMode; - } + }); $scope.uniqueId = 'datepicker-' + $scope.$id + '-' + Math.floor(Math.random() * 10000); @@ -270,6 +154,17 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst this.init = function(ngModelCtrl_) { ngModelCtrl = ngModelCtrl_; ngModelOptions = ngModelCtrl_.$options || datepickerConfig.ngModelOptions; + if ($scope.datepickerOptions.initDate) { + self.activeDate = dateParser.fromTimezone($scope.datepickerOptions.initDate, ngModelOptions.timezone) || new Date(); + $scope.$watch('datepickerOptions.initDate', function(initDate) { + if (initDate && (ngModelCtrl.$isEmpty(ngModelCtrl.$modelValue) || ngModelCtrl.$invalid)) { + self.activeDate = dateParser.fromTimezone(initDate, ngModelOptions.timezone); + self.refreshView(); + } + }); + } else { + self.activeDate = new Date(); + } this.activeDate = ngModelCtrl.$modelValue ? dateParser.fromTimezone(new Date(ngModelCtrl.$modelValue), ngModelOptions.timezone) : @@ -436,9 +331,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst function setMode(mode) { $scope.datepickerMode = mode; - if (optionsUsed) { - $scope.datepickerOptions.datepickerMode = mode; - } + $scope.datepickerOptions.datepickerMode = mode; } }]) @@ -676,11 +569,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst return attrs.templateUrl || 'uib/template/datepicker/datepicker.html'; }, scope: { - datepickerMode: '=?', - datepickerOptions: '=?', - dateDisabled: '&', - customClass: '&', - shortcutPropagation: '&?' + datepickerOptions: '=?' }, require: ['uibDatepicker', '^ngModel'], controller: 'UibDatepickerController', @@ -773,13 +662,12 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $ isHtml5DateInput = false; var dateFormat, closeOnDateSelection, appendToBody, onOpenFocus, datepickerPopupTemplateUrl, datepickerTemplateUrl, popupEl, datepickerEl, scrollParentEl, - ngModel, ngModelOptions, $popup, altInputFormats, watchListeners = []; - - $scope.watchData = {}; + ngModel, ngModelOptions, $popup, altInputFormats, watchListeners = [], + timezone; this.init = function(_ngModel_) { ngModel = _ngModel_; - ngModelOptions = _ngModel_.$options || datepickerConfig.ngModelOptions; + ngModelOptions = _ngModel_.$options; closeOnDateSelection = angular.isDefined($attrs.closeOnDateSelection) ? $scope.$parent.$eval($attrs.closeOnDateSelection) : datepickerPopupConfig.closeOnDateSelection; @@ -831,16 +719,22 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $ // popup element used to display calendar popupEl = angular.element('
'); - $scope.ngModelOptions = angular.copy(ngModelOptions); - $scope.ngModelOptions.timezone = null; - if ($scope.ngModelOptions.updateOnDefault === true) { - $scope.ngModelOptions.updateOn = $scope.ngModelOptions.updateOn ? - $scope.ngModelOptions.updateOn + ' default' : 'default'; + if (ngModelOptions) { + timezone = ngModelOptions.timezone; + $scope.ngModelOptions = angular.copy(ngModelOptions); + $scope.ngModelOptions.timezone = null; + if ($scope.ngModelOptions.updateOnDefault === true) { + $scope.ngModelOptions.updateOn = $scope.ngModelOptions.updateOn ? + $scope.ngModelOptions.updateOn + ' default' : 'default'; + } + + popupEl.attr('ng-model-options', 'ngModelOptions'); + } else { + timezone = null; } popupEl.attr({ 'ng-model': 'date', - 'ng-model-options': 'ngModelOptions', 'ng-change': 'dateSelection(date)', 'template-url': datepickerPopupTemplateUrl }); @@ -849,98 +743,18 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $ datepickerEl = angular.element(popupEl.children()[0]); datepickerEl.attr('template-url', datepickerTemplateUrl); - if (isHtml5DateInput) { - if ($attrs.type === 'month') { - datepickerEl.attr('datepicker-mode', '"month"'); - datepickerEl.attr('min-mode', 'month'); - } - } - - if ($scope.datepickerOptions) { - datepickerEl.attr('datepicker-options', 'datepickerOptions'); + if (!$scope.datepickerOptions) { + $scope.datepickerOptions = {}; } - angular.forEach(['minMode', 'maxMode', 'datepickerMode', 'shortcutPropagation'], function(key) { - if ($attrs[key]) { - if (datepickerPopupAttributeWarning) { - $log.warn('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - } - - var getAttribute = $parse($attrs[key]); - var propConfig = { - get: function() { - return getAttribute($scope.$parent); - } - }; - - datepickerEl.attr(cameltoDash(key), 'watchData.' + key); - - // Propagate changes from datepicker to outside - if (key === 'datepickerMode') { - var setAttribute = getAttribute.assign; - propConfig.set = function(v) { - setAttribute($scope.$parent, v); - }; - } - - Object.defineProperty($scope.watchData, key, propConfig); - } - }); - - angular.forEach(['minDate', 'maxDate', 'initDate'], function(key) { - if ($attrs[key]) { - if (datepickerPopupAttributeWarning) { - $log.warn('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - } - - var getAttribute = $parse($attrs[key]); - - watchListeners.push($scope.$parent.$watch(getAttribute, function(value) { - if (key === 'minDate' || key === 'maxDate') { - if (value === null) { - cache[key] = null; - } else if (angular.isDate(value)) { - cache[key] = dateParser.fromTimezone(new Date(value), ngModelOptions.timezone); - } else { - cache[key] = new Date(dateFilter(value, 'medium')); - } - - $scope.watchData[key] = value === null ? null : cache[key]; - } else { - var date = value ? new Date(value) : new Date(); - $scope.watchData[key] = dateParser.fromTimezone(date, ngModelOptions.timezone); - } - })); - - datepickerEl.attr(cameltoDash(key), 'watchData.' + key); - } - }); - - if ($attrs.dateDisabled) { - if (datepickerPopupAttributeWarning) { - $log.warn('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); + if (isHtml5DateInput) { + if ($attrs.type === 'month') { + $scope.datepickerOptions.datepickerMode = 'month'; + $scope.datepickerOptions.minMode = 'month'; } - - datepickerEl.attr('date-disabled', 'dateDisabled({ date: date, mode: mode })'); } - angular.forEach(['formatDay', 'formatMonth', 'formatYear', 'formatDayHeader', 'formatDayTitle', 'formatMonthTitle', 'showWeeks', 'startingDay', 'yearRows', 'yearColumns'], function(key) { - if (angular.isDefined($attrs[key])) { - if (datepickerPopupAttributeWarning) { - $log.warn('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - } - - datepickerEl.attr(cameltoDash(key), $attrs[key]); - } - }); - - if ($attrs.customClass) { - if (datepickerPopupAttributeWarning) { - $log.warn('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - } - - datepickerEl.attr('custom-class', 'customClass({ date: date, mode: mode })'); - } + datepickerEl.attr('datepicker-options', 'datepickerOptions'); if (!isHtml5DateInput) { // Internal API to maintain the correct ng-invalid-[key] class @@ -953,7 +767,7 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $ return value; } - $scope.date = dateParser.fromTimezone(value, ngModelOptions.timezone); + $scope.date = dateParser.fromTimezone(value, timezone); if (angular.isNumber($scope.date)) { $scope.date = new Date($scope.date); @@ -963,7 +777,7 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $ }); } else { ngModel.$formatters.push(function(value) { - $scope.date = dateParser.fromTimezone(value, ngModelOptions.timezone); + $scope.date = dateParser.fromTimezone(value, timezone); return value; }); } @@ -1015,17 +829,23 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $ $scope.isDisabled = function(date) { if (date === 'today') { - date = dateParser.fromTimezone(new Date(), ngModelOptions.timezone); + date = dateParser.fromTimezone(new Date(), timezone); } - if ($scope.datepickerOptions) { - return $scope.datepickerOptions && - $scope.datepickerOptions.minDate && $scope.compare(date, $scope.datepickerOptions.minDate) < 0 || - $scope.datepickerOptions.maxDate && $scope.compare(date, $scope.datepickerOptions.maxDate) > 0; - } + var dates = {}; + angular.forEach(['minDate', 'maxDate'], function(key) { + if ($scope.datepickerOptions[key] === null) { + dates[key] = null; + } else if (angular.isDate($scope.datepickerOptions[key])) { + dates[key] = dateParser.fromTimezone(new Date($scope.datepickerOptions[key]), timezone); + } else { + dates[key] = new Date(dateFilter($scope.datepickerOptions[key], 'medium')); + } + }); - return $scope.watchData.minDate && $scope.compare(date, cache.minDate) < 0 || - $scope.watchData.maxDate && $scope.compare(date, cache.maxDate) > 0; + return $scope.datepickerOptions && + dates.minDate && $scope.compare(date, dates.minDate) < 0 || + dates.maxDate && $scope.compare(date, dates.maxDate) > 0; }; $scope.compare = function(date1, date2) { @@ -1093,6 +913,7 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $ if (onOpenFocus) { $scope.$broadcast('uib:datepicker.focus'); } + $document.on('click', documentClickBind); var placement = $attrs.popupPlacement ? $attrs.popupPlacement : datepickerPopupConfig.placement; @@ -1153,7 +974,7 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $ if (angular.isString(viewValue)) { var date = parseDateString(viewValue); if (!isNaN(date)) { - return dateParser.toTimezone(date, ngModelOptions.timezone); + return dateParser.toTimezone(date, timezone); } } @@ -1246,9 +1067,7 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $ isOpen: '=?', currentText: '@', clearText: '@', - closeText: '@', - dateDisabled: '&', - customClass: '&' + closeText: '@' }, link: function(scope, element, attrs, ctrls) { var ngModel = ctrls[0], diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index 76f55911d3..77f9e6e41b 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -205,1406 +205,6 @@ describe('datepicker', function() { }); }); - // TODO: Remove on next minor release - describe('uibDatepickerAttributeWarning', function() { - var $compile, - $log, - $scope; - - it('should not log warning for datepickerOptions usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.opts = {}; - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for customClass attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date(), - customClass: 'none' - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker customClass attribute usage is deprecated, use datepicker-options attribute instead'); - }); - - it('should suppress warning for customClass attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date(), - customClass: 'none' - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for dateDisabled attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date(), - dateDisabled: false - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker dateDisabled attribute usage is deprecated, use datepicker-options attribute instead'); - }); - - it('should suppress warning for dateDisabled attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date(), - dateDisabled: false - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for datepickerMode attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date(), - mode: 'day' - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker datepickerMode attribute usage is deprecated, use datepicker-options attribute instead'); - }); - - it('should suppress warning for datepickerMode attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date(), - mode: 'day' - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for formatDay attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker formatDay attribute usage is deprecated, use datepicker-options attribute instead'); - }); - - it('should suppress warning for formatDay attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for formatMonth attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker formatMonth attribute usage is deprecated, use datepicker-options attribute instead'); - }); - - it('should suppress warning for formatMonth attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for formatYear attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker formatYear attribute usage is deprecated, use datepicker-options attribute instead'); - }); - - it('should suppress warning for formatYear attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for formatDayHeader attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker formatDayHeader attribute usage is deprecated, use datepicker-options attribute instead'); - }); - - it('should suppress warning for formatDayHeader attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for formatDayTitle attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker formatDayTitle attribute usage is deprecated, use datepicker-options attribute instead'); - }); - - it('should suppress warning for formatDayTitle attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for formatMonthTitle attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker formatMonthTitle attribute usage is deprecated, use datepicker-options attribute instead'); - }); - - it('should suppress warning for formatMonthTitle attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for showWeeks attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker showWeeks attribute usage is deprecated, use datepicker-options attribute instead'); - }); - - it('should suppress warning for showWeeks attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for shortcutPropagation attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker shortcutPropagation attribute usage is deprecated, use datepicker-options attribute instead'); - }); - - it('should suppress warning for shortcutPropagation attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for yearColumns attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker yearColumns attribute usage is deprecated, use datepicker-options attribute instead'); - }); - - it('should suppress warning for yearColumns attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for yearRows attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker yearRows attribute usage is deprecated, use datepicker-options attribute instead'); - }); - - it('should suppress warning for yearRows attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for minDate attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - $scope.minDate = new Date(); - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker minDate attribute usage is deprecated, use datepicker-options attribute instead'); - }); - - it('should suppress warning for minDate attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - $scope.minDate = new Date(); - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for maxDate attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - $scope.maxDate = new Date(); - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker maxDate attribute usage is deprecated, use datepicker-options attribute instead'); - }); - - it('should suppress warning for maxDate attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - $scope.maxDate = new Date(); - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for minMode attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker minMode attribute usage is deprecated, use datepicker-options attribute instead'); - }); - - it('should suppress warning for minMode attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for maxMode attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker maxMode attribute usage is deprecated, use datepicker-options attribute instead'); - }); - - it('should suppress warning for maxMode attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for initDate attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - $scope.initDate = new Date(); - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker initDate attribute usage is deprecated, use datepicker-options attribute instead'); - }); - - it('should suppress warning for initDate attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.locals = { - date: new Date() - }; - $scope.initDate = new Date(); - - spyOn($log, 'warn'); - element = $compile('')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - }); - - // TODO: Remove on next minor release - describe('uibDatepickerPopupAttributeWarning', function() { - var $compile, - $log, - $scope; - - it('should not log warning for datepickerOptions usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - $scope.opts = {}; - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for customClass attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for customClass attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for dateDisabled attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for dateDisabled attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for minMode attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for minMode attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for maxMode attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for maxMode attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for shortcutPropagation attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for shortcutPropagation attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for minDate attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - $scope.minDate = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for minDate attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - $scope.minDate = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for maxDate attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - $scope.maxDate = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for maxDate attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - $scope.maxDate = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for initDate attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - $scope.initDate = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for initDate attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - $scope.initDate = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for formatDay attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for formatDay attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for formatMonth attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for formatMonth attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for formatYear attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for formatYear attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for formatDayHeader attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for formatDayHeader attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for formatDayTitle attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for formatDayTitle attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for formatMonthTitle attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for formatMonthTitle attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for showWeeks attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for showWeeks attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for startingDay attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for startingDay attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for yearColumns attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for yearColumns attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for yearRows attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for yearRows attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - }); - describe('', function() { beforeEach(inject(function(_$compile_, _$rootScope_, _$templateCache_) { $compile = _$compile_; @@ -2276,10 +876,10 @@ describe('datepicker', function() { describe('attribute `datepicker-options`', function() { describe('startingDay', function() { beforeEach(function() { - $rootScope.datepickerOptions = { + $rootScope.options = { startingDay: 1 }; - element = $compile('')($rootScope); + element = $compile('')($rootScope); $rootScope.$digest(); }); @@ -2305,10 +905,10 @@ describe('datepicker', function() { describe('showWeeks', function() { beforeEach(function() { - $rootScope.datepickerOptions = { + $rootScope.options = { showWeeks: false }; - element = $compile('')($rootScope); + element = $compile('')($rootScope); $rootScope.$digest(); }); @@ -2321,151 +921,53 @@ describe('datepicker', function() { }); }); - describe('minDate', function() { - beforeEach(function() { - $rootScope.datepickerOptions = { - minDate: new Date('September 12, 2010') - }; - element = $compile('')($rootScope); - $rootScope.$digest(); - }); - - it('disables appropriate days in current month', function() { - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(index < 14); - }); - }); - - it('disables appropriate days when min date changes', function() { - $rootScope.datepickerOptions.minDate = new Date('September 5, 2010'); - $rootScope.$digest(); - - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(index < 7); - }); - }); - - it('invalidates when model is a disabled date', function() { - $rootScope.datepickerOptions.minDate = new Date('September 5, 2010'); - $rootScope.date = new Date('September 2, 2010'); - $rootScope.$digest(); - expect(element.hasClass('ng-invalid')).toBeTruthy(); - expect(element.hasClass('ng-invalid-date-disabled')).toBeTruthy(); - }); - - it('disables all days in previous month', function() { - clickPreviousButton(); - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(true); - }); - }); - - it('disables no days in next month', function() { - clickNextButton(); - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(false); - }); - }); - - it('disables appropriate months in current year', function() { - clickTitleButton(); - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(index < 8); - }); - }); - - it('disables all months in previous year', function() { - clickTitleButton(); - clickPreviousButton(); - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(true); - }); - }); - - it('disables no months in next year', function() { - clickTitleButton(); - clickNextButton(); - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(false); - }); - }); - - it('enables everything before if it is cleared', function() { - $rootScope.datepickerOptions.minDate = null; - $rootScope.date = new Date('December 20, 1949'); - $rootScope.$digest(); - - clickTitleButton(); - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(false); - }); - }); - - it('accepts literals, \'yyyy-MM-dd\' case', function() { - $rootScope.datepickerOptions.minDate = '2010-09-05'; - element = $compile('')($rootScope); - $rootScope.$digest(); - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(index < 7); - }); - }); - }); - - describe('maxDate', function() { + describe('minDate', function() { beforeEach(function() { - $rootScope.datepickerOptions = { - maxDate: new Date('September 25, 2010') + $rootScope.options = { + minDate: new Date('September 12, 2010') }; - element = $compile('')($rootScope); + element = $compile('')($rootScope); $rootScope.$digest(); }); it('disables appropriate days in current month', function() { var buttons = getAllOptionsEl(); angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(index > 27); + expect(angular.element(button).prop('disabled')).toBe(index < 14); }); }); - it('disables appropriate days when max date changes', function() { - $rootScope.datepickerOptions.maxDate = new Date('September 18, 2010'); + it('disables appropriate days when min date changes', function() { + $rootScope.options.minDate = new Date('September 5, 2010'); $rootScope.$digest(); var buttons = getAllOptionsEl(); angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(index > 20); + expect(angular.element(button).prop('disabled')).toBe(index < 7); }); }); it('invalidates when model is a disabled date', function() { - $rootScope.datepickerOptions.maxDate = new Date('September 18, 2010'); + $rootScope.options.minDate = new Date('September 5, 2010'); + $rootScope.date = new Date('September 2, 2010'); $rootScope.$digest(); expect(element.hasClass('ng-invalid')).toBeTruthy(); expect(element.hasClass('ng-invalid-date-disabled')).toBeTruthy(); }); - it('disables no days in previous month', function() { + it('disables all days in previous month', function() { clickPreviousButton(); var buttons = getAllOptionsEl(); angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(false); + expect(angular.element(button).prop('disabled')).toBe(true); }); }); - it('disables all days in next month', function() { + it('disables no days in next month', function() { clickNextButton(); var buttons = getAllOptionsEl(); angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(true); + expect(angular.element(button).prop('disabled')).toBe(false); }); }); @@ -2473,464 +975,195 @@ describe('datepicker', function() { clickTitleButton(); var buttons = getAllOptionsEl(); angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(index > 8); + expect(angular.element(button).prop('disabled')).toBe(index < 8); }); }); - it('disables no months in previous year', function() { + it('disables all months in previous year', function() { clickTitleButton(); clickPreviousButton(); var buttons = getAllOptionsEl(); angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(false); + expect(angular.element(button).prop('disabled')).toBe(true); }); }); - it('disables all months in next year', function() { + it('disables no months in next year', function() { clickTitleButton(); clickNextButton(); var buttons = getAllOptionsEl(); angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(true); + expect(angular.element(button).prop('disabled')).toBe(false); }); }); - it('enables everything after if it is cleared', function() { - $rootScope.datepickerOptions.maxDate = null; + it('enables everything before if it is cleared', function() { + $rootScope.options.minDate = null; + $rootScope.date = new Date('December 20, 1949'); $rootScope.$digest(); + + clickTitleButton(); var buttons = getAllOptionsEl(); angular.forEach(buttons, function(button, index) { expect(angular.element(button).prop('disabled')).toBe(false); }); }); - }); - describe('formatting', function() { - beforeEach(function() { - $rootScope.datepickerOptions = { - formatDay: 'd', - formatDayHeader: 'EEEE', - formatDayTitle: 'MMMM, yy', - formatMonth: 'MMM', - formatMonthTitle: 'yy', - formatYear: 'yy', - yearColumns: 4, - yearRows: 3 - }; - element = $compile('')($rootScope); + it('accepts literals, \'yyyy-MM-dd\' case', function() { + $rootScope.options.minDate = '2010-09-05'; + element = $compile('')($rootScope); $rootScope.$digest(); + var buttons = getAllOptionsEl(); + angular.forEach(buttons, function(button, index) { + expect(angular.element(button).prop('disabled')).toBe(index < 7); + }); }); - - it('changes the title format in `day` mode', function() { - expect(getTitle()).toBe('September, 10'); - }); - - it('changes the title & months format in `month` mode', function() { - clickTitleButton(); - - expect(getTitle()).toBe('10'); - expect(getOptions()).toEqual([ - ['Jan', 'Feb', 'Mar'], - ['Apr', 'May', 'Jun'], - ['Jul', 'Aug', 'Sep'], - ['Oct', 'Nov', 'Dec'] - ]); - }); - - it('changes the title, year format & range in `year` mode', function() { - clickTitleButton(); - clickTitleButton(); - - expect(getTitle()).toBe('05 - 16'); - expect(getOptions()).toEqual([ - ['05', '06', '07', '08'], - ['09', '10', '11', '12'], - ['13', '14', '15', '16'] - ]); - }); - - it('shows day labels', function() { - expect(getLabels(true)).toEqual(['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']); - }); - - it('changes the day format', function() { - expect(getOptions(true)).toEqual([ - ['29', '30', '31', '1', '2', '3', '4'], - ['5', '6', '7', '8', '9', '10', '11'], - ['12', '13', '14', '15', '16', '17', '18'], - ['19', '20', '21', '22', '23', '24', '25'], - ['26', '27', '28', '29', '30', '1', '2'], - ['3', '4', '5', '6', '7', '8', '9'] - ]); - }); - }); - }); - - describe('attribute `starting-day`', function() { - beforeEach(function() { - $rootScope.startingDay = 1; - element = $compile('')($rootScope); - $rootScope.$digest(); - }); - - it('shows the day labels rotated', function() { - expect(getLabels(true)).toEqual(['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']); - }); - - it('renders the calendar days correctly', function() { - expect(getOptions(true)).toEqual([ - ['30', '31', '01', '02', '03', '04', '05'], - ['06', '07', '08', '09', '10', '11', '12'], - ['13', '14', '15', '16', '17', '18', '19'], - ['20', '21', '22', '23', '24', '25', '26'], - ['27', '28', '29', '30', '01', '02', '03'], - ['04', '05', '06', '07', '08', '09', '10'] - ]); - }); - - it('renders the week numbers correctly', function() { - expect(getWeeks()).toEqual(['35', '36', '37', '38', '39', '40']); - }); - }); - - describe('attribute `show-weeks`', function() { - beforeEach(function() { - $rootScope.showWeeks = false; - element = $compile('')($rootScope); - $rootScope.$digest(); - }); - - it('hides week numbers based on variable', function() { - expect(getLabelsRow().find('th').length).toEqual(7); - var tr = element.find('tbody').find('tr'); - for (var i = 0; i < 5; i++) { - expect(tr.eq(i).find('td').length).toEqual(7); - } - }); - }); - - describe('`min-date` attribute', function() { - beforeEach(function() { - $rootScope.mindate = new Date('September 12, 2010'); - element = $compile('')($rootScope); - $rootScope.$digest(); - }); - - it('disables appropriate days in current month', function() { - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(index < 14); - }); - }); - - it('disables appropriate days when min date changes', function() { - $rootScope.mindate = new Date('September 5, 2010'); - $rootScope.$digest(); - - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(index < 7); - }); - }); - - it('invalidates when model is a disabled date', function() { - $rootScope.mindate = new Date('September 5, 2010'); - $rootScope.date = new Date('September 2, 2010'); - $rootScope.$digest(); - expect(element.hasClass('ng-invalid')).toBeTruthy(); - expect(element.hasClass('ng-invalid-date-disabled')).toBeTruthy(); - }); - - it('disables all days in previous month', function() { - clickPreviousButton(); - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(true); - }); - }); - - it('disables no days in next month', function() { - clickNextButton(); - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(false); - }); - }); - - it('disables appropriate months in current year', function() { - clickTitleButton(); - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(index < 8); - }); - }); - - it('disables all months in previous year', function() { - clickTitleButton(); - clickPreviousButton(); - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(true); - }); - }); - - it('disables no months in next year', function() { - clickTitleButton(); - clickNextButton(); - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(false); - }); - }); - - it('enables everything before if it is cleared', function() { - $rootScope.mindate = null; - $rootScope.date = new Date('December 20, 1949'); - $rootScope.$digest(); - - clickTitleButton(); - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(false); - }); - }); - - it('accepts literals, \'yyyy-MM-dd\' case', function() { - element = $compile('')($rootScope); - $rootScope.$digest(); - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(index < 7); - }); - }); - }); - - describe('`max-date` attribute', function() { - beforeEach(function() { - $rootScope.maxdate = new Date('September 25, 2010'); - element = $compile('')($rootScope); - $rootScope.$digest(); - }); - - it('disables appropriate days in current month', function() { - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(index > 27); - }); - }); - - it('disables appropriate days when max date changes', function() { - $rootScope.maxdate = new Date('September 18, 2010'); - $rootScope.$digest(); - - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(index > 20); - }); - }); - - it('invalidates when model is a disabled date', function() { - $rootScope.maxdate = new Date('September 18, 2010'); - $rootScope.$digest(); - expect(element.hasClass('ng-invalid')).toBeTruthy(); - expect(element.hasClass('ng-invalid-date-disabled')).toBeTruthy(); - }); - - it('disables no days in previous month', function() { - clickPreviousButton(); - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(false); - }); - }); - - it('disables all days in next month', function() { - clickNextButton(); - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(true); - }); - }); - - it('disables appropriate months in current year', function() { - clickTitleButton(); - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(index > 8); - }); - }); - - it('disables no months in previous year', function() { - clickTitleButton(); - clickPreviousButton(); - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(false); - }); - }); - - it('disables all months in next year', function() { - clickTitleButton(); - clickNextButton(); - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(true); - }); - }); - - it('enables everything after if it is cleared', function() { - $rootScope.maxdate = null; - $rootScope.$digest(); - var buttons = getAllOptionsEl(); - angular.forEach(buttons, function(button, index) { - expect(angular.element(button).prop('disabled')).toBe(false); - }); - }); - }); - - describe('date-disabled expression', function() { - beforeEach(function() { - $rootScope.options = { - dateDisabled: jasmine.createSpy('dateDisabled') - }; - element = $compile('')($rootScope); - $rootScope.$digest(); }); - it('executes the dateDisabled expression for each visible day plus one for validation', function() { - expect($rootScope.options.dateDisabled.calls.count()).toEqual(42 + 1); - }); + describe('maxDate', function() { + beforeEach(function() { + $rootScope.options = { + maxDate: new Date('September 25, 2010') + }; + element = $compile('')($rootScope); + $rootScope.$digest(); + }); - it('executes the dateDisabled expression for each visible month plus one for validation', function() { - $rootScope.options.dateDisabled.calls.reset(); - clickTitleButton(); - expect($rootScope.options.dateDisabled.calls.count()).toEqual(12 + 1); - }); + it('disables appropriate days in current month', function() { + var buttons = getAllOptionsEl(); + angular.forEach(buttons, function(button, index) { + expect(angular.element(button).prop('disabled')).toBe(index > 27); + }); + }); - it('executes the dateDisabled expression for each visible year plus one for validation', function() { - clickTitleButton(); - $rootScope.options.dateDisabled.calls.reset(); - clickTitleButton(); - expect($rootScope.options.dateDisabled.calls.count()).toEqual(20 + 1); - }); - }); + it('disables appropriate days when max date changes', function() { + $rootScope.options.maxDate = new Date('September 18, 2010'); + $rootScope.$digest(); - describe('custom-class expression', function() { - beforeEach(function() { - $rootScope.options = { - customClass: jasmine.createSpy('customClass') - }; - element = $compile('')($rootScope); - $rootScope.$digest(); - }); + var buttons = getAllOptionsEl(); + angular.forEach(buttons, function(button, index) { + expect(angular.element(button).prop('disabled')).toBe(index > 20); + }); + }); - it('executes the customClass expression for each visible day plus one for validation', function() { - expect($rootScope.options.customClass.calls.count()).toEqual(42); - }); + it('invalidates when model is a disabled date', function() { + $rootScope.options.maxDate = new Date('September 18, 2010'); + $rootScope.$digest(); + expect(element.hasClass('ng-invalid')).toBeTruthy(); + expect(element.hasClass('ng-invalid-date-disabled')).toBeTruthy(); + }); - it('executes the customClass expression for each visible month plus one for validation', function() { - $rootScope.options.customClass.calls.reset(); - clickTitleButton(); - expect($rootScope.options.customClass.calls.count()).toEqual(12); - }); + it('disables no days in previous month', function() { + clickPreviousButton(); + var buttons = getAllOptionsEl(); + angular.forEach(buttons, function(button, index) { + expect(angular.element(button).prop('disabled')).toBe(false); + }); + }); - it('executes the customClass expression for each visible year plus one for validation', function() { - clickTitleButton(); - $rootScope.options.customClass.calls.reset(); - clickTitleButton(); - expect($rootScope.options.customClass.calls.count()).toEqual(20); - }); - }); + it('disables all days in next month', function() { + clickNextButton(); + var buttons = getAllOptionsEl(); + angular.forEach(buttons, function(button, index) { + expect(angular.element(button).prop('disabled')).toBe(true); + }); + }); - describe('formatting', function() { - beforeEach(function() { - $rootScope.dayTitle = 'MMMM, yy'; - element = $compile('')($rootScope); - $rootScope.$digest(); - }); + it('disables appropriate months in current year', function() { + clickTitleButton(); + var buttons = getAllOptionsEl(); + angular.forEach(buttons, function(button, index) { + expect(angular.element(button).prop('disabled')).toBe(index > 8); + }); + }); - it('changes the title format in `day` mode', function() { - expect(getTitle()).toBe('September, 10'); - }); + it('disables no months in previous year', function() { + clickTitleButton(); + clickPreviousButton(); + var buttons = getAllOptionsEl(); + angular.forEach(buttons, function(button, index) { + expect(angular.element(button).prop('disabled')).toBe(false); + }); + }); - it('changes the title & months format in `month` mode', function() { - clickTitleButton(); + it('disables all months in next year', function() { + clickTitleButton(); + clickNextButton(); + var buttons = getAllOptionsEl(); + angular.forEach(buttons, function(button, index) { + expect(angular.element(button).prop('disabled')).toBe(true); + }); + }); - expect(getTitle()).toBe('10'); - expect(getOptions()).toEqual([ - ['Jan', 'Feb', 'Mar'], - ['Apr', 'May', 'Jun'], - ['Jul', 'Aug', 'Sep'], - ['Oct', 'Nov', 'Dec'] - ]); + it('enables everything after if it is cleared', function() { + $rootScope.options.maxDate = null; + $rootScope.$digest(); + var buttons = getAllOptionsEl(); + angular.forEach(buttons, function(button, index) { + expect(angular.element(button).prop('disabled')).toBe(false); + }); + }); }); - it('changes the title, year format & range in `year` mode', function() { - clickTitleButton(); - clickTitleButton(); + describe('formatting', function() { + beforeEach(function() { + $rootScope.options = { + formatDay: 'd', + formatDayHeader: 'EEEE', + formatDayTitle: 'MMMM, yy', + formatMonth: 'MMM', + formatMonthTitle: 'yy', + formatYear: 'yy', + yearColumns: 4, + yearRows: 3 + }; + element = $compile('')($rootScope); + $rootScope.$digest(); + }); - expect(getTitle()).toBe('05 - 16'); - expect(getOptions()).toEqual([ - ['05', '06', '07', '08'], - ['09', '10', '11', '12'], - ['13', '14', '15', '16'] - ]); - }); + it('changes the title format in `day` mode', function() { + expect(getTitle()).toBe('September, 10'); + }); - it('shows day labels', function() { - expect(getLabels(true)).toEqual(['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']); - }); + it('changes the title & months format in `month` mode', function() { + clickTitleButton(); - it('changes the day format', function() { - expect(getOptions(true)).toEqual([ - ['29', '30', '31', '1', '2', '3', '4'], - ['5', '6', '7', '8', '9', '10', '11'], - ['12', '13', '14', '15', '16', '17', '18'], - ['19', '20', '21', '22', '23', '24', '25'], - ['26', '27', '28', '29', '30', '1', '2'], - ['3', '4', '5', '6', '7', '8', '9'] - ]); - }); - }); + expect(getTitle()).toBe('10'); + expect(getOptions()).toEqual([ + ['Jan', 'Feb', 'Mar'], + ['Apr', 'May', 'Jun'], + ['Jul', 'Aug', 'Sep'], + ['Oct', 'Nov', 'Dec'] + ]); + }); - describe('gc', function() { - var datepickerScope; - beforeEach(function() { - $rootScope.minDate = new Date(); - $rootScope.maxDate = new Date(); - $rootScope.maxDate.setDate($rootScope.maxDate.getDate() + 1); - $rootScope.minMode = 'day'; - $rootScope.maxMode = 'year'; - $rootScope.initDate = new Date(); - element = $compile('')($rootScope); - $rootScope.$digest(); - datepickerScope = element.isolateScope(); - }); + it('changes the title, year format & range in `year` mode', function() { + clickTitleButton(); + clickTitleButton(); - it('should appropriately clean up $watch expressions', function() { - expect($rootScope.$$watchers.length).toBe(6); - ['minDate', 'maxDate', 'minMode', 'maxMode', 'initDate'].forEach(function(prop) { - var $$watcher; - $rootScope.$$watchers.forEach(function($$watch) { - if ($$watch.exp === prop) { - $$watcher = $$watch; - } - }); - expect(angular.isObject($$watcher)).toBe(true); + expect(getTitle()).toBe('05 - 16'); + expect(getOptions()).toEqual([ + ['05', '06', '07', '08'], + ['09', '10', '11', '12'], + ['13', '14', '15', '16'] + ]); }); - datepickerScope.$destroy(); + it('shows day labels', function() { + expect(getLabels(true)).toEqual(['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']); + }); - expect($rootScope.$$watchers.length).toBe(1); + it('changes the day format', function() { + expect(getOptions(true)).toEqual([ + ['29', '30', '31', '1', '2', '3', '4'], + ['5', '6', '7', '8', '9', '10', '11'], + ['12', '13', '14', '15', '16', '17', '18'], + ['19', '20', '21', '22', '23', '24', '25'], + ['26', '27', '28', '29', '30', '1', '2'], + ['3', '4', '5', '6', '7', '8', '9'] + ]); + }); }); }); @@ -3133,8 +1366,6 @@ describe('datepicker', function() { angular.extend(originalConfig, uibDatepickerConfig); uibDatepickerConfig.ngModelOptions = { timezone: '+600' }; $rootScope.date = new Date('2005-11-07T10:00:00.000Z'); - element = $compile('')($rootScope); - $rootScope.$digest(); })); afterEach(inject(function(uibDatepickerConfig) { @@ -3142,27 +1373,38 @@ describe('datepicker', function() { angular.extend(uibDatepickerConfig, originalConfig); })); - it('sets date to appropriate date', function() { - expectSelectedElement(8); - }); + describe('basics', function() { + beforeEach(function() { + element = $compile('')($rootScope); + $rootScope.$digest(); + }); - it('updates the input when a day is clicked', function() { - clickOption(9); - expect($rootScope.date).toEqual(new Date('2005-11-08T10:00:00.000Z')); + it('sets date to appropriate date', function() { + expectSelectedElement(8); + }); + + it('updates the input when a day is clicked', function() { + clickOption(9); + expect($rootScope.date).toEqual(new Date('2005-11-08T10:00:00.000Z')); + }); }); it('init date', function() { - $rootScope.initDate = new Date('2006-01-01T00:00:00.000Z'); + $rootScope.options = { + initDate: new Date('2006-01-01T00:00:00.000Z') + }; $rootScope.date = null; - element = $compile('')($rootScope); + element = $compile('')($rootScope); $rootScope.$digest(); expect(getTitle()).toEqual('January 2006'); }); it('min date', function() { - $rootScope.minDate = new Date('2010-10-01T00:00:00.000Z'); - element = $compile('')($rootScope); + $rootScope.options = { + minDate: new Date('2010-10-01T00:00:00.000Z') + }; + element = $compile('')($rootScope); $rootScope.$digest(); expect(getSelectedElement().prop('disabled')).toBe(true); @@ -3730,15 +1972,17 @@ describe('datepicker', function() { }); }); - describe('attribute `init-date`', function() { + describe('option `init-date`', function() { beforeEach(function() { $rootScope.date = null; - $rootScope.initDate = new Date('November 9, 1980'); + $rootScope.options = { + initDate: new Date('November 9, 1980') + }; }); describe('when initially set', function() { beforeEach(function() { - var wrapElement = $compile('
')($rootScope); + var wrapElement = $compile('
')($rootScope); $rootScope.$digest(); assignElements(wrapElement); }); @@ -3754,11 +1998,11 @@ describe('datepicker', function() { describe('when modified before date selected.', function() { beforeEach(function() { - var wrapElement = $compile('
')($rootScope); + var wrapElement = $compile('
')($rootScope); $rootScope.$digest(); assignElements(wrapElement); - $rootScope.initDate = new Date('December 20, 1981'); + $rootScope.options.initDate = new Date('December 20, 1981'); $rootScope.$digest(); }); @@ -3773,11 +2017,11 @@ describe('datepicker', function() { describe('when modified after date selected.', function() { beforeEach(function() { - var wrapElement = $compile('
')($rootScope); + var wrapElement = $compile('
')($rootScope); $rootScope.$digest(); assignElements(wrapElement); $rootScope.date = new Date('April 1, 1982'); - $rootScope.initDate = new Date('December 20, 1981'); + $rootScope.options.initDate = new Date('December 20, 1981'); $rootScope.$digest(); }); @@ -4066,8 +2310,12 @@ describe('datepicker', function() { }); it('should disable today button if before min date', function() { - $rootScope.minDate = new Date().setDate(new Date().getDate() + 1); - var wrapElement = $compile('
')($rootScope); + var date = new Date(); + date.setDate(new Date().getDate() + 1); + $rootScope.options = { + minDate: date + }; + var wrapElement = $compile('
')($rootScope); $rootScope.$digest(); assignElements(wrapElement); assignButtonBar(); @@ -4076,9 +2324,13 @@ describe('datepicker', function() { }); it('should disable today button if before min date, yyyy-MM-dd case', inject(function(dateFilter) { - var minDate = new Date(new Date().setDate(new Date().getDate() + 1)); - var literalMinDate = dateFilter(minDate, 'yyyy-MM-dd'); - var wrapElement = $compile('
')($rootScope); + var date = new Date(); + date.setDate(new Date().getDate() + 1); + var literalMinDate = dateFilter(date, 'yyyy-MM-dd'); + $rootScope.options = { + minDate: literalMinDate + }; + var wrapElement = $compile('
')($rootScope); $rootScope.$digest(); assignElements(wrapElement); assignButtonBar(); @@ -4087,8 +2339,10 @@ describe('datepicker', function() { })); it('should not disable any button if min date is null', function() { - $rootScope.minDate = null; - var wrapElement = $compile('
')($rootScope); + $rootScope.options = { + minDate: null + }; + var wrapElement = $compile('
')($rootScope); $rootScope.$digest(); assignElements(wrapElement); assignButtonBar(); @@ -4099,8 +2353,12 @@ describe('datepicker', function() { }); it('should disable today button if after max date', function() { - $rootScope.maxDate = new Date().setDate(new Date().getDate() - 2); - var wrapElement = $compile('
')($rootScope); + var date = new Date(); + date.setDate(new Date().getDate() - 2); + $rootScope.options = { + maxDate: date + }; + var wrapElement = $compile('
')($rootScope); $rootScope.$digest(); assignElements(wrapElement); assignButtonBar(); @@ -4109,8 +2367,10 @@ describe('datepicker', function() { }); it('should not disable any button if max date is null', function() { - $rootScope.maxDate = null; - var wrapElement = $compile('
')($rootScope); + $rootScope.options = { + maxDate: null + }; + var wrapElement = $compile('
')($rootScope); $rootScope.$digest(); assignElements(wrapElement); assignButtonBar(); @@ -4129,7 +2389,10 @@ describe('datepicker', function() { }); it('should hide weeks column on popup', function() { - var wrapElement = $compile('
')($rootScope); + $rootScope.options = { + showWeeks: false + }; + var wrapElement = $compile('
')($rootScope); $rootScope.$digest(); assignElements(wrapElement); @@ -4141,7 +2404,10 @@ describe('datepicker', function() { }); it('should show weeks column on popup', function() { - var wrapElement = $compile('
')($rootScope); + $rootScope.options = { + showWeeks: true + }; + var wrapElement = $compile('
')($rootScope); $rootScope.$digest(); assignElements(wrapElement); @@ -4409,8 +2675,10 @@ describe('datepicker', function() { describe('`datepicker-mode`', function() { beforeEach(inject(function() { $rootScope.date = new Date('August 11, 2013'); - $rootScope.mode = 'month'; - var wrapElement = $compile('
')($rootScope); + $rootScope.options = { + datepickerMode: 'month' + }; + var wrapElement = $compile('
')($rootScope); $rootScope.$digest(); assignElements(wrapElement); })); @@ -4421,7 +2689,7 @@ describe('datepicker', function() { it('updates binding', function() { clickTitleButton(); - expect($rootScope.mode).toBe('year'); + expect($rootScope.options.datepickerMode).toBe('year'); }); }); @@ -4506,94 +2774,6 @@ describe('datepicker', function() { }); }); }); - - describe('pass through attributes', function() { - var wrapElement; - describe('formatting', function() { - beforeEach(function() { - $rootScope.dayTitle = 'MMMM, yy'; - wrapElement = $compile('
')($rootScope); - $rootScope.$digest(); - assignElements(wrapElement); - }); - - it('changes the title format in `day` mode', function() { - expect(getTitle()).toBe('September, 10'); - }); - - it('changes the title & months format in `month` mode', function() { - clickTitleButton(); - assignElements(wrapElement); - expect(getTitle()).toBe('10'); - expect(getOptions()).toEqual([ - ['Jan', 'Feb', 'Mar'], - ['Apr', 'May', 'Jun'], - ['Jul', 'Aug', 'Sep'], - ['Oct', 'Nov', 'Dec'] - ]); - }); - - it('changes the title, year format & range in `year` mode', function() { - clickTitleButton(); - assignElements(wrapElement); - clickTitleButton(); - assignElements(wrapElement); - expect(getTitle()).toBe('05 - 16'); - expect(getOptions()).toEqual([ - ['05', '06', '07', '08'], - ['09', '10', '11', '12'], - ['13', '14', '15', '16'] - ]); - }); - - it('shows day labels', function() { - expect(getLabels(true)).toEqual(['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']); - }); - - it('changes the day format', function() { - expect(getOptions(true)).toEqual([ - ['29', '30', '31', '1', '2', '3', '4'], - ['5', '6', '7', '8', '9', '10', '11'], - ['12', '13', '14', '15', '16', '17', '18'], - ['19', '20', '21', '22', '23', '24', '25'], - ['26', '27', '28', '29', '30', '1', '2'], - ['3', '4', '5', '6', '7', '8', '9'] - ]); - }); - }); - }); - - describe('gc', function() { - var popupScope; - beforeEach(function() { - $rootScope.minDate = new Date(); - $rootScope.maxDate = new Date(); - $rootScope.maxDate.setDate($rootScope.maxDate.getDate() + 1); - $rootScope.minMode = 'day'; - $rootScope.maxMode = 'year'; - $rootScope.initDate = new Date(); - element = $compile('
')($rootScope); - $rootScope.$digest(); - popupScope = element.find('input').isolateScope(); - }); - - it('should appropriately clean up $watch expressions', function() { - expect($rootScope.$$watchers.length).toBe(4); - - popupScope.$destroy(); - - expect($rootScope.$$watchers.length).toBe(1); - }); - }); }); describe('uibDatepickerConfig ngModelOptions', function() { @@ -4622,11 +2802,6 @@ describe('datepicker', function() { assignElements(wrapper); })); - afterEach(inject(function (uibDatepickerConfig) { - // return it to the original state - uibDatepickerConfig.ngModelOptions = {}; - })); - it('interprets the date appropriately', function() { expect(inputEl.val()).toBe('09/30/2010'); }); @@ -4643,18 +2818,22 @@ describe('datepicker', function() { }); it('timezone interprets init date appropriately', function() { - $rootScope.initDate = new Date('2006-01-01T00:00:00.000Z'); + $rootScope.options = { + initDate: new Date('2010-09-30T23:00:00.000Z') + }; $rootScope.date = null; - var wrapper = $compile('
')($rootScope); + var wrapper = $compile('
')($rootScope); $rootScope.$digest(); assignElements(wrapper); - expect(getTitle()).toBe('January 2006'); + expect(getTitle()).toBe('October 2010'); }); it('timezone interprets min date appropriately', function() { - $rootScope.minDate = new Date('2010-10-01T00:00:00.000Z'); - var wrapper = $compile('
')($rootScope); + $rootScope.options = { + minDate: new Date('2010-10-01T00:00:00.000Z') + }; + var wrapper = $compile('
')($rootScope); $rootScope.$digest(); assignElements(wrapper); @@ -4759,8 +2938,10 @@ describe('datepicker', function() { describe('`init-date`', function() { beforeEach(inject(function() { $rootScope.date = null; - $rootScope.initDate = new Date('November 9, 1980'); - element = $compile('')($rootScope); + $rootScope.options = { + initDate: new Date('November 9, 1980') + }; + element = $compile('')($rootScope); $rootScope.$digest(); })); @@ -4776,8 +2957,10 @@ describe('datepicker', function() { describe('`datepicker-mode`', function() { beforeEach(inject(function() { $rootScope.date = new Date('August 11, 2013'); - $rootScope.mode = 'month'; - element = $compile('')($rootScope); + $rootScope.options = { + datepickerMode: 'month' + }; + element = $compile('')($rootScope); $rootScope.$digest(); })); @@ -4787,16 +2970,18 @@ describe('datepicker', function() { it('updates binding', function() { clickTitleButton(); - expect($rootScope.mode).toBe('year'); + expect($rootScope.options.datepickerMode).toBe('year'); }); }); describe('`min-mode`', function() { beforeEach(inject(function() { $rootScope.date = new Date('August 11, 2013'); - $rootScope.mode = 'month'; - $rootScope.minMode = 'month'; - element = $compile('')($rootScope); + $rootScope.options = { + minMode: 'month', + datepickerMode: 'month' + }; + element = $compile('')($rootScope); $rootScope.$digest(); })); @@ -4806,7 +2991,7 @@ describe('datepicker', function() { expect(getTitle()).toBe('2013'); clickTitleButton(); expect(getTitle()).toBe('2001 - 2020'); - $rootScope.minMode = 'year'; + $rootScope.options.minMode = 'year'; $rootScope.$digest(); clickOption( 5 ); expect(getTitle()).toBe('2001 - 2020'); @@ -4814,7 +2999,7 @@ describe('datepicker', function() { it('updates current mode if necessary', function() { expect(getTitle()).toBe('2013'); - $rootScope.minMode = 'year'; + $rootScope.options.minMode = 'year'; $rootScope.$digest(); expect(getTitle()).toBe('2001 - 2020'); }); @@ -4823,8 +3008,10 @@ describe('datepicker', function() { describe('`max-mode`', function() { beforeEach(inject(function() { $rootScope.date = new Date('August 11, 2013'); - $rootScope.maxMode = 'month'; - element = $compile('')($rootScope); + $rootScope.options = { + maxMode: 'month' + }; + element = $compile('')($rootScope); $rootScope.$digest(); })); @@ -4836,7 +3023,7 @@ describe('datepicker', function() { expect(getTitle()).toBe('2013'); clickOption( 10 ); expect(getTitle()).toBe('November 2013'); - $rootScope.maxMode = 'day'; + $rootScope.options.maxMode = 'day'; $rootScope.$digest(); clickTitleButton(); expect(getTitle()).toBe('November 2013'); @@ -4850,7 +3037,7 @@ describe('datepicker', function() { expect(getTitleButton().prop('disabled')).toBe(true); clickOption( 10 ); expect(getTitleButton().prop('disabled')).toBe(false); - $rootScope.maxMode = 'day'; + $rootScope.options.maxMode = 'day'; $rootScope.$digest(); expect(getTitleButton().prop('disabled')).toBe(true); }); @@ -4859,7 +3046,7 @@ describe('datepicker', function() { expect(getTitle()).toBe('August 2013'); clickTitleButton(); expect(getTitle()).toBe('2013'); - $rootScope.maxMode = 'day'; + $rootScope.options.maxMode = 'day'; $rootScope.$digest(); expect(getTitle()).toBe('August 2013'); }); @@ -4905,21 +3092,30 @@ describe('datepicker', function() { describe('when starting date', function() { it('is monday', function() { - element = $compile('')($rootScope); + $rootScope.options = { + startingDay: 1 + }; + element = $compile('')($rootScope); $rootScope.$digest(); expect(getWeeks()).toEqual(['22', '23', '24', '25', '26', '27']); }); it('is thursday', function() { - element = $compile('')($rootScope); + $rootScope.options = { + startingDay: 4 + }; + element = $compile('')($rootScope); $rootScope.$digest(); expect(getWeeks()).toEqual(['22', '23', '24', '25', '26', '27']); }); it('is saturday', function() { - element = $compile('')($rootScope); + $rootScope.options = { + startingDay: 6 + }; + element = $compile('')($rootScope); $rootScope.$digest(); expect(getWeeks()).toEqual(['23', '24', '25', '26', '27', '28']);