Skip to content

Commit 2e62269

Browse files
committed
Fixing tests / datepicker
1 parent c205739 commit 2e62269

File tree

5 files changed

+22
-59
lines changed

5 files changed

+22
-59
lines changed
Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import Ember from 'ember';
2+
import jquiWidget from 'ember-cli-jquery-ui/mixins/jqui-widget';
23

3-
var OPTIONS = ["altField", "altFormat", "appendText", "autoSize",
4+
export default Ember.TextField.extend(jquiWidget, {
5+
uiType: 'datepicker',
6+
uiOptions: ["altField", "altFormat", "appendText", "autoSize",
47
"beforeShow", "beforeShowDay", "buttonImage", "buttonImageOnly",
58
"buttonText", "calculateWeek", "changeMonth", "changeYear", "closeText",
69
"constrainInput", "currentText", "dateFormat", "dayNames", "dayNamesMin",
@@ -11,55 +14,6 @@ var OPTIONS = ["altField", "altFormat", "appendText", "autoSize",
1114
"selectOtherMonths", "shortYearCutoff", "showAnim", "showButtonPanel",
1215
"showCurrentAtPos", "showMonthAfterYear", "showOn", "showOptions",
1316
"showOtherMonths", "showWeek", "stepMonths", "weekHeader", "yearRange",
14-
"yearSuffix"];
15-
16-
var EVENTS = ['onChangeMonthYear', 'onClose', 'onSelect'];
17-
18-
function sendAction(context, actionName) {
19-
return function() {
20-
var args = [].slice.call(arguments);
21-
context.send.apply(context, [actionName].concat(args));
22-
};
23-
}
24-
25-
var DatePickerComponent = Ember.TextField.extend({
26-
initDatePicker: function() {
27-
var _this = this;
28-
Ember.run.schedule('afterRender', function() {
29-
var properties = _this.getProperties.apply(_this, OPTIONS);
30-
_this.proxyDatepickerEvents(properties);
31-
_this.$().datepicker(properties);
32-
});
33-
}.on('didInsertElement'),
34-
35-
proxyDatepickerEvents: function(properties) {
36-
var component = this;
37-
var event;
38-
for (var i = 0, l = EVENTS.length; i < l; i++) {
39-
event = EVENTS[i];
40-
properties[event] = sendAction(component, event);
41-
}
42-
},
43-
44-
actions: {
45-
onSelect: function() {
46-
this.set('value', this.$().val());
47-
},
48-
onClose: Ember.K,
49-
onChangeMonthYear: Ember.K
50-
},
51-
52-
destroyDatepicker: function() {
53-
this.method('destroy');
54-
}.on('willDestroyElement'),
55-
56-
method: function(method) {
57-
return this.$().datepicker(method);
58-
}
17+
"yearSuffix"],
18+
uiEvents: ['onChangeMonthYear', 'onClose', 'onSelect']
5919
});
60-
61-
DatePickerComponent.reopenClass({
62-
OPTIONS: OPTIONS
63-
});
64-
65-
export default DatePickerComponent;

addon/mixins/jqui-widget.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,18 @@ export default Ember.Mixin.create({
1616
// Make sure that jQuery UI events trigger methods on this view.
1717
_this._gatherEvents(options);
1818

19-
// Create a new instance of the jQuery UI widget based on its `uiType`
20-
// and the current element.
21-
var ui = Ember.$.ui[_this.get('uiType')](options, _this.get('element'));
19+
// Workaround for bug in jQuery UI datepicker
20+
var ui;
21+
var uiType = _this.get('uiType');
22+
if ((typeof Ember.$.ui[uiType] !== "function") && uiType === "datepicker") {
23+
_this.$().datepicker();
24+
ui = _this.$(uiType)['widget'];
25+
} else {
26+
27+
// Create a new instance of the jQuery UI widget based on its `uiType`
28+
// and the current element.
29+
ui = Ember.$.ui[_this.get('uiType')](options, _this.get('element'));
30+
}
2231

2332
// Save off the instance of the jQuery UI widget as the `ui` property
2433
// on this Ember view.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
normalizeEntityName: function() {},
33
afterInstall: function() {
4-
return this.addBowerPackageToProject('jquery-ui');
4+
return this.addBowerPackageToProject('jquery-ui#1.11.1');
55
}
6-
};
6+
};

tests/unit/components/jqui-autocomplete-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ test('it renders', function() {
1616
equal(component._state, 'preRender');
1717

1818
// appends the component to the page
19-
this.append();
19+
this.render();
2020
equal(component._state, 'inDOM');
2121
});

tests/unit/components/jqui-datepicker-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ test('it renders', function() {
1717
equal(component._state, 'preRender');
1818

1919
// appends the component to the page
20-
this.append();
20+
this.render();
2121
equal(component._state, 'inDOM');
2222
});

0 commit comments

Comments
 (0)