OLD | NEW |
1 /* | 1 /* |
2 This file is part of the Juju GUI, which lets users view and manage Juju | 2 This file is part of the Juju GUI, which lets users view and manage Juju |
3 environments within a graphical interface (https://launchpad.net/juju-gui). | 3 environments within a graphical interface (https://launchpad.net/juju-gui). |
4 Copyright (C) 2012-2013 Canonical Ltd. | 4 Copyright (C) 2012-2013 Canonical Ltd. |
5 | 5 |
6 This program is free software: you can redistribute it and/or modify it under | 6 This program is free software: you can redistribute it and/or modify it under |
7 the terms of the GNU Affero General Public License version 3, as published by | 7 the terms of the GNU Affero General Public License version 3, as published by |
8 the Free Software Foundation. | 8 the Free Software Foundation. |
9 | 9 |
10 This program is distributed in the hope that it will be useful, but WITHOUT | 10 This program is distributed in the hope that it will be useful, but WITHOUT |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 view.resized(); | 88 view.resized(); |
89 events.should.eql( | 89 events.should.eql( |
90 ['beforePageSizeRecalculation', | 90 ['beforePageSizeRecalculation', |
91 'setAllTheDimensions called', | 91 'setAllTheDimensions called', |
92 'afterPageSizeRecalculation']); | 92 'afterPageSizeRecalculation']); |
93 }); | 93 }); |
94 }); | 94 }); |
95 | 95 |
96 describe('views.ViewportModule.setAllTheDimensions', function() { | 96 describe('views.ViewportModule.setAllTheDimensions', function() { |
97 var views, Y, testUtils, view, width, height, canvas, svg, topo, zoomPlane, | 97 var views, Y, testUtils, view, width, height, canvas, svg, topo, zoomPlane, |
98 eventFired; | 98 eventFired, dimentions; |
99 before(function(done) { | 99 before(function(done) { |
100 Y = YUI(GlobalConfig).use(['node', 'juju-views', 'juju-tests-utils'], | 100 Y = YUI(GlobalConfig).use(['node', 'juju-views', 'juju-tests-utils'], |
101 function(Y) { | 101 function(Y) { |
102 views = Y.namespace('juju.views'); | 102 views = Y.namespace('juju.views'); |
103 testUtils = Y.namespace('juju-tests').utils; | 103 testUtils = Y.namespace('juju-tests').utils; |
104 done(); | 104 done(); |
105 }); | 105 }); |
106 }); | 106 }); |
107 | 107 |
108 beforeEach(function() { | 108 beforeEach(function() { |
109 height = Math.floor(Math.random() * 1000); | 109 height = Math.floor(Math.random() * 1000); |
110 width = Math.floor(Math.random() * 1000); | 110 width = Math.floor(Math.random() * 1000); |
111 // Build test doubles that record height and width settings. | 111 // Build test doubles that record height and width settings. |
112 topo = { | 112 topo = { |
| 113 get: function() { |
| 114 return [width + 1, height + 1]; |
| 115 }, |
113 vis: {}, | 116 vis: {}, |
114 fire: function(evt) { | 117 fire: function(evt) { |
115 eventFired = evt; | 118 eventFired = evt; |
116 } | 119 } |
117 }; | 120 }; |
118 topo.set = testUtils.setter(topo); | 121 topo.set = testUtils.setter(topo); |
119 topo.vis.attr = testUtils.setter(topo.vis); | 122 topo.vis.attr = testUtils.setter(topo.vis); |
120 view = new views.ViewportModule(); | 123 view = new views.ViewportModule(); |
121 canvas = {style: {}}; | 124 canvas = {style: {}}; |
122 canvas.setStyles = function(styles) { | 125 canvas.setStyles = function(styles) { |
123 Y.mix(canvas.style, styles, true); | 126 Y.mix(canvas.style, styles, true); |
124 }; | 127 }; |
125 zoomPlane = {}; | 128 zoomPlane = {}; |
126 zoomPlane.setAttribute = testUtils.setter(zoomPlane); | 129 zoomPlane.setAttribute = testUtils.setter(zoomPlane); |
127 svg = {}; | 130 svg = {}; |
128 svg.setAttribute = testUtils.setter(svg); | 131 svg.setAttribute = testUtils.setter(svg); |
129 var dimentions = { | 132 dimentions = { |
130 height: height, | 133 height: height, |
131 width: width | 134 width: width |
132 }; | 135 }; |
133 // Since all of the tests inspect the output of setAllTheDimensions, we can | 136 // Since all of the tests inspect the output of setAllTheDimensions, we can |
134 // just call it here and the tests will just contain assertions. | 137 // just call it here and the tests will just contain assertions. |
135 view.setAllTheDimensions(dimentions, canvas, svg, topo, zoomPlane); | 138 view.setAllTheDimensions(dimentions, canvas, svg, topo, zoomPlane); |
136 }); | 139 }); |
137 | 140 |
138 it('should set canvas dimensions', function() { | 141 it('should set canvas dimensions', function() { |
139 assert.equal(canvas.style.width, width + 'px'); | 142 assert.equal(canvas.style.width, width + 'px'); |
(...skipping 15 matching lines...) Expand all Loading... |
155 }); | 158 }); |
156 | 159 |
157 it('should set topo.vis dimensions', function() { | 160 it('should set topo.vis dimensions', function() { |
158 assert.equal(topo.vis.width, width); | 161 assert.equal(topo.vis.width, width); |
159 assert.equal(topo.vis.height, height); | 162 assert.equal(topo.vis.height, height); |
160 }); | 163 }); |
161 | 164 |
162 it('should center canvas', function() { | 165 it('should center canvas', function() { |
163 assert.equal(eventFired, 'panToCenter'); | 166 assert.equal(eventFired, 'panToCenter'); |
164 }); | 167 }); |
| 168 |
| 169 it('should not center canvas if no changes', function() { |
| 170 topo.get = function() { |
| 171 return [width, height]; |
| 172 }; |
| 173 eventFired = false; |
| 174 view.setAllTheDimensions(dimentions, canvas, svg, topo, zoomPlane); |
| 175 assert.equal(eventFired, false); |
| 176 }); |
165 }); | 177 }); |
OLD | NEW |