Merge ~ya-bo-ng/maas:enable-fix-js-tests into maas: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)
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
Blake Rouse (blake-rouse) wrote :

Thank you for fixing these tests.

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :
~ya-bo-ng/maas:enable-fix-js-tests updated
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
1diff --git a/src/maasserver/static/js/angular/directives/call_to_action.js b/src/maasserver/static/js/angular/directives/call_to_action.js
2index 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 'data-ng-click="shown=!shown"',
7 '>',
8 '{$ getTitle() $}',
9- '&nbsp;&nbsp;<i class="p-icon--chevron"></i>',
10+ '<i class="p-icon--chevron"></i>',
11 '</button>',
12 '<div class="p-contextual-menu__dropdown" ',
13 'id="cta-menu" ',
14diff --git a/src/maasserver/static/js/angular/directives/maas_obj_form.js b/src/maasserver/static/js/angular/directives/maas_obj_form.js
15index 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 },
20 transclude: true,
21 template: (
22- '<form class="form" data-ng-class="{saving: saving, ' +
23+ '<form class="p-form" data-ng-class="{saving: saving, ' +
24 '\'p-form--inline\': inline, ' +
25 '\'p-form--stacked\': tableForm}" ' +
26 'ng-transclude></form>'),
27@@ -963,7 +963,7 @@ angular.module('MAAS').directive('maasObjField', ['$compile',
28
29 // Called by controller to see if error is set on field.
30 scope.hasErrors = function() {
31- return inputElement.hasClass("has-error");
32+ return inputWrapper.hasClass("is-error");
33 };
34
35 // Subtle text element.
36diff --git a/src/maasserver/static/js/angular/directives/tests/test_accordion.js b/src/maasserver/static/js/angular/directives/tests/test_accordion.js
37index 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 var html = [
42 '<div>',
43 '<div class="maas-accordion">',
44- '<h4 class="maas-accordion-tab is-active">One</h4>',
45+ '<h4 class="maas-accordion-tab is-selected">One</h4>',
46 '<h4 class="maas-accordion-tab">Two</h4>',
47 '<h4 class="maas-accordion-tab">Three</h4>',
48 '</div>',
49@@ -46,23 +46,28 @@ describe("maasAccodion", function() {
50 tabs = directive.find('.maas-accordion-tab');
51 });
52
53- xit("sets a new active removing other actives", function() {
54+ it("sets a new selected and leaves others open", function() {
55 angular.element(tabs[1]).click();
56- expect(angular.element(tabs[0]).hasClass("is-active")).toBe(false);
57- expect(angular.element(tabs[1]).hasClass("is-active")).toBe(true);
58- expect(angular.element(tabs[2]).hasClass("is-active")).toBe(false);
59+ expect(angular.element(tabs[0]).hasClass("is-selected")).toBe(true);
60+ expect(angular.element(tabs[1]).hasClass("is-selected")).toBe(true);
61+ expect(angular.element(tabs[2]).hasClass("is-selected")).toBe(false);
62
63 angular.element(tabs[2]).click();
64- expect(angular.element(tabs[0]).hasClass("is-active")).toBe(false);
65- expect(angular.element(tabs[1]).hasClass("is-active")).toBe(false);
66- expect(angular.element(tabs[2]).hasClass("is-active")).toBe(true);
67+ expect(angular.element(tabs[0]).hasClass("is-selected")).toBe(true);
68+ expect(angular.element(tabs[1]).hasClass("is-selected")).toBe(true);
69+ expect(angular.element(tabs[2]).hasClass("is-selected")).toBe(true);
70 });
71
72- it("leaves current active if clicked", function() {
73+ it("closes a section when clicked and open", function() {
74+ angular.element(tabs[1]).click();
75+ expect(angular.element(tabs[0]).hasClass("is-selected")).toBe(true);
76+ expect(angular.element(tabs[1]).hasClass("is-selected")).toBe(true);
77+ expect(angular.element(tabs[2]).hasClass("is-selected")).toBe(false);
78+
79 angular.element(tabs[0]).click();
80- expect(angular.element(tabs[0]).hasClass("is-active")).toBe(true);
81- expect(angular.element(tabs[1]).hasClass("is-active")).toBe(false);
82- expect(angular.element(tabs[2]).hasClass("is-active")).toBe(false);
83+ expect(angular.element(tabs[0]).hasClass("is-selected")).toBe(false);
84+ expect(angular.element(tabs[1]).hasClass("is-selected")).toBe(true);
85+ expect(angular.element(tabs[2]).hasClass("is-selected")).toBe(false);
86 });
87
88 it("removes all click handlers on $destroy", function() {
89diff --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
90index 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 * Unit tests for Call-To-Action dropdown directive.
95 */
96
97-xdescribe("maasCta", function() {
98+describe("maasCta", function() {
99
100 // Load the MAAS module.
101 beforeEach(module("MAAS"));
102@@ -66,25 +66,26 @@ xdescribe("maasCta", function() {
103 it("sets default title to 'Take action'", function() {
104 var directive = compileDirective("items", "active");
105 expect(
106- directive.find("button.button-group__link").text())
107+ directive.find("button.p-contextual-menu__toggle").text())
108 .toBe("Take action");
109 });
110
111 it("sets default title to another name", function() {
112 var name = makeName("title");
113 var directive = compileDirective("items", "active", null, null, name);
114- expect(directive.find("button.button-group__link").text()).toBe(name);
115+ var selector = "button.p-contextual-menu__toggle";
116+ expect(directive.find(selector).text()).toBe(name);
117 });
118
119 it("click link sets shown to true", function() {
120 var directive = compileDirective("items", "active");
121- directive.find("button.button-group__link").click();
122+ directive.find("button.p-contextual-menu__toggle").click();
123 expect(directive.isolateScope().shown).toBe(true);
124 });
125
126 it("dropdown hidden when shown is false", function() {
127 var directive = compileDirective("items", "active");
128- var dropdown = directive.find("ul.button-group__dropdown");
129+ var dropdown = directive.find("div.p-contextual-menu__dropdown");
130 expect(dropdown.hasClass("ng-hide")).toBe(true);
131 });
132
133@@ -93,7 +94,7 @@ xdescribe("maasCta", function() {
134 directive.isolateScope().shown = true;
135 $scope.$digest();
136
137- var dropdown = directive.find("ul.button-group__dropdown");
138+ var dropdown = directive.find("div.p-contextual-menu__dropdown");
139 expect(dropdown.hasClass("ng-hide")).toBe(false);
140 });
141
142@@ -107,7 +108,7 @@ xdescribe("maasCta", function() {
143
144 it("dropdown list options", function() {
145 var directive = compileDirective("items", "active");
146- var links = directive.find("li.button-group__item > button");
147+ var links = directive.find("div.p-contextual-menu__dropdown > button");
148
149 var listItems = [];
150 angular.forEach(links, function(ele, i) {
151@@ -123,10 +124,10 @@ xdescribe("maasCta", function() {
152
153 it("dropdown select sets shown to false", function() {
154 var directive = compileDirective("items", "active");
155- var links = directive.find("li.button-group__item > button");
156+ var links = directive.find("div.p-contextual-menu__dropdown > button");
157
158 // Open the dropdown.
159- directive.find("button.button-group__link").click();
160+ directive.find("button.p-contextual-menu__toggle").click();
161 expect(directive.isolateScope().shown).toBe(true);
162
163 // Clicking a link should close the dropdown.
164@@ -136,7 +137,7 @@ xdescribe("maasCta", function() {
165
166 it("dropdown select sets model", function() {
167 var directive = compileDirective("items", "active");
168- var links = directive.find("li.button-group__item > button");
169+ var links = directive.find("div.p-contextual-menu__dropdown > button");
170
171 angular.element(links[0]).click();
172 expect(directive.scope().active).toBe($scope.items[0]);
173@@ -144,16 +145,16 @@ xdescribe("maasCta", function() {
174
175 it("dropdown select sets title", function() {
176 var directive = compileDirective("items", "active");
177- var links = directive.find("li.button-group__item > button");
178+ var links = directive.find("div.p-contextual-menu__dropdown > button");
179
180 angular.element(links[0]).click();
181- var title = directive.find("button.button-group__link").text();
182+ var title = directive.find("button.p-contextual-menu__toggle").text();
183 expect(title).toBe($scope.items[0].title);
184 });
185
186 it("dropdown select sets secondary", function() {
187 var directive = compileDirective("items", "active");
188- var links = directive.find("li.button-group__item > button");
189+ var links = directive.find("div.p-contextual-menu__dropdown > button");
190
191 angular.element(links[0]).click();
192 expect(directive.isolateScope().secondary).toBe(true);
193@@ -162,7 +163,7 @@ xdescribe("maasCta", function() {
194 it("dropdown select sets selectedTitle", function() {
195 $scope.items[0].selectedTitle = "Different if Selected";
196 var directive = compileDirective("items", "active");
197- var links = directive.find("li.button-group__item > button");
198+ var links = directive.find("div.p-contextual-menu__dropdown > button");
199
200 var iscope = directive.isolateScope();
201 expect(iscope.getTitle()).toBe("Take action");
202@@ -173,7 +174,7 @@ xdescribe("maasCta", function() {
203 it("dropdown select sets other options' selectedTitle", function() {
204 $scope.items[1].selectedTitle = "Different if Selected";
205 var directive = compileDirective("items", "active");
206- var links = directive.find("li.button-group__item > button");
207+ var links = directive.find("div.p-contextual-menu__dropdown > button");
208
209 var iscope = directive.isolateScope();
210 expect(iscope.getTitle()).toBe("Take action");
211@@ -184,10 +185,10 @@ xdescribe("maasCta", function() {
212
213 it("clicking body will set shown to false", function() {
214 var directive = compileDirective("items", "active");
215- var links = directive.find("li.button-group__item > button");
216+ var links = directive.find("div.p-contextual-menu__dropdown > button");
217
218 // Open the dropdown.
219- directive.find("button.button-group__link").click();
220+ directive.find("button.p-contextual-menu__toggle").click();
221 expect(directive.isolateScope().shown).toBe(true);
222
223 // Click the body.
224@@ -203,10 +204,10 @@ xdescribe("maasCta", function() {
225 it("clicking button will fire ng-click", function() {
226 $scope.clicked = jasmine.createSpy("clicked");
227 var directive = compileDirective("items", "active", null, "clicked()");
228- var links = directive.find("li.button-group__item > button");
229+ var links = directive.find("div.p-contextual-menu__dropdown > button");
230
231 // Open the dropdown.
232- directive.find("button.button-group__link").click();
233+ directive.find("button.p-contextual-menu__toggle").click();
234 expect($scope.clicked).toHaveBeenCalled();
235 });
236 });
237diff --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
238index 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 * Unit tests for placeholder directive.
243 */
244
245-xdescribe("maasCodeLines", function() {
246+describe("maasCodeLines", function() {
247
248 // Load the MAAS module.
249 beforeEach(module("MAAS"));
250@@ -41,6 +41,6 @@ beforeEach(module("MAAS"));
251 };
252
253 var directive = compileDirective("getText()");
254- expect(directive.find('code').hasClass("code-block__line")).toBe(true);
255+ expect(directive.find('code span').hasClass("code-line")).toBe(true);
256 });
257 });
258diff --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
259index 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 return directive.find("div");
264 }
265
266- xit("sets serviceClass in the class for element", function() {
267+ it("sets serviceClass in the class for element", function() {
268 var directive = compileDirective();
269 var serviceClass = makeName("serviceClass");
270 directive.isolateScope().serviceClass = serviceClass;
271 $scope.$digest();
272 expect(
273- directive.find("span").hasClass("icon--" + serviceClass)).toBe(true);
274+ directive.find("span").hasClass("p-icon--" + serviceClass)
275+ ).toBe(true);
276 });
277
278 it("services is ServicesManager.getItems()", function() {
279diff --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
280index 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 * Unit tests for MAAS object form.
285 */
286
287-xdescribe("maasObjForm", function() {
288+describe("maasObjForm", function() {
289
290 // Load the MAAS module.
291 beforeEach(module("MAAS"));
292@@ -42,20 +42,10 @@ xdescribe("maasObjForm", function() {
293 $scope.$digest();
294 }
295
296- // Return the list of rendered errors on the field.
297- function getFieldErrorList(field) {
298- var errors = [];
299- var lis = field.siblings("ul.form__error").children();
300- lis.each(function() {
301- errors.push(angular.element(this).text());
302- });
303- return errors;
304- }
305-
306 // Return the list of rendered errors in the element.
307 function getErrorList(element) {
308 var errors = [];
309- var lis = element.find("ul.form__error").children();
310+ var lis = element.find("ul.p-list").children();
311 lis.each(function() {
312 errors.push(angular.element(this).text());
313 });
314@@ -64,7 +54,7 @@ xdescribe("maasObjForm", function() {
315
316 describe("inline form", function() {
317
318- it("adds 'form--inline'", function() {
319+ it("adds 'p-form--inline'", function() {
320 $scope.obj = {};
321 $scope.manager = {};
322 var html = [
323@@ -73,7 +63,7 @@ xdescribe("maasObjForm", function() {
324 ].join('');
325 var directive = compileDirective(html);
326 var form = directive.find("form");
327- expect(form.hasClass("form--inline")).toBe(true);
328+ expect(form.hasClass("p-form--inline")).toBe(true);
329 });
330 });
331
332@@ -89,8 +79,8 @@ xdescribe("maasObjForm", function() {
333 var html = [
334 '<maas-obj-form obj="obj" manager="manager">',
335 '<maas-obj-field type="text" key="key" label="Key" ',
336- 'placeholder="Placeholder" label-width="two" ',
337- 'input-width="three"></maas-obj-field>',
338+ 'placeholder="Placeholder" label-width="2" ',
339+ 'input-width="3"></maas-obj-field>',
340 '</maas-obj-form>'
341 ].join('');
342 directive = compileDirective(html);
343@@ -110,14 +100,13 @@ xdescribe("maasObjForm", function() {
344 it("adds label with width", function() {
345 var labelField = angular.element(directive.find("label"));
346 expect(labelField.text()).toBe("Key");
347- expect(labelField.hasClass("two-col")).toBe(true);
348+ expect(labelField.hasClass("col-2")).toBe(true);
349 });
350
351 it("adds inputWrapper with width", function() {
352 var labelField = angular.element(directive.find("label "));
353 var inputWrapper = angular.element(labelField.next("div"));
354- expect(inputWrapper.hasClass("three-col")).toBe(true);
355- expect(inputWrapper.hasClass("last-col")).toBe(true);
356+ expect(inputWrapper.hasClass("col-3")).toBe(true);
357 });
358
359 it("reverts value on esc", function() {
360@@ -137,9 +126,9 @@ xdescribe("maasObjForm", function() {
361 expect($scope.obj.$maasForm).toBeDefined();
362 });
363
364- it("hasErrors returns true if has-error class exists", function() {
365- var inputField = angular.element(directive.find("#key"));
366- inputField.addClass('has-error');
367+ it("hasErrors returns true if is-error class exists", function() {
368+ var control = angular.element(directive.find('.p-form__control'));
369+ control.addClass('is-error');
370 expect($scope.obj.$maasForm.hasErrors()).toBe(true);
371 });
372 });
373@@ -153,8 +142,8 @@ xdescribe("maasObjForm", function() {
374 var html = [
375 '<maas-obj-form obj="obj" manager="manager">',
376 '<maas-obj-field type="textarea" key="key" label="Key" ',
377- 'placeholder="Placeholder" label-width="two" ',
378- 'input-width="three"></maas-obj-field>',
379+ 'placeholder="Placeholder" label-width="2" ',
380+ 'input-width="3"></maas-obj-field>',
381 '</maas-obj-form>'
382 ].join('');
383 directive = compileDirective(html);
384@@ -173,14 +162,13 @@ xdescribe("maasObjForm", function() {
385 it("adds label with width", function() {
386 var labelField = angular.element(directive.find("label"));
387 expect(labelField.text()).toBe("Key");
388- expect(labelField.hasClass("two-col")).toBe(true);
389+ expect(labelField.hasClass("col-2")).toBe(true);
390 });
391
392 it("adds inputWrapper with width", function() {
393 var labelField = angular.element(directive.find("label "));
394 var inputWrapper = angular.element(labelField.next("div"));
395- expect(inputWrapper.hasClass("three-col")).toBe(true);
396- expect(inputWrapper.hasClass("last-col")).toBe(true);
397+ expect(inputWrapper.hasClass("col-3")).toBe(true);
398 });
399 });
400
401@@ -196,8 +184,8 @@ xdescribe("maasObjForm", function() {
402 var html = [
403 '<maas-obj-form obj="obj" manager="manager">',
404 '<maas-obj-field type="password" key="key" label="Key" ',
405- 'placeholder="Placeholder" label-width="two" ',
406- 'input-width="three"></maas-obj-field>',
407+ 'placeholder="Placeholder" label-width="2" ',
408+ 'input-width="3"></maas-obj-field>',
409 '</maas-obj-form>'
410 ].join('');
411 directive = compileDirective(html);
412@@ -217,14 +205,13 @@ xdescribe("maasObjForm", function() {
413 it("adds label with width", function() {
414 var labelField = angular.element(directive.find("label"));
415 expect(labelField.text()).toBe("Key");
416- expect(labelField.hasClass("two-col")).toBe(true);
417+ expect(labelField.hasClass("col-2")).toBe(true);
418 });
419
420 it("adds inputWrapper with width", function() {
421 var labelField = angular.element(directive.find("label "));
422 var inputWrapper = angular.element(labelField.next("div"));
423- expect(inputWrapper.hasClass("three-col")).toBe(true);
424- expect(inputWrapper.hasClass("last-col")).toBe(true);
425+ expect(inputWrapper.hasClass("col-3")).toBe(true);
426 });
427
428 it("reverts value on esc", function() {
429@@ -245,8 +232,8 @@ xdescribe("maasObjForm", function() {
430 });
431
432 it("hasErrors returns true if has-error class exists", function() {
433- var inputField = angular.element(directive.find("#key"));
434- inputField.addClass('has-error');
435+ var control = angular.element(directive.find('.p-form__control'));
436+ control.addClass('is-error');
437 expect($scope.obj.$maasForm.hasErrors()).toBe(true);
438 });
439 });
440@@ -265,8 +252,8 @@ xdescribe("maasObjForm", function() {
441 var html = [
442 '<maas-obj-form obj="obj" manager="manager">',
443 '<maas-obj-field type="options" key="key" label="Key" ',
444- 'placeholder="Placeholder" label-width="two" ',
445- 'input-width="three" options="' + options + '">',
446+ 'placeholder="Placeholder" label-width="2" ',
447+ 'input-width="3" options="' + options + '">',
448 '</maas-obj-field>',
449 '</maas-obj-form>'
450 ].join('');
451@@ -304,14 +291,13 @@ xdescribe("maasObjForm", function() {
452 it("adds label with width", function() {
453 var labelField = angular.element(directive.find("label"));
454 expect(labelField.text()).toBe("Key");
455- expect(labelField.hasClass("two-col")).toBe(true);
456+ expect(labelField.hasClass("col-2")).toBe(true);
457 });
458
459 it("adds inputWrapper with width", function() {
460 var labelField = angular.element(directive.find("label "));
461 var inputWrapper = angular.element(labelField.next("div"));
462- expect(inputWrapper.hasClass("three-col")).toBe(true);
463- expect(inputWrapper.hasClass("last-col")).toBe(true);
464+ expect(inputWrapper.hasClass("col-3")).toBe(true);
465 });
466
467 it("calls on-change function", function() {
468@@ -332,13 +318,13 @@ xdescribe("maasObjForm", function() {
469 var html = [
470 '<maas-obj-form obj="obj" manager="manager">',
471 '<maas-obj-field type="options" key="key" label="Key" ',
472- 'placeholder="Placeholder" label-width="two" ',
473+ 'placeholder="Placeholder" label-width="2" ',
474 'on-change="changeForm" ',
475- 'input-width="three" options="' + options + '">',
476+ 'input-width="3" options="' + options + '">',
477 '</maas-obj-field>',
478 '<maas-obj-field type="text" key="key2" label="Key2" ',
479- 'placeholder="" label-width="two" ',
480- 'input-width="three"',
481+ 'placeholder="" label-width="2" ',
482+ 'input-width="3"',
483 '</maas-obj-field>',
484 '</maas-obj-form>'
485 ].join('');
486@@ -365,7 +351,7 @@ xdescribe("maasObjForm", function() {
487 var html = [
488 '<maas-obj-form obj="obj" manager="manager">',
489 '<maas-obj-field type="checkboxes" key="key" label="Key" ',
490- 'label-width="two" input-width="three" ',
491+ 'label-width="2" input-width="3" ',
492 'values="values">',
493 '</maas-obj-field>',
494 '</maas-obj-form>'
495@@ -390,7 +376,7 @@ xdescribe("maasObjForm", function() {
496 var labelField = angular.element(
497 directive.find('label[for="key"]'));
498 expect(labelField.text()).toBe("Key");
499- expect(labelField.hasClass("two-col")).toBe(true);
500+ expect(labelField.hasClass("col-2")).toBe(true);
501 });
502 });
503
504@@ -405,7 +391,7 @@ xdescribe("maasObjForm", function() {
505 var html = [
506 '<maas-obj-form obj="obj" manager="manager">',
507 '<maas-obj-field type="tags" key="key" label="Key" ',
508- 'label-width="two" input-width="three">',
509+ 'label-width="2" input-width="3">',
510 '</maas-obj-field>',
511 '</maas-obj-form>'
512 ].join('');
513@@ -421,7 +407,7 @@ xdescribe("maasObjForm", function() {
514 var labelField = angular.element(
515 directive.find('label[for="key"]'));
516 expect(labelField.text()).toBe("Key");
517- expect(labelField.hasClass("two-col")).toBe(true);
518+ expect(labelField.hasClass("col-2")).toBe(true);
519 });
520 });
521
522@@ -436,7 +422,7 @@ xdescribe("maasObjForm", function() {
523 var html = [
524 '<maas-obj-form obj="obj" manager="manager">',
525 '<maas-obj-field type="onoffswitch" key="key" label="Key" ',
526- 'label-width="two" input-width="three">',
527+ 'label-width="2" input-width="3">',
528 '</maas-obj-field>',
529 '</maas-obj-form>'
530 ].join('');
531@@ -444,21 +430,15 @@ xdescribe("maasObjForm", function() {
532 });
533
534 it("creates onoffswitch", function() {
535- var onoff = angular.element(directive.find("div.onoffswitch"));
536- var input = angular.element(
537- onoff.find("input.onoffswitch-checkbox"));
538- var label = angular.element(
539- onoff.find("label.onoffswitch-label u-no-margin--top"));
540+ var onoff = angular.element(directive.find("div.maas-p-switch"));
541 expect(onoff.length).toBe(1);
542- expect(input.length).toBe(1);
543- expect(label.length).toBe(1);
544 });
545
546 it("adds label with width", function() {
547 var labelField = angular.element(
548 directive.find('label[for="key"]'));
549 expect(labelField.text()).toBe("Key");
550- expect(labelField.hasClass("two-col")).toBe(true);
551+ expect(labelField.hasClass("col-2")).toBe(true);
552 });
553 });
554
555@@ -478,8 +458,8 @@ xdescribe("maasObjForm", function() {
556 var html = [
557 '<maas-obj-form obj="obj" manager="manager">',
558 '<maas-obj-field type="text" key="key" label="Key" ',
559- 'placeholder="Placeholder" label-width="two" ',
560- 'input-width="three"></maas-obj-field>',
561+ 'placeholder="Placeholder" label-width="2" ',
562+ 'input-width="3"></maas-obj-field>',
563 '</maas-obj-form>'
564 ].join('');
565 directive = compileDirective(html);
566@@ -558,18 +538,20 @@ xdescribe("maasObjForm", function() {
567
568 it("sets string error on field", function() {
569 var field = angular.element(directive.find("#key"));
570+ var control = angular.element(directive.find('.p-form__control'));
571 changeFieldValue(field, makeName("new_key"));
572
573 var error = makeName("error");
574 saveDefer.reject(error);
575 $scope.$digest();
576
577- var errorsList = getFieldErrorList(field);
578- expect(errorsList).toEqual([error]);
579+ var errorsList = getErrorList(control);
580+ expect(errorsList).toEqual(["Error: " + error]);
581 });
582
583 it("sets field error on field", function() {
584 var field = angular.element(directive.find("#key"));
585+ var control = angular.element(directive.find('.p-form__control'));
586 changeFieldValue(field, makeName("new_key"));
587
588 var error = makeName("error");
589@@ -578,13 +560,14 @@ xdescribe("maasObjForm", function() {
590 }));
591 $scope.$digest();
592
593- var errorsList = getFieldErrorList(field);
594- expect(errorsList).toEqual([error]);
595- expect(field.hasClass("has-error")).toBe(true);
596+ var errorsList = getErrorList(control);
597+ expect(errorsList).toEqual(["Error: " + error]);
598+ expect(control.hasClass("is-error")).toBe(true);
599 });
600
601 it("sets field error on another field", function() {
602 var field = angular.element(directive.find("#key"));
603+ var control = angular.element(directive.find('.p-form__control'));
604 changeFieldValue(field, makeName("new_key"));
605
606 var error = makeName("error");
607@@ -593,13 +576,14 @@ xdescribe("maasObjForm", function() {
608 }));
609 $scope.$digest();
610
611- var errorsList = getFieldErrorList(field);
612- expect(errorsList).toEqual(["otherKey: " + error]);
613- expect(field.hasClass("has-error")).toBe(true);
614+ var errorsList = getErrorList(control);
615+ expect(errorsList).toEqual(["Error: otherKey: " + error]);
616+ expect(control.hasClass("is-error")).toBe(true);
617 });
618
619 it("sets multiple errors on field", function() {
620 var field = angular.element(directive.find("#key"));
621+ var control = angular.element(directive.find('.p-form__control'));
622 changeFieldValue(field, makeName("new_key"));
623
624 var error1 = makeName("error");
625@@ -609,9 +593,9 @@ xdescribe("maasObjForm", function() {
626 }));
627 $scope.$digest();
628
629- var errorsList = getFieldErrorList(field);
630- expect(errorsList).toEqual([error1, error2]);
631- expect(field.hasClass("has-error")).toBe(true);
632+ var errList = getErrorList(control);
633+ expect(errList).toEqual(["Error: " + error1, "Error: " + error2]);
634+ expect(control.hasClass("is-error")).toBe(true);
635 });
636 });
637
638@@ -633,8 +617,8 @@ xdescribe("maasObjForm", function() {
639 '<maas-obj-form obj="obj" manager="manager" ',
640 'pre-process="process">',
641 '<maas-obj-field type="text" key="key" label="Key" ',
642- 'placeholder="Placeholder" label-width="two" ',
643- 'input-width="three"></maas-obj-field>',
644+ 'placeholder="Placeholder" label-width="2" ',
645+ 'input-width="3"></maas-obj-field>',
646 '</maas-obj-form>'
647 ].join('');
648 var directive = compileDirective(html);
649@@ -662,11 +646,11 @@ xdescribe("maasObjForm", function() {
650 var html = [
651 '<maas-obj-form obj="obj" manager="manager">',
652 '<maas-obj-field type="text" key="key1" label="Key1" ',
653- 'placeholder="Placeholder" label-width="two" ',
654- 'input-width="three"></maas-obj-field>',
655+ 'placeholder="Placeholder" label-width="2" ',
656+ 'input-width="3"></maas-obj-field>',
657 '<maas-obj-field type="text" key="key2" label="Key2" ',
658- 'placeholder="Placeholder" label-width="two" ',
659- 'input-width="three"></maas-obj-field>',
660+ 'placeholder="Placeholder" label-width="2" ',
661+ 'input-width="3"></maas-obj-field>',
662 '</maas-obj-form>'
663 ].join('');
664 directive = compileDirective(html);
665@@ -675,6 +659,10 @@ xdescribe("maasObjForm", function() {
666 it("sets field error on both fields", function() {
667 var field1 = angular.element(directive.find("#key1"));
668 var field2 = angular.element(directive.find("#key2"));
669+ var selector1 = "label[for='key1'] + .p-form__control";
670+ var selector2 = "label[for='key2'] + .p-form__control";
671+ var control1 = angular.element(directive.find(selector1));
672+ var control2 = angular.element(directive.find(selector2));
673 changeFieldValue(field1, makeName("new_key"));
674
675 var error1 = makeName("error");
676@@ -685,8 +673,8 @@ xdescribe("maasObjForm", function() {
677 }));
678 $scope.$digest();
679
680- expect(getFieldErrorList(field1)).toEqual([error1]);
681- expect(getFieldErrorList(field2)).toEqual([error2]);
682+ expect(getErrorList(control1)).toEqual(["Error: " + error1]);
683+ expect(getErrorList(control2)).toEqual(["Error: " + error2]);
684 });
685 });
686
687@@ -708,11 +696,11 @@ xdescribe("maasObjForm", function() {
688 '<maas-obj-form obj="obj" manager="manager">',
689 '<maas-obj-field-group>',
690 '<maas-obj-field type="text" key="key1" label="Key1" ',
691- 'placeholder="Placeholder" label-width="two" ',
692- 'input-width="three"></maas-obj-field>',
693+ 'placeholder="Placeholder" label-width="2" ',
694+ 'input-width="3"></maas-obj-field>',
695 '<maas-obj-field type="text" key="key2" label="Key2" ',
696- 'placeholder="Placeholder" label-width="two" ',
697- 'input-width="three"></maas-obj-field>',
698+ 'placeholder="Placeholder" label-width="2" ',
699+ 'input-width="3"></maas-obj-field>',
700 '</maas-obj-field-group>',
701 '</maas-obj-form>'
702 ].join('');
703@@ -795,11 +783,11 @@ xdescribe("maasObjForm", function() {
704 '<maas-obj-form obj="obj" manager="manager" ' +
705 'data-ng-disabled="disabled">',
706 '<maas-obj-field type="text" key="key" label="Key" ',
707- 'placeholder="Placeholder" label-width="two" ',
708- 'input-width="three"></maas-obj-field>',
709+ 'placeholder="Placeholder" label-width="2" ',
710+ 'input-width="3"></maas-obj-field>',
711 '<maas-obj-field type="options" key="key2" label="Key 2" ',
712- 'placeholder="Placeholder 2" label-width="two" ',
713- 'input-width="three" options="' + options + '">',
714+ 'placeholder="Placeholder 2" label-width="2" ',
715+ 'input-width="3" options="' + options + '">',
716 '</maas-obj-field>',
717 '</maas-obj-form>'
718 ].join('');
719@@ -839,8 +827,8 @@ xdescribe("maasObjForm", function() {
720 '<maas-obj-form obj="obj" manager="manager" ',
721 'after-save="saved">',
722 '<maas-obj-field type="text" key="key" label="Key" ',
723- 'placeholder="Placeholder" label-width="two" ',
724- 'input-width="three"></maas-obj-field>',
725+ 'placeholder="Placeholder" label-width="2" ',
726+ 'input-width="3"></maas-obj-field>',
727 '</maas-obj-form>'
728 ].join('');
729 var directive = compileDirective(html);
730@@ -867,40 +855,17 @@ xdescribe("maasObjForm", function() {
731 var html = [
732 '<maas-obj-form obj="obj" manager="manager">',
733 '<maas-obj-field type="text" key="key" label="Key" ',
734- 'placeholder="Placeholder" label-width="two" ',
735- 'input-width="three"></maas-obj-field>',
736- '</maas-obj-form>'
737- ].join('');
738- var directive = compileDirective(html);
739- var group = angular.element(
740- directive.find('maas-obj-field[key="key"]'));
741- var field = angular.element(directive.find("#key"));
742- expect(group.hasClass("form__group")).toBe(true);
743- expect(group.hasClass("form__group--subtle")).toBe(true);
744- expect(
745- field.parent("div").hasClass("form__group-input")).toBe(true);
746- });
747-
748- it("adds form__group classes without subtle", function() {
749- $scope.obj = {
750- key: makeName("key")
751- };
752- $scope.manager = {};
753- var html = [
754- '<maas-obj-form obj="obj" manager="manager">',
755- '<maas-obj-field type="text" key="key" label="Key" ',
756- 'placeholder="Placeholder" label-width="two" ',
757- 'input-width="three" subtle="false"></maas-obj-field>',
758+ 'placeholder="Placeholder" label-width="2" ',
759+ 'input-width="3"></maas-obj-field>',
760 '</maas-obj-form>'
761 ].join('');
762 var directive = compileDirective(html);
763 var group = angular.element(
764 directive.find('maas-obj-field[key="key"]'));
765 var field = angular.element(directive.find("#key"));
766- expect(group.hasClass("form__group")).toBe(true);
767- expect(group.hasClass("form__group--subtle")).toBe(false);
768+ expect(group.hasClass("p-form__group")).toBe(true);
769 expect(
770- field.parent("div").hasClass("form__group-input")).toBe(true);
771+ field.parent("div").hasClass("p-form__control")).toBe(true);
772 });
773 });
774
775@@ -920,8 +885,8 @@ xdescribe("maasObjForm", function() {
776 '<maas-obj-form obj="obj" manager="manager" ',
777 'save-on-blur="false">',
778 '<maas-obj-field type="text" key="key" label="Key" ',
779- 'placeholder="Placeholder" label-width="two" ',
780- 'input-width="three"></maas-obj-field>',
781+ 'placeholder="Placeholder" label-width="2" ',
782+ 'input-width="3"></maas-obj-field>',
783 '</maas-obj-form>'
784 ].join('');
785 var directive = compileDirective(html);
786@@ -947,8 +912,8 @@ xdescribe("maasObjForm", function() {
787 '<maas-obj-form obj="obj" manager="manager" ',
788 'save-on-blur="false">',
789 '<maas-obj-field type="text" key="key" label="Key" ',
790- 'placeholder="Placeholder" label-width="two" ',
791- 'input-width="three"></maas-obj-field>',
792+ 'placeholder="Placeholder" label-width="2" ',
793+ 'input-width="3"></maas-obj-field>',
794 '<button maas-obj-save></button>',
795 '</maas-obj-form>'
796 ].join('');
797@@ -981,14 +946,14 @@ xdescribe("maasObjForm", function() {
798 '<maas-obj-form obj="obj" manager="manager" ',
799 'save-on-blur="false">',
800 '<maas-obj-field type="text" key="key" label="Key" ',
801- 'placeholder="Placeholder" label-width="two" ',
802- 'input-width="three"></maas-obj-field>',
803+ 'placeholder="Placeholder" label-width="2" ',
804+ 'input-width="3"></maas-obj-field>',
805 '<maas-obj-errors></maas-obj-errors>',
806 '<button maas-obj-save></button>',
807 '</maas-obj-form>'
808 ].join('');
809 var directive = compileDirective(html);
810- var field = angular.element(directive.find("#key"));
811+ var field = angular.element(directive.find(".p-form__group"));
812 var errors = angular.element(directive.find("maas-obj-errors"));
813 var button = angular.element(directive.find("button"));
814
815@@ -1005,8 +970,8 @@ xdescribe("maasObjForm", function() {
816 $scope.$digest();
817
818 // Error is placed on the input and in the global section.
819- expect(getFieldErrorList(field)).toEqual([keyError]);
820- expect(getErrorList(errors)).toEqual([error]);
821+ expect(getErrorList(field)).toEqual(["Error: " + keyError]);
822+ expect(getErrorList(errors)).toEqual([' ' + error]);
823
824 // Has error returns true.
825 expect($scope.obj.$maasForm.hasErrors()).toBe(true);
826@@ -1054,11 +1019,12 @@ xdescribe("maasObjForm", function() {
827 it("icon add with tooltip added in label", function() {
828 var label = directive.find("label");
829 var icon = label.find("i");
830- expect(label.text()).toBe("key ");
831- expect(icon.hasClass("icon")).toBe(true);
832- expect(icon.hasClass("icon--info")).toBe(true);
833- expect(icon.hasClass("tooltip")).toBe(true);
834- expect(icon.attr('aria-label')).toBe("My Info");
835+ var tooltip = directive.find("span");
836+ var tooltipMessage = directive.find(".p-tooltip__message");
837+ expect(label.text()).toContain("key");
838+ expect(icon.hasClass("p-icon--information")).toBe(true);
839+ expect(tooltip.hasClass("p-tooltip")).toBe(true);
840+ expect(tooltipMessage.text()).toBe("My Info");
841 });
842
843 it('should call preventDefault on click', function() {

Subscribers

People subscribed via source and target branches