Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/project/ProjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@ define(function (require, exports, module) {
return null;
};

var _RENDER_DEBOUNCE_TIME = 100;

/**
* @private
*
Expand All @@ -621,6 +623,8 @@ define(function (require, exports, module) {
FileTreeView.render(fileTreeViewContainer, model._viewModel, projectRoot, actionCreator, forceRender, brackets.platform);
};

_renderTree = _.debounce(_renderTree, _RENDER_DEBOUNCE_TIME);

/**
* @private
*
Expand Down Expand Up @@ -1375,7 +1379,8 @@ define(function (require, exports, module) {


// Private API helpful in testing
exports._actionCreator = actionCreator;
exports._actionCreator = actionCreator;
exports._RENDER_DEBOUNCE_TIME = _RENDER_DEBOUNCE_TIME;

// Private API for use with SidebarView
exports._setFileTreeSelectionWidth = _setFileTreeSelectionWidth;
Expand Down
18 changes: 17 additions & 1 deletion test/spec/ProjectManager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, describe, it, expect, afterEach, waitsFor, runs, waitsForDone, beforeFirst, afterLast */
/*global define, describe, it, expect, afterEach, waitsFor, runs, waitsForDone, beforeFirst, afterLast, waits */

define(function (require, exports, module) {
"use strict";
Expand Down Expand Up @@ -367,6 +367,14 @@ define(function (require, exports, module) {
expect($selectedItem.text().trim()).toBe(name);
}
}

/**
* ProjectManager pauses between renders for performance reasons. For some tests,
* we'll need to wait for the next render.
*/
function waitForRenderDebounce() {
waits(ProjectManager._RENDER_DEBOUNCE_TIME);
}

it("should deselect after opening file not rendered in tree", function () {
var promise,
Expand All @@ -377,12 +385,14 @@ define(function (require, exports, module) {
promise = CommandManager.execute(Commands.FILE_OPEN, { fullPath: exposedFile });
waitsForDone(promise);
});
waitForRenderDebounce();
runs(function () {
expectSelected(exposedFile);

promise = CommandManager.execute(Commands.FILE_OPEN, { fullPath: unexposedFile });
waitsForDone(promise);
});
waitForRenderDebounce();
runs(function () {
expectSelected(null);
});
Expand Down Expand Up @@ -429,6 +439,7 @@ define(function (require, exports, module) {
promise = CommandManager.execute(Commands.FILE_OPEN, { fullPath: initialFile });
waitsForDone(promise);
});
waitForRenderDebounce();
runs(function () {
expectSelected(initialFile);
toggleFolder(folder, true); // open folder
Expand All @@ -437,13 +448,15 @@ define(function (require, exports, module) {
promise = CommandManager.execute(Commands.FILE_OPEN, { fullPath: fileInFolder });
waitsForDone(promise);
});
waitForRenderDebounce();
runs(function () {
expectSelected(fileInFolder);
toggleFolder(folder, false); // close folder
});
runs(function () {
toggleFolder(folder, true); // open folder again
});
waitForRenderDebounce();
runs(function () {
expectSelected(fileInFolder);
toggleFolder(folder, false); // close folder
Expand All @@ -460,6 +473,7 @@ define(function (require, exports, module) {
promise = CommandManager.execute(Commands.FILE_OPEN, { fullPath: initialFile });
waitsForDone(promise);
});
waitForRenderDebounce();
runs(function () {
expectSelected(initialFile);
toggleFolder(folder, true); // open folder
Expand All @@ -471,10 +485,12 @@ define(function (require, exports, module) {
promise = CommandManager.execute(Commands.FILE_OPEN, { fullPath: fileInFolder });
waitsForDone(promise);
});
waitForRenderDebounce();
runs(function () {
expectSelected(null);
toggleFolder(folder, true); // open folder again
});
waitForRenderDebounce();
runs(function () {
expectSelected(fileInFolder);
toggleFolder(folder, false); // close folder
Expand Down
17 changes: 12 additions & 5 deletions test/spec/WorkingSetView-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
/*global $, define, describe, it, xit, expect, beforeEach, afterEach, waitsFor, waitsForDone, runs, beforeFirst, afterLast */
/*global $, define, describe, it, xit, expect, beforeEach, afterEach, waitsFor, waitsForDone, runs, beforeFirst, afterLast, waits */

define(function (require, exports, module) {
"use strict";
Expand All @@ -33,6 +33,7 @@ define(function (require, exports, module) {
DocumentManager, // Load from brackets.test
FileViewController, // Load from brackets.test
MainViewManager, // Load from brackets.test
ProjectManager, // Load from brackets.test
WorkingSetView,
SpecRunnerUtils = require("spec/SpecRunnerUtils");

Expand Down Expand Up @@ -74,6 +75,7 @@ define(function (require, exports, module) {
FileViewController = testWindow.brackets.test.FileViewController;
MainViewManager = testWindow.brackets.test.MainViewManager;
WorkingSetView = testWindow.brackets.test.WorkingSetView;
ProjectManager = testWindow.brackets.test.ProjectManager;

// Open a directory
if (loadProject) {
Expand Down Expand Up @@ -254,17 +256,22 @@ define(function (require, exports, module) {
});

it("should show the file in project tree when a file is being renamed", function () {
var $ = testWindow.$;
var secondItem = $(".open-files-container > ul").children().eq(1);
var fileName = secondItem.text();

runs(function () {
var $ = testWindow.$;
var secondItem = $(".open-files-container > ul").children().eq(1);
var fileName = secondItem.text();
secondItem.trigger("click");

// Calling FILE_RENAME synchronously works fine here since the item is already visible in project file tree.
// However, if the selected item is not already visible in the tree, this command will complete asynchronously.
// In that case, waitsFor will be needed before continuing with the rest of the test.
CommandManager.execute(Commands.FILE_RENAME);

});

waits(ProjectManager._RENDER_DEBOUNCE_TIME);

runs(function () {
expect($("#project-files-container ul input").val()).toBe(fileName);
});
});
Expand Down