appetizer-ui 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. data/.gitignore +1 -0
  2. data/appetizer-ui.gemspec +1 -1
  3. data/lib/appetizer/ui/jasmine/js/backbone.modelbinding/appetizerExtensions.spec.js +54 -0
  4. data/lib/appetizer/ui/jasmine/js/backbone.modelbinding/checkboxConventionBindings.spec.js +110 -0
  5. data/lib/appetizer/ui/jasmine/js/backbone.modelbinding/configurableBindingAttributes.spec.js +117 -0
  6. data/lib/appetizer/ui/jasmine/js/backbone.modelbinding/configureAllBindingAttributes.spec.js +139 -0
  7. data/lib/appetizer/ui/jasmine/js/backbone.modelbinding/customConvention.spec.js +53 -0
  8. data/lib/appetizer/ui/jasmine/js/backbone.modelbinding/dataBindConvention.spec.js +151 -0
  9. data/lib/appetizer/ui/jasmine/js/backbone.modelbinding/dataBindMultiple.spec.js +36 -0
  10. data/lib/appetizer/ui/jasmine/js/backbone.modelbinding/dataBindSubstitutions.spec.js +137 -0
  11. data/lib/appetizer/ui/jasmine/js/backbone.modelbinding/globalConfiguraAllBindingAttributes.spec.js +124 -0
  12. data/lib/appetizer/ui/jasmine/js/backbone.modelbinding/globalConfigurableBindingAttributes.spec.js +36 -0
  13. data/lib/appetizer/ui/jasmine/js/backbone.modelbinding/helpers/SpecHelper.js +4 -0
  14. data/lib/appetizer/ui/jasmine/js/backbone.modelbinding/helpers/sample.backbone.app.js +159 -0
  15. data/lib/appetizer/ui/jasmine/js/backbone.modelbinding/html5inputConventionBinding.spec.js +142 -0
  16. data/lib/appetizer/ui/jasmine/js/backbone.modelbinding/modelUnbinding.spec.js +73 -0
  17. data/lib/appetizer/ui/jasmine/js/backbone.modelbinding/noConflict.spec.js +36 -0
  18. data/lib/appetizer/ui/jasmine/js/backbone.modelbinding/radioButtonConventionBinding.spec.js +41 -0
  19. data/lib/appetizer/ui/jasmine/js/backbone.modelbinding/selectboxConventionBindings.spec.js +60 -0
  20. data/lib/appetizer/ui/jasmine/js/backbone.modelbinding/textareaConventionBinding.spec.js +29 -0
  21. data/lib/appetizer/ui/jasmine/js/backbone.modelbinding/textboxConventionBinding.spec.js +66 -0
  22. data/lib/appetizer/ui/jasmine/js/jasmine-jquery-matchers.js +1 -1
  23. data/lib/appetizer/ui/jasmine/js/spec-runner.coffee +1 -0
  24. data/lib/appetizer/ui/vendor/js/backbone.modelbinding.js +68 -10
  25. metadata +45 -26
