From ea652e3e53ec882c09a9f0ea10aa00f3ce7a948f Mon Sep 17 00:00:00 2001 From: Jeff Pihach Date: Tue, 11 Feb 2014 16:18:44 -0600 Subject: [PATCH] Fire destroy-inspector event when a zip is dropped on the canvas fixes #1278559 --- app/views/topology/service.js | 1 + test/test_service_module.js | 56 ++++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/app/views/topology/service.js b/app/views/topology/service.js index 886ea8eee2..dbbdfa2910 100644 --- a/app/views/topology/service.js +++ b/app/views/topology/service.js @@ -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 diff --git a/test/test_service_module.js b/test/test_service_module.js index 68870eb459..a4a722953a 100644 --- a/test/test_service_module.js +++ b/test/test_service_module.js @@ -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', @@ -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'); + + 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', @@ -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(); }); });