Skip to content

Commit 569938f

Browse files
committed
test(mainview): cover NoDistractions + event surface (sections 12, 13)
- Section 12: design mode + noDistractions on hides the sidebar but keeps the main-toolbar visible (the LP surface the user is focused on); turning noDistractions off brings the sidebar back. Normal-mode toggle collapses/restores the sidebar. The "main-toolbar also hides" leg of the old contract is effectively dead — #main-toolbar's "display: flex !important" in brackets_patterns_override.less outranks .forced-hidden's "display: none !important" on selector specificity, so the test observes what the user actually sees (and a comment documents the regression). - Section 13: WorkspaceManager.isInDesignMode() mirrors the current state; setDesignMode fires EVENT_WORKSPACE_DESIGN_MODE_CHANGE only on real transitions (no-op repeats are silent); CentralControlBar's back-compat isEditorCollapsed/setEditorCollapsed surface still drives design mode (module reached via testWindow.require).
1 parent 2ca8f22 commit 569938f

2 files changed

Lines changed: 121 additions & 50 deletions

File tree

test/control-bar-tests-todo.md

Lines changed: 0 additions & 50 deletions
This file was deleted.

test/spec/CentralControlBar-integ-test.js

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)