From 657a8bcadaa425af0e3d6bf17d533ccbdc4ac462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Fri, 26 Jul 2013 19:57:18 -0300 Subject: [PATCH 1/3] Use one window for htmlToCSSProvider tests --- test/spec/EditorOptionHandlers-test.js | 10 +--- test/spec/InlineEditorProviders-test.js | 43 +++++++++++------ test/spec/SpecRunnerUtils.js | 62 ++++++++++++++----------- 3 files changed, 65 insertions(+), 50 deletions(-) diff --git a/test/spec/EditorOptionHandlers-test.js b/test/spec/EditorOptionHandlers-test.js index ce7516b6cfb..fb3820fd65f 100644 --- a/test/spec/EditorOptionHandlers-test.js +++ b/test/spec/EditorOptionHandlers-test.js @@ -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(); }); diff --git a/test/spec/InlineEditorProviders-test.js b/test/spec/InlineEditorProviders-test.js index 06973108f8c..c2b3653fbaa 100644 --- a/test/spec/InlineEditorProviders-test.js +++ b/test/spec/InlineEditorProviders-test.js @@ -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, beforeAll, afterAll */ define(function (require, exports, module) { 'use strict'; @@ -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. @@ -167,17 +166,35 @@ define(function (require, exports, module) { return false; } - beforeEach(function () { - initInlineTest = _initInlineTest.bind(this); + beforeAll(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; + + SpecRunnerUtils.loadProjectInTestWindow(testPath); }); - + }); + + afterAll(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) { @@ -245,14 +262,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(); }); @@ -1238,6 +1249,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)); @@ -1295,6 +1307,7 @@ define(function (require, exports, module) { testDoc = null; }); + it("should prefer positive higher priority providers (1)", function () { var widget0 = new InlineWidget(), widget1 = new InlineWidget(), diff --git a/test/spec/SpecRunnerUtils.js b/test/spec/SpecRunnerUtils.js index 2c273f4d781..dce9365dcbf 100644 --- a/test/spec/SpecRunnerUtils.js +++ b/test/spec/SpecRunnerUtils.js @@ -268,6 +268,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); + } + + function createTestWindowAndRun(spec, callback) { runs(function () { // Position popup windows in the lower right so they're out of the way @@ -305,6 +331,16 @@ define(function (require, exports, module) { _testWindow.closeAllDocuments = function closeAllDocuments() { _testWindow.brackets.test.DocumentManager.closeAll(); }; + + _testWindow.closeAllFiles = function closeAllFiles() { + 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"); + } + }; }); // FIXME (issue #249): Need an event or something a little more reliable... @@ -344,32 +380,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); - } - - function loadProjectInTestWindow(path) { var isReady = false; From c91ae374de90b38eb98ce75ca7f19706020c7937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Tue, 30 Jul 2013 23:47:57 -0300 Subject: [PATCH 2/3] Use runs when closing all the files. --- test/spec/SpecRunnerUtils.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/spec/SpecRunnerUtils.js b/test/spec/SpecRunnerUtils.js index 0883cb75b11..ea17e58836a 100644 --- a/test/spec/SpecRunnerUtils.js +++ b/test/spec/SpecRunnerUtils.js @@ -364,13 +364,15 @@ define(function (require, exports, module) { }; _testWindow.closeAllFiles = function closeAllFiles() { - 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"); - } + 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"); + } + }); }; }); From 5aa2547d965105bc9118d1715b774bd134ed8f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Wed, 31 Jul 2013 22:29:21 -0300 Subject: [PATCH 3/3] Changes after #4581 --- test/spec/InlineEditorProviders-test.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/test/spec/InlineEditorProviders-test.js b/test/spec/InlineEditorProviders-test.js index c2b3653fbaa..f70e73be8db 100644 --- a/test/spec/InlineEditorProviders-test.js +++ b/test/spec/InlineEditorProviders-test.js @@ -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, beforeAll, afterAll */ +/*global define, describe, it, expect, beforeEach, afterEach, waits, waitsFor, waitsForDone, waitsForFail, runs, $, brackets, beforeFirst, afterLast */ define(function (require, exports, module) { 'use strict'; @@ -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, @@ -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, @@ -166,7 +166,7 @@ define(function (require, exports, module) { return false; } - beforeAll(function () { + beforeFirst(function () { // Create a new window that will be shared by ALL tests in this spec. SpecRunnerUtils.createTestWindowAndRun(this, function (w) { testWindow = w; @@ -177,12 +177,10 @@ define(function (require, exports, module) { FileSyncManager = testWindow.brackets.test.FileSyncManager; DocumentManager = testWindow.brackets.test.DocumentManager; FileViewController = testWindow.brackets.test.FileViewController; - - SpecRunnerUtils.loadProjectInTestWindow(testPath); }); }); - afterAll(function () { + afterLast(function () { testWindow = null; Commands = null; EditorManager = null;