Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 578bdf3

Browse files
committed
Fix WorkingSetView test based on review feedback.
1 parent c931ef2 commit 578bdf3

3 files changed

Lines changed: 31 additions & 14 deletions

File tree

test/spec/ProjectManager-test.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
26-
/*global $, define, describe, it, expect, afterEach, waitsFor, runs, waitsForDone, beforeFirst, afterLast */
26+
/*global $, define, describe, it, expect, afterEach, waitsFor, runs, waitsForDone, beforeFirst, afterLast, waitsForTime */
2727

2828
define(function (require, exports, module) {
2929
"use strict";
@@ -373,13 +373,7 @@ define(function (require, exports, module) {
373373
* we'll need to wait for the next render.
374374
*/
375375
function waitForRenderDebounce() {
376-
runs(function () {
377-
var d = new $.Deferred();
378-
setTimeout(function () {
379-
d.resolve();
380-
}, ProjectManager._RENDER_DEBOUNCE_TIME);
381-
waitsForDone(d.promise());
382-
});
376+
waitsForTime(ProjectManager._RENDER_DEBOUNCE_TIME);
383377
}
384378

385379
it("should deselect after opening file not rendered in tree", function () {

test/spec/SpecRunnerUtils.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,23 @@ define(function (require, exports, module) {
195195
return promise.state() === "rejected";
196196
}, "failure " + operationName, timeout);
197197
};
198-
198+
199+
/**
200+
* Utility for *rare* situations in which a test needs to pause for a *known* amount of time.
201+
* Tests that sporadically fail due to timing issues can't really be fixed by this. This function
202+
* was created when a debounce delay was added to updating the project tree, so we have a specific,
203+
* known amount of time to pause for.
204+
*/
205+
window.waitsForTime = function (timeout) {
206+
runs(function () {
207+
var d = new $.Deferred();
208+
setTimeout(function () {
209+
d.resolve();
210+
}, timeout);
211+
waitsForDone(d.promise());
212+
});
213+
};
214+
199215
/**
200216
* Get or create a NativeFileSystem rooted at the system root.
201217
* @return {$.Promise} A promise resolved when the native file system is found or rejected when an error occurs.

test/spec/WorkingSetView-test.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

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

2828
define(function (require, exports, module) {
2929
"use strict";
@@ -33,6 +33,7 @@ define(function (require, exports, module) {
3333
DocumentManager, // Load from brackets.test
3434
FileViewController, // Load from brackets.test
3535
MainViewManager, // Load from brackets.test
36+
ProjectManager, // Load from brackets.test
3637
WorkingSetView,
3738
SpecRunnerUtils = require("spec/SpecRunnerUtils");
3839

@@ -74,6 +75,7 @@ define(function (require, exports, module) {
7475
FileViewController = testWindow.brackets.test.FileViewController;
7576
MainViewManager = testWindow.brackets.test.MainViewManager;
7677
WorkingSetView = testWindow.brackets.test.WorkingSetView;
78+
ProjectManager = testWindow.brackets.test.ProjectManager;
7779

7880
// Open a directory
7981
if (loadProject) {
@@ -254,17 +256,22 @@ define(function (require, exports, module) {
254256
});
255257

256258
it("should show the file in project tree when a file is being renamed", function () {
259+
var $ = testWindow.$;
260+
var secondItem = $(".open-files-container > ul").children().eq(1);
261+
var fileName = secondItem.text();
262+
257263
runs(function () {
258-
var $ = testWindow.$;
259-
var secondItem = $(".open-files-container > ul").children().eq(1);
260-
var fileName = secondItem.text();
261264
secondItem.trigger("click");
262265

263266
// Calling FILE_RENAME synchronously works fine here since the item is already visible in project file tree.
264267
// However, if the selected item is not already visible in the tree, this command will complete asynchronously.
265268
// In that case, waitsFor will be needed before continuing with the rest of the test.
266269
CommandManager.execute(Commands.FILE_RENAME);
267-
270+
});
271+
272+
waitsForTime(ProjectManager._RENDER_DEBOUNCE_TIME);
273+
274+
runs(function () {
268275
expect($("#project-files-container ul input").val()).toBe(fileName);
269276
});
270277
});

0 commit comments

Comments
 (0)