Skip to content

Commit 98e51ce

Browse files
committed
test(mainview): cover Toggle Design Mode command (section 3)
Adds a "3. Toggle Design Mode command" describe block that uses the real command + CCB click paths (no spies): asserts VIEW_TOGGLE_DESIGN_MODE flips WorkspaceManager.isInDesignMode(), Command.getChecked() mirrors the flag on entry and exit, clicking #ccbCollapseEditorBtn toggles design mode, and the icon (pen-nib svg ↔ fa-code) and title (CCB_SWITCH_TO_DESIGN_MODE ↔ CCB_SWITCH_TO_CODE_EDITOR) swap on state change. afterEach exits design mode and closes Live Preview so the baseline stays clean for later tests.
1 parent 3eef26e commit 98e51ce

2 files changed

Lines changed: 97 additions & 24 deletions

File tree

test/control-bar-tests-todo.md

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,11 @@ Keep this file updated as we add coverage; remove lines as suites land.
1111

1212
---
1313

14-
15-
## 2a. #show-in-file-tree button (sidebar)
16-
17-
- [ ] `#show-in-file-tree` is a child of `#project-files-header` and sits
18-
before `#collapse-folders` in DOM order. Title equals
19-
`Strings.CMD_SHOW_IN_TREE`.
20-
- [ ] Binoculars `<svg>` uses `fill="currentColor"` so the glyph tracks the
21-
sidebar text color.
22-
- [ ] Button is hidden by default (`opacity: 0`, `visibility: hidden`) and
23-
only shows on `#sidebar:hover`, matching the `#collapse-folders`
24-
affordance.
25-
- [ ] Clicking `#show-in-file-tree` executes `NAVIGATE_SHOW_IN_FILE_TREE`.
26-
27-
## 3. Toggle Design Mode command
28-
29-
- [ ] `Commands.VIEW_TOGGLE_DESIGN_MODE === "view.toggleDesignMode"` is
30-
registered at module load, visible via `CommandManager.get`.
31-
- [ ] Command's checked state mirrors `WorkspaceManager.isInDesignMode()` on
32-
both entry and exit.
33-
- [ ] Clicking `#ccbCollapseEditorBtn`toggles design mode
34-
- [ ] Icon swap: `pen-nib svg` (expanded) ↔ `fa-code` (design mode). Title
35-
swap: "Switch to desin mode" ↔ "Switch to Code Editor".(please see the exact string to check.)
36-
3714
## 4. Enter design mode
3815

3916
- [ ] With live preview closed: executing the toggle first opens LP (verify a
4017
single execution of `FILE_LIVE_FILE_PREVIEW`), then applies collapsed
41-
layout on its `.always()`.
18+
layout
4219
- [ ] With live preview open: sidebar width is preserved, `.content` goes to
4320
`width: 0`, `#main-toolbar` gets `left: sidebarW + 30`, `width:
4421
innerWidth - sidebarW - 30` with `!important`, `right: auto`.

