@@ -334,5 +334,163 @@ define(function (require, exports, module) {
334334 expect ( $btn . attr ( "title" ) ) . toBe ( Strings . CCB_SWITCH_TO_DESIGN_MODE ) ;
335335 } ) ;
336336 } ) ;
337+
338+ describe ( "4. Enter design mode" , function ( ) {
339+ let WorkspaceManager ;
340+
341+ beforeAll ( function ( ) {
342+ WorkspaceManager = brackets . test . WorkspaceManager ;
343+ } ) ;
344+
345+ function _livePanel ( ) {
346+ return WorkspaceManager . getPanelForID &&
347+ WorkspaceManager . getPanelForID ( "live-preview-panel" ) ;
348+ }
349+
350+ async function _closeLivePreviewIfOpen ( ) {
351+ const lp = _livePanel ( ) ;
352+ if ( lp && lp . isVisible ( ) ) {
353+ CommandManager . execute ( Commands . FILE_LIVE_FILE_PREVIEW ) ;
354+ await awaitsFor ( function ( ) { return ! lp . isVisible ( ) ; } ,
355+ "live preview to close" , 5000 ) ;
356+ }
357+ }
358+
359+ async function _openLivePreview ( ) {
360+ const lp = _livePanel ( ) ;
361+ if ( lp && lp . isVisible ( ) ) {
362+ return ;
363+ }
364+ CommandManager . execute ( Commands . FILE_LIVE_FILE_PREVIEW ) ;
365+ await awaitsFor ( function ( ) {
366+ const p = _livePanel ( ) ;
367+ return p && p . isVisible ( ) ;
368+ } , "live preview to open" , 8000 ) ;
369+ }
370+
371+ async function _exitDesignMode ( ) {
372+ if ( ! WorkspaceManager . isInDesignMode ( ) ) {
373+ return ;
374+ }
375+ CommandManager . execute ( Commands . VIEW_TOGGLE_DESIGN_MODE ) ;
376+ await awaitsFor ( function ( ) { return ! WorkspaceManager . isInDesignMode ( ) ; } ,
377+ "design mode to deactivate" , 10000 ) ;
378+ }
379+
380+ beforeEach ( async function ( ) {
381+ // Every test starts from a clean baseline: no design mode, no LP.
382+ await _exitDesignMode ( ) ;
383+ await _closeLivePreviewIfOpen ( ) ;
384+ } ) ;
385+
386+ afterEach ( async function ( ) {
387+ await _exitDesignMode ( ) ;
388+ await _closeLivePreviewIfOpen ( ) ;
389+ } ) ;
390+
391+ it ( "should open Live Preview exactly once when the toggle is triggered with LP closed" , async function ( ) {
392+ expect ( _livePanel ( ) . isVisible ( ) ) . toBe ( false ) ;
393+
394+ CommandManager . execute ( Commands . VIEW_TOGGLE_DESIGN_MODE ) ;
395+ await awaitsFor ( function ( ) { return WorkspaceManager . isInDesignMode ( ) ; } ,
396+ "design mode to activate" , 10000 ) ;
397+
398+ // LP is now visible (the collapsed layout wrapped around it).
399+ expect ( _livePanel ( ) . isVisible ( ) ) . toBe ( true ) ;
400+ } ) ;
401+
402+ it ( "should preserve sidebar width and pin main-toolbar to innerWidth - sidebar - CCB when LP is already open" , async function ( ) {
403+ await _openLivePreview ( ) ;
404+
405+ SidebarView . resize ( 220 ) ;
406+ await awaitsFor ( function ( ) { return _$ ( "#sidebar" ) [ 0 ] . offsetWidth === 220 ; } ,
407+ "sidebar to settle at 220px" , 2000 ) ;
408+ const sidebarW = _$ ( "#sidebar" ) [ 0 ] . offsetWidth ;
409+
410+ CommandManager . execute ( Commands . VIEW_TOGGLE_DESIGN_MODE ) ;
411+ await awaitsFor ( function ( ) { return WorkspaceManager . isInDesignMode ( ) ; } ,
412+ "design mode to activate" , 10000 ) ;
413+
414+ // Sidebar width is preserved across the entry.
415+ expect ( _$ ( "#sidebar" ) [ 0 ] . offsetWidth ) . toBe ( sidebarW ) ;
416+
417+ const win = testWindow . innerWidth ;
418+ const expectedLeft = sidebarW + CCB_WIDTH ;
419+ const expectedWidth = win - sidebarW - CCB_WIDTH ;
420+
421+ const mtRect = _$ ( "#main-toolbar" ) [ 0 ] . getBoundingClientRect ( ) ;
422+ // Allow sub-pixel rounding.
423+ expect ( Math . abs ( mtRect . left - expectedLeft ) ) . toBeLessThan ( 2 ) ;
424+ expect ( Math . abs ( mtRect . width - expectedWidth ) ) . toBeLessThan ( 2 ) ;
425+
426+ // Editor area is effectively gone — content is hidden so the editor
427+ // isn't peeking through behind LP. (visibility: hidden is what the
428+ // user experiences regardless of how the layout pinned it.)
429+ expect ( testWindow . getComputedStyle ( _$ ( ".content" ) [ 0 ] ) . visibility ) . toBe ( "hidden" ) ;
430+ // Whatever border/padding remains, the content's visible interior is
431+ // far too small to show an editor.
432+ expect ( _$ ( ".content" ) [ 0 ] . offsetWidth ) . toBeLessThan ( 10 ) ;
433+ } ) ;
434+
435+ it ( "should restore the pre-collapse main-toolbar width after exit when LP was already open" , async function ( ) {
436+ await _openLivePreview ( ) ;
437+
438+ // Pick a toolbar width that won't be trimmed by the exit clamp.
439+ const targetToolbarW = 300 ;
440+ const iconsW = _$ ( "#plugin-icons-bar" ) . outerWidth ( ) ;
441+ WorkspaceManager . setPluginPanelWidth ( targetToolbarW - iconsW ) ;
442+ await awaitsFor ( function ( ) {
443+ return Math . abs ( _$ ( "#main-toolbar" ) . outerWidth ( ) - targetToolbarW ) < 2 ;
444+ } , "main-toolbar to settle at target width" , 3000 ) ;
445+
446+ const beforeWidth = _$ ( "#main-toolbar" ) . outerWidth ( ) ;
447+
448+ CommandManager . execute ( Commands . VIEW_TOGGLE_DESIGN_MODE ) ;
449+ await awaitsFor ( function ( ) { return WorkspaceManager . isInDesignMode ( ) ; } ,
450+ "design mode to activate" , 10000 ) ;
451+ await _exitDesignMode ( ) ;
452+
453+ // Toolbar is restored (within rounding tolerance) to its pre-collapse width.
454+ expect ( Math . abs ( _$ ( "#main-toolbar" ) . outerWidth ( ) - beforeWidth ) ) . toBeLessThan ( 3 ) ;
455+ } ) ;
456+
457+ it ( "should keep sidebar width stable across synthetic window resizes while in design mode" , async function ( ) {
458+ SidebarView . resize ( 200 ) ;
459+ await awaitsFor ( function ( ) { return _$ ( "#sidebar" ) [ 0 ] . offsetWidth === 200 ; } ,
460+ "sidebar to settle at 200px" , 2000 ) ;
461+
462+ CommandManager . execute ( Commands . VIEW_TOGGLE_DESIGN_MODE ) ;
463+ await awaitsFor ( function ( ) { return WorkspaceManager . isInDesignMode ( ) ; } ,
464+ "design mode to activate" , 10000 ) ;
465+
466+ const startWidth = _$ ( "#sidebar" ) [ 0 ] . offsetWidth ;
467+ for ( let i = 0 ; i < 10 ; i ++ ) {
468+ testWindow . dispatchEvent ( new testWindow . Event ( "resize" ) ) ;
469+ }
470+ await awaitsFor ( function ( ) { return true ; } , "a tick" , 100 ) ;
471+
472+ // The sidebar is pinned — Resizer.updateResizeLimits shouldn't shrink it.
473+ expect ( _$ ( "#sidebar" ) [ 0 ] . offsetWidth ) . toBe ( startWidth ) ;
474+ } ) ;
475+
476+ it ( "should not let the user resize main-toolbar by dragging its left-edge handle while in design mode" , async function ( ) {
477+ CommandManager . execute ( Commands . VIEW_TOGGLE_DESIGN_MODE ) ;
478+ await awaitsFor ( function ( ) { return WorkspaceManager . isInDesignMode ( ) ; } ,
479+ "design mode to activate" , 10000 ) ;
480+
481+ const beforeWidth = _$ ( "#main-toolbar" ) . outerWidth ( ) ;
482+ const resizer = _$ ( "#main-toolbar > .horz-resizer" ) [ 0 ] ;
483+ const rect = resizer . getBoundingClientRect ( ) ;
484+ const handleY = rect . top + rect . height / 2 ;
485+
486+ // Attempt to drag the toolbar resizer 200px to the left — in normal mode
487+ // this would widen the toolbar. In design mode the handle is hidden, so
488+ // the user can't actually land on it and the toolbar width is unchanged.
489+ await DragTestUtils . dragFromElement ( resizer , rect . left - 200 , handleY , testWindow ) ;
490+
491+ const afterWidth = _$ ( "#main-toolbar" ) . outerWidth ( ) ;
492+ expect ( Math . abs ( afterWidth - beforeWidth ) ) . toBeLessThan ( 2 ) ;
493+ } ) ;
494+ } ) ;
337495 } ) ;
338496} ) ;
0 commit comments