@@ -1237,5 +1237,102 @@ define(function (require, exports, module) {
12371237 expect ( maxSize ) . toBeLessThanOrEqual ( testWindow . innerWidth * 0.75 ) ;
12381238 } ) ;
12391239 } ) ;
1240+
1241+ describe ( "Plugin panel clamping on window resize" , function ( ) {
1242+ let pluginPanel , $toolbarIcon ;
1243+ const MIN_WIDTH = 200 ;
1244+
1245+ beforeAll ( function ( ) {
1246+ $toolbarIcon = _$ ( '<a id="test-clamp-icon" href="#"></a>' ) ;
1247+ _$ ( "#plugin-icons-bar" ) . append ( $toolbarIcon ) ;
1248+
1249+ let panelTemplate = '<div id="test-clamp-panel">Test Panel</div>' ;
1250+ pluginPanel = WorkspaceManager . createPluginPanel (
1251+ "test-clamp-panel" , _$ ( panelTemplate ) , MIN_WIDTH , $toolbarIcon
1252+ ) ;
1253+ } ) ;
1254+
1255+ afterAll ( function ( ) {
1256+ if ( pluginPanel ) {
1257+ pluginPanel . hide ( ) ;
1258+ }
1259+ $toolbarIcon . remove ( ) ;
1260+ } ) ;
1261+
1262+ afterEach ( function ( ) {
1263+ pluginPanel . hide ( ) ;
1264+ } ) ;
1265+
1266+ it ( "should clamp plugin panel when window resizes smaller" , function ( ) {
1267+ pluginPanel . show ( ) ;
1268+ WorkspaceManager . setPluginPanelWidth ( 600 ) ;
1269+
1270+ const $mainToolbar = _$ ( "#main-toolbar" ) ;
1271+ const widthBefore = $mainToolbar . width ( ) ;
1272+
1273+ // Simulate a narrow window resize
1274+ const sidebarWidth = _$ ( "#sidebar" ) . outerWidth ( ) || 0 ;
1275+ const maxAllowed = Math . min (
1276+ testWindow . innerWidth * 0.75 ,
1277+ testWindow . innerWidth - sidebarWidth - 100
1278+ ) ;
1279+
1280+ // Only expect clamping if the panel was wider than max
1281+ if ( widthBefore > maxAllowed ) {
1282+ testWindow . dispatchEvent ( new testWindow . Event ( "resize" ) ) ;
1283+ expect ( $mainToolbar . width ( ) ) . toBeLessThanOrEqual ( maxAllowed ) ;
1284+ } else {
1285+ // Panel fits, dispatch resize and verify it stays unchanged
1286+ testWindow . dispatchEvent ( new testWindow . Event ( "resize" ) ) ;
1287+ expect ( $mainToolbar . width ( ) ) . toEqual ( widthBefore ) ;
1288+ }
1289+ } ) ;
1290+
1291+ it ( "should not let toolbar disappear on window resize" , function ( ) {
1292+ pluginPanel . show ( ) ;
1293+
1294+ const $mainToolbar = _$ ( "#main-toolbar" ) ;
1295+ const $pluginIconsBar = _$ ( "#plugin-icons-bar" ) ;
1296+
1297+ testWindow . dispatchEvent ( new testWindow . Event ( "resize" ) ) ;
1298+
1299+ // Toolbar must remain at least as wide as the icons bar + panel minWidth
1300+ const minToolbarWidth = MIN_WIDTH + $pluginIconsBar . outerWidth ( ) ;
1301+ expect ( $mainToolbar . width ( ) ) . toBeGreaterThanOrEqual ( minToolbarWidth ) ;
1302+ } ) ;
1303+
1304+ it ( "should clamp panel width when shown after window was resized" , function ( ) {
1305+ // Panel is hidden; compute what the max toolbar width would be
1306+ const sidebarWidth = _$ ( "#sidebar" ) . outerWidth ( ) || 0 ;
1307+ const $pluginIconsBar = _$ ( "#plugin-icons-bar" ) ;
1308+ const maxToolbarWidth = Math . min (
1309+ testWindow . innerWidth * 0.75 ,
1310+ testWindow . innerWidth - sidebarWidth - 100
1311+ ) ;
1312+
1313+ // Now show the panel — it should be clamped to maxToolbarWidth
1314+ pluginPanel . show ( ) ;
1315+
1316+ const $mainToolbar = _$ ( "#main-toolbar" ) ;
1317+ expect ( $mainToolbar . width ( ) ) . toBeLessThanOrEqual ( maxToolbarWidth ) ;
1318+
1319+ // And content area should match
1320+ const $windowContent = _$ ( ".content" ) ;
1321+ const rightOffset = parseInt ( $windowContent . css ( "right" ) , 10 ) ;
1322+ expect ( rightOffset ) . toEqual ( $mainToolbar . width ( ) ) ;
1323+ } ) ;
1324+
1325+ it ( "should keep content right offset in sync after resize clamp" , function ( ) {
1326+ pluginPanel . show ( ) ;
1327+ WorkspaceManager . setPluginPanelWidth ( 600 ) ;
1328+
1329+ testWindow . dispatchEvent ( new testWindow . Event ( "resize" ) ) ;
1330+
1331+ const $mainToolbar = _$ ( "#main-toolbar" ) ;
1332+ const $windowContent = _$ ( ".content" ) ;
1333+ const rightOffset = parseInt ( $windowContent . css ( "right" ) , 10 ) ;
1334+ expect ( rightOffset ) . toEqual ( $mainToolbar . width ( ) ) ;
1335+ } ) ;
1336+ } ) ;
12401337 } ) ;
12411338} ) ;
0 commit comments