Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Fire destroy-inspector event when a zip is dropped on the canvas fixes #1278559 #121

Merged
merged 1 commit into from
Feb 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions app/views/topology/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ YUI.add('juju-topology-service', function(Y) {
if ((file.type === 'application/zip' ||
file.type === 'application/x-zip-compressed') &&
ext === 'zip') {
topo.fire('destroyServiceInspector');
localCharmHelpers.deployLocalCharm(file, env, db);
} else {
// We are going to assume it's a bundle if it's not a zip
Expand Down
56 changes: 36 additions & 20 deletions test/test_service_module.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ describe('service module events', function() {
serviceModule.canvasDropHandler(fakeEventObject);
});

it('deploys a local charm on .zip file drop events', function(done) {
it('deploys a local charm on .zip file drop events', function() {
var file = {
// Using a complex name to make sure the extension filtering works
name: 'foo-bar.baz.zip',
Expand All @@ -400,21 +400,29 @@ describe('service module events', function() {
};

// mock out the Y.BundleHelpers call.
var deployLocalCharm = juju.localCharmHelpers.deployLocalCharm;
juju.localCharmHelpers.deployLocalCharm = function(files, env, db) {
assert.deepEqual(files, file);
assert.isObject(env);
assert.isObject(db);
// Restore the deployBundleFiles call for future tests.
juju.localCharmHelpers.deployLocalCharm = deployLocalCharm;
done();
};
var deployLocalCharmStub, topoFireStub;
deployLocalCharmStub = utils.makeStubMethod(
juju.localCharmHelpers, 'deployLocalCharm');
topoFireStub = utils.makeStubMethod(view.topo, 'fire');

serviceModule.set('component', view.topo);
serviceModule.canvasDropHandler(fakeEventObject);

var args = deployLocalCharmStub.lastArguments();
assert.deepEqual(args[0], file);
assert.isObject(args[1]);
assert.isObject(args[2]);

// Check to make sure the event to destroy any previously
// open inspector is fired
assert.equal(topoFireStub.calledOnce(), true);
assert.equal(topoFireStub.lastArguments()[0], 'destroyServiceInspector');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The topoFireStub code is the new test addition. The rest is just refactor to use the makeStubMethod util method.


deployLocalCharmStub.reset();
topoFireStub.reset();
});

it('deploys a local charm on .zip file drop events (IE)', function(done) {
it('deploys a local charm on .zip file drop events (IE)', function() {
var file = {
// Using a complex name to make sure the extension filtering works
name: 'foo-bar.baz.zip',
Expand All @@ -433,18 +441,26 @@ describe('service module events', function() {
};

// mock out the Y.BundleHelpers call.
var deployLocalCharm = juju.localCharmHelpers.deployLocalCharm;
juju.localCharmHelpers.deployLocalCharm = function(files, env, db) {
assert.deepEqual(files, file);
assert.isObject(env);
assert.isObject(db);
// Restore the deployBundleFiles call for future tests.
juju.localCharmHelpers.deployLocalCharm = deployLocalCharm;
done();
};
var deployLocalCharmStub, topoFireStub;
deployLocalCharmStub = utils.makeStubMethod(
juju.localCharmHelpers, 'deployLocalCharm');
topoFireStub = utils.makeStubMethod(view.topo, 'fire');

serviceModule.set('component', view.topo);
serviceModule.canvasDropHandler(fakeEventObject);

var args = deployLocalCharmStub.lastArguments();
assert.deepEqual(args[0], file);
assert.isObject(args[1]);
assert.isObject(args[2]);

// Check to make sure the event to destroy any previously
// open inspector is fired
assert.equal(topoFireStub.calledOnce(), true);
assert.equal(topoFireStub.lastArguments()[0], 'destroyServiceInspector');

deployLocalCharmStub.reset();
topoFireStub.reset();
});

});