From 521d73b8c5f9233b0038427f41b8bc5315423e56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Thu, 1 Aug 2013 19:09:06 -0300 Subject: [PATCH 1/2] Improve closeAllFiles and runBeforeFirst --- src/brackets.js | 1 + src/widgets/Dialogs.js | 5 +++-- test/spec/SpecRunnerUtils.js | 42 ++++++++++++++++++++++++------------ 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/brackets.js b/src/brackets.js index 7ad2fa80345..d12f04de8d9 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 075795e7f3f..f0aae4b55c0 100644 --- a/src/widgets/Dialogs.js +++ b/src/widgets/Dialogs.js @@ -277,11 +277,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 (index, dlg) { if ($(dlg).is(":visible")) { // Bootstrap breaks if try to hide dialog that's already hidden - _dismissDialog($(dlg), DIALOG_CANCELED); + _dismissDialog($(dlg), buttonId || DIALOG_CANCELED); } }); } diff --git a/test/spec/SpecRunnerUtils.js b/test/spec/SpecRunnerUtils.js index b7f6418149e..6fc4c317a16 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) { + 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; - } + }); } From e1a7bc183c582cd1ebfedce9d4a56c3c12efccd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Tue, 3 Sep 2013 22:33:39 -0300 Subject: [PATCH 2/2] Fixes after review --- src/widgets/Dialogs.js | 2 +- test/spec/SpecRunnerUtils.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/widgets/Dialogs.js b/src/widgets/Dialogs.js index 72dee0048e3..649620b33dc 100644 --- a/src/widgets/Dialogs.js +++ b/src/widgets/Dialogs.js @@ -333,7 +333,7 @@ define(function (require, exports, module) { 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 237eb8a930d..5bac5460d5e 100644 --- a/test/spec/SpecRunnerUtils.js +++ b/test/spec/SpecRunnerUtils.js @@ -1070,7 +1070,7 @@ define(function (require, exports, module) { function runBeforeFirst() { var suites = _getParentSuites().reverse(); - // Iterate throught all the parent suites of the current spec + // 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) {