test/spec/CentralControlBar-integ-test.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,5 +238,101 @@ define(function (require, exports, module) {
238238
expect(executed).toContain(Commands.NAVIGATE_SHOW_IN_FILE_TREE);
239239
});
240240
});
241+
242+
describe("3. Toggle Design Mode command", function () {
243+
let WorkspaceManager;
244+
245+
beforeAll(function () {
246+
WorkspaceManager = brackets.test.WorkspaceManager;
247+
});
248+
249+
async function _enterDesignMode() {
250+
CommandManager.execute(Commands.VIEW_TOGGLE_DESIGN_MODE);
251+
await awaitsFor(function () { return WorkspaceManager.isInDesignMode(); },
252+
"design mode to activate", 10000);
253+
}
254+
255+
async function _exitDesignMode() {
256+
if (!WorkspaceManager.isInDesignMode()) {
257+
return;
258+
}
259+
CommandManager.execute(Commands.VIEW_TOGGLE_DESIGN_MODE);
260+
await awaitsFor(function () { return !WorkspaceManager.isInDesignMode(); },
261+
"design mode to deactivate", 10000);
262+
}
263+
264+
afterEach(async function () {
265+
await _exitDesignMode();
266+
// The toggle opens Live Preview if it wasn't already open; close it so later
267+
// tests start from a clean baseline.
268+
const lp = WorkspaceManager.getPanelForID && WorkspaceManager.getPanelForID("live-preview-panel");
269+
if (lp && lp.isVisible()) {
270+
CommandManager.execute(Commands.FILE_LIVE_FILE_PREVIEW);
271+
await awaitsFor(function () { return !lp.isVisible(); },
272+
"live preview to close", 5000);
273+
}
274+
});
275+
276+
it("should execute VIEW_TOGGLE_DESIGN_MODE and flip isInDesignMode() from false to true and back", async function () {
277+
expect(WorkspaceManager.isInDesignMode()).toBe(false);
278+
279+
await _enterDesignMode();
280+
expect(WorkspaceManager.isInDesignMode()).toBe(true);
281+
282+
await _exitDesignMode();
283+
expect(WorkspaceManager.isInDesignMode()).toBe(false);
284+
});
285+
286+
it("should mirror Command.getChecked() against WorkspaceManager.isInDesignMode() on entry and exit", async function () {
287+
const cmd = CommandManager.get(Commands.VIEW_TOGGLE_DESIGN_MODE);
288+
expect(cmd).toBeDefined();
289+
290+
expect(!!cmd.getChecked()).toBe(false);
291+
expect(WorkspaceManager.isInDesignMode()).toBe(false);
292+
293+
await _enterDesignMode();
294+
expect(!!cmd.getChecked()).toBe(true);
295+
expect(WorkspaceManager.isInDesignMode()).toBe(true);
296+
297+
await _exitDesignMode();
298+
expect(!!cmd.getChecked()).toBe(false);
299+
expect(WorkspaceManager.isInDesignMode()).toBe(false);
300+
});
301+
302+
it("should toggle design mode when #ccbCollapseEditorBtn is clicked", async function () {
303+
expect(WorkspaceManager.isInDesignMode()).toBe(false);
304+
305+
_$("#ccbCollapseEditorBtn").trigger("click");
306+
await awaitsFor(function () { return WorkspaceManager.isInDesignMode(); },
307+
"design mode to activate from click", 10000);
308+
309+
_$("#ccbCollapseEditorBtn").trigger("click");
310+
await awaitsFor(function () { return !WorkspaceManager.isInDesignMode(); },
311+
"design mode to deactivate from click", 10000);
312+
});
313+
314+
it("should swap icon (pen-nib svg ↔ fa-code) and title on state change", async function () {
315+
const $btn = _$("#ccbCollapseEditorBtn");
316+
317+
// Expanded (not in design mode): svg pen-nib + "Switch to Design Mode".
318+
expect($btn.find("svg").length).toBe(1);
319+
expect($btn.find("i.fa-code").length).toBe(0);
320+
expect($btn.attr("title")).toBe(Strings.CCB_SWITCH_TO_DESIGN_MODE);
321+
322+
await _enterDesignMode();
323+
324+
// Design mode: <i class="fa-solid fa-code"> + "Switch to Code Editor".
325+
expect($btn.find("i.fa-code").length).toBe(1);
326+
expect($btn.find("svg").length).toBe(0);
327+
expect($btn.attr("title")).toBe(Strings.CCB_SWITCH_TO_CODE_EDITOR);
328+
329+
await _exitDesignMode();
330+
331+
// Back to expanded — svg restored, title restored.
332+
expect($btn.find("svg").length).toBe(1);
333+
expect($btn.find("i.fa-code").length).toBe(0);
334+
expect($btn.attr("title")).toBe(Strings.CCB_SWITCH_TO_DESIGN_MODE);
335+
});
336+
});
241337
});
242338
});

0 commit comments

Comments
 (0)