Merge lp:~bac/juju-gui/1083935 into lp:juju-gui/experimental

Proposed by Brad Crittenden
Status: Merged
Merged at revision: 294
Proposed branch: lp:~bac/juju-gui/1083935
Merge into: lp:juju-gui/experimental
Diff against target: 221 lines (+146/-7)
6 files modified
app/views/topology/mega.js (+4/-4)
app/views/topology/panzoom.js (+0/-1)
package.json (+1/-1)
test/index.html (+1/-0)
test/test_application_notifications.js (+2/-1)
test/test_panzoom.js (+138/-0)
To merge this branch: bzr merge lp:~bac/juju-gui/1083935
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+141135@code.launchpad.net

Description of the change

Add tests for panzoom.

Tests are added for panzoom. Due to agreed upon time-boxing, the testing is
not thorough but is a start. Another bug to complete the testing will be
filed.

https://codereview.appspot.com/7001047/

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

Reviewers: mp+141135_code.launchpad.net,

Message:
Please take a look.

Description:
Add tests for panzoom.

Tests are added for panzoom. Due to agreed upon time-boxing, the
testing is
not thorough but is a start. Another but to complete the testing will
be
filed.

https://code.launchpad.net/~bac/juju-gui/1083935/+merge/141135

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/7001047/

Affected files:
   A [revision details]
   M app/views/topology/mega.js
   M app/views/topology/panzoom.js
   M test/index.html
   M test/test_application_notifications.js
   A test/test_panzoom.js

Revision history for this message
Madison Scott-Clary (makyo) wrote :

Looks good, few minors, land otherwise.

In the past, we've been taking mocha's style pretty seriously and
treating the it function as the first word in a sentence. I know that
we may be changing testing frameworks soon, so it's up to you, but it
might be more readable to continue that with this package of tests
(i.e.: it('should set initial values').) It's a minor naming thing, and
I'm not too hung up on it, so if everyone else is cool with it, so am I
:)

https://codereview.appspot.com/7001047/

Revision history for this message
Gary Poster (gary) wrote :

Land with changes.

Hey Brad. Thank you. Looks good.

Actually, unrelated to your work, but new branches are broken right now
because of the new d3. Could you change packages.json to specify d3 in
this way?

"d3": "2.10.x"

I agree with Matt that it would be nice if you tried to make a sentence
with "it." I also agree that I'm kinda low on caring.

I wish you didn't have to redefine Y, but I'm guessing you did it for a
reason. Please at least try to change the async: false approach that
Kapil suggests for the "before" Y, and then delete the "beforeEach"
version, and see if that works. If not, land it.

Thanks

Gary

https://codereview.appspot.com/7001047/diff/1/test/test_panzoom.js
File test/test_panzoom.js (right):

