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

Commit aa8a0c4

Browse files
committed
Merge pull request #4629 from TomMalbran/tom/tests-utils-updates
Followup updates to #4581 and #4598
2 parents 348272a + e1a7bc1 commit aa8a0c4

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

src/brackets.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ define(function (require, exports, module) {
143143
KeyBindingManager : KeyBindingManager,
144144
CodeHintManager : CodeHintManager,
145145
Dialogs : Dialogs,
146+
DefaultDialogs : DefaultDialogs,
146147
CSSUtils : require("language/CSSUtils"),
147148
LiveDevelopment : require("LiveDevelopment/LiveDevelopment"),
148149
LiveDevServerManager : require("LiveDevelopment/LiveDevServerManager"),

src/widgets/Dialogs.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,12 @@ define(function (require, exports, module) {
328328
* Immediately closes any dialog instances with the given class. The dialog callback for each instance will
329329
* be called with the special buttonId DIALOG_CANCELED (note: callback is run asynchronously).
330330
* @param {string} dlgClass The class name identifier for the dialog.
331+
* @param {string=} buttonId The button id to use when closing the dialog. Defaults to DIALOG_CANCELED
331332
*/
332-
function cancelModalDialogIfOpen(dlgClass) {
333+
function cancelModalDialogIfOpen(dlgClass, buttonId) {
333334
$("." + dlgClass + ".instance").each(function () {
334335
if ($(this).is(":visible")) { // Bootstrap breaks if try to hide dialog that's already hidden
335-
_dismissDialog($(this), DIALOG_CANCELED);
336+
_dismissDialog($(this), buttonId || DIALOG_CANCELED);
336337
}
337338
});
338339
}

test/spec/SpecRunnerUtils.js

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,10 @@ define(function (require, exports, module) {
368368
var promise = _testWindow.executeCommand(_testWindow.brackets.test.Commands.FILE_CLOSE_ALL);
369369
waitsForDone(promise, "Close all open files in working set");
370370

371-
var $dlg = _testWindow.$(".modal.instance");
372-
if ($dlg.length) {
373-
clickDialogButton("dontsave");
374-
}
371+
_testWindow.brackets.test.Dialogs.cancelModalDialogIfOpen(
372+
_testWindow.brackets.test.DefaultDialogs.DIALOG_ID_SAVE_CLOSE,
373+
_testWindow.brackets.test.DefaultDialogs.DIALOG_BTN_DONTSAVE
374+
);
375375
});
376376
};
377377
});
@@ -1036,6 +1036,22 @@ define(function (require, exports, module) {
10361036
_addSuiteFunction("afterLast", func);
10371037
};
10381038

1039+
/**
1040+
* @private
1041+
* Returns an array with the parent suites of the current spec with the top most suite last
1042+
* @return {Array.<jasmine.Suite>}
1043+
*/
1044+
function _getParentSuites() {
1045+
var suite = jasmine.getEnv().currentSpec.suite,
1046+
suites = [];
1047+
1048+
while (suite) {
1049+
suites.push(suite);
1050+
suite = suite.parentSuite;
1051+
}
1052+
return suites;
1053+
}
1054+
10391055
/**
10401056
* @private
10411057
* Calls each function in the given array of functions
@@ -1049,30 +1065,29 @@ define(function (require, exports, module) {
10491065
}
10501066

10511067
/**
1052-
* Calls the before first functions for the parent suites of the current spec when is the first spec of each suite.
1068+
* Calls the before first functions for the parent suites of the current spec when is the first spec of the suite.
10531069
*/
10541070
function runBeforeFirst() {
1055-
var suite = jasmine.getEnv().currentSpec.suite;
1071+
var suites = _getParentSuites().reverse();
10561072

1057-
// Iterate throught all the parent suites of the current spec
1058-
while (suite) {
1073+
// Iterate through all the parent suites of the current spec
1074+
suites.forEach(function (suite) {
10591075
// If we have functions for this suite and it was never called, initialize the spec counter
10601076
if (_testSuites[suite.id] && _testSuites[suite.id].specCounter === null) {
10611077
_callFunctions(_testSuites[suite.id].beforeFirst);
10621078
_testSuites[suite.id].specCounter = countSpecs(suite);
10631079
}
1064-
suite = suite.parentSuite;
1065-
}
1080+
});
10661081
}
10671082

10681083
/**
1069-
* Calls the after last functions for the parent suites of the current spec when is the last spec of each suite.
1084+
* Calls the after last functions for the parent suites of the current spec when is the last spec of the suite.
10701085
*/
10711086
function runAfterLast() {
1072-
var suite = jasmine.getEnv().currentSpec.suite;
1087+
var suites = _getParentSuites();
10731088

10741089
// Iterate throught all the parent suites of the current spec
1075-
while (suite) {
1090+
suites.forEach(function (suite) {
10761091
// If we have functions for this suite, reduce the spec counter
10771092
if (_testSuites[suite.id] && _testSuites[suite.id].specCounter > 0) {
10781093
_testSuites[suite.id].specCounter--;
@@ -1083,8 +1098,7 @@ define(function (require, exports, module) {
10831098
delete _testSuites[suite.id];
10841099
}
10851100
}
1086-
suite = suite.parentSuite;
1087-
}
1101+
});
10881102
}
10891103

10901104

0 commit comments

Comments
 (0)