|
19 | 19 | * |
20 | 20 | */ |
21 | 21 |
|
22 | | -/*global describe, beforeEach, beforeAll, afterAll, it, expect, awaitsForDone, spyOn, jasmine, awaitsFor */ |
| 22 | +/*global describe, beforeEach, beforeAll, afterAll, afterEach, it, expect, awaitsForDone, spyOn, jasmine, awaitsFor */ |
23 | 23 |
|
24 | 24 | define(function (require, exports, module) { |
25 | 25 |
|
@@ -1139,5 +1139,105 @@ define(function (require, exports, module) { |
1139 | 1139 | panel2.registerCanBeShownHandler(null); |
1140 | 1140 | }); |
1141 | 1141 | }); |
| 1142 | + |
| 1143 | + describe("setPluginPanelWidth", function () { |
| 1144 | + let pluginPanel, $toolbarIcon; |
| 1145 | + const MIN_WIDTH = 200; |
| 1146 | + |
| 1147 | + beforeAll(function () { |
| 1148 | + // Create a toolbar icon in #plugin-icons-bar |
| 1149 | + $toolbarIcon = _$('<a id="test-plugin-icon" href="#"></a>'); |
| 1150 | + _$("#plugin-icons-bar").append($toolbarIcon); |
| 1151 | + |
| 1152 | + let panelTemplate = '<div id="test-plugin-panel">Test Panel</div>'; |
| 1153 | + pluginPanel = WorkspaceManager.createPluginPanel( |
| 1154 | + "test-setwidth-panel", _$(panelTemplate), MIN_WIDTH, $toolbarIcon |
| 1155 | + ); |
| 1156 | + }); |
| 1157 | + |
| 1158 | + afterAll(function () { |
| 1159 | + if (pluginPanel) { |
| 1160 | + pluginPanel.hide(); |
| 1161 | + } |
| 1162 | + $toolbarIcon.remove(); |
| 1163 | + }); |
| 1164 | + |
| 1165 | + afterEach(function () { |
| 1166 | + pluginPanel.hide(); |
| 1167 | + }); |
| 1168 | + |
| 1169 | + it("should be a no-op when no panel is visible", function () { |
| 1170 | + expect(pluginPanel.isVisible()).toBeFalse(); |
| 1171 | + var toolbarWidthBefore = _$("#main-toolbar").width(); |
| 1172 | + WorkspaceManager.setPluginPanelWidth(500); |
| 1173 | + var toolbarWidthAfter = _$("#main-toolbar").width(); |
| 1174 | + expect(toolbarWidthAfter).toEqual(toolbarWidthBefore); |
| 1175 | + }); |
| 1176 | + |
| 1177 | + it("should resize the panel to the specified width", function () { |
| 1178 | + pluginPanel.show(); |
| 1179 | + expect(pluginPanel.isVisible()).toBeTrue(); |
| 1180 | + |
| 1181 | + WorkspaceManager.setPluginPanelWidth(500); |
| 1182 | + |
| 1183 | + var $mainToolbar = _$("#main-toolbar"); |
| 1184 | + var $pluginIconsBar = _$("#plugin-icons-bar"); |
| 1185 | + var panelContentWidth = $mainToolbar.width() - $pluginIconsBar.outerWidth(); |
| 1186 | + expect(panelContentWidth).toEqual(500); |
| 1187 | + }); |
| 1188 | + |
| 1189 | + it("should clamp width to panel minWidth", function () { |
| 1190 | + pluginPanel.show(); |
| 1191 | + |
| 1192 | + // Request a width smaller than minWidth |
| 1193 | + WorkspaceManager.setPluginPanelWidth(50); |
| 1194 | + |
| 1195 | + var $mainToolbar = _$("#main-toolbar"); |
| 1196 | + var $pluginIconsBar = _$("#plugin-icons-bar"); |
| 1197 | + var panelContentWidth = $mainToolbar.width() - $pluginIconsBar.outerWidth(); |
| 1198 | + expect(panelContentWidth).toBeGreaterThanOrEqual(MIN_WIDTH); |
| 1199 | + }); |
| 1200 | + |
| 1201 | + it("should clamp width to max size (75% of window)", function () { |
| 1202 | + pluginPanel.show(); |
| 1203 | + |
| 1204 | + var maxContentWidth = (testWindow.innerWidth * 0.75) - |
| 1205 | + _$("#plugin-icons-bar").outerWidth(); |
| 1206 | + |
| 1207 | + // Request a width larger than max |
| 1208 | + WorkspaceManager.setPluginPanelWidth(testWindow.innerWidth); |
| 1209 | + |
| 1210 | + var $mainToolbar = _$("#main-toolbar"); |
| 1211 | + var $pluginIconsBar = _$("#plugin-icons-bar"); |
| 1212 | + var panelContentWidth = $mainToolbar.width() - $pluginIconsBar.outerWidth(); |
| 1213 | + expect(panelContentWidth).toBeLessThanOrEqual(maxContentWidth + 1); |
| 1214 | + }); |
| 1215 | + |
| 1216 | + it("should update $windowContent right offset to match toolbar width", function () { |
| 1217 | + pluginPanel.show(); |
| 1218 | + |
| 1219 | + WorkspaceManager.setPluginPanelWidth(600); |
| 1220 | + |
| 1221 | + var $mainToolbar = _$("#main-toolbar"); |
| 1222 | + var $windowContent = _$(".content"); |
| 1223 | + var toolbarWidth = $mainToolbar.width(); |
| 1224 | + var rightOffset = parseInt($windowContent.css("right"), 10); |
| 1225 | + expect(rightOffset).toEqual(toolbarWidth); |
| 1226 | + }); |
| 1227 | + |
| 1228 | + it("should handle multiple successive resizes", function () { |
| 1229 | + pluginPanel.show(); |
| 1230 | + |
| 1231 | + var widths = [300, 500, 400, 700]; |
| 1232 | + var $mainToolbar = _$("#main-toolbar"); |
| 1233 | + var $pluginIconsBar = _$("#plugin-icons-bar"); |
| 1234 | + |
| 1235 | + widths.forEach(function (targetWidth) { |
| 1236 | + WorkspaceManager.setPluginPanelWidth(targetWidth); |
| 1237 | + var panelContentWidth = $mainToolbar.width() - $pluginIconsBar.outerWidth(); |
| 1238 | + expect(panelContentWidth).toEqual(targetWidth); |
| 1239 | + }); |
| 1240 | + }); |
| 1241 | + }); |
1142 | 1242 | }); |
1143 | 1243 | }); |
0 commit comments