From 570dba904fb5b44eb35981c66debce3477c31af1 Mon Sep 17 00:00:00 2001 From: metimus Date: Thu, 24 Oct 2013 11:34:54 +0300 Subject: [PATCH] fix(datepicker): properly handle showWeeks config option Closes #1132 --- src/datepicker/datepicker.js | 6 +++--- src/datepicker/test/datepicker.spec.js | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index c995dad9f3..a4579873c5 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -261,8 +261,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.position']) appendToBody: false }) -.directive('datepickerPopup', ['$compile', '$parse', '$document', '$position', 'dateFilter', 'datepickerPopupConfig', -function ($compile, $parse, $document, $position, dateFilter, datepickerPopupConfig) { +.directive('datepickerPopup', ['$compile', '$parse', '$document', '$position', 'dateFilter', 'datepickerPopupConfig', 'datepickerConfig', +function ($compile, $parse, $document, $position, dateFilter, datepickerPopupConfig, datepickerConfig) { return { restrict: 'EA', require: 'ngModel', @@ -406,7 +406,7 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon if (attrs.showWeeks) { addWatchableAttribute(attrs.showWeeks, 'showWeeks', 'show-weeks'); } else { - scope.showWeeks = true; + scope.showWeeks = datepickerConfig.showWeeks; datepickerEl.attr('show-weeks', 'showWeeks'); } if (attrs.dateDisabled) { diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index c1757869a0..af69093103 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -1259,6 +1259,30 @@ describe('datepicker directive', function () { expect(elm.children().length).toEqual(1); }); }); + + describe('with setting datepickerConfig.showWeeks to false', function() { + var originalConfig = {}; + beforeEach(inject(function(datepickerConfig) { + angular.extend(originalConfig, datepickerConfig); + datepickerConfig.showWeeks = false; + + var wrapElement = $compile('
')($rootScope); + $rootScope.$digest(); + assignElements(wrapElement); + })); + afterEach(inject(function(datepickerConfig) { + // return it to the original state + angular.extend(datepickerConfig, originalConfig); + })); + + it('changes initial visibility for weeks', function() { + expect(getLabelsRow().find('th').eq(0).css('display')).toBe('none'); + var tr = element.find('tbody').find('tr'); + for (var i = 0; i < 5; i++) { + expect(tr.eq(i).find('td').eq(0).css('display')).toBe('none'); + } + }); + }); }); });