Skip to content

Instantly share code, notes, and snippets.

@hatched
Last active August 29, 2015 14:03
Show Gist options
  • Save hatched/087d9e30e3eb92a46657 to your computer and use it in GitHub Desktop.
Save hatched/087d9e30e3eb92a46657 to your computer and use it in GitHub Desktop.
runWhenCalled
it('opens the options with the correct constraints details', function(done) {
// It shouldn't show constraints details if the manual placement radio
// is selected.
var toggleScaleUp = utils.makeStubMethod(View.prototype, '_toggleScaleUp');
this._cleanups.push(toggleScaleUp.reset);
var toggleConstraints = utils.makeStubMethod(
View.prototype, '_toggleConstraints');
this._cleanups.push(toggleConstraints.reset);
instantiateView(this).render();
var button = container.one('.add.button');
toggleScaleUp.resume(function() {
validateVisibility({ constraints: 'block' });
// Change the radio options to 'manually place'
var radio = container.one('input#manually-place');
radio.simulate('click');
}, view);
toggleConstraints.resume(null, view);
toggleConstraints.resume(function() {
// Constraints should not be shown if 'manually-place' radio button is
// checked.
validateVisibility({ constraints: 'none' });
// Close the scale-up up
button.simulate('click');
}, view);
toggleScaleUp.resume(function() {
// The placement UI should be hidden.
validateVisibility({ placement: 'none' });
// Open the scale-up view
button.simulate('click');
}, view);
toggleScaleUp.resume(function() {
// Validate that it ends up in the proper state.
validateVisibility({
placement: 'block',
constraints: 'none',
editConstraints: 'none',
inspectorButtons: 'block'
});
done();
}, view);
// Open the scale-up view.
button.simulate('click');
});
diff --git a/test/utils.js b/test/utils.js
index 493a99c..15b5ed9 100644
--- a/test/utils.js
+++ b/test/utils.js
@@ -38,8 +38,14 @@ YUI(GlobalConfig).add('juju-tests-utils', function(Y) {
}
var f = function() {
var response = responses[(f._allArguments.length) % responses.length];
- f._allArguments.push(Array.prototype.slice.call(arguments, 0));
+ var index = f._allArguments.push(
+ Array.prototype.slice.call(arguments, 0));
f._callbacks.forEach(function(cb) {cb.call(f);});
+ if (Y.Lang.isArray(f._resumeCallbacks)) {
+ if (typeof f._resumeCallbacks[index - 1] === 'function') {
+ f._resumeCallbacks[index - 1]();
+ }
+ }
return response;
};
f._allArguments = [];
@@ -83,6 +89,18 @@ YUI(GlobalConfig).add('juju-tests-utils', function(Y) {
var original = context[name];
var f = context[name] = jujuTests.utils.makeStubFunction.apply(
jujuTests.utils, responses);
+ f._resumeCallbacks = [];
+ f.resume = function(callback, instance) {
+ if (!Y.Lang.isValue(instance)) {
+ instance = context;
+ }
+ f._resumeCallbacks.push(function() {
+ f.passThroughToOriginalMethod(instance);
+ if (typeof callback === 'function') {
+ callback.apply(instance, f.lastArguments());
+ }
+ });
+ };
f.reset = function() {
context[name] = original;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment