Skip to content

Commit 0919336

Browse files
committed
test: color preview prefer3ences change test
1 parent 9aeca87 commit 0919336

File tree

2 files changed

+121
-3
lines changed

2 files changed

+121
-3
lines changed

src/extensions/default/DebugCommands/MacroRunner.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ define(function (require, exports, module) {
5050
KeyEvent = brackets.getModule("utils/KeyEvent"),
5151
Commands = brackets.getModule("command/Commands"),
5252
FileSystem = brackets.getModule("filesystem/FileSystem"),
53+
MainViewManager = brackets.getModule("view/MainViewManager"),
5354
FileUtils = brackets.getModule("file/FileUtils"),
5455
PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
5556
Editor = brackets.getModule("editor/Editor"),
@@ -425,6 +426,14 @@ define(function (require, exports, module) {
425426
return PreferencesManager.get(key);
426427
}
427428

429+
// Helper function to get full path (reusing existing openFile logic)
430+
function _getFullPath(filePath) {
431+
if(filePath.startsWith('/')) {
432+
return filePath;
433+
}
434+
return path.join(ProjectManager.getProjectRoot().fullPath, filePath);
435+
}
436+
428437
const EDITING = {
429438
setEditorSpacing: function (useTabs, spaceOrTabCount, isAutoMode) {
430439
const activeEditor = EditorManager.getActiveEditor();
@@ -442,6 +451,85 @@ define(function (require, exports, module) {
442451
} else {
443452
Editor.Editor.setSpaceUnits(spaceOrTabCount, fullPath);
444453
}
454+
},
455+
/**
456+
* Split the editor pane vertically
457+
*/
458+
splitVertical: function() {
459+
CommandManager.execute(Commands.CMD_SPLITVIEW_VERTICAL);
460+
},
461+
462+
/**
463+
* Split the editor pane horizontally
464+
*/
465+
splitHorizontal: function() {
466+
CommandManager.execute(Commands.CMD_SPLITVIEW_HORIZONTAL);
467+
},
468+
469+
/**
470+
* Remove split pane and return to single pane view
471+
*/
472+
splitNone: function() {
473+
CommandManager.execute(Commands.CMD_SPLITVIEW_NONE);
474+
},
475+
/**
476+
* Gets the editor in the first pane (left/top)
477+
* @return {?Editor} The editor in first pane or null if not available
478+
*/
479+
getFirstPaneEditor: function() {
480+
return MainViewManager.getCurrentlyViewedEditor("first-pane");
481+
},
482+
483+
/**
484+
* Gets the editor in the second pane (right/bottom)
485+
* @return {?Editor} The editor in second pane or null if not available
486+
*/
487+
getSecondPaneEditor: function() {
488+
return MainViewManager.getCurrentlyViewedEditor("second-pane");
489+
},
490+
491+
/**
492+
* Checks if the view is currently split
493+
* @return {boolean} True if view is split, false otherwise
494+
*/
495+
isSplit: function() {
496+
return MainViewManager.getPaneCount() > 1;
497+
},
498+
/**
499+
* Opens a file in the first pane (left/top)
500+
* @param {string} filePath - Project relative or absolute file path
501+
* @returns {Promise} A promise that resolves when the file is opened
502+
*/
503+
openFileInFirstPane: function(filePath) {
504+
return jsPromise(CommandManager.execute(Commands.FILE_OPEN, {
505+
fullPath: _getFullPath(filePath),
506+
paneId: "first-pane"
507+
}));
508+
},
509+
510+
/**
511+
* Opens a file in the second pane (right/bottom)
512+
* @param {string} filePath - Project relative or absolute file path
513+
* @returns {Promise} A promise that resolves when the file is opened
514+
*/
515+
openFileInSecondPane: function(filePath) {
516+
return jsPromise(CommandManager.execute(Commands.FILE_OPEN, {
517+
fullPath: _getFullPath(filePath),
518+
paneId: "second-pane"
519+
}));
520+
},
521+
/**
522+
* Focus the first pane (left/top)
523+
*/
524+
focusFirstPane: function() {
525+
MainViewManager.setActivePaneId("first-pane");
526+
},
527+
528+
/**
529+
* Focus the second pane (right/bottom)
530+
*/
531+
focusSecondPane: function() {
532+
MainViewManager.setActivePaneId("second-pane");
445533
}
446534
};
447535

test/spec/Extn-CSSColorPreview-integ-test.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
*/
2121

22-
/*global describe, it, expect, beforeAll, afterAll, beforeEach, awaitsForDone, awaits, awaitsFor, path, jsPromise */
22+
/*global describe, it, beforeAll, afterAll*/
2323

2424
define(function (require, exports, module) {
2525

@@ -48,6 +48,7 @@ define(function (require, exports, module) {
4848

4949
afterAll(async function () {
5050
await __PR.closeAll();
51+
await __PR.EDITING.splitNone();
5152
testWindow = null;
5253
__PR = null;
5354
EditorManager = null;
@@ -277,8 +278,6 @@ define(function (require, exports, module) {
277278
_verifyExpectedColors(editor, [8, 11, 12, 13, 14, 15]);
278279
await __PR.closeFile();
279280
});
280-
281-
// todo test preference change, multi pane tests
282281
}
283282

284283
const htmlFiles = ["a.html", "a.htm", "a.xhtml", "a.php", "a.jsp", "a.jsx", "a.tsx"];
@@ -289,5 +288,36 @@ define(function (require, exports, module) {
289288
for (let cssFile of cssFiles){
290289
testFile("base.css", cssFile);
291290
}
291+
292+
it(`Changing preferences should enable or disable the color box`, async function () {
293+
const htmlText = await __PR.readTextFile("base.html");
294+
await __PR.writeTextFile("b.html", htmlText, true);
295+
await __PR.writeTextFile("c.html", htmlText, true);
296+
await __PR.EDITING.splitVertical();
297+
await __PR.EDITING.openFileInSecondPane("b.html");
298+
await __PR.EDITING.openFileInFirstPane("c.html");
299+
__PR.EDITING.focusFirstPane();
300+
let editor = EditorManager.getActiveEditor();
301+
__PR.validateEqual(editor.isGutterActive(GUTTER_NAME), true);
302+
validateSingleColor(editor, 8, "blue");
303+
304+
__PR.setPreference("colorPreview", false);
305+
__PR.validateEqual(editor.isGutterActive(GUTTER_NAME), false);
306+
validateNoColors(editor, 8);
307+
__PR.EDITING.focusSecondPane();
308+
editor = EditorManager.getActiveEditor();
309+
__PR.validateEqual(editor.isGutterActive(GUTTER_NAME), false);
310+
validateNoColors(editor, 8);
311+
312+
__PR.setPreference("colorPreview", true);
313+
__PR.validateEqual(editor.isGutterActive(GUTTER_NAME), true);
314+
validateSingleColor(editor, 8, "blue");
315+
__PR.EDITING.focusSecondPane();
316+
editor = EditorManager.getActiveEditor();
317+
__PR.validateEqual(editor.isGutterActive(GUTTER_NAME), true);
318+
validateSingleColor(editor, 8, "blue");
319+
320+
await __PR.closeFile();
321+
});
292322
});
293323
});

0 commit comments

Comments
 (0)