')($rootScope);
- $rootScope.$digest();
- assignElements(wrapElement);
- assignButtonBar();
- }));
+ 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);
+ }
+ });
- it('should exist', function() {
- expect(dropdownEl.length).toBe(1);
- expect(dropdownEl.find('li').length).toBe(2);
+ it('should show weeks column on popup', function() {
+ var wrapElement = $compile('
')($rootScope);
+ $rootScope.$digest();
+ assignElements(wrapElement);
+
+ expect(getLabelsRow().find('th').eq(0)).not.toBeHidden();
+ var tr = element.find('tbody').find('tr');
+ for (var i = 0; i < 5; i++) {
+ expect(tr.eq(i).find('td').eq(0)).not.toBeHidden();
+ }
+ });
});
- it('should have three buttons', function() {
- expect(buttons.length).toBe(3);
+ describe('`ng-change`', function() {
+ beforeEach(inject(function() {
+ $rootScope.changeHandler = jasmine.createSpy('changeHandler');
+ var wrapElement = $compile('
')($rootScope);
+ $rootScope.$digest();
+ assignElements(wrapElement);
+ assignButtonBar();
+ }));
- expect(buttons.eq(0).text()).toBe('Today');
- expect(buttons.eq(1).text()).toBe('Clear');
- expect(buttons.eq(2).text()).toBe('Done');
- });
+ it('should be called when `today` is clicked', function() {
+ buttons.eq(0).click();
+ expect($rootScope.changeHandler).toHaveBeenCalled();
+ });
- it('should have a button to set today date without altering time part', function() {
- var today = new Date();
- buttons.eq(0).click();
- expect($rootScope.date.getFullYear()).toBe(today.getFullYear());
- expect($rootScope.date.getMonth()).toBe(today.getMonth());
- expect($rootScope.date.getDate()).toBe(today.getDate());
+ it('should be called when `clear` is clicked', function() {
+ buttons.eq(1).click();
+ expect($rootScope.changeHandler).toHaveBeenCalled();
+ });
- expect($rootScope.date.getHours()).toBe(15);
- expect($rootScope.date.getMinutes()).toBe(30);
- expect($rootScope.date.getSeconds()).toBe(0);
+ it('should not be called when `close` is clicked', function() {
+ buttons.eq(2).click();
+ expect($rootScope.changeHandler).not.toHaveBeenCalled();
+ });
});
+ });
- it('should have a button to set today date if blank', function() {
- $rootScope.date = null;
- $rootScope.$digest();
+ describe('use with `ng-required` directive', function() {
+ describe('`ng-required is true`', function() {
+ beforeEach(inject(function() {
+ $rootScope.date = '';
+ var wrapElement = $compile('
')($rootScope);
+ $rootScope.$digest();
+ assignElements(wrapElement);
+ }));
- var today = new Date();
- buttons.eq(0).click();
- expect($rootScope.date.getFullYear()).toBe(today.getFullYear());
- expect($rootScope.date.getMonth()).toBe(today.getMonth());
- expect($rootScope.date.getDate()).toBe(today.getDate());
+ it('should be invalid initially and when no date', function() {
+ expect(inputEl.hasClass('ng-invalid')).toBeTruthy();
+ });
- expect($rootScope.date.getHours()).toBe(0);
- expect($rootScope.date.getMinutes()).toBe(0);
- expect($rootScope.date.getSeconds()).toBe(0);
- });
+ it('should be valid if model has been specified', function() {
+ $rootScope.date = new Date();
+ $rootScope.$digest();
+ expect(inputEl.hasClass('ng-valid')).toBeTruthy();
+ });
- it('should have a button to clear value', function() {
- buttons.eq(1).click();
- expect($rootScope.date).toBe(null);
+ it('should be valid if model value is a valid timestamp', function() {
+ $rootScope.date = Date.now();
+ $rootScope.$digest();
+ expect(inputEl.hasClass('ng-valid')).toBeTruthy();
+ });
});
+ describe('`ng-required is false`', function() {
+ beforeEach(inject(function() {
+ $rootScope.date = '';
+ var wrapElement = $compile('
')($rootScope);
+ $rootScope.$digest();
+ assignElements(wrapElement);
+ }));
- it('should have a button to close calendar', function() {
- buttons.eq(2).click();
- assignElements(wrapElement);
- expect(dropdownEl.length).toBe(0);
+ it('should be valid initially and when no date', function() {
+ expect(inputEl.hasClass('ng-valid')).toBeTruthy();
+ });
});
});
- describe('customization', function() {
- it('should change text from attributes', function() {
- $rootScope.clearText = 'Null it!';
- $rootScope.close = 'Close';
- var wrapElement = $compile('
')($rootScope);
+ describe('use with `ng-change` directive', function() {
+ beforeEach(inject(function() {
+ $rootScope.changeHandler = jasmine.createSpy('changeHandler');
+ $rootScope.date = new Date('09/16/2010');
+ var wrapElement = $compile('
')($rootScope);
$rootScope.$digest();
assignElements(wrapElement);
- assignButtonBar();
+ }));
- expect(buttons.eq(0).text()).toBe('Now');
- expect(buttons.eq(1).text()).toBe('Null it!');
- expect(buttons.eq(2).text()).toBe('CloseME');
+ it('should not be called initially', function() {
+ expect($rootScope.changeHandler).not.toHaveBeenCalled();
+ });
+
+ it('should be called when a day is clicked', function() {
+ clickOption(17);
+ expect($rootScope.changeHandler).toHaveBeenCalled();
});
- it('should remove bar', function() {
- $rootScope.showBar = false;
- var wrapElement = $compile('
')($rootScope);
+ it('should not be called when model changes programatically', function() {
+ $rootScope.date = new Date();
$rootScope.$digest();
- assignElements(wrapElement);
- expect(dropdownEl.find('li').length).toBe(1);
+ expect($rootScope.changeHandler).not.toHaveBeenCalled();
+ });
+ });
+
+ describe('with an append-to-body attribute', function() {
+ beforeEach(function() {
+ $rootScope.date = new Date();
});
- it('should hide weeks column on popup', function() {
- var wrapElement = $compile('
')($rootScope);
+ afterEach(function () {
+ $document.find('body').find('.dropdown-menu').remove();
+ });
+
+ it('should append to the body', function() {
+ var $body = $document.find('body'),
+ bodyLength = $body.children().length,
+ elm = angular.element(
+ ''
+ );
+ $compile(elm)($rootScope);
$rootScope.$digest();
- assignElements(wrapElement);
- 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);
- }
+ expect($body.children().length).toEqual(bodyLength + 1);
+ expect(elm.children().length).toEqual(1);
});
+ it('should be removed on scope destroy', function() {
+ var $body = $document.find('body'),
+ bodyLength = $body.children().length,
+ isolatedScope = $rootScope.$new(),
+ elm = angular.element(
+ ''
+ );
+ $compile(elm)(isolatedScope);
+ isolatedScope.$digest();
+ expect($body.children().length).toEqual(bodyLength + 1);
+ isolatedScope.$destroy();
+ expect($body.children().length).toEqual(bodyLength);
+ });
+ });
- it('should show weeks column on popup', function() {
- var wrapElement = $compile('
')($rootScope);
+ 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);
+ }));
- expect(getLabelsRow().find('th').eq(0)).not.toBeHidden();
+ it('changes initial visibility for weeks', 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').eq(0)).not.toBeHidden();
+ expect(tr.eq(i).find('td').length).toEqual(7);
}
});
});
- describe('`ng-change`', function() {
+ describe('`datepicker-mode`', function () {
beforeEach(inject(function() {
- $rootScope.changeHandler = jasmine.createSpy('changeHandler');
- var wrapElement = $compile('
')($rootScope);
+ $rootScope.date = new Date('August 11, 2013');
+ $rootScope.mode = 'month';
+ var wrapElement = $compile('')($rootScope);
$rootScope.$digest();
assignElements(wrapElement);
- assignButtonBar();
}));
- it('should be called when `today` is clicked', function() {
- buttons.eq(0).click();
- expect($rootScope.changeHandler).toHaveBeenCalled();
- });
-
- it('should be called when `clear` is clicked', function() {
- buttons.eq(1).click();
- expect($rootScope.changeHandler).toHaveBeenCalled();
+ it('shows the correct title', function() {
+ expect(getTitle()).toBe('2013');
});
- it('should not be called when `close` is clicked', function() {
- buttons.eq(2).click();
- expect($rootScope.changeHandler).not.toHaveBeenCalled();
+ it('updates binding', function() {
+ clickTitleButton();
+ expect($rootScope.mode).toBe('year');
});
});
- });
- describe('use with `ng-required` directive', function() {
- describe('`ng-required is true`', function() {
- beforeEach(inject(function() {
- $rootScope.date = '';
- var wrapElement = $compile('
')($rootScope);
+ describe('attribute `initDate`', function () {
+ var weekHeader, weekElement;
+ beforeEach(function() {
+ $rootScope.date = null;
+ $rootScope.initDate = new Date('November 9, 1980');
+ var wrapElement = $compile('')($rootScope);
$rootScope.$digest();
assignElements(wrapElement);
- }));
-
- it('should be invalid initially and when no date', function() {
- expect(inputEl.hasClass('ng-invalid')).toBeTruthy();
- });
-
- it('should be valid if model has been specified', function() {
- $rootScope.date = new Date();
- $rootScope.$digest();
- expect(inputEl.hasClass('ng-valid')).toBeTruthy();
});
- it('should be valid if model value is a valid timestamp', function() {
- $rootScope.date = Date.now();
- $rootScope.$digest();
- expect(inputEl.hasClass('ng-valid')).toBeTruthy();
+ it('should not alter the model', function() {
+ expect($rootScope.date).toBe(null);
});
- });
- describe('`ng-required is false`', function() {
- beforeEach(inject(function() {
- $rootScope.date = '';
- var wrapElement = $compile('
')($rootScope);
- $rootScope.$digest();
- assignElements(wrapElement);
- }));
- it('should be valid initially and when no date', function() {
- expect(inputEl.hasClass('ng-valid')).toBeTruthy();
+ it('shows the correct title', function() {
+ expect(getTitle()).toBe('November 1980');
});
});
});
- describe('use with `ng-change` directive', function() {
+ describe('with empty initial state', function () {
beforeEach(inject(function() {
- $rootScope.changeHandler = jasmine.createSpy('changeHandler');
- $rootScope.date = new Date('09/16/2010');
- var wrapElement = $compile('
')($rootScope);
+ $rootScope.date = null;
+ element = $compile('')($rootScope);
$rootScope.$digest();
- assignElements(wrapElement);
}));
- it('should not be called initially', function() {
- expect($rootScope.changeHandler).not.toHaveBeenCalled();
+ it('is has a `
` element', function() {
+ expect(element.find('table').length).toBe(1);
});
- it('should be called when a day is clicked', function() {
- clickOption(17);
- expect($rootScope.changeHandler).toHaveBeenCalled();
+ it('is shows rows with days', function() {
+ expect(element.find('tbody').find('tr').length).toBeGreaterThan(3);
});
- it('should not be called when model changes programatically', function() {
- $rootScope.date = new Date();
+ it('sets default 00:00:00 time for selected date', function() {
+ $rootScope.date = new Date('August 1, 2013');
$rootScope.$digest();
- expect($rootScope.changeHandler).not.toHaveBeenCalled();
- });
- });
-
- describe('with an append-to-body attribute', function() {
- beforeEach(function() {
- $rootScope.date = new Date();
- });
-
- afterEach(function () {
- $document.find('body').find('.dropdown-menu').remove();
- });
-
- it('should append to the body', function() {
- var $body = $document.find('body'),
- bodyLength = $body.children().length,
- elm = angular.element(
- ''
- );
- $compile(elm)($rootScope);
+ $rootScope.date = null;
$rootScope.$digest();
- expect($body.children().length).toEqual(bodyLength + 1);
- expect(elm.children().length).toEqual(1);
- });
- it('should be removed on scope destroy', function() {
- var $body = $document.find('body'),
- bodyLength = $body.children().length,
- isolatedScope = $rootScope.$new(),
- elm = angular.element(
- ''
- );
- $compile(elm)(isolatedScope);
- isolatedScope.$digest();
- expect($body.children().length).toEqual(bodyLength + 1);
- isolatedScope.$destroy();
- expect($body.children().length).toEqual(bodyLength);
+ clickOption(14);
+ expect($rootScope.date).toEqual(new Date('August 11, 2013 00:00:00'));
});
});
- 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);
+ describe('`init-date`', function () {
+ beforeEach(inject(function() {
+ $rootScope.date = null;
+ $rootScope.initDate = new Date('November 9, 1980');
+ element = $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').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);
- }
+ it('does not alter the model', function() {
+ expect($rootScope.date).toBe(null);
+ });
+
+ it('shows the correct title', function() {
+ expect(getTitle()).toBe('November 1980');
});
});
@@ -2003,9 +2153,8 @@ describe('datepicker directive', function () {
beforeEach(inject(function() {
$rootScope.date = new Date('August 11, 2013');
$rootScope.mode = 'month';
- var wrapElement = $compile('')($rootScope);
+ element = $compile('')($rootScope);
$rootScope.$digest();
- assignElements(wrapElement);
}));
it('shows the correct title', function() {
@@ -2018,219 +2167,139 @@ describe('datepicker directive', function () {
});
});
- describe('attribute `initDate`', function () {
- var weekHeader, weekElement;
- beforeEach(function() {
- $rootScope.date = null;
- $rootScope.initDate = new Date('November 9, 1980');
- var wrapElement = $compile('')($rootScope);
+ describe('`min-mode`', function () {
+ beforeEach(inject(function() {
+ $rootScope.date = new Date('August 11, 2013');
+ $rootScope.mode = 'month';
+ element = $compile('')($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');
+ it('does not move below it', function() {
+ expect(getTitle()).toBe('2013');
+ clickOption( 5 );
+ expect(getTitle()).toBe('2013');
+ clickTitleButton();
+ expect(getTitle()).toBe('2001 - 2020');
});
});
- });
-
- describe('with empty initial state', function () {
- beforeEach(inject(function() {
- $rootScope.date = null;
- element = $compile('')($rootScope);
- $rootScope.$digest();
- }));
-
- it('is has a `
` element', function() {
- expect(element.find('table').length).toBe(1);
- });
-
- it('is shows rows with days', function() {
- expect(element.find('tbody').find('tr').length).toBeGreaterThan(3);
- });
-
- it('sets default 00:00:00 time for selected date', function() {
- $rootScope.date = new Date('August 1, 2013');
- $rootScope.$digest();
- $rootScope.date = null;
- $rootScope.$digest();
-
- clickOption(14);
- expect($rootScope.date).toEqual(new Date('August 11, 2013 00:00:00'));
- });
- });
-
- describe('`init-date`', function () {
- beforeEach(inject(function() {
- $rootScope.date = null;
- $rootScope.initDate = new Date('November 9, 1980');
- element = $compile('')($rootScope);
- $rootScope.$digest();
- }));
-
- it('does not alter the model', function() {
- expect($rootScope.date).toBe(null);
- });
-
- it('shows the correct title', function() {
- expect(getTitle()).toBe('November 1980');
- });
- });
-
- describe('`datepicker-mode`', function () {
- beforeEach(inject(function() {
- $rootScope.date = new Date('August 11, 2013');
- $rootScope.mode = 'month';
- element = $compile('')($rootScope);
- $rootScope.$digest();
- }));
-
- it('shows the correct title', function() {
- expect(getTitle()).toBe('2013');
- });
-
- it('updates binding', function() {
- clickTitleButton();
- expect($rootScope.mode).toBe('year');
- });
- });
-
- describe('`min-mode`', function () {
- beforeEach(inject(function() {
- $rootScope.date = new Date('August 11, 2013');
- $rootScope.mode = 'month';
- element = $compile('')($rootScope);
- $rootScope.$digest();
- }));
-
- it('does not move below it', function() {
- expect(getTitle()).toBe('2013');
- clickOption( 5 );
- expect(getTitle()).toBe('2013');
- clickTitleButton();
- expect(getTitle()).toBe('2001 - 2020');
- });
- });
- describe('`max-mode`', function () {
- beforeEach(inject(function() {
- $rootScope.date = new Date('August 11, 2013');
- element = $compile('')($rootScope);
- $rootScope.$digest();
- }));
+ describe('`max-mode`', function () {
+ beforeEach(inject(function() {
+ $rootScope.date = new Date('August 11, 2013');
+ element = $compile('')($rootScope);
+ $rootScope.$digest();
+ }));
- it('does not move above it', function() {
- expect(getTitle()).toBe('August 2013');
- clickTitleButton();
- expect(getTitle()).toBe('2013');
- clickTitleButton();
- expect(getTitle()).toBe('2013');
- });
+ it('does not move above it', function() {
+ expect(getTitle()).toBe('August 2013');
+ clickTitleButton();
+ expect(getTitle()).toBe('2013');
+ clickTitleButton();
+ expect(getTitle()).toBe('2013');
+ });
- it('disables the title button at it', function() {
- expect(getTitleButton().prop('disabled')).toBe(false);
- clickTitleButton();
- expect(getTitleButton().prop('disabled')).toBe(true);
- clickTitleButton();
- expect(getTitleButton().prop('disabled')).toBe(true);
+ it('disables the title button at it', function() {
+ expect(getTitleButton().prop('disabled')).toBe(false);
+ clickTitleButton();
+ expect(getTitleButton().prop('disabled')).toBe(true);
+ clickTitleButton();
+ expect(getTitleButton().prop('disabled')).toBe(true);
+ });
});
- });
- describe('with an ngModelController having formatters and parsers', function() {
- beforeEach(inject(function() {
- // Custom date object.
- $rootScope.date = { type: 'date', date: 'April 1, 2015 00:00:00' };
+ describe('with an ngModelController having formatters and parsers', function() {
+ beforeEach(inject(function() {
+ // Custom date object.
+ $rootScope.date = { type: 'date', date: 'April 1, 2015 00:00:00' };
- // Use dateModel directive to add formatters and parsers to the
- // ngModelController that translate the custom date object.
- element = $compile('')($rootScope);
- $rootScope.$digest();
- }));
+ // Use dateModel directive to add formatters and parsers to the
+ // ngModelController that translate the custom date object.
+ element = $compile('')($rootScope);
+ $rootScope.$digest();
+ }));
- it('updates the view', function() {
- $rootScope.date = { type: 'date', date: 'April 15, 2015 00:00:00' };
- $rootScope.$digest();
+ it('updates the view', function() {
+ $rootScope.date = { type: 'date', date: 'April 15, 2015 00:00:00' };
+ $rootScope.$digest();
- expectSelectedElement(17);
- });
+ expectSelectedElement(17);
+ });
- it('updates the model', function() {
- clickOption(17);
+ it('updates the model', function() {
+ clickOption(17);
- expect($rootScope.date.type).toEqual('date');
- expect(new Date($rootScope.date.date)).toEqual(new Date('April 15, 2015 00:00:00'));
+ expect($rootScope.date.type).toEqual('date');
+ expect(new Date($rootScope.date.date)).toEqual(new Date('April 15, 2015 00:00:00'));
+ });
});
- });
-
- describe('thurdays determine week count', function() {
-
- beforeEach(inject(function() {
- $rootScope.date = new Date('June 07, 2014');
- }));
- it('with the default starting day (sunday)', function() {
- element = $compile('')($rootScope);
- $rootScope.$digest();
+ describe('thurdays determine week count', function() {
- expect(getWeeks()).toEqual(['23', '24', '25', '26', '27', '28']);
- });
+ beforeEach(inject(function() {
+ $rootScope.date = new Date('June 07, 2014');
+ }));
- describe('when starting date', function() {
- it('is monday', function() {
- element = $compile('')($rootScope);
+ it('with the default starting day (sunday)', function() {
+ element = $compile('')($rootScope);
$rootScope.$digest();
- expect(getWeeks()).toEqual(['22', '23', '24', '25', '26', '27']);
+ expect(getWeeks()).toEqual(['23', '24', '25', '26', '27', '28']);
});
- it('is thursday', function() {
- element = $compile('')($rootScope);
- $rootScope.$digest();
+ describe('when starting date', function() {
+ it('is monday', function() {
+ element = $compile('')($rootScope);
+ $rootScope.$digest();
- expect(getWeeks()).toEqual(['22', '23', '24', '25', '26', '27']);
- });
+ expect(getWeeks()).toEqual(['22', '23', '24', '25', '26', '27']);
+ });
- it('is saturday', function() {
- element = $compile('')($rootScope);
- $rootScope.$digest();
+ it('is thursday', function() {
+ element = $compile('')($rootScope);
+ $rootScope.$digest();
- expect(getWeeks()).toEqual(['23', '24', '25', '26', '27', '28']);
- });
- });
+ expect(getWeeks()).toEqual(['22', '23', '24', '25', '26', '27']);
+ });
- describe('first week in january', function() {
- it('in current year', function() {
- $rootScope.date = new Date('January 07, 2014');
- element = $compile('')($rootScope);
- $rootScope.$digest();
+ it('is saturday', function() {
+ element = $compile('')($rootScope);
+ $rootScope.$digest();
- expect(getWeeks()).toEqual(['1', '2', '3', '4', '5', '6']);
+ expect(getWeeks()).toEqual(['23', '24', '25', '26', '27', '28']);
+ });
});
- it('in last year', function() {
- $rootScope.date = new Date('January 07, 2010');
- element = $compile('')($rootScope);
- $rootScope.$digest();
+ describe('first week in january', function() {
+ it('in current year', function() {
+ $rootScope.date = new Date('January 07, 2014');
+ element = $compile('')($rootScope);
+ $rootScope.$digest();
+
+ expect(getWeeks()).toEqual(['1', '2', '3', '4', '5', '6']);
+ });
- expect(getWeeks()).toEqual(['53', '1', '2', '3', '4', '5']);
+ it('in last year', function() {
+ $rootScope.date = new Date('January 07, 2010');
+ element = $compile('')($rootScope);
+ $rootScope.$digest();
+
+ expect(getWeeks()).toEqual(['53', '1', '2', '3', '4', '5']);
+ });
});
- });
- describe('last week(s) in december', function() {
- beforeEach(inject(function() {
- $rootScope.date = new Date('December 07, 2014');
- }));
+ describe('last week(s) in december', function() {
+ beforeEach(inject(function() {
+ $rootScope.date = new Date('December 07, 2014');
+ }));
- it('in next year', function() {
- element = $compile('')($rootScope);
- $rootScope.$digest();
+ it('in next year', function() {
+ element = $compile('')($rootScope);
+ $rootScope.$digest();
- expect(getWeeks()).toEqual(['49', '50', '51', '52', '1', '2']);
- });
+ expect(getWeeks()).toEqual(['49', '50', '51', '52', '1', '2']);
+ });
+ });
});
});
});