diff --git a/src/brackets.js b/src/brackets.js index a9ac0bd01b7..769f55c2199 100644 --- a/src/brackets.js +++ b/src/brackets.js @@ -143,6 +143,7 @@ define(function (require, exports, module) { KeyBindingManager : KeyBindingManager, CodeHintManager : CodeHintManager, Dialogs : Dialogs, + DefaultDialogs : DefaultDialogs, CSSUtils : require("language/CSSUtils"), LiveDevelopment : require("LiveDevelopment/LiveDevelopment"), LiveDevServerManager : require("LiveDevelopment/LiveDevServerManager"), diff --git a/src/widgets/Dialogs.js b/src/widgets/Dialogs.js index 9e0431bf20d..649620b33dc 100644 --- a/src/widgets/Dialogs.js +++ b/src/widgets/Dialogs.js @@ -328,11 +328,12 @@ define(function (require, exports, module) { * Immediately closes any dialog instances with the given class. The dialog callback for each instance will * be called with the special buttonId DIALOG_CANCELED (note: callback is run asynchronously). * @param {string} dlgClass The class name identifier for the dialog. + * @param {string=} buttonId The button id to use when closing the dialog. Defaults to DIALOG_CANCELED */ - function cancelModalDialogIfOpen(dlgClass) { + function cancelModalDialogIfOpen(dlgClass, buttonId) { $("." + dlgClass + ".instance").each(function () { if ($(this).is(":visible")) { // Bootstrap breaks if try to hide dialog that's already hidden - _dismissDialog($(this), DIALOG_CANCELED); + _dismissDialog($(this), buttonId || DIALOG_CANCELED); } }); } diff --git a/test/spec/SpecRunnerUtils.js b/test/spec/SpecRunnerUtils.js index 7169b96cf9c..5bac5460d5e 100644 --- a/test/spec/SpecRunnerUtils.js +++ b/test/spec/SpecRunnerUtils.js @@ -368,10 +368,10 @@ define(function (require, exports, module) { 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"); - } + _testWindow.brackets.test.Dialogs.cancelModalDialogIfOpen( + _testWindow.brackets.test.DefaultDialogs.DIALOG_ID_SAVE_CLOSE, + _testWindow.brackets.test.DefaultDialogs.DIALOG_BTN_DONTSAVE + ); }); }; }); @@ -1036,6 +1036,22 @@ define(function (require, exports, module) { _addSuiteFunction("afterLast", func); }; + /** + * @private + * Returns an array with the parent suites of the current spec with the top most suite last + * @return {Array.} + */ + function _getParentSuites() { + var suite = jasmine.getEnv().currentSpec.suite, + suites = []; + + while (suite) { + suites.push(suite); + suite = suite.parentSuite; + } + return suites; + } + /** * @private * Calls each function in the given array of functions @@ -1049,30 +1065,29 @@ define(function (require, exports, module) { } /** - * Calls the before first functions for the parent suites of the current spec when is the first spec of each suite. + * Calls the before first functions for the parent suites of the current spec when is the first spec of the suite. */ function runBeforeFirst() { - var suite = jasmine.getEnv().currentSpec.suite; + var suites = _getParentSuites().reverse(); - // Iterate throught all the parent suites of the current spec - while (suite) { + // Iterate through all the parent suites of the current spec + suites.forEach(function (suite) { // If we have functions for this suite and it was never called, initialize the spec counter if (_testSuites[suite.id] && _testSuites[suite.id].specCounter === null) { _callFunctions(_testSuites[suite.id].beforeFirst); _testSuites[suite.id].specCounter = countSpecs(suite); } - suite = suite.parentSuite; - } + }); } /** - * Calls the after last functions for the parent suites of the current spec when is the last spec of each suite. + * Calls the after last functions for the parent suites of the current spec when is the last spec of the suite. */ function runAfterLast() { - var suite = jasmine.getEnv().currentSpec.suite; + var suites = _getParentSuites(); // Iterate throught all the parent suites of the current spec - while (suite) { + suites.forEach(function (suite) { // If we have functions for this suite, reduce the spec counter if (_testSuites[suite.id] && _testSuites[suite.id].specCounter > 0) { _testSuites[suite.id].specCounter--; @@ -1083,8 +1098,7 @@ define(function (require, exports, module) { delete _testSuites[suite.id]; } } - suite = suite.parentSuite; - } + }); }