@@ -0,0 +1,151 @@
1
+ describe("data-bind conventions", function(){
2
+ beforeEach(function(){
3
+ this.model = new AModel({
4
+ villain: "mrMonster",
5
+ doctor: "Seuss",
6
+ pet: "cat",
7
+ isValid: false
8
+ });
9
+ this.view = new AView({model: this.model});
10
+ });
11
+
12
+ describe("when data-bind is configured for an event and the event is triggered", function(){
13
+ beforeEach(function(){
14
+ this.view.render();
15
+ this.el = this.view.$("#eventDiv");
16
+ this.model.trigger("foo", "bar");
17
+ });
18
+
19
+ it("should update the element with the event's value", function(){
20
+ expect(this.el.text()).toBe("bar");
21
+ });
22
+ });
23
+
24
+ describe("when a data-bind is configured with no html element attribute specified", function(){
25
+ beforeEach(function(){
26
+ this.view.render();
27
+ this.el = this.view.$("#doctor_no_elem");
28
+ });
29
+
30
+ it("should set the element's text to the model's property value immediately", function(){
31
+ expect(this.el.text()).toBe("Seuss");
32
+ });
33
+
34
+ it("should set the text of the element when the model's property changes", function(){
35
+ this.model.set({doctor: "Who"});
36
+ expect(this.el.text()).toBe("Who");
37
+ });
38
+ });
39
+
40
+ describe("when a data-bind is configured to set text", function(){
41
+ beforeEach(function(){
42
+ this.view.render();
43
+ this.el = this.view.$("#doctor");
44
+ });
45
+
46
+ it("should set the element's text to the model's property value immediately", function(){
47
+ expect(this.el.text()).toBe("Seuss");
48
+ });
49
+
50
+ it("should set the text of the element when the model's property changes", function(){
51
+ this.model.set({doctor: "Who"});
52
+ expect(this.el.text()).toBe("Who");
53
+ });
54
+ });
55
+
56
+ describe("when a data-bind is configured to set html", function(){
57
+ beforeEach(function(){
58
+ this.view.render();
59
+ this.el = this.view.$("#villain");
60
+ });
61
+
62
+ it("should set the element's contents to the model's property value immediately", function(){
63
+ expect(this.el.html()).toBe("mrMonster");
64
+ });
65
+
66
+ it("should replace the contents of the element when the model's property changes", function(){
67
+ this.model.set({villain: "boogerFace"});
68
+ expect(this.el.html()).toBe("boogerFace");
69
+ });
70
+ });
71
+
72
+ describe("when a data-bind is configured to set enabled", function(){
73
+ beforeEach(function(){
74
+ this.view.render();
75
+ this.el = this.view.$("#clicker");
76
+ });
77
+
78
+ it("should set the element's disabled value to the model's value, immediately", function(){
79
+ expect(this.el.attr("disabled")).toBeTruthy();
80
+ });
81
+
82
+ it("should set the element's disabled value when the model's value is changed", function(){
83
+ this.model.set({isValid: true});
84
+ expect(this.el.attr("disabled")).toBeFalsy();
85
+ });
86
+ });
87
+
88
+ describe("when a data-bind is configured to set disabled", function(){
89
+ beforeEach(function(){
90
+ this.view.render();
91
+ this.el = this.view.$("#unclicker");
92
+ });
93
+
94
+ it("should set the element's disabled value to the model's value, immediately", function(){
95
+ expect(this.el.attr("disabled")).toBeFalsy();
96
+ });
97
+
98
+ it("should set the element's disabled value when the model's value is changed", function(){
99
+ this.model.set({isValid: true});
100
+ expect(this.el.attr("disabled")).toBeTruthy();
101
+ });
102
+ });
103
+
104
+ describe("when a data-bind is configured to set an arbitrary attribute", function(){
105
+ beforeEach(function(){
106
+ this.view.render();
107
+ this.el = this.view.$("#pet");
108
+ });
109
+
110
+ it("should set the element's attribute to the model's property value immediately", function(){
111
+ expect(this.el.attr("someAttr")).toBe("cat");
112
+ });
113
+
114
+ it("should set the value of the attribute", function(){
115
+ this.model.set({pet: "bunnies"});
116
+ expect(this.el.attr("someAttr")).toBe("bunnies");
117
+ });
118
+ });
119
+
120
+ describe("when a data-bind is configured to set displayed", function(){
121
+ beforeEach(function(){
122
+ this.view.render();
123
+ this.el = $(this.view.el).find("#showHideThing");
124
+ });
125
+
126
+ it("should set the element's disabled value to the model's value, immediately", function(){
127
+ expect(this.el.css("display")).toBe("none");
128
+ });
129
+
130
+ it("should set the element's disabled value when the model's value is changed", function(){
131
+ this.model.set({isValid: true});
132
+ expect(this.el).toBeVisible();
133
+ });
134
+ });
135
+
136
+ describe("when a data-bind is configured to set visible", function(){
137
+ beforeEach(function(){
138
+ this.view.render();
139
+ this.el = $(this.view.el).find("#showHideAnotherThing");
140
+ });
141
+
142
+ it("should set the element's disabled value to the model's value, immediately", function(){
143
+ expect(this.el.css("display")).not.toBe("none");
144
+ });
145
+
146
+ it("should set the element's disabled value when the model's value is changed", function(){
147
+ this.model.set({isValid: true});
148
+ expect(this.el).toBeHidden();
149
+ });
150
+ });
151
+ });
@@ -0,0 +1,36 @@
1
+ describe("data-bind multiple attributes", function(){
2
+ beforeEach(function(){
3
+ this.model = new AModel({
4
+ urlSrc: "/foo/bar.gif",
5
+ name: "me"
6
+ });
7
+ this.view = new AView({model: this.model});
8
+ this.view.render();
9
+ this.el = this.view.$("#avatar");
10
+ });
11
+
12
+ describe ("when initializing", function(){
13
+ it("should set the first bound attribute", function(){
14
+ expect(this.el.attr("src")).toBe("/foo/bar.gif");
15
+ });
16
+
17
+ it("shoudl set the second bound attribute", function(){
18
+ expect(this.el.attr("class")).toBe("me");
19
+ });
20
+ });
21
+
22
+ describe("when setting the values", function(){
23
+ beforeEach(function(){
24
+ this.model.set({urlSrc: "/empty.png", name: "you"});
25
+ });
26
+
27
+ it("should update the first bound attribute", function(){
28
+ expect(this.el.attr("src")).toBe("/empty.png");
29
+ });
30
+
31
+ it("should update the second bound attribute", function(){
32
+ expect(this.el.attr("class")).toBe("you");
33
+ });
34
+ });
35
+
36
+ });
@@ -0,0 +1,137 @@
1
+ describe("default data-bind substitutions", function(){
2
+ beforeEach(function(){
3
+ this.model = new AModel({
4
+ doctor: "Seuss",
5
+ name: "foo"
6
+ });
7
+ this.view = new AView({model: this.model});
8
+ this.view.render();
9
+ });
10
+
11
+ describe("when binding unsetting the model's property that is bound to an unconfigured attribute", function(){
12
+ beforeEach(function(){
13
+ this.model.unset("name");
14
+ this.el = this.view.$("#avatar");
15
+ });
16
+
17
+ it("should use the 'default' substitution setting", function(){
18
+ expect(this.el.attr("class")).toBe("");
19
+ });
20
+ });
21
+
22
+ describe("when binding to text and unsetting the model's property", function(){
23
+ beforeEach(function(){
24
+ this.model.unset("doctor");
25
+ this.el = this.view.$("#doctor");
26
+ });
27
+
28
+ it("should set the text to an empty string", function(){
29
+ expect(this.el.text()).toBe("");
30
+ });
31
+ });
32
+
33
+ describe("when binding to html and unsetting the model's property", function(){
34
+ beforeEach(function(){
35
+ this.model.unset("villain");
36
+ this.el = this.view.$("#villain");
37
+ });
38
+
39
+ it("should set the html to an empty string", function(){
40
+ expect(this.el.html()).toBe("");
41
+ });
42
+ });
43
+
44
+ });
45
+
46
+ describe("configured data-bind substitutions", function(){
47
+ beforeEach(function(){
48
+ Backbone.ModelBinding.Configuration.dataBindSubst({
49
+ text: "text subst",
50
+ html: " "
51
+ });
52
+ this.model = new AModel({
53
+ doctor: "Seuss"
54
+ });
55
+ this.view = new AView({model: this.model});
56
+ this.view.render();
57
+ });
58
+
59
+ afterEach(function(){
60
+ Backbone.ModelBinding.Configuration.restoreDataBindSubstConfig();
61
+ });
62
+
63
+ describe("when binding to text and unsetting the model's property", function(){
64
+ beforeEach(function(){
65
+ this.model.unset("doctor");
66
+ this.el = this.view.$("#doctor");
67
+ });
68
+
69
+ it("should set the text to an empty string", function(){
70
+ expect(this.el.text()).toBe("text subst");
71
+ });
72
+ });
73
+
74
+ describe("when binding to html and unsetting the model's property", function(){
75
+ beforeEach(function(){
76
+ this.model.unset("villain");
77
+ this.el = this.view.$("#villain");
78
+ });
79
+
80
+ it("should set the html to an empty string", function(){
81
+ expect(this.el.html()).toBe(" ");
82
+ });
83
+ });
84
+
85
+ });
86
+
87
+ describe("resetting the data bind substitutions", function(){
88
+ beforeEach(function(){
89
+ Backbone.ModelBinding.Configuration.dataBindSubst({
90
+ text: "text subst",
91
+ html: "html subst"
92
+ });
93
+ this.model = new AModel({
94
+ doctor: "Seuss",
95
+ villain: "mort"
96
+ });
97
+ this.view = new AView({model: this.model});
98
+ this.view.render();
99
+
100
+ Backbone.ModelBinding.Configuration.restoreDataBindSubstConfig();
101
+ });
102
+
103
+ it("should use the default for text substitutions", function(){
104
+ this.model.unset("doctor");
105
+ this.doctorEl = this.view.$("#doctor");
106
+ expect(this.doctorEl.text()).toBe("");
107
+ });
108
+
109
+ it("should use the default for html substitutions", function(){
110
+ this.model.unset("villain");
111
+ this.villainEl = this.view.$("#villain");
112
+ expect(this.villainEl.html()).toBe("");
113
+ });
114
+ });
115
+
116
+ describe("when the data-bind attribute is manually configured", function(){
117
+ beforeEach(function(){
118
+ Backbone.ModelBinding.Conventions.databind.selector = "*[data-bind-bb]";
119
+ this.model = new AModel({
120
+ doctor: "Seuss",
121
+ villain: "mort"
122
+ });
123
+ this.view = new AView({model: this.model});
124
+ this.view.render();
125
+ this.el = this.view.$("#doctor_data_bind_bb");
126
+ Backbone.ModelBinding.Conventions.databind.selector = "*[data-bind]";
127
+ });
128
+
129
+ it("should set the element's text to the model's property value immediately", function(){
130
+ expect(this.el.text()).toBe("Seuss");
131
+ });
132
+
133
+ it("should set the text of the element when the model's property changes", function(){
134
+ this.model.set({doctor: "Who"});
135
+ expect(this.el.text()).toBe("Who");
136
+ });
137
+ });
@@ -0,0 +1,124 @@
1
+ describe("global configure all binding attributes", function(){
2
+ beforeEach(function(){
3
+ Backbone.ModelBinding.Configuration.store();
4
+
5
+ this.model = new AModel({
6
+ name: "some dude",
7
+ education: "graduate",
8
+ graduated: "maybe",
9
+ drivers_license: true
10
+ });
11
+
12
+ Backbone.ModelBinding.Configuration.configureAllBindingAttributes("class");
13
+ this.view = new GlobalAllBindingAttributesView({model: this.model});
14
+ this.view.render();
15
+ });
16
+
17
+ afterEach(function(){
18
+ Backbone.ModelBinding.Configuration.restore();
19
+ });
20
+
21
+ describe("text element binding using configurable attribute", function(){
22
+ it("bind view changes to the model's field, by configurable convention", function(){
23
+ var el = this.view.$("#v_name");
24
+ el.val("that guy");
25
+ el.trigger('change');
26
+
27
+ expect(this.model.get('name')).toEqual("that guy");
28
+ });
29
+
30
+ it("bind model field changes to the form input, by convention of id", function(){
31
+ this.model.set({name: "joe bob"});
32
+ var el = this.view.$("#v_name");
33
+ expect(el.val()).toEqual("joe bob");
34
+ });
35
+
36
+ it("binds the model's value to the form field on render", function(){
37
+ var el = this.view.$("#v_name");
38
+ expect(el.val()).toEqual("some dude");
39
+ });
40
+ });
41
+
42
+ describe("radio element binding using configurable attribute", function(){
43
+ it("bind view changes to the model's field, by configurable convention", function(){
44
+ var el = $(this.view.el).find("#graduated_no");
45
+ el.attr("checked", "checked");
46
+ el.trigger('change');
47
+ expect(this.model.get('graduated')).toEqual("no");
48
+ });
49
+
50
+ it("bind model field changes to the form input, by configurable convention", function(){
51
+ this.model.set({graduated: "yes"});
52
+ var el = this.view.$("#graduated_yes");
53
+ var selected = el.attr("checked");
54
+
55
+ expect(selected).toBeTruthy();
56
+ });
57
+
58
+ it("binds the model's value to the form field on render", function(){
59
+ var el = this.view.$("input[type=radio][class=graduated]:checked");
60
+ var selected = el.val();
61
+
62
+ expect(selected).toBe("maybe");
63
+ });
64
+ });
65
+
66
+ describe("select element binding using configurable attribute", function(){
67
+ it("bind view changes to the model's field, by configurable convention", function(){
68
+ var el = this.view.$(".education");
69
+ el.val("college");
70
+ el.trigger('change');
71
+
72
+ expect(this.model.get('education')).toEqual("college");
73
+ });
74
+
75
+ it("bind model field changes to the form input, by configurable convention", function(){
76
+ this.model.set({education: "high school"});
77
+ var el = this.view.$(".education");
78
+ expect(el.val()).toEqual("high school");
79
+ });
80
+
81
+ it("binds the model's value to the form field on render", function(){
82
+ var el = this.view.$(".education");
83
+ expect(el.val()).toEqual("graduate");
84
+ });
85
+
86
+ it("applies the text of the selection to the model", function(){
87
+ var el = this.view.$(".education");
88
+ el.val("grade_school");
89
+ el.trigger('change');
90
+
91
+ expect(this.model.get('education_text')).toEqual("i dun learned at grade skool");
92
+ });
93
+ });
94
+
95
+ describe("checkbox element binding using configurable attribute", function(){
96
+ it("bind view changes to the model's field", function(){
97
+ var el = this.view.$(".drivers_license");
98
+ el.removeAttr("checked");
99
+ el.trigger('change');
100
+ expect(this.model.get('drivers_license')).toBeFalsy();
101
+ });
102
+
103
+ it("bind model field changes to the form input", function(){
104
+ var el = this.view.$(".drivers_license");
105
+
106
+ // uncheck it
107
+ this.model.set({drivers_license: false});
108
+ var selected = el.attr("checked");
109
+ expect(selected).toBeFalsy();
110
+
111
+ // then check it
112
+ this.model.set({drivers_license: true});
113
+ var selected = el.attr("checked");
114
+ expect(selected).toBeTruthy();
115
+ });
116
+
117
+ it("binds the model's value to the form field on render", function(){
118
+ var el = this.view.$(".drivers_license");
119
+ var selected = el.attr("checked");
120
+
121
+ expect(selected).toBeTruthy();
122
+ });
123
+ });
124
+ });