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

Improvements to the Inline Editor Tests #4598

Merged
merged 5 commits 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
10 changes: 1 addition & 9 deletions test/spec/EditorOptionHandlers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,7 @@ define(function (require, exports, module) {


afterEach(function () {
runs(function () {
var promise = CommandManager.execute(Commands.FILE_CLOSE_ALL);
waitsForDone(promise, "Close all open files in working set");

var $dlg = testWindow.$(".modal.instance");
if ($dlg.length) {
SpecRunnerUtils.clickDialogButton("dontsave");
}
});
testWindow.closeAllFiles();
});


Expand Down
49 changes: 30 additions & 19 deletions test/spec/InlineEditorProviders-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, beforeEach, afterEach, waits, waitsFor, waitsForDone, waitsForFail, runs, $, brackets */
/*global define, describe, it, expect, beforeEach, afterEach, waits, waitsFor, waitsForDone, waitsForFail, runs, $, brackets, beforeFirst, afterLast */

define(function (require, exports, module) {
'use strict';
Expand Down Expand Up @@ -79,9 +79,9 @@ define(function (require, exports, module) {
* then attempts opens an inline editor at the given offset. Installs an after()
* function restore all file content back to original state with offset markup.
*
* @param {!string} openFile Project relative file path to open in a main editor.
* @param {!number} openOffset The offset index location within openFile to open an inline editor.
* @param {?boolean} expectInline Use false to verify that an inline editor should not be opened. Omit otherwise.
* @param {string} openFile Project relative file path to open in a main editor.
* @param {number} openOffset The offset index location within openFile to open an inline editor.
* @param {?boolean} expectInline Use false to verify that an inline editor should not be opened. Omit otherwise.
*/
var _initInlineTest = function (openFile, openOffset, expectInline, workingSet) {
var allFiles,
Expand Down Expand Up @@ -110,7 +110,7 @@ define(function (require, exports, module) {

runs(function () {
editor = EditorManager.getCurrentFullEditor();

// open inline editor at specified offset index
var inlineEditorResult = SpecRunnerUtils.toggleQuickEditAtOffset(
editor,
Expand Down Expand Up @@ -147,8 +147,7 @@ define(function (require, exports, module) {
function expectTextToBeEqual(editor1, editor2) {
expect(editor1._codeMirror.getValue()).toBe(editor2._codeMirror.getValue());
}




/*
* Note that the bulk of selector matching tests are in CSSutils-test.js.
Expand All @@ -167,17 +166,33 @@ define(function (require, exports, module) {
return false;
}

beforeEach(function () {
initInlineTest = _initInlineTest.bind(this);
beforeFirst(function () {
// Create a new window that will be shared by ALL tests in this spec.
SpecRunnerUtils.createTestWindowAndRun(this, function (w) {
testWindow = w;
testWindow = w;

// Load module instances from brackets.test
Commands = testWindow.brackets.test.Commands;
EditorManager = testWindow.brackets.test.EditorManager;
FileSyncManager = testWindow.brackets.test.FileSyncManager;
DocumentManager = testWindow.brackets.test.DocumentManager;
FileViewController = testWindow.brackets.test.FileViewController;
});

});

afterLast(function () {
testWindow = null;
Commands = null;
EditorManager = null;
FileSyncManager = null;
DocumentManager = null;
FileViewController = null;
SpecRunnerUtils.closeTestWindow();
});


beforeEach(function () {
initInlineTest = _initInlineTest.bind(this);
this.addMatchers({

toHaveInlineEditorRange: function (range) {
Expand Down Expand Up @@ -245,14 +260,8 @@ define(function (require, exports, module) {
//waits(1000);

// revert files to original content with offset markup
initInlineTest = null;
testWindow = null;
Commands = null;
EditorManager = null;
FileSyncManager = null;
DocumentManager = null;
FileViewController = null;
SpecRunnerUtils.closeTestWindow();
initInlineTest = null;
testWindow.closeAllFiles();
});


Expand Down Expand Up @@ -1238,6 +1247,7 @@ define(function (require, exports, module) {
expect(hostEditor.getInlineWidgets().length).toBe(1);
expect(inlineEditor).toHaveInlineEditorRange(toRange(0, 2));
});

it("should insert new line at bottom and not close on undo", function () {
expect(inlineEditor).toHaveInlineEditorRange(toRange(0, 2));

Expand Down Expand Up @@ -1295,6 +1305,7 @@ define(function (require, exports, module) {
testDoc = null;
});


it("should prefer positive higher priority providers (1)", function () {
var widget0 = new InlineWidget(),
widget1 = new InlineWidget(),
Expand Down
64 changes: 38 additions & 26 deletions test/spec/SpecRunnerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,32 @@ define(function (require, exports, module) {
$("#mock-editor-holder").remove();
}

/**
* Dismiss the currently open dialog as if the user had chosen the given button. Dialogs close
* asynchronously; after calling this, you need to start a new runs() block before testing the
* outcome. Also, in cases where asynchronous tasks are performed after the dialog closes,
* clients must also wait for any additional promises.
* @param {string} buttonId One of the Dialogs.DIALOG_BTN_* symbolic constants.
*/
function clickDialogButton(buttonId) {
// Make sure there's one and only one dialog open
var $dlg = _testWindow.$(".modal.instance"),
promise = $dlg.data("promise");

expect($dlg.length).toBe(1);

// Make sure desired button exists
var dismissButton = $dlg.find(".dialog-button[data-button-id='" + buttonId + "']");
expect(dismissButton.length).toBe(1);

// Click the button
dismissButton.click();

// Dialog should resolve/reject the promise
waitsForDone(promise, "dismiss dialog");
}


function createTestWindowAndRun(spec, callback) {
runs(function () {
// Position popup windows in the lower right so they're out of the way
Expand Down Expand Up @@ -336,6 +362,18 @@ define(function (require, exports, module) {
_testWindow.closeAllDocuments = function closeAllDocuments() {
_testWindow.brackets.test.DocumentManager.closeAll();
};

_testWindow.closeAllFiles = function closeAllFiles() {
runs(function () {
var promise = _testWindow.executeCommand(_testWindow.brackets.test.Commands.FILE_CLOSE_ALL);
waitsForDone(promise, "Close all open files in working set");

var $dlg = _testWindow.$(".modal.instance");
if ($dlg.length) {
clickDialogButton("dontsave");
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be replaced with Dialogs.cancelModalDialogIfOpen if it could receive an additional and optional button ID parameter.

});
};
});

// FIXME (issue #249): Need an event or something a little more reliable...
Expand Down Expand Up @@ -375,32 +413,6 @@ define(function (require, exports, module) {
}


/**
* Dismiss the currently open dialog as if the user had chosen the given button. Dialogs close
* asynchronously; after calling this, you need to start a new runs() block before testing the
* outcome. Also, in cases where asynchronous tasks are performed after the dialog closes,
* clients must also wait for any additional promises.
* @param {string} buttonId One of the Dialogs.DIALOG_BTN_* symbolic constants.
*/
function clickDialogButton(buttonId) {
// Make sure there's one and only one dialog open
var $dlg = _testWindow.$(".modal.instance"),
promise = $dlg.data("promise");

expect($dlg.length).toBe(1);

// Make sure desired button exists
var dismissButton = $dlg.find(".dialog-button[data-button-id='" + buttonId + "']");
expect(dismissButton.length).toBe(1);

// Click the button
dismissButton.click();

// Dialog should resolve/reject the promise
waitsForDone(promise, "dismiss dialog");
}


function loadProjectInTestWindow(path) {
runs(function () {
// begin loading project path
Expand Down