Skip to content

Commit

Permalink
test(datepicker): refactorize some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Foxandxss committed Jan 24, 2016
1 parent 97af6a9 commit 096e171
Showing 1 changed file with 24 additions and 48 deletions.
72 changes: 24 additions & 48 deletions src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -994,15 +994,10 @@ describe('datepicker', function() {
expect(angular.element(button).prop('disabled')).toBe(false);
});
});
});

describe('`min-date` attribute', function () {
beforeEach(function() {
it('accepts literals, \'yyyy-MM-dd\' case', function() {
element = $compile('<uib-datepicker ng-model="date" min-date="\'2010-09-05\'"></uib-datepicker>')($rootScope);
$rootScope.$digest();
});

it('accepts literals, \'yyyy-MM-dd\' case', function() {
var buttons = getAllOptionsEl();
angular.forEach(buttons, function(button, index) {
expect(angular.element(button).prop('disabled')).toBe(index < 7);
Expand Down Expand Up @@ -2650,25 +2645,6 @@ describe('datepicker', function() {
});
});

describe('attribute `initDate`', function() {
var weekHeader, weekElement;
beforeEach(function() {
$rootScope.date = null;
$rootScope.initDate = new Date('November 9, 1980');
var wrapElement = $compile('<div><input ng-model="date" uib-datepicker-popup init-date="initDate" is-open="true"></div>')($rootScope);
$rootScope.$digest();
assignElements(wrapElement);
});

it('should not alter the model', function() {
expect($rootScope.date).toBe(null);
});

it('shows the correct title', function() {
expect(getTitle()).toBe('November 1980');
});
});

describe('attribute `onOpenFocus`', function() {
beforeEach(function() {
$rootScope.date = null;
Expand Down Expand Up @@ -2822,6 +2798,29 @@ describe('datepicker', function() {
expect(dropdownEl.find('div').attr('date-disabled')).toBe('dateDisabled({ date: date, mode: mode })');
});
});

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('<div><input ng-model="date" uib-datepicker-popup min-date="minDate" max-date="maxDate" min-mode="minMode" max-mode="maxMode" init-date="initDate"></uib-datepicker>')($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() {
Expand Down Expand Up @@ -2958,29 +2957,6 @@ describe('datepicker', function() {
});
});

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('<div><input ng-model="date" uib-datepicker-popup min-date="minDate" max-date="maxDate" min-mode="minMode" max-mode="maxMode" init-date="initDate"></uib-datepicker>')($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('with empty initial state', function() {
beforeEach(inject(function() {
$rootScope.date = null;
Expand Down

0 comments on commit 096e171

Please sign in to comment.