Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Datepicker popup config tests #1842

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.position'])
})

.constant('datepickerPopupConfig', {
dateFormat: 'yyyy-MM-dd',
datepickerPopup: 'yyyy-MM-dd',
currentText: 'Today',
clearText: 'Clear',
closeText: 'Done',
Expand Down
73 changes: 73 additions & 0 deletions src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,79 @@ describe('datepicker directive', function () {

});

describe('setting datepickerPopupConfig', function() {
var inputEl, buttons, buttonBarEl, dropdownEl;

function assignElements(wrapElement) {
inputEl = wrapElement.find('input');
dropdownEl = wrapElement.find('.dropdown-menu');
buttonBarEl = dropdownEl.find('.button-bar');
buttons = buttonBarEl.find('button');
element = dropdownEl.find('table');
}

var originalConfig = {};
beforeEach(inject(function(datepickerPopupConfig) {
angular.extend(originalConfig, datepickerPopupConfig);
datepickerPopupConfig.datepickerPopup = 'MM-dd-yyyy';
datepickerPopupConfig.currentText = 'TestToday';
datepickerPopupConfig.clearText = 'TestClear';
datepickerPopupConfig.closeText = 'TestDone';
datepickerPopupConfig.closeOnDateSelection = true;
datepickerPopupConfig.appendToBody = false;
datepickerPopupConfig.showButtonBar = true;

wrapElement = $compile('<div><input ng-model="date" datepicker-popup></div>')($rootScope);
$rootScope.$digest();
assignElements(wrapElement);
}));
afterEach(inject(function(datepickerPopupConfig) {
// return it to the original state
angular.extend(datepickerPopupConfig, originalConfig);
}));

it('changes date format', function() {
expect(inputEl.val()).toEqual('09-30-2010');
});

it('changes the current text', function() {
expect(buttons.eq(0).text()).toEqual('TestToday');
});

it('changes the clear text', function() {
expect(buttons.eq(1).text()).toEqual('TestClear');
});

it('changes the close text', function() {
expect(buttons.eq(2).text()).toEqual('TestDone');
});

it('hide the button bar', inject(function(datepickerPopupConfig) {
datepickerPopupConfig.showButtonBar = false;
wrapElement = $compile('<div><input ng-model="date" datepicker-popup></div>')($rootScope);
$rootScope.$digest();
assignElements(wrapElement);

expect(buttonBarEl.length).toBe(0);
}));

it('changes on date selection behaviour', inject(function(datepickerPopupConfig) {
inputEl.focus();
clickOption(30);
expect(dropdownEl).toBeHidden();

datepickerPopupConfig.closeOnDateSelection = false;
wrapElement = $compile('<div><input ng-model="date" datepicker-popup></div>')($rootScope);
$rootScope.$digest();
assignElements(wrapElement);

inputEl.focus();
clickOption(30);
expect(dropdownEl).not.toBeHidden();
}));

});

describe('as popup', function () {
var inputEl, dropdownEl, changeInputValueTo, $document;

Expand Down
2 changes: 1 addition & 1 deletion template/datepicker/popup.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ul class="dropdown-menu" ng-style="{display: (isOpen && 'block') || 'none', top: position.top+'px', left: position.left+'px'}">
<li ng-transclude></li>
<li ng-if="showButtonBar" style="padding:10px 9px 2px">
<li ng-if="showButtonBar" class="button-bar" style="padding:10px 9px 2px">
<span class="btn-group">
<button type="button" class="btn btn-sm btn-info" ng-click="select('today')">{{ getText('current') }}</button>
<button type="button" class="btn btn-sm btn-danger" ng-click="select(null)">{{ getText('clear') }}</button>
Expand Down