https://codereview.appspot.com/7001047/diff/1/test/test_panzoom.js#newcode23
test/test_panzoom.js:23: Y = YUI(GlobalConfig).use(['node',
Why can't you just use the Y from before? This is a pattern I have not
seen before in our tests.

https://codereview.appspot.com/7001047/

Revision history for this message
Brad Crittenden (bac) wrote :

I'd just read this post by jml and thought I'd put it in practice,
neglecting the inherited style:

https://plus.google.com/115348217455779620753/posts/YA3ThKWhSAj

I've made the changes you request but perhaps we can bear this in mind
if we do change testing infrastructures so our descriptions can be more
precise.

https://codereview.appspot.com/7001047/

Revision history for this message
Brad Crittenden (bac) wrote :

The changes suggested by Matt and Gary have been incorporated, except
for the 'async': false suggestion. I found removing the async in
beforeEach() was unnecessary but it was required in before() regardless
of setting async:false. Perhaps I have missed something. Will clarify
before landing.

https://codereview.appspot.com/7001047/diff/1/test/test_panzoom.js
File test/test_panzoom.js (right):

https://codereview.appspot.com/7001047/diff/1/test/test_panzoom.js#newcode23
test/test_panzoom.js:23: Y = YUI(GlobalConfig).use(['node',
This was just plain dumb and has been removed.

https://codereview.appspot.com/7001047/

lp:~bac/juju-gui/1083935 updated
302. By Brad Crittenden

Fix mocha test names to conform, remove unneeded complexity in test setup.

Revision history for this message
Brad Crittenden (bac) wrote :
Revision history for this message
Gary Poster (gary) wrote :

Hey Brad. I'm out today as planned vacation, and I'm also unfortunately sick with fever. If you need another look from someone please ask around

Gary

On Jan 2, 2013, at 8:02 AM, <email address hidden> wrote:

> Please take a look.
>
> https://codereview.appspot.com/7001047/

Revision history for this message
Brad Crittenden (bac) wrote :

*** Submitted:

Add tests for panzoom.

Tests are added for panzoom. Due to agreed upon time-boxing, the
testing is
not thorough but is a start. Another bug to complete the testing will
be
filed.

R=matthew.scott, gary.poster
CC=
https://codereview.appspot.com/7001047

https://codereview.appspot.com/7001047/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'app/views/topology/mega.js'
--- app/views/topology/mega.js 2012-12-20 13:34:43 +0000
+++ app/views/topology/mega.js 2013-01-02 13:00:31 +0000
@@ -1289,12 +1289,12 @@
1289 },1289 },
12901290
1291 /*1291 /*
1292 * Actions to be called on clicking a service.1292 * Actions to be called on clicking a service.
1293 */1293 */
1294 service_click_actions: {1294 service_click_actions: {
1295 /*1295 /*
1296 * Default action: show or hide control panel.1296 * Default action: show or hide control panel.
1297 */1297 */
1298 toggleControlPanel: function(m, view, context) {1298 toggleControlPanel: function(m, view, context) {
1299 var container = view.get('container'),1299 var container = view.get('container'),
1300 cp = container.one('#service-menu');1300 cp = container.one('#service-menu');
13011301
=== modified file 'app/views/topology/panzoom.js'
--- app/views/topology/panzoom.js 2012-12-20 16:23:32 +0000
+++ app/views/topology/panzoom.js 2013-01-02 13:00:31 +0000
@@ -48,7 +48,6 @@
48 renderSlider: function() {48 renderSlider: function() {
49 var self = this,49 var self = this,
50 topo = this.get('component'),50 topo = this.get('component'),
51 contianer = topo.get('container'),
52 value = 100,51 value = 100,
53 currentScale = topo.get('scale');52 currentScale = topo.get('scale');
5453
5554
=== modified file 'package.json'
--- package.json 2012-12-11 04:11:39 +0000
+++ package.json 2013-01-02 13:00:31 +0000
@@ -15,7 +15,7 @@
15 "cryptojs": ">= 2.5.3"15 "cryptojs": ">= 2.5.3"
16 },16 },
17 "devDependencies": {17 "devDependencies": {
18 "d3": ">=2.10.1",18 "d3": "2.10.x",
19 "yui": ">=3.7.0",19 "yui": ">=3.7.0",
20 "mocha": "1.5.x",20 "mocha": "1.5.x",
21 "express": "3.x",21 "express": "3.x",
2222
=== modified file 'test/index.html'
--- test/index.html 2012-12-17 14:53:46 +0000
+++ test/index.html 2013-01-02 13:00:31 +0000
@@ -21,6 +21,7 @@
2121
22 <script src="test_d3_components.js"></script>22 <script src="test_d3_components.js"></script>
23 <script src="test_topology.js"></script>23 <script src="test_topology.js"></script>
24 <script src="test_panzoom.js"></script>
24 <script src="test_env.js"></script>25 <script src="test_env.js"></script>
25 <script src="test_model.js"></script>26 <script src="test_model.js"></script>
26 <script src="test_notifications.js"></script>27 <script src="test_notifications.js"></script>
2728
=== modified file 'test/test_application_notifications.js'
--- test/test_application_notifications.js 2012-12-13 11:44:57 +0000
+++ test/test_application_notifications.js 2013-01-02 13:00:31 +0000
@@ -4,7 +4,7 @@
4 var _setTimeout, _viewsHighlightRow, db, ERR_EV, juju, models, NO_OP,4 var _setTimeout, _viewsHighlightRow, db, ERR_EV, juju, models, NO_OP,
5 viewContainer, views, Y;5 viewContainer, views, Y;
66
7 before(function() {7 before(function(done) {
8 Y = YUI(GlobalConfig).use(['node',8 Y = YUI(GlobalConfig).use(['node',
9 'juju-models',9 'juju-models',
10 'juju-views',10 'juju-views',
@@ -16,6 +16,7 @@
16 juju = Y.namespace('juju');16 juju = Y.namespace('juju');
17 models = Y.namespace('juju.models');17 models = Y.namespace('juju.models');
18 views = Y.namespace('juju.views');18 views = Y.namespace('juju.views');
19 done();
19 });20 });
2021
21 ERR_EV = {22 ERR_EV = {
2223
=== added file 'test/test_panzoom.js'
--- test/test_panzoom.js 1970-01-01 00:00:00 +0000
+++ test/test_panzoom.js 2013-01-02 13:00:31 +0000
@@ -0,0 +1,138 @@
1'use strict';
2
3describe('pan zoom module', function() {
4 var db, juju, models, viewContainer, views, Y, pz, topo, vis;
5
6 before(function(done) {
7 Y = YUI(GlobalConfig).use(['node',
8 'juju-models',
9 'juju-views',
10 'juju-gui',
11 'juju-env',
12 'juju-tests-utils',
13 'node-event-simulate'],
14 function(Y) {
15 juju = Y.namespace('juju');
16 models = Y.namespace('juju.models');
17 views = Y.namespace('juju.views');
18 done();
19 });
20 });
21
22 beforeEach(function() {
23 viewContainer = Y.Node.create('<div />');
24 viewContainer.appendTo(Y.one('body'));
25 viewContainer.hide();
26 db = new models.Database();
27 var view = new views.environment({container: viewContainer, db: db});
28 view.render();
29 view.postRender();
30 pz = view.topo.modules.PanZoomModule;
31 topo = pz.get('component');
32 vis = topo.vis;
33 });
34
35 afterEach(function() {
36 viewContainer.remove(true);
37 });
38
39 it('should set initial values',
40 function() {
41 pz._translate.should.eql([0, 0]);
42 pz._scale.should.equal(1.0);
43 });
44
45 // Test the zoom handler calculations.
46 it('should handle fractional values properly in zoom scale',
47 function() {
48 // Floor is used so the scale will round down.
49 var evt = { scale: 0.609 };
50 var rescaleCalled = false;
51 pz.rescale = function() {
52 rescaleCalled = true;
53 };
54 pz.zoomHandler(evt);
55 pz.slider.get('value').should.equal(60);
56 assert.isTrue(rescaleCalled);
57 });
58
59 it('should have an upper limit on the slider',
60 function() {
61 var evt = { scale: 3.5 };
62 var rescaleCalled = false;
63 pz.rescale = function() {
64 rescaleCalled = true;
65 };
66 pz.zoomHandler(evt);
67 pz.slider.get('value').should.equal(200);
68 assert.isTrue(rescaleCalled);
69 });
70
71 it('should have a lower limint on the slider',
72 function() {
73 var evt = { scale: 0.18 };
74 var rescaleCalled = false;
75 pz.rescale = function() {
76 rescaleCalled = true;
77 };
78 pz.zoomHandler(evt);
79 pz.slider.get('value').should.equal(25);
80 assert.isTrue(rescaleCalled);
81 });
82
83 // Test the zoom calculations.
84 it('should handle fractional values within the limit for rescale',
85 function(done) {
86 // Floor is used so the scale will round down.
87 var evt =
88 { scale: 0.609,
89 translate: 't'};
90 var rescaled = false;
91 topo.once('rescaled', function() {
92 rescaled = true;
93 done();
94 });
95 pz.rescale(vis, evt);
96 pz._scale.should.equal(0.609);
97 var expected = 'translate(' + evt.translate + ') scale(0.609)';
98 vis.attr('transform').should.equal(expected);
99 assert.isTrue(rescaled);
100 });
101
102 it('should set an upper limit for rescale',
103 function(done) {
104 var evt =
105 { scale: 2.1,
106 translate: 'u'};
107 var rescaled = false;
108 topo.once('rescaled', function() {
109 rescaled = true;
110 done();
111 });
112 topo.set('scale', 2.0);
113 pz.rescale(vis, evt);
114 pz._scale.should.equal(2.0);
115 var expected = 'translate(' + evt.translate + ') scale(2)';
116 vis.attr('transform').should.equal(expected);
117 assert.isTrue(rescaled);
118 });
119
120 it('should set a lower limit for rescale',
121 function(done) {
122 var evt =
123 { scale: 0.2,
124 translate: 'v'};
125 var rescaled = false;
126 topo.once('rescaled', function() {
127 rescaled = true;
128 done();
129 });
130 topo.set('scale', 0.25);
131 pz.rescale(vis, evt);
132 pz._scale.should.equal(0.25);
133 var expected = 'translate(' + evt.translate + ') scale(0.25)';
134 vis.attr('transform').should.equal(expected);
135 assert.isTrue(rescaled);
136 });
137
138});

Subscribers

People subscribed via source and target branches