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

Reuse test windows during integration suites #4618

Merged
merged 1 commit into from
Aug 1, 2013
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
36 changes: 36 additions & 0 deletions src/editor/CodeHintManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,41 @@ define(function (require, exports, module) {
});
}
}

/**
* @private
* Remove a code hint provider
* @param {!CodeHintProvider} provider Code hint provider to remove
* @param {(string|Array.<string>)=} targetLanguageId Optional set of
* language IDs for languages to remove the provider for. Defaults
* to all languages.
*/
function _removeHintProvider(provider, targetLanguageId) {
var languageId,
languages,
index,
providers,
targetLanguageIdArr;

if (Array.isArray(targetLanguageId)) {
targetLanguageIdArr = targetLanguageId;
} else if (targetLanguageId) {
targetLanguageIdArr = [targetLanguageId];
} else {
targetLanguageIdArr = Object.keys(hintProviders);
}

targetLanguageIdArr.forEach(function (languageId) {
providers = hintProviders[languageId];

for (index = 0; index < providers.length; index++) {
if (providers[index].provider === provider) {
providers.splice(index, 1);
break;
}
}
});
}

/**
* Return the array of hint providers for the given language id.
Expand Down Expand Up @@ -546,6 +581,7 @@ define(function (require, exports, module) {
CommandManager.register(Strings.CMD_SHOW_CODE_HINTS, Commands.SHOW_CODE_HINTS, _startNewSession);

exports._getCodeHintList = _getCodeHintList;
exports._removeHintProvider = _removeHintProvider;

// Define public API
exports.isOpen = isOpen;
Expand Down
31 changes: 20 additions & 11 deletions test/spec/CodeHint-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

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

define(function (require, exports, module) {
"use strict";
Expand Down Expand Up @@ -50,22 +50,21 @@ define(function (require, exports, module) {
* @param {!string} openFile Project relative file path to open in a main editor.
* @param {!number} openPos The pos within openFile to place the IP.
*/
var _initCodeHintTest = function (openFile, openPos) {

function initCodeHintTest(openFile, openPos) {
SpecRunnerUtils.loadProjectInTestWindow(testPath);

runs(function () {
var promise = SpecRunnerUtils.openProjectFiles([openFile]);
waitsForDone(promise);
});

runs(function () {
var editor = EditorManager.getCurrentFullEditor();
editor.setCursorPos(openPos.line, openPos.ch);
});
};

beforeEach(function () {
initCodeHintTest = _initCodeHintTest.bind(this);
}

beforeFirst(function () {
SpecRunnerUtils.createTestWindowAndRun(this, function (w) {
testWindow = w;

Expand All @@ -79,9 +78,8 @@ define(function (require, exports, module) {
KeyBindingManager = testWindow.brackets.test.KeyBindingManager;
});
});

afterEach(function () {
initCodeHintTest = null;

afterLast(function () {
testWindow = null;
CodeHintManager = null;
EditorManager = null;
Expand All @@ -90,6 +88,11 @@ define(function (require, exports, module) {
SpecRunnerUtils.closeTestWindow();
});

afterEach(function () {
runs(function () {
testWindow.closeAllFiles();
});
});

function invokeCodeHints() {
CommandManager.execute(Commands.SHOW_CODE_HINTS);
Expand All @@ -100,14 +103,14 @@ define(function (require, exports, module) {
var codeHintList = CodeHintManager._getCodeHintList();
expect(codeHintList).toBeFalsy();
}

function expectSomeHints() {
var codeHintList = CodeHintManager._getCodeHintList();
expect(codeHintList).toBeTruthy();
expect(codeHintList.isOpen()).toBe(true);
return codeHintList;
}


describe("Hint Provider Registration", function () {
beforeEach(function () {
initCodeHintTest("test1.html", {line: 0, ch: 0});
Expand Down Expand Up @@ -144,6 +147,8 @@ define(function (require, exports, module) {
runs(function () {
invokeCodeHints();
expectMockHints();

CodeHintManager._removeHintProvider(mockProvider, ["clojure"], 0);
});
});

Expand All @@ -156,6 +161,8 @@ define(function (require, exports, module) {
editor.setCursorPos(3, 1);
invokeCodeHints();
expectMockHints();

CodeHintManager._removeHintProvider(mockProvider, ["html"], 1);
});
});

Expand All @@ -174,6 +181,8 @@ define(function (require, exports, module) {
runs(function () {
invokeCodeHints();
expectMockHints();

CodeHintManager._removeHintProvider(mockProvider, ["all"], 0);
});
});
});
Expand Down
8 changes: 7 additions & 1 deletion test/spec/DocumentCommandHandlers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ define(function (require, exports, module) {

afterEach(function () {
promise = null;
testWindow.closeAllDocuments();

runs(function () {
// Call closeAll() directly. Some tests set a spy on the save as
// dialog preventing SpecRunnerUtils.closeAllFiles() from
// working properly.
testWindow.brackets.test.DocumentManager.closeAll();
});
});


Expand Down
Loading