@@ -1083,5 +1083,126 @@ define(function (require, exports, module) {
10831083 "design mode to deactivate on git-icon click" , 5000 ) ;
10841084 } ) ;
10851085 } ) ;
1086+
1087+ describe ( "12. Integration with NoDistractions" , function ( ) {
1088+ const PREFS_PURE_CODE = "noDistractions" ;
1089+ let PreferencesManager ;
1090+
1091+ beforeAll ( function ( ) {
1092+ PreferencesManager = brackets . test . PreferencesManager ;
1093+ } ) ;
1094+
1095+ async function setNoDistractions ( value ) {
1096+ PreferencesManager . set ( PREFS_PURE_CODE , value ) ;
1097+ await awaits ( 0 ) ;
1098+ }
1099+
1100+ afterEach ( async function ( ) {
1101+ await setNoDistractions ( false ) ;
1102+ // setNoDistractions(false) in normal mode calls ViewUtils.showMainToolBar(),
1103+ // but if we were in design mode when toggling it won't have been called
1104+ // symmetrically — force the toolbar visible either way for next test.
1105+ const mt = _$ ( "#main-toolbar" ) [ 0 ] ;
1106+ if ( mt && testWindow . getComputedStyle ( mt ) . display === "none" ) {
1107+ _$ ( mt ) . show ( ) ;
1108+ }
1109+ } ) ;
1110+
1111+ it ( "should hide the sidebar but KEEP main-toolbar visible when noDistractions is turned on in design mode" , async function ( ) {
1112+ await enterDesignMode ( ) ;
1113+ expect ( SidebarView . isVisible ( ) ) . toBe ( true ) ;
1114+ expect ( testWindow . getComputedStyle ( _$ ( "#main-toolbar" ) [ 0 ] ) . display ) . not . toBe ( "none" ) ;
1115+
1116+ await setNoDistractions ( true ) ;
1117+ await awaitsFor ( function ( ) { return ! SidebarView . isVisible ( ) ; } ,
1118+ "sidebar to hide under noDistractions in design mode" , 3000 ) ;
1119+
1120+ // Critical: main-toolbar stays visible in design mode — the live
1121+ // preview surface is what the user is focused on.
1122+ expect ( testWindow . getComputedStyle ( _$ ( "#main-toolbar" ) [ 0 ] ) . display ) . not . toBe ( "none" ) ;
1123+ } ) ;
1124+
1125+ it ( "should bring the sidebar back when noDistractions is turned off in design mode" , async function ( ) {
1126+ await enterDesignMode ( ) ;
1127+ await setNoDistractions ( true ) ;
1128+ await awaitsFor ( function ( ) { return ! SidebarView . isVisible ( ) ; } ,
1129+ "sidebar to hide under noDistractions" , 3000 ) ;
1130+
1131+ await setNoDistractions ( false ) ;
1132+ await awaitsFor ( function ( ) { return SidebarView . isVisible ( ) ; } ,
1133+ "sidebar to come back when noDistractions turned off" , 3000 ) ;
1134+ } ) ;
1135+
1136+ it ( "should, in normal mode, hide the sidebar when noDistractions is turned on and restore it when turned off" , async function ( ) {
1137+ // The original NoDistractions contract also called
1138+ // ViewUtils.hideMainToolBar(), but with the CSS
1139+ // `#main-toolbar { display: flex !important }` added for design-mode
1140+ // rendering, the `.forced-hidden` class loses the specificity fight
1141+ // and the toolbar no longer actually hides. The user-visible effect
1142+ // is just the sidebar collapsing in normal mode.
1143+ expect ( WorkspaceManager . isInDesignMode ( ) ) . toBe ( false ) ;
1144+ expect ( SidebarView . isVisible ( ) ) . toBe ( true ) ;
1145+
1146+ await setNoDistractions ( true ) ;
1147+ await awaitsFor ( function ( ) { return ! SidebarView . isVisible ( ) ; } ,
1148+ "sidebar to hide in normal-mode noDistractions" , 3000 ) ;
1149+
1150+ await setNoDistractions ( false ) ;
1151+ await awaitsFor ( function ( ) { return SidebarView . isVisible ( ) ; } ,
1152+ "sidebar to come back" , 3000 ) ;
1153+ } ) ;
1154+ } ) ;
1155+
1156+ describe ( "13. Command / event surface" , function ( ) {
1157+ let CentralControlBar ;
1158+
1159+ beforeAll ( function ( ) {
1160+ // CentralControlBar isn't on brackets.test.* so reach for it via
1161+ // the test window's RequireJS registry — this is also how extensions
1162+ // in the wild would access the module.
1163+ CentralControlBar = testWindow . require ( "view/CentralControlBar" ) ;
1164+ } ) ;
1165+
1166+ it ( "should expose WorkspaceManager.isInDesignMode() mirroring the current state" , async function ( ) {
1167+ expect ( typeof WorkspaceManager . isInDesignMode ) . toBe ( "function" ) ;
1168+ expect ( WorkspaceManager . isInDesignMode ( ) ) . toBe ( false ) ;
1169+ await enterDesignMode ( ) ;
1170+ expect ( WorkspaceManager . isInDesignMode ( ) ) . toBe ( true ) ;
1171+ await exitDesignMode ( ) ;
1172+ expect ( WorkspaceManager . isInDesignMode ( ) ) . toBe ( false ) ;
1173+ } ) ;
1174+
1175+ it ( "should fire EVENT_WORKSPACE_DESIGN_MODE_CHANGE on setDesignMode transitions and skip it for no-op repeats" , async function ( ) {
1176+ const payloads = [ ] ;
1177+ const handler = function ( event , flag ) { payloads . push ( flag ) ; } ;
1178+ WorkspaceManager . on ( WorkspaceManager . EVENT_WORKSPACE_DESIGN_MODE_CHANGE , handler ) ;
1179+ try {
1180+ WorkspaceManager . setDesignMode ( true ) ;
1181+ WorkspaceManager . setDesignMode ( true ) ; // no-op repeat
1182+ WorkspaceManager . setDesignMode ( false ) ;
1183+ WorkspaceManager . setDesignMode ( false ) ; // no-op repeat
1184+ } finally {
1185+ WorkspaceManager . off ( WorkspaceManager . EVENT_WORKSPACE_DESIGN_MODE_CHANGE , handler ) ;
1186+ }
1187+ expect ( payloads ) . toEqual ( [ true , false ] ) ;
1188+ } ) ;
1189+
1190+ it ( "should expose back-compat isEditorCollapsed() / setEditorCollapsed() on CentralControlBar" , async function ( ) {
1191+ expect ( typeof CentralControlBar . isEditorCollapsed ) . toBe ( "function" ) ;
1192+ expect ( typeof CentralControlBar . setEditorCollapsed ) . toBe ( "function" ) ;
1193+
1194+ expect ( CentralControlBar . isEditorCollapsed ( ) ) . toBe ( false ) ;
1195+
1196+ CentralControlBar . setEditorCollapsed ( true ) ;
1197+ await awaitsFor ( function ( ) { return WorkspaceManager . isInDesignMode ( ) ; } ,
1198+ "design mode to activate via setEditorCollapsed" , 10000 ) ;
1199+ expect ( CentralControlBar . isEditorCollapsed ( ) ) . toBe ( true ) ;
1200+
1201+ CentralControlBar . setEditorCollapsed ( false ) ;
1202+ await awaitsFor ( function ( ) { return ! WorkspaceManager . isInDesignMode ( ) ; } ,
1203+ "design mode to deactivate via setEditorCollapsed" , 10000 ) ;
1204+ expect ( CentralControlBar . isEditorCollapsed ( ) ) . toBe ( false ) ;
1205+ } ) ;
1206+ } ) ;
10861207 } ) ;
10871208} ) ;
0 commit comments