Merge ~ya-bo-ng/maas:enable-fix-js-tests into maas:master
- Git
- lp:~ya-bo-ng/maas
- enable-fix-js-tests
- Merge into master
Proposed by
Anthony Dillon
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Andres Rodriguez | ||||
Approved revision: | 2a352f401a54e59857389b9d9108f68e35da6716 | ||||
Merge reported by: | MAAS Lander | ||||
Merged at revision: | not available | ||||
Proposed branch: | ~ya-bo-ng/maas:enable-fix-js-tests | ||||
Merge into: | maas:master | ||||
Diff against target: |
843 lines (+139/-166) 7 files modified
src/maasserver/static/js/angular/directives/call_to_action.js (+1/-1) src/maasserver/static/js/angular/directives/maas_obj_form.js (+2/-2) src/maasserver/static/js/angular/directives/tests/test_accordion.js (+17/-12) src/maasserver/static/js/angular/directives/tests/test_call_to_action.js (+20/-19) src/maasserver/static/js/angular/directives/tests/test_code_lines.js (+2/-2) src/maasserver/static/js/angular/directives/tests/test_controller_status.js (+3/-2) src/maasserver/static/js/angular/directives/tests/test_maas_obj_form.js (+94/-128) |
||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Blake Rouse (community) | Approve | ||
Review via email: mp+338427@code.launchpad.net |
Commit message
LP: #1750092 - Enable and fix js tests
Description of the change
Enabled all the disabled JavaScript tests. Updated the tests to use the new Vanilla classes and mark up. All tests should still pass.
To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote : | # |
LANDING
-b enable-fix-js-tests lp:~ya-bo-ng/maas/+git/maas into -b master lp:~maas-committers/maas
STATUS: FAILED BUILD
LOG: http://
- 2a352f4... by Anthony Dillon
-
Fix js-lint issues
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/src/maasserver/static/js/angular/directives/call_to_action.js b/src/maasserver/static/js/angular/directives/call_to_action.js | |||
2 | index 9416530..b82d57c 100644 | |||
3 | --- a/src/maasserver/static/js/angular/directives/call_to_action.js | |||
4 | +++ b/src/maasserver/static/js/angular/directives/call_to_action.js | |||
5 | @@ -16,7 +16,7 @@ angular.module('MAAS').run(['$templateCache', function ($templateCache) { | |||
6 | 16 | 'data-ng-click="shown=!shown"', | 16 | 'data-ng-click="shown=!shown"', |
7 | 17 | '>', | 17 | '>', |
8 | 18 | '{$ getTitle() $}', | 18 | '{$ getTitle() $}', |
10 | 19 | ' <i class="p-icon--chevron"></i>', | 19 | '<i class="p-icon--chevron"></i>', |
11 | 20 | '</button>', | 20 | '</button>', |
12 | 21 | '<div class="p-contextual-menu__dropdown" ', | 21 | '<div class="p-contextual-menu__dropdown" ', |
13 | 22 | 'id="cta-menu" ', | 22 | 'id="cta-menu" ', |
14 | diff --git a/src/maasserver/static/js/angular/directives/maas_obj_form.js b/src/maasserver/static/js/angular/directives/maas_obj_form.js | |||
15 | index b9f3a3c..954b94b 100644 | |||
16 | --- a/src/maasserver/static/js/angular/directives/maas_obj_form.js | |||
17 | +++ b/src/maasserver/static/js/angular/directives/maas_obj_form.js | |||
18 | @@ -337,7 +337,7 @@ angular.module('MAAS').directive('maasObjForm', ['JSONService', | |||
19 | 337 | }, | 337 | }, |
20 | 338 | transclude: true, | 338 | transclude: true, |
21 | 339 | template: ( | 339 | template: ( |
23 | 340 | '<form class="form" data-ng-class="{saving: saving, ' + | 340 | '<form class="p-form" data-ng-class="{saving: saving, ' + |
24 | 341 | '\'p-form--inline\': inline, ' + | 341 | '\'p-form--inline\': inline, ' + |
25 | 342 | '\'p-form--stacked\': tableForm}" ' + | 342 | '\'p-form--stacked\': tableForm}" ' + |
26 | 343 | 'ng-transclude></form>'), | 343 | 'ng-transclude></form>'), |
27 | @@ -963,7 +963,7 @@ angular.module('MAAS').directive('maasObjField', ['$compile', | |||
28 | 963 | 963 | ||
29 | 964 | // Called by controller to see if error is set on field. | 964 | // Called by controller to see if error is set on field. |
30 | 965 | scope.hasErrors = function() { | 965 | scope.hasErrors = function() { |
32 | 966 | return inputElement.hasClass("has-error"); | 966 | return inputWrapper.hasClass("is-error"); |
33 | 967 | }; | 967 | }; |
34 | 968 | 968 | ||
35 | 969 | // Subtle text element. | 969 | // Subtle text element. |
36 | diff --git a/src/maasserver/static/js/angular/directives/tests/test_accordion.js b/src/maasserver/static/js/angular/directives/tests/test_accordion.js | |||
37 | index 66305db..b1ad60f 100644 | |||
38 | --- a/src/maasserver/static/js/angular/directives/tests/test_accordion.js | |||
39 | +++ b/src/maasserver/static/js/angular/directives/tests/test_accordion.js | |||
40 | @@ -22,7 +22,7 @@ describe("maasAccodion", function() { | |||
41 | 22 | var html = [ | 22 | var html = [ |
42 | 23 | '<div>', | 23 | '<div>', |
43 | 24 | '<div class="maas-accordion">', | 24 | '<div class="maas-accordion">', |
45 | 25 | '<h4 class="maas-accordion-tab is-active">One</h4>', | 25 | '<h4 class="maas-accordion-tab is-selected">One</h4>', |
46 | 26 | '<h4 class="maas-accordion-tab">Two</h4>', | 26 | '<h4 class="maas-accordion-tab">Two</h4>', |
47 | 27 | '<h4 class="maas-accordion-tab">Three</h4>', | 27 | '<h4 class="maas-accordion-tab">Three</h4>', |
48 | 28 | '</div>', | 28 | '</div>', |
49 | @@ -46,23 +46,28 @@ describe("maasAccodion", function() { | |||
50 | 46 | tabs = directive.find('.maas-accordion-tab'); | 46 | tabs = directive.find('.maas-accordion-tab'); |
51 | 47 | }); | 47 | }); |
52 | 48 | 48 | ||
54 | 49 | xit("sets a new active removing other actives", function() { | 49 | it("sets a new selected and leaves others open", function() { |
55 | 50 | angular.element(tabs[1]).click(); | 50 | angular.element(tabs[1]).click(); |
59 | 51 | expect(angular.element(tabs[0]).hasClass("is-active")).toBe(false); | 51 | expect(angular.element(tabs[0]).hasClass("is-selected")).toBe(true); |
60 | 52 | expect(angular.element(tabs[1]).hasClass("is-active")).toBe(true); | 52 | expect(angular.element(tabs[1]).hasClass("is-selected")).toBe(true); |
61 | 53 | expect(angular.element(tabs[2]).hasClass("is-active")).toBe(false); | 53 | expect(angular.element(tabs[2]).hasClass("is-selected")).toBe(false); |
62 | 54 | 54 | ||
63 | 55 | angular.element(tabs[2]).click(); | 55 | angular.element(tabs[2]).click(); |
67 | 56 | expect(angular.element(tabs[0]).hasClass("is-active")).toBe(false); | 56 | expect(angular.element(tabs[0]).hasClass("is-selected")).toBe(true); |
68 | 57 | expect(angular.element(tabs[1]).hasClass("is-active")).toBe(false); | 57 | expect(angular.element(tabs[1]).hasClass("is-selected")).toBe(true); |
69 | 58 | expect(angular.element(tabs[2]).hasClass("is-active")).toBe(true); | 58 | expect(angular.element(tabs[2]).hasClass("is-selected")).toBe(true); |
70 | 59 | }); | 59 | }); |
71 | 60 | 60 | ||
73 | 61 | it("leaves current active if clicked", function() { | 61 | it("closes a section when clicked and open", function() { |
74 | 62 | angular.element(tabs[1]).click(); | ||
75 | 63 | expect(angular.element(tabs[0]).hasClass("is-selected")).toBe(true); | ||
76 | 64 | expect(angular.element(tabs[1]).hasClass("is-selected")).toBe(true); | ||
77 | 65 | expect(angular.element(tabs[2]).hasClass("is-selected")).toBe(false); | ||
78 | 66 | |||
79 | 62 | angular.element(tabs[0]).click(); | 67 | angular.element(tabs[0]).click(); |
83 | 63 | expect(angular.element(tabs[0]).hasClass("is-active")).toBe(true); | 68 | expect(angular.element(tabs[0]).hasClass("is-selected")).toBe(false); |
84 | 64 | expect(angular.element(tabs[1]).hasClass("is-active")).toBe(false); | 69 | expect(angular.element(tabs[1]).hasClass("is-selected")).toBe(true); |
85 | 65 | expect(angular.element(tabs[2]).hasClass("is-active")).toBe(false); | 70 | expect(angular.element(tabs[2]).hasClass("is-selected")).toBe(false); |
86 | 66 | }); | 71 | }); |
87 | 67 | 72 | ||
88 | 68 | it("removes all click handlers on $destroy", function() { | 73 | it("removes all click handlers on $destroy", function() { |
89 | diff --git a/src/maasserver/static/js/angular/directives/tests/test_call_to_action.js b/src/maasserver/static/js/angular/directives/tests/test_call_to_action.js | |||
90 | index 696e019..97fe8d1 100644 | |||
91 | --- a/src/maasserver/static/js/angular/directives/tests/test_call_to_action.js | |||
92 | +++ b/src/maasserver/static/js/angular/directives/tests/test_call_to_action.js | |||
93 | @@ -4,7 +4,7 @@ | |||
94 | 4 | * Unit tests for Call-To-Action dropdown directive. | 4 | * Unit tests for Call-To-Action dropdown directive. |
95 | 5 | */ | 5 | */ |
96 | 6 | 6 | ||
98 | 7 | xdescribe("maasCta", function() { | 7 | describe("maasCta", function() { |
99 | 8 | 8 | ||
100 | 9 | // Load the MAAS module. | 9 | // Load the MAAS module. |
101 | 10 | beforeEach(module("MAAS")); | 10 | beforeEach(module("MAAS")); |
102 | @@ -66,25 +66,26 @@ xdescribe("maasCta", function() { | |||
103 | 66 | it("sets default title to 'Take action'", function() { | 66 | it("sets default title to 'Take action'", function() { |
104 | 67 | var directive = compileDirective("items", "active"); | 67 | var directive = compileDirective("items", "active"); |
105 | 68 | expect( | 68 | expect( |
107 | 69 | directive.find("button.button-group__link").text()) | 69 | directive.find("button.p-contextual-menu__toggle").text()) |
108 | 70 | .toBe("Take action"); | 70 | .toBe("Take action"); |
109 | 71 | }); | 71 | }); |
110 | 72 | 72 | ||
111 | 73 | it("sets default title to another name", function() { | 73 | it("sets default title to another name", function() { |
112 | 74 | var name = makeName("title"); | 74 | var name = makeName("title"); |
113 | 75 | var directive = compileDirective("items", "active", null, null, name); | 75 | var directive = compileDirective("items", "active", null, null, name); |
115 | 76 | expect(directive.find("button.button-group__link").text()).toBe(name); | 76 | var selector = "button.p-contextual-menu__toggle"; |
116 | 77 | expect(directive.find(selector).text()).toBe(name); | ||
117 | 77 | }); | 78 | }); |
118 | 78 | 79 | ||
119 | 79 | it("click link sets shown to true", function() { | 80 | it("click link sets shown to true", function() { |
120 | 80 | var directive = compileDirective("items", "active"); | 81 | var directive = compileDirective("items", "active"); |
122 | 81 | directive.find("button.button-group__link").click(); | 82 | directive.find("button.p-contextual-menu__toggle").click(); |
123 | 82 | expect(directive.isolateScope().shown).toBe(true); | 83 | expect(directive.isolateScope().shown).toBe(true); |
124 | 83 | }); | 84 | }); |
125 | 84 | 85 | ||
126 | 85 | it("dropdown hidden when shown is false", function() { | 86 | it("dropdown hidden when shown is false", function() { |
127 | 86 | var directive = compileDirective("items", "active"); | 87 | var directive = compileDirective("items", "active"); |
129 | 87 | var dropdown = directive.find("ul.button-group__dropdown"); | 88 | var dropdown = directive.find("div.p-contextual-menu__dropdown"); |
130 | 88 | expect(dropdown.hasClass("ng-hide")).toBe(true); | 89 | expect(dropdown.hasClass("ng-hide")).toBe(true); |
131 | 89 | }); | 90 | }); |
132 | 90 | 91 | ||
133 | @@ -93,7 +94,7 @@ xdescribe("maasCta", function() { | |||
134 | 93 | directive.isolateScope().shown = true; | 94 | directive.isolateScope().shown = true; |
135 | 94 | $scope.$digest(); | 95 | $scope.$digest(); |
136 | 95 | 96 | ||
138 | 96 | var dropdown = directive.find("ul.button-group__dropdown"); | 97 | var dropdown = directive.find("div.p-contextual-menu__dropdown"); |
139 | 97 | expect(dropdown.hasClass("ng-hide")).toBe(false); | 98 | expect(dropdown.hasClass("ng-hide")).toBe(false); |
140 | 98 | }); | 99 | }); |
141 | 99 | 100 | ||
142 | @@ -107,7 +108,7 @@ xdescribe("maasCta", function() { | |||
143 | 107 | 108 | ||
144 | 108 | it("dropdown list options", function() { | 109 | it("dropdown list options", function() { |
145 | 109 | var directive = compileDirective("items", "active"); | 110 | var directive = compileDirective("items", "active"); |
147 | 110 | var links = directive.find("li.button-group__item > button"); | 111 | var links = directive.find("div.p-contextual-menu__dropdown > button"); |
148 | 111 | 112 | ||
149 | 112 | var listItems = []; | 113 | var listItems = []; |
150 | 113 | angular.forEach(links, function(ele, i) { | 114 | angular.forEach(links, function(ele, i) { |
151 | @@ -123,10 +124,10 @@ xdescribe("maasCta", function() { | |||
152 | 123 | 124 | ||
153 | 124 | it("dropdown select sets shown to false", function() { | 125 | it("dropdown select sets shown to false", function() { |
154 | 125 | var directive = compileDirective("items", "active"); | 126 | var directive = compileDirective("items", "active"); |
156 | 126 | var links = directive.find("li.button-group__item > button"); | 127 | var links = directive.find("div.p-contextual-menu__dropdown > button"); |
157 | 127 | 128 | ||
158 | 128 | // Open the dropdown. | 129 | // Open the dropdown. |
160 | 129 | directive.find("button.button-group__link").click(); | 130 | directive.find("button.p-contextual-menu__toggle").click(); |
161 | 130 | expect(directive.isolateScope().shown).toBe(true); | 131 | expect(directive.isolateScope().shown).toBe(true); |
162 | 131 | 132 | ||
163 | 132 | // Clicking a link should close the dropdown. | 133 | // Clicking a link should close the dropdown. |
164 | @@ -136,7 +137,7 @@ xdescribe("maasCta", function() { | |||
165 | 136 | 137 | ||
166 | 137 | it("dropdown select sets model", function() { | 138 | it("dropdown select sets model", function() { |
167 | 138 | var directive = compileDirective("items", "active"); | 139 | var directive = compileDirective("items", "active"); |
169 | 139 | var links = directive.find("li.button-group__item > button"); | 140 | var links = directive.find("div.p-contextual-menu__dropdown > button"); |
170 | 140 | 141 | ||
171 | 141 | angular.element(links[0]).click(); | 142 | angular.element(links[0]).click(); |
172 | 142 | expect(directive.scope().active).toBe($scope.items[0]); | 143 | expect(directive.scope().active).toBe($scope.items[0]); |
173 | @@ -144,16 +145,16 @@ xdescribe("maasCta", function() { | |||
174 | 144 | 145 | ||
175 | 145 | it("dropdown select sets title", function() { | 146 | it("dropdown select sets title", function() { |
176 | 146 | var directive = compileDirective("items", "active"); | 147 | var directive = compileDirective("items", "active"); |
178 | 147 | var links = directive.find("li.button-group__item > button"); | 148 | var links = directive.find("div.p-contextual-menu__dropdown > button"); |
179 | 148 | 149 | ||
180 | 149 | angular.element(links[0]).click(); | 150 | angular.element(links[0]).click(); |
182 | 150 | var title = directive.find("button.button-group__link").text(); | 151 | var title = directive.find("button.p-contextual-menu__toggle").text(); |
183 | 151 | expect(title).toBe($scope.items[0].title); | 152 | expect(title).toBe($scope.items[0].title); |
184 | 152 | }); | 153 | }); |
185 | 153 | 154 | ||
186 | 154 | it("dropdown select sets secondary", function() { | 155 | it("dropdown select sets secondary", function() { |
187 | 155 | var directive = compileDirective("items", "active"); | 156 | var directive = compileDirective("items", "active"); |
189 | 156 | var links = directive.find("li.button-group__item > button"); | 157 | var links = directive.find("div.p-contextual-menu__dropdown > button"); |
190 | 157 | 158 | ||
191 | 158 | angular.element(links[0]).click(); | 159 | angular.element(links[0]).click(); |
192 | 159 | expect(directive.isolateScope().secondary).toBe(true); | 160 | expect(directive.isolateScope().secondary).toBe(true); |
193 | @@ -162,7 +163,7 @@ xdescribe("maasCta", function() { | |||
194 | 162 | it("dropdown select sets selectedTitle", function() { | 163 | it("dropdown select sets selectedTitle", function() { |
195 | 163 | $scope.items[0].selectedTitle = "Different if Selected"; | 164 | $scope.items[0].selectedTitle = "Different if Selected"; |
196 | 164 | var directive = compileDirective("items", "active"); | 165 | var directive = compileDirective("items", "active"); |
198 | 165 | var links = directive.find("li.button-group__item > button"); | 166 | var links = directive.find("div.p-contextual-menu__dropdown > button"); |
199 | 166 | 167 | ||
200 | 167 | var iscope = directive.isolateScope(); | 168 | var iscope = directive.isolateScope(); |
201 | 168 | expect(iscope.getTitle()).toBe("Take action"); | 169 | expect(iscope.getTitle()).toBe("Take action"); |
202 | @@ -173,7 +174,7 @@ xdescribe("maasCta", function() { | |||
203 | 173 | it("dropdown select sets other options' selectedTitle", function() { | 174 | it("dropdown select sets other options' selectedTitle", function() { |
204 | 174 | $scope.items[1].selectedTitle = "Different if Selected"; | 175 | $scope.items[1].selectedTitle = "Different if Selected"; |
205 | 175 | var directive = compileDirective("items", "active"); | 176 | var directive = compileDirective("items", "active"); |
207 | 176 | var links = directive.find("li.button-group__item > button"); | 177 | var links = directive.find("div.p-contextual-menu__dropdown > button"); |
208 | 177 | 178 | ||
209 | 178 | var iscope = directive.isolateScope(); | 179 | var iscope = directive.isolateScope(); |
210 | 179 | expect(iscope.getTitle()).toBe("Take action"); | 180 | expect(iscope.getTitle()).toBe("Take action"); |
211 | @@ -184,10 +185,10 @@ xdescribe("maasCta", function() { | |||
212 | 184 | 185 | ||
213 | 185 | it("clicking body will set shown to false", function() { | 186 | it("clicking body will set shown to false", function() { |
214 | 186 | var directive = compileDirective("items", "active"); | 187 | var directive = compileDirective("items", "active"); |
216 | 187 | var links = directive.find("li.button-group__item > button"); | 188 | var links = directive.find("div.p-contextual-menu__dropdown > button"); |
217 | 188 | 189 | ||
218 | 189 | // Open the dropdown. | 190 | // Open the dropdown. |
220 | 190 | directive.find("button.button-group__link").click(); | 191 | directive.find("button.p-contextual-menu__toggle").click(); |
221 | 191 | expect(directive.isolateScope().shown).toBe(true); | 192 | expect(directive.isolateScope().shown).toBe(true); |
222 | 192 | 193 | ||
223 | 193 | // Click the body. | 194 | // Click the body. |
224 | @@ -203,10 +204,10 @@ xdescribe("maasCta", function() { | |||
225 | 203 | it("clicking button will fire ng-click", function() { | 204 | it("clicking button will fire ng-click", function() { |
226 | 204 | $scope.clicked = jasmine.createSpy("clicked"); | 205 | $scope.clicked = jasmine.createSpy("clicked"); |
227 | 205 | var directive = compileDirective("items", "active", null, "clicked()"); | 206 | var directive = compileDirective("items", "active", null, "clicked()"); |
229 | 206 | var links = directive.find("li.button-group__item > button"); | 207 | var links = directive.find("div.p-contextual-menu__dropdown > button"); |
230 | 207 | 208 | ||
231 | 208 | // Open the dropdown. | 209 | // Open the dropdown. |
233 | 209 | directive.find("button.button-group__link").click(); | 210 | directive.find("button.p-contextual-menu__toggle").click(); |
234 | 210 | expect($scope.clicked).toHaveBeenCalled(); | 211 | expect($scope.clicked).toHaveBeenCalled(); |
235 | 211 | }); | 212 | }); |
236 | 212 | }); | 213 | }); |
237 | diff --git a/src/maasserver/static/js/angular/directives/tests/test_code_lines.js b/src/maasserver/static/js/angular/directives/tests/test_code_lines.js | |||
238 | index 398f37f..80028b4 100644 | |||
239 | --- a/src/maasserver/static/js/angular/directives/tests/test_code_lines.js | |||
240 | +++ b/src/maasserver/static/js/angular/directives/tests/test_code_lines.js | |||
241 | @@ -4,7 +4,7 @@ | |||
242 | 4 | * Unit tests for placeholder directive. | 4 | * Unit tests for placeholder directive. |
243 | 5 | */ | 5 | */ |
244 | 6 | 6 | ||
246 | 7 | xdescribe("maasCodeLines", function() { | 7 | describe("maasCodeLines", function() { |
247 | 8 | 8 | ||
248 | 9 | // Load the MAAS module. | 9 | // Load the MAAS module. |
249 | 10 | beforeEach(module("MAAS")); | 10 | beforeEach(module("MAAS")); |
250 | @@ -41,6 +41,6 @@ beforeEach(module("MAAS")); | |||
251 | 41 | }; | 41 | }; |
252 | 42 | 42 | ||
253 | 43 | var directive = compileDirective("getText()"); | 43 | var directive = compileDirective("getText()"); |
255 | 44 | expect(directive.find('code').hasClass("code-block__line")).toBe(true); | 44 | expect(directive.find('code span').hasClass("code-line")).toBe(true); |
256 | 45 | }); | 45 | }); |
257 | 46 | }); | 46 | }); |
258 | diff --git a/src/maasserver/static/js/angular/directives/tests/test_controller_status.js b/src/maasserver/static/js/angular/directives/tests/test_controller_status.js | |||
259 | index 387a6f6..3e77bff 100644 | |||
260 | --- a/src/maasserver/static/js/angular/directives/tests/test_controller_status.js | |||
261 | +++ b/src/maasserver/static/js/angular/directives/tests/test_controller_status.js | |||
262 | @@ -65,13 +65,14 @@ describe("maasControllerStatus", function() { | |||
263 | 65 | return directive.find("div"); | 65 | return directive.find("div"); |
264 | 66 | } | 66 | } |
265 | 67 | 67 | ||
267 | 68 | xit("sets serviceClass in the class for element", function() { | 68 | it("sets serviceClass in the class for element", function() { |
268 | 69 | var directive = compileDirective(); | 69 | var directive = compileDirective(); |
269 | 70 | var serviceClass = makeName("serviceClass"); | 70 | var serviceClass = makeName("serviceClass"); |
270 | 71 | directive.isolateScope().serviceClass = serviceClass; | 71 | directive.isolateScope().serviceClass = serviceClass; |
271 | 72 | $scope.$digest(); | 72 | $scope.$digest(); |
272 | 73 | expect( | 73 | expect( |
274 | 74 | directive.find("span").hasClass("icon--" + serviceClass)).toBe(true); | 74 | directive.find("span").hasClass("p-icon--" + serviceClass) |
275 | 75 | ).toBe(true); | ||
276 | 75 | }); | 76 | }); |
277 | 76 | 77 | ||
278 | 77 | it("services is ServicesManager.getItems()", function() { | 78 | it("services is ServicesManager.getItems()", function() { |
279 | diff --git a/src/maasserver/static/js/angular/directives/tests/test_maas_obj_form.js b/src/maasserver/static/js/angular/directives/tests/test_maas_obj_form.js | |||
280 | index 95c0aed..d37b891 100644 | |||
281 | --- a/src/maasserver/static/js/angular/directives/tests/test_maas_obj_form.js | |||
282 | +++ b/src/maasserver/static/js/angular/directives/tests/test_maas_obj_form.js | |||
283 | @@ -4,7 +4,7 @@ | |||
284 | 4 | * Unit tests for MAAS object form. | 4 | * Unit tests for MAAS object form. |
285 | 5 | */ | 5 | */ |
286 | 6 | 6 | ||
288 | 7 | xdescribe("maasObjForm", function() { | 7 | describe("maasObjForm", function() { |
289 | 8 | 8 | ||
290 | 9 | // Load the MAAS module. | 9 | // Load the MAAS module. |
291 | 10 | beforeEach(module("MAAS")); | 10 | beforeEach(module("MAAS")); |
292 | @@ -42,20 +42,10 @@ xdescribe("maasObjForm", function() { | |||
293 | 42 | $scope.$digest(); | 42 | $scope.$digest(); |
294 | 43 | } | 43 | } |
295 | 44 | 44 | ||
296 | 45 | // Return the list of rendered errors on the field. | ||
297 | 46 | function getFieldErrorList(field) { | ||
298 | 47 | var errors = []; | ||
299 | 48 | var lis = field.siblings("ul.form__error").children(); | ||
300 | 49 | lis.each(function() { | ||
301 | 50 | errors.push(angular.element(this).text()); | ||
302 | 51 | }); | ||
303 | 52 | return errors; | ||
304 | 53 | } | ||
305 | 54 | |||
306 | 55 | // Return the list of rendered errors in the element. | 45 | // Return the list of rendered errors in the element. |
307 | 56 | function getErrorList(element) { | 46 | function getErrorList(element) { |
308 | 57 | var errors = []; | 47 | var errors = []; |
310 | 58 | var lis = element.find("ul.form__error").children(); | 48 | var lis = element.find("ul.p-list").children(); |
311 | 59 | lis.each(function() { | 49 | lis.each(function() { |
312 | 60 | errors.push(angular.element(this).text()); | 50 | errors.push(angular.element(this).text()); |
313 | 61 | }); | 51 | }); |
314 | @@ -64,7 +54,7 @@ xdescribe("maasObjForm", function() { | |||
315 | 64 | 54 | ||
316 | 65 | describe("inline form", function() { | 55 | describe("inline form", function() { |
317 | 66 | 56 | ||
319 | 67 | it("adds 'form--inline'", function() { | 57 | it("adds 'p-form--inline'", function() { |
320 | 68 | $scope.obj = {}; | 58 | $scope.obj = {}; |
321 | 69 | $scope.manager = {}; | 59 | $scope.manager = {}; |
322 | 70 | var html = [ | 60 | var html = [ |
323 | @@ -73,7 +63,7 @@ xdescribe("maasObjForm", function() { | |||
324 | 73 | ].join(''); | 63 | ].join(''); |
325 | 74 | var directive = compileDirective(html); | 64 | var directive = compileDirective(html); |
326 | 75 | var form = directive.find("form"); | 65 | var form = directive.find("form"); |
328 | 76 | expect(form.hasClass("form--inline")).toBe(true); | 66 | expect(form.hasClass("p-form--inline")).toBe(true); |
329 | 77 | }); | 67 | }); |
330 | 78 | }); | 68 | }); |
331 | 79 | 69 | ||
332 | @@ -89,8 +79,8 @@ xdescribe("maasObjForm", function() { | |||
333 | 89 | var html = [ | 79 | var html = [ |
334 | 90 | '<maas-obj-form obj="obj" manager="manager">', | 80 | '<maas-obj-form obj="obj" manager="manager">', |
335 | 91 | '<maas-obj-field type="text" key="key" label="Key" ', | 81 | '<maas-obj-field type="text" key="key" label="Key" ', |
338 | 92 | 'placeholder="Placeholder" label-width="two" ', | 82 | 'placeholder="Placeholder" label-width="2" ', |
339 | 93 | 'input-width="three"></maas-obj-field>', | 83 | 'input-width="3"></maas-obj-field>', |
340 | 94 | '</maas-obj-form>' | 84 | '</maas-obj-form>' |
341 | 95 | ].join(''); | 85 | ].join(''); |
342 | 96 | directive = compileDirective(html); | 86 | directive = compileDirective(html); |
343 | @@ -110,14 +100,13 @@ xdescribe("maasObjForm", function() { | |||
344 | 110 | it("adds label with width", function() { | 100 | it("adds label with width", function() { |
345 | 111 | var labelField = angular.element(directive.find("label")); | 101 | var labelField = angular.element(directive.find("label")); |
346 | 112 | expect(labelField.text()).toBe("Key"); | 102 | expect(labelField.text()).toBe("Key"); |
348 | 113 | expect(labelField.hasClass("two-col")).toBe(true); | 103 | expect(labelField.hasClass("col-2")).toBe(true); |
349 | 114 | }); | 104 | }); |
350 | 115 | 105 | ||
351 | 116 | it("adds inputWrapper with width", function() { | 106 | it("adds inputWrapper with width", function() { |
352 | 117 | var labelField = angular.element(directive.find("label ")); | 107 | var labelField = angular.element(directive.find("label ")); |
353 | 118 | var inputWrapper = angular.element(labelField.next("div")); | 108 | var inputWrapper = angular.element(labelField.next("div")); |
356 | 119 | expect(inputWrapper.hasClass("three-col")).toBe(true); | 109 | expect(inputWrapper.hasClass("col-3")).toBe(true); |
355 | 120 | expect(inputWrapper.hasClass("last-col")).toBe(true); | ||
357 | 121 | }); | 110 | }); |
358 | 122 | 111 | ||
359 | 123 | it("reverts value on esc", function() { | 112 | it("reverts value on esc", function() { |
360 | @@ -137,9 +126,9 @@ xdescribe("maasObjForm", function() { | |||
361 | 137 | expect($scope.obj.$maasForm).toBeDefined(); | 126 | expect($scope.obj.$maasForm).toBeDefined(); |
362 | 138 | }); | 127 | }); |
363 | 139 | 128 | ||
367 | 140 | it("hasErrors returns true if has-error class exists", function() { | 129 | it("hasErrors returns true if is-error class exists", function() { |
368 | 141 | var inputField = angular.element(directive.find("#key")); | 130 | var control = angular.element(directive.find('.p-form__control')); |
369 | 142 | inputField.addClass('has-error'); | 131 | control.addClass('is-error'); |
370 | 143 | expect($scope.obj.$maasForm.hasErrors()).toBe(true); | 132 | expect($scope.obj.$maasForm.hasErrors()).toBe(true); |
371 | 144 | }); | 133 | }); |
372 | 145 | }); | 134 | }); |
373 | @@ -153,8 +142,8 @@ xdescribe("maasObjForm", function() { | |||
374 | 153 | var html = [ | 142 | var html = [ |
375 | 154 | '<maas-obj-form obj="obj" manager="manager">', | 143 | '<maas-obj-form obj="obj" manager="manager">', |
376 | 155 | '<maas-obj-field type="textarea" key="key" label="Key" ', | 144 | '<maas-obj-field type="textarea" key="key" label="Key" ', |
379 | 156 | 'placeholder="Placeholder" label-width="two" ', | 145 | 'placeholder="Placeholder" label-width="2" ', |
380 | 157 | 'input-width="three"></maas-obj-field>', | 146 | 'input-width="3"></maas-obj-field>', |
381 | 158 | '</maas-obj-form>' | 147 | '</maas-obj-form>' |
382 | 159 | ].join(''); | 148 | ].join(''); |
383 | 160 | directive = compileDirective(html); | 149 | directive = compileDirective(html); |
384 | @@ -173,14 +162,13 @@ xdescribe("maasObjForm", function() { | |||
385 | 173 | it("adds label with width", function() { | 162 | it("adds label with width", function() { |
386 | 174 | var labelField = angular.element(directive.find("label")); | 163 | var labelField = angular.element(directive.find("label")); |
387 | 175 | expect(labelField.text()).toBe("Key"); | 164 | expect(labelField.text()).toBe("Key"); |
389 | 176 | expect(labelField.hasClass("two-col")).toBe(true); | 165 | expect(labelField.hasClass("col-2")).toBe(true); |
390 | 177 | }); | 166 | }); |
391 | 178 | 167 | ||
392 | 179 | it("adds inputWrapper with width", function() { | 168 | it("adds inputWrapper with width", function() { |
393 | 180 | var labelField = angular.element(directive.find("label ")); | 169 | var labelField = angular.element(directive.find("label ")); |
394 | 181 | var inputWrapper = angular.element(labelField.next("div")); | 170 | var inputWrapper = angular.element(labelField.next("div")); |
397 | 182 | expect(inputWrapper.hasClass("three-col")).toBe(true); | 171 | expect(inputWrapper.hasClass("col-3")).toBe(true); |
396 | 183 | expect(inputWrapper.hasClass("last-col")).toBe(true); | ||
398 | 184 | }); | 172 | }); |
399 | 185 | }); | 173 | }); |
400 | 186 | 174 | ||
401 | @@ -196,8 +184,8 @@ xdescribe("maasObjForm", function() { | |||
402 | 196 | var html = [ | 184 | var html = [ |
403 | 197 | '<maas-obj-form obj="obj" manager="manager">', | 185 | '<maas-obj-form obj="obj" manager="manager">', |
404 | 198 | '<maas-obj-field type="password" key="key" label="Key" ', | 186 | '<maas-obj-field type="password" key="key" label="Key" ', |
407 | 199 | 'placeholder="Placeholder" label-width="two" ', | 187 | 'placeholder="Placeholder" label-width="2" ', |
408 | 200 | 'input-width="three"></maas-obj-field>', | 188 | 'input-width="3"></maas-obj-field>', |
409 | 201 | '</maas-obj-form>' | 189 | '</maas-obj-form>' |
410 | 202 | ].join(''); | 190 | ].join(''); |
411 | 203 | directive = compileDirective(html); | 191 | directive = compileDirective(html); |
412 | @@ -217,14 +205,13 @@ xdescribe("maasObjForm", function() { | |||
413 | 217 | it("adds label with width", function() { | 205 | it("adds label with width", function() { |
414 | 218 | var labelField = angular.element(directive.find("label")); | 206 | var labelField = angular.element(directive.find("label")); |
415 | 219 | expect(labelField.text()).toBe("Key"); | 207 | expect(labelField.text()).toBe("Key"); |
417 | 220 | expect(labelField.hasClass("two-col")).toBe(true); | 208 | expect(labelField.hasClass("col-2")).toBe(true); |
418 | 221 | }); | 209 | }); |
419 | 222 | 210 | ||
420 | 223 | it("adds inputWrapper with width", function() { | 211 | it("adds inputWrapper with width", function() { |
421 | 224 | var labelField = angular.element(directive.find("label ")); | 212 | var labelField = angular.element(directive.find("label ")); |
422 | 225 | var inputWrapper = angular.element(labelField.next("div")); | 213 | var inputWrapper = angular.element(labelField.next("div")); |
425 | 226 | expect(inputWrapper.hasClass("three-col")).toBe(true); | 214 | expect(inputWrapper.hasClass("col-3")).toBe(true); |
424 | 227 | expect(inputWrapper.hasClass("last-col")).toBe(true); | ||
426 | 228 | }); | 215 | }); |
427 | 229 | 216 | ||
428 | 230 | it("reverts value on esc", function() { | 217 | it("reverts value on esc", function() { |
429 | @@ -245,8 +232,8 @@ xdescribe("maasObjForm", function() { | |||
430 | 245 | }); | 232 | }); |
431 | 246 | 233 | ||
432 | 247 | it("hasErrors returns true if has-error class exists", function() { | 234 | it("hasErrors returns true if has-error class exists", function() { |
435 | 248 | var inputField = angular.element(directive.find("#key")); | 235 | var control = angular.element(directive.find('.p-form__control')); |
436 | 249 | inputField.addClass('has-error'); | 236 | control.addClass('is-error'); |
437 | 250 | expect($scope.obj.$maasForm.hasErrors()).toBe(true); | 237 | expect($scope.obj.$maasForm.hasErrors()).toBe(true); |
438 | 251 | }); | 238 | }); |
439 | 252 | }); | 239 | }); |
440 | @@ -265,8 +252,8 @@ xdescribe("maasObjForm", function() { | |||
441 | 265 | var html = [ | 252 | var html = [ |
442 | 266 | '<maas-obj-form obj="obj" manager="manager">', | 253 | '<maas-obj-form obj="obj" manager="manager">', |
443 | 267 | '<maas-obj-field type="options" key="key" label="Key" ', | 254 | '<maas-obj-field type="options" key="key" label="Key" ', |
446 | 268 | 'placeholder="Placeholder" label-width="two" ', | 255 | 'placeholder="Placeholder" label-width="2" ', |
447 | 269 | 'input-width="three" options="' + options + '">', | 256 | 'input-width="3" options="' + options + '">', |
448 | 270 | '</maas-obj-field>', | 257 | '</maas-obj-field>', |
449 | 271 | '</maas-obj-form>' | 258 | '</maas-obj-form>' |
450 | 272 | ].join(''); | 259 | ].join(''); |
451 | @@ -304,14 +291,13 @@ xdescribe("maasObjForm", function() { | |||
452 | 304 | it("adds label with width", function() { | 291 | it("adds label with width", function() { |
453 | 305 | var labelField = angular.element(directive.find("label")); | 292 | var labelField = angular.element(directive.find("label")); |
454 | 306 | expect(labelField.text()).toBe("Key"); | 293 | expect(labelField.text()).toBe("Key"); |
456 | 307 | expect(labelField.hasClass("two-col")).toBe(true); | 294 | expect(labelField.hasClass("col-2")).toBe(true); |
457 | 308 | }); | 295 | }); |
458 | 309 | 296 | ||
459 | 310 | it("adds inputWrapper with width", function() { | 297 | it("adds inputWrapper with width", function() { |
460 | 311 | var labelField = angular.element(directive.find("label ")); | 298 | var labelField = angular.element(directive.find("label ")); |
461 | 312 | var inputWrapper = angular.element(labelField.next("div")); | 299 | var inputWrapper = angular.element(labelField.next("div")); |
464 | 313 | expect(inputWrapper.hasClass("three-col")).toBe(true); | 300 | expect(inputWrapper.hasClass("col-3")).toBe(true); |
463 | 314 | expect(inputWrapper.hasClass("last-col")).toBe(true); | ||
465 | 315 | }); | 301 | }); |
466 | 316 | 302 | ||
467 | 317 | it("calls on-change function", function() { | 303 | it("calls on-change function", function() { |
468 | @@ -332,13 +318,13 @@ xdescribe("maasObjForm", function() { | |||
469 | 332 | var html = [ | 318 | var html = [ |
470 | 333 | '<maas-obj-form obj="obj" manager="manager">', | 319 | '<maas-obj-form obj="obj" manager="manager">', |
471 | 334 | '<maas-obj-field type="options" key="key" label="Key" ', | 320 | '<maas-obj-field type="options" key="key" label="Key" ', |
473 | 335 | 'placeholder="Placeholder" label-width="two" ', | 321 | 'placeholder="Placeholder" label-width="2" ', |
474 | 336 | 'on-change="changeForm" ', | 322 | 'on-change="changeForm" ', |
476 | 337 | 'input-width="three" options="' + options + '">', | 323 | 'input-width="3" options="' + options + '">', |
477 | 338 | '</maas-obj-field>', | 324 | '</maas-obj-field>', |
478 | 339 | '<maas-obj-field type="text" key="key2" label="Key2" ', | 325 | '<maas-obj-field type="text" key="key2" label="Key2" ', |
481 | 340 | 'placeholder="" label-width="two" ', | 326 | 'placeholder="" label-width="2" ', |
482 | 341 | 'input-width="three"', | 327 | 'input-width="3"', |
483 | 342 | '</maas-obj-field>', | 328 | '</maas-obj-field>', |
484 | 343 | '</maas-obj-form>' | 329 | '</maas-obj-form>' |
485 | 344 | ].join(''); | 330 | ].join(''); |
486 | @@ -365,7 +351,7 @@ xdescribe("maasObjForm", function() { | |||
487 | 365 | var html = [ | 351 | var html = [ |
488 | 366 | '<maas-obj-form obj="obj" manager="manager">', | 352 | '<maas-obj-form obj="obj" manager="manager">', |
489 | 367 | '<maas-obj-field type="checkboxes" key="key" label="Key" ', | 353 | '<maas-obj-field type="checkboxes" key="key" label="Key" ', |
491 | 368 | 'label-width="two" input-width="three" ', | 354 | 'label-width="2" input-width="3" ', |
492 | 369 | 'values="values">', | 355 | 'values="values">', |
493 | 370 | '</maas-obj-field>', | 356 | '</maas-obj-field>', |
494 | 371 | '</maas-obj-form>' | 357 | '</maas-obj-form>' |
495 | @@ -390,7 +376,7 @@ xdescribe("maasObjForm", function() { | |||
496 | 390 | var labelField = angular.element( | 376 | var labelField = angular.element( |
497 | 391 | directive.find('label[for="key"]')); | 377 | directive.find('label[for="key"]')); |
498 | 392 | expect(labelField.text()).toBe("Key"); | 378 | expect(labelField.text()).toBe("Key"); |
500 | 393 | expect(labelField.hasClass("two-col")).toBe(true); | 379 | expect(labelField.hasClass("col-2")).toBe(true); |
501 | 394 | }); | 380 | }); |
502 | 395 | }); | 381 | }); |
503 | 396 | 382 | ||
504 | @@ -405,7 +391,7 @@ xdescribe("maasObjForm", function() { | |||
505 | 405 | var html = [ | 391 | var html = [ |
506 | 406 | '<maas-obj-form obj="obj" manager="manager">', | 392 | '<maas-obj-form obj="obj" manager="manager">', |
507 | 407 | '<maas-obj-field type="tags" key="key" label="Key" ', | 393 | '<maas-obj-field type="tags" key="key" label="Key" ', |
509 | 408 | 'label-width="two" input-width="three">', | 394 | 'label-width="2" input-width="3">', |
510 | 409 | '</maas-obj-field>', | 395 | '</maas-obj-field>', |
511 | 410 | '</maas-obj-form>' | 396 | '</maas-obj-form>' |
512 | 411 | ].join(''); | 397 | ].join(''); |
513 | @@ -421,7 +407,7 @@ xdescribe("maasObjForm", function() { | |||
514 | 421 | var labelField = angular.element( | 407 | var labelField = angular.element( |
515 | 422 | directive.find('label[for="key"]')); | 408 | directive.find('label[for="key"]')); |
516 | 423 | expect(labelField.text()).toBe("Key"); | 409 | expect(labelField.text()).toBe("Key"); |
518 | 424 | expect(labelField.hasClass("two-col")).toBe(true); | 410 | expect(labelField.hasClass("col-2")).toBe(true); |
519 | 425 | }); | 411 | }); |
520 | 426 | }); | 412 | }); |
521 | 427 | 413 | ||
522 | @@ -436,7 +422,7 @@ xdescribe("maasObjForm", function() { | |||
523 | 436 | var html = [ | 422 | var html = [ |
524 | 437 | '<maas-obj-form obj="obj" manager="manager">', | 423 | '<maas-obj-form obj="obj" manager="manager">', |
525 | 438 | '<maas-obj-field type="onoffswitch" key="key" label="Key" ', | 424 | '<maas-obj-field type="onoffswitch" key="key" label="Key" ', |
527 | 439 | 'label-width="two" input-width="three">', | 425 | 'label-width="2" input-width="3">', |
528 | 440 | '</maas-obj-field>', | 426 | '</maas-obj-field>', |
529 | 441 | '</maas-obj-form>' | 427 | '</maas-obj-form>' |
530 | 442 | ].join(''); | 428 | ].join(''); |
531 | @@ -444,21 +430,15 @@ xdescribe("maasObjForm", function() { | |||
532 | 444 | }); | 430 | }); |
533 | 445 | 431 | ||
534 | 446 | it("creates onoffswitch", function() { | 432 | it("creates onoffswitch", function() { |
540 | 447 | var onoff = angular.element(directive.find("div.onoffswitch")); | 433 | var onoff = angular.element(directive.find("div.maas-p-switch")); |
536 | 448 | var input = angular.element( | ||
537 | 449 | onoff.find("input.onoffswitch-checkbox")); | ||
538 | 450 | var label = angular.element( | ||
539 | 451 | onoff.find("label.onoffswitch-label u-no-margin--top")); | ||
541 | 452 | expect(onoff.length).toBe(1); | 434 | expect(onoff.length).toBe(1); |
542 | 453 | expect(input.length).toBe(1); | ||
543 | 454 | expect(label.length).toBe(1); | ||
544 | 455 | }); | 435 | }); |
545 | 456 | 436 | ||
546 | 457 | it("adds label with width", function() { | 437 | it("adds label with width", function() { |
547 | 458 | var labelField = angular.element( | 438 | var labelField = angular.element( |
548 | 459 | directive.find('label[for="key"]')); | 439 | directive.find('label[for="key"]')); |
549 | 460 | expect(labelField.text()).toBe("Key"); | 440 | expect(labelField.text()).toBe("Key"); |
551 | 461 | expect(labelField.hasClass("two-col")).toBe(true); | 441 | expect(labelField.hasClass("col-2")).toBe(true); |
552 | 462 | }); | 442 | }); |
553 | 463 | }); | 443 | }); |
554 | 464 | 444 | ||
555 | @@ -478,8 +458,8 @@ xdescribe("maasObjForm", function() { | |||
556 | 478 | var html = [ | 458 | var html = [ |
557 | 479 | '<maas-obj-form obj="obj" manager="manager">', | 459 | '<maas-obj-form obj="obj" manager="manager">', |
558 | 480 | '<maas-obj-field type="text" key="key" label="Key" ', | 460 | '<maas-obj-field type="text" key="key" label="Key" ', |
561 | 481 | 'placeholder="Placeholder" label-width="two" ', | 461 | 'placeholder="Placeholder" label-width="2" ', |
562 | 482 | 'input-width="three"></maas-obj-field>', | 462 | 'input-width="3"></maas-obj-field>', |
563 | 483 | '</maas-obj-form>' | 463 | '</maas-obj-form>' |
564 | 484 | ].join(''); | 464 | ].join(''); |
565 | 485 | directive = compileDirective(html); | 465 | directive = compileDirective(html); |
566 | @@ -558,18 +538,20 @@ xdescribe("maasObjForm", function() { | |||
567 | 558 | 538 | ||
568 | 559 | it("sets string error on field", function() { | 539 | it("sets string error on field", function() { |
569 | 560 | var field = angular.element(directive.find("#key")); | 540 | var field = angular.element(directive.find("#key")); |
570 | 541 | var control = angular.element(directive.find('.p-form__control')); | ||
571 | 561 | changeFieldValue(field, makeName("new_key")); | 542 | changeFieldValue(field, makeName("new_key")); |
572 | 562 | 543 | ||
573 | 563 | var error = makeName("error"); | 544 | var error = makeName("error"); |
574 | 564 | saveDefer.reject(error); | 545 | saveDefer.reject(error); |
575 | 565 | $scope.$digest(); | 546 | $scope.$digest(); |
576 | 566 | 547 | ||
579 | 567 | var errorsList = getFieldErrorList(field); | 548 | var errorsList = getErrorList(control); |
580 | 568 | expect(errorsList).toEqual([error]); | 549 | expect(errorsList).toEqual(["Error: " + error]); |
581 | 569 | }); | 550 | }); |
582 | 570 | 551 | ||
583 | 571 | it("sets field error on field", function() { | 552 | it("sets field error on field", function() { |
584 | 572 | var field = angular.element(directive.find("#key")); | 553 | var field = angular.element(directive.find("#key")); |
585 | 554 | var control = angular.element(directive.find('.p-form__control')); | ||
586 | 573 | changeFieldValue(field, makeName("new_key")); | 555 | changeFieldValue(field, makeName("new_key")); |
587 | 574 | 556 | ||
588 | 575 | var error = makeName("error"); | 557 | var error = makeName("error"); |
589 | @@ -578,13 +560,14 @@ xdescribe("maasObjForm", function() { | |||
590 | 578 | })); | 560 | })); |
591 | 579 | $scope.$digest(); | 561 | $scope.$digest(); |
592 | 580 | 562 | ||
596 | 581 | var errorsList = getFieldErrorList(field); | 563 | var errorsList = getErrorList(control); |
597 | 582 | expect(errorsList).toEqual([error]); | 564 | expect(errorsList).toEqual(["Error: " + error]); |
598 | 583 | expect(field.hasClass("has-error")).toBe(true); | 565 | expect(control.hasClass("is-error")).toBe(true); |
599 | 584 | }); | 566 | }); |
600 | 585 | 567 | ||
601 | 586 | it("sets field error on another field", function() { | 568 | it("sets field error on another field", function() { |
602 | 587 | var field = angular.element(directive.find("#key")); | 569 | var field = angular.element(directive.find("#key")); |
603 | 570 | var control = angular.element(directive.find('.p-form__control')); | ||
604 | 588 | changeFieldValue(field, makeName("new_key")); | 571 | changeFieldValue(field, makeName("new_key")); |
605 | 589 | 572 | ||
606 | 590 | var error = makeName("error"); | 573 | var error = makeName("error"); |
607 | @@ -593,13 +576,14 @@ xdescribe("maasObjForm", function() { | |||
608 | 593 | })); | 576 | })); |
609 | 594 | $scope.$digest(); | 577 | $scope.$digest(); |
610 | 595 | 578 | ||
614 | 596 | var errorsList = getFieldErrorList(field); | 579 | var errorsList = getErrorList(control); |
615 | 597 | expect(errorsList).toEqual(["otherKey: " + error]); | 580 | expect(errorsList).toEqual(["Error: otherKey: " + error]); |
616 | 598 | expect(field.hasClass("has-error")).toBe(true); | 581 | expect(control.hasClass("is-error")).toBe(true); |
617 | 599 | }); | 582 | }); |
618 | 600 | 583 | ||
619 | 601 | it("sets multiple errors on field", function() { | 584 | it("sets multiple errors on field", function() { |
620 | 602 | var field = angular.element(directive.find("#key")); | 585 | var field = angular.element(directive.find("#key")); |
621 | 586 | var control = angular.element(directive.find('.p-form__control')); | ||
622 | 603 | changeFieldValue(field, makeName("new_key")); | 587 | changeFieldValue(field, makeName("new_key")); |
623 | 604 | 588 | ||
624 | 605 | var error1 = makeName("error"); | 589 | var error1 = makeName("error"); |
625 | @@ -609,9 +593,9 @@ xdescribe("maasObjForm", function() { | |||
626 | 609 | })); | 593 | })); |
627 | 610 | $scope.$digest(); | 594 | $scope.$digest(); |
628 | 611 | 595 | ||
632 | 612 | var errorsList = getFieldErrorList(field); | 596 | var errList = getErrorList(control); |
633 | 613 | expect(errorsList).toEqual([error1, error2]); | 597 | expect(errList).toEqual(["Error: " + error1, "Error: " + error2]); |
634 | 614 | expect(field.hasClass("has-error")).toBe(true); | 598 | expect(control.hasClass("is-error")).toBe(true); |
635 | 615 | }); | 599 | }); |
636 | 616 | }); | 600 | }); |
637 | 617 | 601 | ||
638 | @@ -633,8 +617,8 @@ xdescribe("maasObjForm", function() { | |||
639 | 633 | '<maas-obj-form obj="obj" manager="manager" ', | 617 | '<maas-obj-form obj="obj" manager="manager" ', |
640 | 634 | 'pre-process="process">', | 618 | 'pre-process="process">', |
641 | 635 | '<maas-obj-field type="text" key="key" label="Key" ', | 619 | '<maas-obj-field type="text" key="key" label="Key" ', |
644 | 636 | 'placeholder="Placeholder" label-width="two" ', | 620 | 'placeholder="Placeholder" label-width="2" ', |
645 | 637 | 'input-width="three"></maas-obj-field>', | 621 | 'input-width="3"></maas-obj-field>', |
646 | 638 | '</maas-obj-form>' | 622 | '</maas-obj-form>' |
647 | 639 | ].join(''); | 623 | ].join(''); |
648 | 640 | var directive = compileDirective(html); | 624 | var directive = compileDirective(html); |
649 | @@ -662,11 +646,11 @@ xdescribe("maasObjForm", function() { | |||
650 | 662 | var html = [ | 646 | var html = [ |
651 | 663 | '<maas-obj-form obj="obj" manager="manager">', | 647 | '<maas-obj-form obj="obj" manager="manager">', |
652 | 664 | '<maas-obj-field type="text" key="key1" label="Key1" ', | 648 | '<maas-obj-field type="text" key="key1" label="Key1" ', |
655 | 665 | 'placeholder="Placeholder" label-width="two" ', | 649 | 'placeholder="Placeholder" label-width="2" ', |
656 | 666 | 'input-width="three"></maas-obj-field>', | 650 | 'input-width="3"></maas-obj-field>', |
657 | 667 | '<maas-obj-field type="text" key="key2" label="Key2" ', | 651 | '<maas-obj-field type="text" key="key2" label="Key2" ', |
660 | 668 | 'placeholder="Placeholder" label-width="two" ', | 652 | 'placeholder="Placeholder" label-width="2" ', |
661 | 669 | 'input-width="three"></maas-obj-field>', | 653 | 'input-width="3"></maas-obj-field>', |
662 | 670 | '</maas-obj-form>' | 654 | '</maas-obj-form>' |
663 | 671 | ].join(''); | 655 | ].join(''); |
664 | 672 | directive = compileDirective(html); | 656 | directive = compileDirective(html); |
665 | @@ -675,6 +659,10 @@ xdescribe("maasObjForm", function() { | |||
666 | 675 | it("sets field error on both fields", function() { | 659 | it("sets field error on both fields", function() { |
667 | 676 | var field1 = angular.element(directive.find("#key1")); | 660 | var field1 = angular.element(directive.find("#key1")); |
668 | 677 | var field2 = angular.element(directive.find("#key2")); | 661 | var field2 = angular.element(directive.find("#key2")); |
669 | 662 | var selector1 = "label[for='key1'] + .p-form__control"; | ||
670 | 663 | var selector2 = "label[for='key2'] + .p-form__control"; | ||
671 | 664 | var control1 = angular.element(directive.find(selector1)); | ||
672 | 665 | var control2 = angular.element(directive.find(selector2)); | ||
673 | 678 | changeFieldValue(field1, makeName("new_key")); | 666 | changeFieldValue(field1, makeName("new_key")); |
674 | 679 | 667 | ||
675 | 680 | var error1 = makeName("error"); | 668 | var error1 = makeName("error"); |
676 | @@ -685,8 +673,8 @@ xdescribe("maasObjForm", function() { | |||
677 | 685 | })); | 673 | })); |
678 | 686 | $scope.$digest(); | 674 | $scope.$digest(); |
679 | 687 | 675 | ||
682 | 688 | expect(getFieldErrorList(field1)).toEqual([error1]); | 676 | expect(getErrorList(control1)).toEqual(["Error: " + error1]); |
683 | 689 | expect(getFieldErrorList(field2)).toEqual([error2]); | 677 | expect(getErrorList(control2)).toEqual(["Error: " + error2]); |
684 | 690 | }); | 678 | }); |
685 | 691 | }); | 679 | }); |
686 | 692 | 680 | ||
687 | @@ -708,11 +696,11 @@ xdescribe("maasObjForm", function() { | |||
688 | 708 | '<maas-obj-form obj="obj" manager="manager">', | 696 | '<maas-obj-form obj="obj" manager="manager">', |
689 | 709 | '<maas-obj-field-group>', | 697 | '<maas-obj-field-group>', |
690 | 710 | '<maas-obj-field type="text" key="key1" label="Key1" ', | 698 | '<maas-obj-field type="text" key="key1" label="Key1" ', |
693 | 711 | 'placeholder="Placeholder" label-width="two" ', | 699 | 'placeholder="Placeholder" label-width="2" ', |
694 | 712 | 'input-width="three"></maas-obj-field>', | 700 | 'input-width="3"></maas-obj-field>', |
695 | 713 | '<maas-obj-field type="text" key="key2" label="Key2" ', | 701 | '<maas-obj-field type="text" key="key2" label="Key2" ', |
698 | 714 | 'placeholder="Placeholder" label-width="two" ', | 702 | 'placeholder="Placeholder" label-width="2" ', |
699 | 715 | 'input-width="three"></maas-obj-field>', | 703 | 'input-width="3"></maas-obj-field>', |
700 | 716 | '</maas-obj-field-group>', | 704 | '</maas-obj-field-group>', |
701 | 717 | '</maas-obj-form>' | 705 | '</maas-obj-form>' |
702 | 718 | ].join(''); | 706 | ].join(''); |
703 | @@ -795,11 +783,11 @@ xdescribe("maasObjForm", function() { | |||
704 | 795 | '<maas-obj-form obj="obj" manager="manager" ' + | 783 | '<maas-obj-form obj="obj" manager="manager" ' + |
705 | 796 | 'data-ng-disabled="disabled">', | 784 | 'data-ng-disabled="disabled">', |
706 | 797 | '<maas-obj-field type="text" key="key" label="Key" ', | 785 | '<maas-obj-field type="text" key="key" label="Key" ', |
709 | 798 | 'placeholder="Placeholder" label-width="two" ', | 786 | 'placeholder="Placeholder" label-width="2" ', |
710 | 799 | 'input-width="three"></maas-obj-field>', | 787 | 'input-width="3"></maas-obj-field>', |
711 | 800 | '<maas-obj-field type="options" key="key2" label="Key 2" ', | 788 | '<maas-obj-field type="options" key="key2" label="Key 2" ', |
714 | 801 | 'placeholder="Placeholder 2" label-width="two" ', | 789 | 'placeholder="Placeholder 2" label-width="2" ', |
715 | 802 | 'input-width="three" options="' + options + '">', | 790 | 'input-width="3" options="' + options + '">', |
716 | 803 | '</maas-obj-field>', | 791 | '</maas-obj-field>', |
717 | 804 | '</maas-obj-form>' | 792 | '</maas-obj-form>' |
718 | 805 | ].join(''); | 793 | ].join(''); |
719 | @@ -839,8 +827,8 @@ xdescribe("maasObjForm", function() { | |||
720 | 839 | '<maas-obj-form obj="obj" manager="manager" ', | 827 | '<maas-obj-form obj="obj" manager="manager" ', |
721 | 840 | 'after-save="saved">', | 828 | 'after-save="saved">', |
722 | 841 | '<maas-obj-field type="text" key="key" label="Key" ', | 829 | '<maas-obj-field type="text" key="key" label="Key" ', |
725 | 842 | 'placeholder="Placeholder" label-width="two" ', | 830 | 'placeholder="Placeholder" label-width="2" ', |
726 | 843 | 'input-width="three"></maas-obj-field>', | 831 | 'input-width="3"></maas-obj-field>', |
727 | 844 | '</maas-obj-form>' | 832 | '</maas-obj-form>' |
728 | 845 | ].join(''); | 833 | ].join(''); |
729 | 846 | var directive = compileDirective(html); | 834 | var directive = compileDirective(html); |
730 | @@ -867,40 +855,17 @@ xdescribe("maasObjForm", function() { | |||
731 | 867 | var html = [ | 855 | var html = [ |
732 | 868 | '<maas-obj-form obj="obj" manager="manager">', | 856 | '<maas-obj-form obj="obj" manager="manager">', |
733 | 869 | '<maas-obj-field type="text" key="key" label="Key" ', | 857 | '<maas-obj-field type="text" key="key" label="Key" ', |
758 | 870 | 'placeholder="Placeholder" label-width="two" ', | 858 | 'placeholder="Placeholder" label-width="2" ', |
759 | 871 | 'input-width="three"></maas-obj-field>', | 859 | 'input-width="3"></maas-obj-field>', |
736 | 872 | '</maas-obj-form>' | ||
737 | 873 | ].join(''); | ||
738 | 874 | var directive = compileDirective(html); | ||
739 | 875 | var group = angular.element( | ||
740 | 876 | directive.find('maas-obj-field[key="key"]')); | ||
741 | 877 | var field = angular.element(directive.find("#key")); | ||
742 | 878 | expect(group.hasClass("form__group")).toBe(true); | ||
743 | 879 | expect(group.hasClass("form__group--subtle")).toBe(true); | ||
744 | 880 | expect( | ||
745 | 881 | field.parent("div").hasClass("form__group-input")).toBe(true); | ||
746 | 882 | }); | ||
747 | 883 | |||
748 | 884 | it("adds form__group classes without subtle", function() { | ||
749 | 885 | $scope.obj = { | ||
750 | 886 | key: makeName("key") | ||
751 | 887 | }; | ||
752 | 888 | $scope.manager = {}; | ||
753 | 889 | var html = [ | ||
754 | 890 | '<maas-obj-form obj="obj" manager="manager">', | ||
755 | 891 | '<maas-obj-field type="text" key="key" label="Key" ', | ||
756 | 892 | 'placeholder="Placeholder" label-width="two" ', | ||
757 | 893 | 'input-width="three" subtle="false"></maas-obj-field>', | ||
760 | 894 | '</maas-obj-form>' | 860 | '</maas-obj-form>' |
761 | 895 | ].join(''); | 861 | ].join(''); |
762 | 896 | var directive = compileDirective(html); | 862 | var directive = compileDirective(html); |
763 | 897 | var group = angular.element( | 863 | var group = angular.element( |
764 | 898 | directive.find('maas-obj-field[key="key"]')); | 864 | directive.find('maas-obj-field[key="key"]')); |
765 | 899 | var field = angular.element(directive.find("#key")); | 865 | var field = angular.element(directive.find("#key")); |
768 | 900 | expect(group.hasClass("form__group")).toBe(true); | 866 | expect(group.hasClass("p-form__group")).toBe(true); |
767 | 901 | expect(group.hasClass("form__group--subtle")).toBe(false); | ||
769 | 902 | expect( | 867 | expect( |
771 | 903 | field.parent("div").hasClass("form__group-input")).toBe(true); | 868 | field.parent("div").hasClass("p-form__control")).toBe(true); |
772 | 904 | }); | 869 | }); |
773 | 905 | }); | 870 | }); |
774 | 906 | 871 | ||
775 | @@ -920,8 +885,8 @@ xdescribe("maasObjForm", function() { | |||
776 | 920 | '<maas-obj-form obj="obj" manager="manager" ', | 885 | '<maas-obj-form obj="obj" manager="manager" ', |
777 | 921 | 'save-on-blur="false">', | 886 | 'save-on-blur="false">', |
778 | 922 | '<maas-obj-field type="text" key="key" label="Key" ', | 887 | '<maas-obj-field type="text" key="key" label="Key" ', |
781 | 923 | 'placeholder="Placeholder" label-width="two" ', | 888 | 'placeholder="Placeholder" label-width="2" ', |
782 | 924 | 'input-width="three"></maas-obj-field>', | 889 | 'input-width="3"></maas-obj-field>', |
783 | 925 | '</maas-obj-form>' | 890 | '</maas-obj-form>' |
784 | 926 | ].join(''); | 891 | ].join(''); |
785 | 927 | var directive = compileDirective(html); | 892 | var directive = compileDirective(html); |
786 | @@ -947,8 +912,8 @@ xdescribe("maasObjForm", function() { | |||
787 | 947 | '<maas-obj-form obj="obj" manager="manager" ', | 912 | '<maas-obj-form obj="obj" manager="manager" ', |
788 | 948 | 'save-on-blur="false">', | 913 | 'save-on-blur="false">', |
789 | 949 | '<maas-obj-field type="text" key="key" label="Key" ', | 914 | '<maas-obj-field type="text" key="key" label="Key" ', |
792 | 950 | 'placeholder="Placeholder" label-width="two" ', | 915 | 'placeholder="Placeholder" label-width="2" ', |
793 | 951 | 'input-width="three"></maas-obj-field>', | 916 | 'input-width="3"></maas-obj-field>', |
794 | 952 | '<button maas-obj-save></button>', | 917 | '<button maas-obj-save></button>', |
795 | 953 | '</maas-obj-form>' | 918 | '</maas-obj-form>' |
796 | 954 | ].join(''); | 919 | ].join(''); |
797 | @@ -981,14 +946,14 @@ xdescribe("maasObjForm", function() { | |||
798 | 981 | '<maas-obj-form obj="obj" manager="manager" ', | 946 | '<maas-obj-form obj="obj" manager="manager" ', |
799 | 982 | 'save-on-blur="false">', | 947 | 'save-on-blur="false">', |
800 | 983 | '<maas-obj-field type="text" key="key" label="Key" ', | 948 | '<maas-obj-field type="text" key="key" label="Key" ', |
803 | 984 | 'placeholder="Placeholder" label-width="two" ', | 949 | 'placeholder="Placeholder" label-width="2" ', |
804 | 985 | 'input-width="three"></maas-obj-field>', | 950 | 'input-width="3"></maas-obj-field>', |
805 | 986 | '<maas-obj-errors></maas-obj-errors>', | 951 | '<maas-obj-errors></maas-obj-errors>', |
806 | 987 | '<button maas-obj-save></button>', | 952 | '<button maas-obj-save></button>', |
807 | 988 | '</maas-obj-form>' | 953 | '</maas-obj-form>' |
808 | 989 | ].join(''); | 954 | ].join(''); |
809 | 990 | var directive = compileDirective(html); | 955 | var directive = compileDirective(html); |
811 | 991 | var field = angular.element(directive.find("#key")); | 956 | var field = angular.element(directive.find(".p-form__group")); |
812 | 992 | var errors = angular.element(directive.find("maas-obj-errors")); | 957 | var errors = angular.element(directive.find("maas-obj-errors")); |
813 | 993 | var button = angular.element(directive.find("button")); | 958 | var button = angular.element(directive.find("button")); |
814 | 994 | 959 | ||
815 | @@ -1005,8 +970,8 @@ xdescribe("maasObjForm", function() { | |||
816 | 1005 | $scope.$digest(); | 970 | $scope.$digest(); |
817 | 1006 | 971 | ||
818 | 1007 | // Error is placed on the input and in the global section. | 972 | // Error is placed on the input and in the global section. |
821 | 1008 | expect(getFieldErrorList(field)).toEqual([keyError]); | 973 | expect(getErrorList(field)).toEqual(["Error: " + keyError]); |
822 | 1009 | expect(getErrorList(errors)).toEqual([error]); | 974 | expect(getErrorList(errors)).toEqual([' ' + error]); |
823 | 1010 | 975 | ||
824 | 1011 | // Has error returns true. | 976 | // Has error returns true. |
825 | 1012 | expect($scope.obj.$maasForm.hasErrors()).toBe(true); | 977 | expect($scope.obj.$maasForm.hasErrors()).toBe(true); |
826 | @@ -1054,11 +1019,12 @@ xdescribe("maasObjForm", function() { | |||
827 | 1054 | it("icon add with tooltip added in label", function() { | 1019 | it("icon add with tooltip added in label", function() { |
828 | 1055 | var label = directive.find("label"); | 1020 | var label = directive.find("label"); |
829 | 1056 | var icon = label.find("i"); | 1021 | var icon = label.find("i"); |
835 | 1057 | expect(label.text()).toBe("key "); | 1022 | var tooltip = directive.find("span"); |
836 | 1058 | expect(icon.hasClass("icon")).toBe(true); | 1023 | var tooltipMessage = directive.find(".p-tooltip__message"); |
837 | 1059 | expect(icon.hasClass("icon--info")).toBe(true); | 1024 | expect(label.text()).toContain("key"); |
838 | 1060 | expect(icon.hasClass("tooltip")).toBe(true); | 1025 | expect(icon.hasClass("p-icon--information")).toBe(true); |
839 | 1061 | expect(icon.attr('aria-label')).toBe("My Info"); | 1026 | expect(tooltip.hasClass("p-tooltip")).toBe(true); |
840 | 1027 | expect(tooltipMessage.text()).toBe("My Info"); | ||
841 | 1062 | }); | 1028 | }); |
842 | 1063 | 1029 | ||
843 | 1064 | it('should call preventDefault on click', function() { | 1030 | it('should call preventDefault on click', function() { |
Thank you for fixing these tests.