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

Commit

Permalink
fix(tests): Attempted to fix most tests and added new angular-module …
Browse files Browse the repository at this point in the history
…component
  • Loading branch information
Dean Sofer committed Mar 13, 2013
1 parent 8581ede commit b4d243d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
components/
3 changes: 2 additions & 1 deletion component.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dependencies": {
"angular": "~1.x",
"jquery": ">= 1.6",
"jquery-ui": ">= 1.9"
"jquery-ui": ">= 1.9",
"angular-module": "latest"
}
}
14 changes: 7 additions & 7 deletions date.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
jQuery UI Datepicker plugin wrapper
@note If ≤ IE8 make sure you have a polyfill for Date.toISOString()
@param [ui-date] {object} Options to pass to $.fn.datepicker() merged onto ui.config
@param [ui-date] {object} Options to pass to $.fn.datepicker() merged onto uiDateConfig
*/

angular.module('ui.date', [])
Expand All @@ -14,14 +14,12 @@ angular.module('ui.date', [])
'use strict';
var options;
options = {};
if (angular.isObject(uiDateConfig.date)) {
angular.extend(options, uiDateConfig.date);
}
angular.extend(options, uiDateConfig);
return {
require:'?ngModel',
link:function (scope, element, attrs, controller) {
var getOptions = function () {
return angular.extend({}, uiDateConfig.date, scope.$eval(attrs.uiDate));
return angular.extend({}, uiDateConfig, scope.$eval(attrs.uiDate));
};
var initDateWidget = function () {
var opts = getOptions();
Expand Down Expand Up @@ -77,11 +75,13 @@ angular.module('ui.date', [])
}
])

.directive('uiDateFormat', ['ui.config', function(uiDateConfig) {
.constant('uiDateFormatConfig', '')

.directive('uiDateFormat', ['uiDateFormatConfig', function(uiDateFormatConfig) {
var directive = {
require:'ngModel',
link: function(scope, element, attrs, modelCtrl) {
var dateFormat = attrs.uiDateFormat || uiDateConfig.dateFormat;
var dateFormat = attrs.uiDateFormat || uiDateFormatConfig;
if ( dateFormat ) {
// Use the datepicker with the attribute value as the dateFormat string to convert to and from a string
modelCtrl.$formatters.push(function(value) {
Expand Down
5 changes: 0 additions & 5 deletions dependencies.json

This file was deleted.

13 changes: 7 additions & 6 deletions test/dateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('uiDate', function() {
element.datepicker('setDate', date);
$.datepicker._selectDate(element);
};
beforeEach(module('ui.directives'));
beforeEach(module('ui.date'));
describe('simple use on input element', function() {
it('should have a date picker attached', function() {
inject(function($compile, $rootScope) {
Expand Down Expand Up @@ -250,7 +250,7 @@ describe('uiDate', function() {
});

describe('uiDateFormat', function() {
beforeEach(module('ui.directives'));
beforeEach(module('ui.date'));

describe('$formatting', function() {
it('should parse the date correctly from an ISO string', function() {
Expand Down Expand Up @@ -345,14 +345,15 @@ describe('uiDateFormat', function() {
});
});

describe('with uiConfig', function() {
describe('with uiDateConfig', function() {
var element, scope, config;
var format = 'DD, d MM, yy';
var aDate = new Date(2012,9,11);
var aDateString = "Thursday, 11 October, 2012";
var aISODateString = aDate.toISOString();
beforeEach(inject(['$compile', '$rootScope', 'ui.config', function($compile, $rootScope, uiConfig) {
config = uiConfig;
beforeEach(inject(['$compile', '$rootScope', 'uiDateConfig', 'uiDateFormatConfig', function($compile, $rootScope, uiDateConfig, uiDateFormatConfig) {
config = uiDateConfig;
formatConfig = uiDateFormatConfig;
element = $compile('<input ui-date-format ng-model="x"/>')($rootScope);
scope = $rootScope;
}]));
Expand All @@ -363,7 +364,7 @@ describe('uiDateFormat', function() {
expect(element.controller('ngModel').$viewValue).toEqual(aDate);
});
it('use format value if config given', function() {
config.dateFormat = format;
formatConfig = format;
scope.x = aDateString;
scope.$digest();
expect(element.controller('ngModel').$viewValue).toEqual(aDate);
Expand Down

0 comments on commit b4d243d

Please sign in to comment.