From 7b5218c5ba1a409f65d20dfc607cc6d15a599044 Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 2 Mar 2016 10:14:25 -0800 Subject: [PATCH] [Edit Mode] #627 Fixed failing tests Removed reference to defunct NavigationServiceDecorator Removed virtual panels from drop gesture --- platform/commonUI/browse/bundle.js | 6 ++ .../browse/test/BrowseControllerSpec.js | 6 +- .../test/controllers/EditControllerSpec.js | 16 ++--- .../test/directives/MCTBeforeUnloadSpec.js | 11 +--- .../src/gestures/DropGesture.js | 63 +++---------------- 5 files changed, 29 insertions(+), 73 deletions(-) diff --git a/platform/commonUI/browse/bundle.js b/platform/commonUI/browse/bundle.js index 388d484bb1..9b6e37fbe9 100644 --- a/platform/commonUI/browse/bundle.js +++ b/platform/commonUI/browse/bundle.js @@ -248,6 +248,12 @@ define([ "implementation": NavigationService } ], + "services": [ + { + "key": "navigationService", + "implementation": NavigationService + } + ], "policies": [ { "implementation": CreationPolicy, diff --git a/platform/commonUI/browse/test/BrowseControllerSpec.js b/platform/commonUI/browse/test/BrowseControllerSpec.js index e40e39f6ef..cc14b4d0e5 100644 --- a/platform/commonUI/browse/test/BrowseControllerSpec.js +++ b/platform/commonUI/browse/test/BrowseControllerSpec.js @@ -256,7 +256,11 @@ define( it("after failed navigation event resets the selected tree" + " object", function () { mockScope.navigatedObject = mockDomainObject; - mockNavigationService.setNavigation.andReturn(false); + mockWindow.confirm.andReturn(false); + mockPolicyService.allow.andCallFake(function(category, object, context, callback){ + callback("unsaved changes"); + return false; + }); //Simulate a change in selected tree object mockScope.treeModel = {selectedObject: mockDomainObject}; diff --git a/platform/commonUI/edit/test/controllers/EditControllerSpec.js b/platform/commonUI/edit/test/controllers/EditControllerSpec.js index 0af357f9c0..0ed0ddecc7 100644 --- a/platform/commonUI/edit/test/controllers/EditControllerSpec.js +++ b/platform/commonUI/edit/test/controllers/EditControllerSpec.js @@ -89,25 +89,25 @@ define( controller = new EditObjectController( mockScope, - mockLocation + mockLocation, + mockPolicyService ); }); it("exposes a warning message for unload", function () { var obj = mockObject, - mockEditor = jasmine.createSpyObj('editor', ['dirty']); + errorMessage = "Unsaved changes"; // Normally, should be undefined expect(controller.getUnloadWarning()).toBeUndefined(); - // Override the object's editor capability, make it look - // like there are unsaved changes. - mockCapabilities.editor = mockEditor; - mockEditor.dirty.andReturn(true); - mockStatusCapability.get.andReturn(true); + // Override the policy service to prevent navigation + mockPolicyService.allow.andCallFake(function(category, object, context, callback){ + callback(errorMessage); + }); // Should have some warning message here now - expect(controller.getUnloadWarning()).toEqual(jasmine.any(String)); + expect(controller.getUnloadWarning()).toEqual(errorMessage); }); diff --git a/platform/commonUI/edit/test/directives/MCTBeforeUnloadSpec.js b/platform/commonUI/edit/test/directives/MCTBeforeUnloadSpec.js index fd94e3e90d..41070d76f5 100644 --- a/platform/commonUI/edit/test/directives/MCTBeforeUnloadSpec.js +++ b/platform/commonUI/edit/test/directives/MCTBeforeUnloadSpec.js @@ -31,7 +31,6 @@ define( mockScope, testAttrs, mockEvent, - mockNavigationService, directive; function fireListener(eventType, value) { @@ -47,8 +46,7 @@ define( mockScope = jasmine.createSpyObj("$scope", ['$eval', '$on']); testAttrs = { mctBeforeUnload: "someExpression" }; mockEvent = jasmine.createSpyObj("event", ["preventDefault"]); - mockNavigationService = jasmine.createSpyObj("navigationService", ["addListener", "removeListener"]); - directive = new MCTBeforeUnload(mockWindow, mockNavigationService); + directive = new MCTBeforeUnload(mockWindow); directive.link(mockScope, {}, testAttrs); }); @@ -67,10 +65,6 @@ define( ); }); - it("listens for navigation changes", function () { - expect(mockNavigationService.addListener).toHaveBeenCalledWith(jasmine.any(Function), "before"); - }); - it("listens for its scope's destroy event", function () { expect(mockScope.$on).toHaveBeenCalledWith( "$destroy", @@ -114,10 +108,9 @@ define( it("cleans up listeners when destroyed", function () { fireListener("$destroy", mockEvent); expect(mockWindow.onbeforeunload).toBeUndefined(); - expect(mockNavigationService.removeListener).toHaveBeenCalled(); }); }); } -); +); \ No newline at end of file diff --git a/platform/representation/src/gestures/DropGesture.js b/platform/representation/src/gestures/DropGesture.js index a8ff9ac397..1e884c14f7 100644 --- a/platform/representation/src/gestures/DropGesture.js +++ b/platform/representation/src/gestures/DropGesture.js @@ -80,13 +80,6 @@ define( }).length > 0; } - function shouldCreateVirtualPanel(domainObject){ - return domainObject.useCapability('view').filter(function (view){ - return (view.key === 'plot' || view.key === 'scrolling') - && domainObject.getModel().type !== 'telemetry.panel'; - }).length > 0; - } - function dragOver(e) { //Refresh domain object on each dragOver to catch external // updates to the model @@ -111,9 +104,7 @@ define( key: 'compose', selectedObject: selectedObject })[0]; - //TODO: Fix this. Define an action for creating new - // virtual panel - if (action || shouldCreateVirtualPanel(domainObject, selectedObject)) { + if (action) { event.dataTransfer.dropEffect = 'move'; // Indicate that we will accept the drag @@ -123,61 +114,23 @@ define( } } - function createVirtualPanel(base, selectedObject){ - - var typeKey = 'telemetry.panel', - type = typeService.getType(typeKey), - model = type.getInitialModel(), - newPanel; - - model.type = typeKey; - newPanel = new EditableDomainObject(instantiate(model), $q); - if (!canCompose(newPanel, selectedObject)) { - return undefined; - } - - [base.getId(), selectedObject.getId()].forEach(function(id){ - newPanel.getCapability('composition').add(id); - }); - - newPanel.getCapability('location') - .setPrimaryLocation(base.getCapability('location') - .getContextualLocation()); - - newPanel.setOriginalObject(base); - return newPanel; - - } - function drop(e) { var event = (e || {}).originalEvent || e, id = event.dataTransfer.getData(GestureConstants.MCT_DRAG_TYPE), - domainObjectType = editableDomainObject.getModel().type, - selectedObject = dndService.getData( - GestureConstants.MCT_EXTENDED_DRAG_TYPE - ); - + domainObjectType = editableDomainObject.getModel().type; + // Handle the drop; add the dropped identifier to the // destination domain object's composition, and persist // the change. if (id) { - if (shouldCreateVirtualPanel(domainObject, selectedObject)){ - editableDomainObject = createVirtualPanel(domainObject, selectedObject); - if (editableDomainObject) { + $q.when(action && action.perform()).then(function (result) { + //Don't go into edit mode for folders + if (domainObjectType!=='folder') { editableDomainObject.getCapability('action').perform('edit'); - broadcastDrop(id, event); } - } else { - $q.when(action && action.perform()).then(function (result) { - //Don't go into edit mode for folders - if (domainObjectType!=='folder') { - editableDomainObject.getCapability('action').perform('edit'); - } - broadcastDrop(id, event); - }); - } + broadcastDrop(id, event); + }); } - // TODO: Alert user if drag and drop is not allowed } // We can only handle drops if we have access to actions...