|
| 1 | +describe('Component: pfBootstrapDatepicker', function () { |
| 2 | + var $scope; |
| 3 | + var $compile; |
| 4 | + var element; |
| 5 | + |
| 6 | + // load the controller's module |
| 7 | + beforeEach(function () { |
| 8 | + module('patternfly.datepicker', 'datepicker/datepicker.html'); |
| 9 | + }); |
| 10 | + |
| 11 | + beforeEach(inject(function (_$compile_, _$rootScope_) { |
| 12 | + $compile = _$compile_; |
| 13 | + $scope = _$rootScope_; |
| 14 | + })); |
| 15 | + |
| 16 | + var compileHTML = function (markup, scope) { |
| 17 | + element = angular.element(markup); |
| 18 | + $compile(element)(scope); |
| 19 | + |
| 20 | + scope.$digest(); |
| 21 | + }; |
| 22 | + |
| 23 | + beforeEach(function () { |
| 24 | + $scope.date = new Date("Jan 1, 2000"); |
| 25 | + $scope.format = "MMM dd, yyyy"; |
| 26 | + $scope.dateOptions = { |
| 27 | + showWeeks : true |
| 28 | + }; |
| 29 | + |
| 30 | + var htmlTmp = '<pf-bootstrap-datepicker date="date" format="{{format}}"></pf-bootstrap-datepicker>'; |
| 31 | + |
| 32 | + compileHTML(htmlTmp, $scope); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should display the date in the correct format', function () { |
| 36 | + var input = element.find('input.datepicker')[0]; |
| 37 | + expect(input.value).toBe("Jan 01, 2000"); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should open datepicker when button clicked', function () { |
| 41 | + var button = element.find('button.datepicker')[0], |
| 42 | + datepicker; |
| 43 | + |
| 44 | + datepicker = element.find('ul.uib-datepicker-popup'); |
| 45 | + expect(datepicker.length).toBe(0); |
| 46 | + |
| 47 | + eventFire(button, 'click'); |
| 48 | + |
| 49 | + datepicker = element.find('ul.uib-datepicker-popup'); |
| 50 | + expect(datepicker.length).toBe(1); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should not display week numbers by default on datepicker', function () { |
| 54 | + var button = element.find('button.datepicker')[0], |
| 55 | + week; |
| 56 | + |
| 57 | + eventFire(button, 'click'); |
| 58 | + week = $(element.find('.uib-weeks')[0]); |
| 59 | + expect($("td", week).length).toBe(7); |
| 60 | + |
| 61 | + }); |
| 62 | + |
| 63 | + it('should display week numbers if dateOptions is modified', function () { |
| 64 | + |
| 65 | + // rebuild the element with the dateOptions included |
| 66 | + var htmlTmp = '<pf-bootstrap-datepicker date="date" format="{{format}}" date-options="dateOptions"></pf-bootstrap-datepicker>'; |
| 67 | + compileHTML(htmlTmp, $scope); |
| 68 | + |
| 69 | + // check each uib-weeks row in the datepicker has the week number + the seven days |
| 70 | + var button = element.find('button.datepicker')[0], |
| 71 | + week; |
| 72 | + eventFire(button, 'click'); |
| 73 | + week = $(element.find('.uib-weeks')[0]); |
| 74 | + expect($("td", week).length).toBe(8); |
| 75 | + |
| 76 | + }); |
| 77 | + |
| 78 | +}); |
0 commit comments