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

Proposed by Brad Crittenden
Status: Merged
Merged at revision: 316
Proposed branch: lp:~bac/juju-gui/1083933
Merge into: lp:juju-gui/experimental
Diff against target: 140 lines (+87/-14)
3 files modified
app/views/topology/viewport.js (+1/-14)
test/index.html (+1/-0)
test/test_viewport_module.js (+85/-0)
To merge this branch: bzr merge lp:~bac/juju-gui/1083933
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+143120@code.launchpad.net

Description of the change

Add tests for new viewport module.

Add tests for the new module. Also removed an unused function. It looked
useful but I didn't think it should hang around if not called. Ben might have
had a plan for it.

https://codereview.appspot.com/7085057/

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

Reviewers: mp+143120_code.launchpad.net,

Message:
Please take a look.

Description:
Add tests for new viewport module.

Add tests for the new module. Also removed an unused function. It
looked
useful but I didn't think it should hang around if not called. Ben
might have
had a plan for it.

https://code.launchpad.net/~bac/juju-gui/1083933/+merge/143120

(do not edit description out of merge proposal)

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

Affected files:
   A [revision details]
   M app/views/topology/viewport.js
   M test/index.html
   A test/test_viewport_module.js

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

Land as is, thanks for the tests.

https://codereview.appspot.com/7085057/

lp:~bac/juju-gui/1083933 updated
318. By Brad Crittenden

Merge from trunk

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

*** Submitted:

Add tests for new viewport module.

Add tests for the new module. Also removed an unused function. It
looked
useful but I didn't think it should hang around if not called. Ben
might have
had a plan for it.

R=matthew.scott, benji
CC=
https://codereview.appspot.com/7085057

https://codereview.appspot.com/7085057/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/views/topology/viewport.js'
2--- app/views/topology/viewport.js 2013-01-08 17:52:24 +0000
3+++ app/views/topology/viewport.js 2013-01-14 20:14:21 +0000
4@@ -7,18 +7,6 @@
5 d3ns = Y.namespace('d3');
6
7 /**
8- * Utility function to get a number from a computed style.
9- * @method styleToNumber
10- */
11- function styleToNumber(selector, style, defaultSize) {
12- style = style || 'height';
13- defaultSize = defaultSize || 0;
14- return parseInt(Y.one(selector).getComputedStyle(style) || defaultSize,
15- 10);
16- }
17-
18-
19- /**
20 * @module topology-viewport
21 * @class ViewportModule
22 * @namespace views
23@@ -57,14 +45,13 @@
24 // smallest size we accept--no smaller or bigger--or else the
25 // presence or absence of scrollbars may affect our calculations
26 // incorrectly.
27- canvas.setStyles({height: 600, width: 800});
28+ canvas.setStyles({height: '600px', width: '800px'});
29 var dimensions = utils.getEffectiveViewportSize(true, 800, 600);
30 svg.setAttribute('width', dimensions.width);
31 svg.setAttribute('height', dimensions.height);
32 vis.attr('width', dimensions.width);
33 vis.attr('height', dimensions.height);
34
35-
36 zoomPlane.setAttribute('width', dimensions.width);
37 zoomPlane.setAttribute('height', dimensions.height);
38 canvas.setStyles({
39
40=== modified file 'test/index.html'
41--- test/index.html 2013-01-10 18:17:46 +0000
42+++ test/index.html 2013-01-14 20:14:21 +0000
43@@ -54,6 +54,7 @@
44 <script src="test_service_view.js"></script>
45 <script src="test_unit_view.js"></script>
46 <script src="test_utils.js"></script>
47+ <script src="test_viewport_module.js"></script>
48
49
50 <script>
51
52=== added file 'test/test_viewport_module.js'
53--- test/test_viewport_module.js 1970-01-01 00:00:00 +0000
54+++ test/test_viewport_module.js 2013-01-14 20:14:21 +0000
55@@ -0,0 +1,85 @@
56+'use strict';
57+
58+describe('viewport module', function() {
59+ var db, juju, models, viewContainer, views, Y, viewportModule;
60+ before(function(done) {
61+ Y = YUI(GlobalConfig).use(['node',
62+ 'juju-models',
63+ 'juju-views',
64+ 'juju-gui',
65+ 'juju-env',
66+ 'juju-tests-utils',
67+ 'node-event-simulate'],
68+ function(Y) {
69+ juju = Y.namespace('juju');
70+ models = Y.namespace('juju.models');
71+ views = Y.namespace('juju.views');
72+ done();
73+ });
74+ });
75+
76+ beforeEach(function() {
77+ viewContainer = Y.Node.create('<div />');
78+ viewContainer.appendTo(Y.one('body'));
79+ viewContainer.hide();
80+ db = new models.Database();
81+ var view = new views.environment(
82+ { container: viewContainer,
83+ db: db});
84+ view.render();
85+ view.rendered();
86+ viewportModule = view.topo.modules.ViewportModule;
87+ });
88+
89+ afterEach(function() {
90+ if (viewContainer) {
91+ viewContainer.remove(true);
92+ }
93+ });
94+
95+ it('should fire before and after events', function() {
96+ var topo = viewportModule.get('component');
97+ var events = [];
98+ topo.fire = function(e) {
99+ events.push(e);
100+ };
101+ viewportModule.resized();
102+ events.should.eql(
103+ ['beforePageSizeRecalculation',
104+ 'sizeChange',
105+ 'afterPageSizeRecalculation']);
106+ });
107+
108+ it('should set canvas dimensions', function() {
109+ var container = viewportModule.get('container');
110+ var canvas = container.one('.topology-canvas');
111+ // Initialize to absurd dimensions.
112+ canvas.setStyles({height: '60px', width: '80px'});
113+ viewportModule.resized();
114+ canvas.getStyle('width').should.equal('800px');
115+ canvas.getStyle('height').should.equal('600px');
116+ });
117+
118+ it('should set zoom plane dimensions', function() {
119+ var container = viewportModule.get('container');
120+ var zoomPlane = container.one('.zoom-plane');
121+ // Initialize to absurd dimensions.
122+ zoomPlane.setAttribute('width', 10);
123+ zoomPlane.setAttribute('height', 10);
124+ viewportModule.resized();
125+ zoomPlane.getAttribute('width').should.equal('800');
126+ zoomPlane.getAttribute('height').should.equal('600');
127+ });
128+
129+ it('should set svg dimensions', function() {
130+ var container = viewportModule.get('container');
131+ var svg = container.one('svg');
132+ // Initialize to absurd dimensions.
133+ svg.setAttribute('width', 10);
134+ svg.setAttribute('height', 10);
135+ viewportModule.resized();
136+ svg.getAttribute('width').should.equal('800');
137+ svg.getAttribute('height').should.equal('600');
138+ });
139+
140+});

Subscribers

People subscribed via source and target branches