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
1=== modified file 'app/views/topology/mega.js'
2--- app/views/topology/mega.js 2012-12-20 13:34:43 +0000
3+++ app/views/topology/mega.js 2013-01-02 13:00:31 +0000
4@@ -1289,12 +1289,12 @@
5 },
6
7 /*
8- * Actions to be called on clicking a service.
9- */
10+ * Actions to be called on clicking a service.
11+ */
12 service_click_actions: {
13 /*
14- * Default action: show or hide control panel.
15- */
16+ * Default action: show or hide control panel.
17+ */
18 toggleControlPanel: function(m, view, context) {
19 var container = view.get('container'),
20 cp = container.one('#service-menu');
21
22=== modified file 'app/views/topology/panzoom.js'
23--- app/views/topology/panzoom.js 2012-12-20 16:23:32 +0000
24+++ app/views/topology/panzoom.js 2013-01-02 13:00:31 +0000
25@@ -48,7 +48,6 @@
26 renderSlider: function() {
27 var self = this,
28 topo = this.get('component'),
29- contianer = topo.get('container'),
30 value = 100,
31 currentScale = topo.get('scale');
32
33
34=== modified file 'package.json'
35--- package.json 2012-12-11 04:11:39 +0000
36+++ package.json 2013-01-02 13:00:31 +0000
37@@ -15,7 +15,7 @@
38 "cryptojs": ">= 2.5.3"
39 },
40 "devDependencies": {
41- "d3": ">=2.10.1",
42+ "d3": "2.10.x",
43 "yui": ">=3.7.0",
44 "mocha": "1.5.x",
45 "express": "3.x",
46
47=== modified file 'test/index.html'
48--- test/index.html 2012-12-17 14:53:46 +0000
49+++ test/index.html 2013-01-02 13:00:31 +0000
50@@ -21,6 +21,7 @@
51
52 <script src="test_d3_components.js"></script>
53 <script src="test_topology.js"></script>
54+ <script src="test_panzoom.js"></script>
55 <script src="test_env.js"></script>
56 <script src="test_model.js"></script>
57 <script src="test_notifications.js"></script>
58
59=== modified file 'test/test_application_notifications.js'
60--- test/test_application_notifications.js 2012-12-13 11:44:57 +0000
61+++ test/test_application_notifications.js 2013-01-02 13:00:31 +0000
62@@ -4,7 +4,7 @@
63 var _setTimeout, _viewsHighlightRow, db, ERR_EV, juju, models, NO_OP,
64 viewContainer, views, Y;
65
66- before(function() {
67+ before(function(done) {
68 Y = YUI(GlobalConfig).use(['node',
69 'juju-models',
70 'juju-views',
71@@ -16,6 +16,7 @@
72 juju = Y.namespace('juju');
73 models = Y.namespace('juju.models');
74 views = Y.namespace('juju.views');
75+ done();
76 });
77
78 ERR_EV = {
79
80=== added file 'test/test_panzoom.js'
81--- test/test_panzoom.js 1970-01-01 00:00:00 +0000
82+++ test/test_panzoom.js 2013-01-02 13:00:31 +0000
83@@ -0,0 +1,138 @@
84+'use strict';
85+
86+describe('pan zoom module', function() {
87+ var db, juju, models, viewContainer, views, Y, pz, topo, vis;
88+
89+ before(function(done) {
90+ Y = YUI(GlobalConfig).use(['node',
91+ 'juju-models',
92+ 'juju-views',
93+ 'juju-gui',
94+ 'juju-env',
95+ 'juju-tests-utils',
96+ 'node-event-simulate'],
97+ function(Y) {
98+ juju = Y.namespace('juju');
99+ models = Y.namespace('juju.models');
100+ views = Y.namespace('juju.views');
101+ done();
102+ });
103+ });
104+
105+ beforeEach(function() {
106+ viewContainer = Y.Node.create('<div />');
107+ viewContainer.appendTo(Y.one('body'));
108+ viewContainer.hide();
109+ db = new models.Database();
110+ var view = new views.environment({container: viewContainer, db: db});
111+ view.render();
112+ view.postRender();
113+ pz = view.topo.modules.PanZoomModule;
114+ topo = pz.get('component');
115+ vis = topo.vis;
116+ });
117+
118+ afterEach(function() {
119+ viewContainer.remove(true);
120+ });
121+
122+ it('should set initial values',
123+ function() {
124+ pz._translate.should.eql([0, 0]);
125+ pz._scale.should.equal(1.0);
126+ });
127+
128+ // Test the zoom handler calculations.
129+ it('should handle fractional values properly in zoom scale',
130+ function() {
131+ // Floor is used so the scale will round down.
132+ var evt = { scale: 0.609 };
133+ var rescaleCalled = false;
134+ pz.rescale = function() {
135+ rescaleCalled = true;
136+ };
137+ pz.zoomHandler(evt);
138+ pz.slider.get('value').should.equal(60);
139+ assert.isTrue(rescaleCalled);
140+ });
141+
142+ it('should have an upper limit on the slider',
143+ function() {
144+ var evt = { scale: 3.5 };
145+ var rescaleCalled = false;
146+ pz.rescale = function() {
147+ rescaleCalled = true;
148+ };
149+ pz.zoomHandler(evt);
150+ pz.slider.get('value').should.equal(200);
151+ assert.isTrue(rescaleCalled);
152+ });
153+
154+ it('should have a lower limint on the slider',
155+ function() {
156+ var evt = { scale: 0.18 };
157+ var rescaleCalled = false;
158+ pz.rescale = function() {
159+ rescaleCalled = true;
160+ };
161+ pz.zoomHandler(evt);
162+ pz.slider.get('value').should.equal(25);
163+ assert.isTrue(rescaleCalled);
164+ });
165+
166+ // Test the zoom calculations.
167+ it('should handle fractional values within the limit for rescale',
168+ function(done) {
169+ // Floor is used so the scale will round down.
170+ var evt =
171+ { scale: 0.609,
172+ translate: 't'};
173+ var rescaled = false;
174+ topo.once('rescaled', function() {
175+ rescaled = true;
176+ done();
177+ });
178+ pz.rescale(vis, evt);
179+ pz._scale.should.equal(0.609);
180+ var expected = 'translate(' + evt.translate + ') scale(0.609)';
181+ vis.attr('transform').should.equal(expected);
182+ assert.isTrue(rescaled);
183+ });
184+
185+ it('should set an upper limit for rescale',
186+ function(done) {
187+ var evt =
188+ { scale: 2.1,
189+ translate: 'u'};
190+ var rescaled = false;
191+ topo.once('rescaled', function() {
192+ rescaled = true;
193+ done();
194+ });
195+ topo.set('scale', 2.0);
196+ pz.rescale(vis, evt);
197+ pz._scale.should.equal(2.0);
198+ var expected = 'translate(' + evt.translate + ') scale(2)';
199+ vis.attr('transform').should.equal(expected);
200+ assert.isTrue(rescaled);
201+ });
202+
203+ it('should set a lower limit for rescale',
204+ function(done) {
205+ var evt =
206+ { scale: 0.2,
207+ translate: 'v'};
208+ var rescaled = false;
209+ topo.once('rescaled', function() {
210+ rescaled = true;
211+ done();
212+ });
213+ topo.set('scale', 0.25);
214+ pz.rescale(vis, evt);
215+ pz._scale.should.equal(0.25);
216+ var expected = 'translate(' + evt.translate + ') scale(0.25)';
217+ vis.attr('transform').should.equal(expected);
218+ assert.isTrue(rescaled);
219+ });
220+
221+});

Subscribers

People subscribed via source and target branches