diff --git a/platform/features/layout/src/FixedController.js b/platform/features/layout/src/FixedController.js index db742aa3da..465d6a1d3b 100644 --- a/platform/features/layout/src/FixedController.js +++ b/platform/features/layout/src/FixedController.js @@ -253,6 +253,7 @@ define( if (e.isDefaultPrevented()) { return; } + e.preventDefault(); // Store the position of this element. addElement({ type: "fixed.telemetry", diff --git a/platform/features/layout/test/FixedControllerSpec.js b/platform/features/layout/test/FixedControllerSpec.js index a858910d76..b4e05c9665 100644 --- a/platform/features/layout/test/FixedControllerSpec.js +++ b/platform/features/layout/test/FixedControllerSpec.js @@ -34,6 +34,7 @@ define( mockFormatter, mockDomainObject, mockSubscription, + mockEvent, testGrid, testModel, testValues, @@ -98,6 +99,10 @@ define( 'subscription', [ 'unsubscribe', 'getTelemetryObjects', 'getRangeValue' ] ); + mockEvent = jasmine.createSpyObj( + 'event', + [ 'preventDefault', 'isDefaultPrevented' ] + ); testGrid = [ 123, 456 ]; testModel = { @@ -302,7 +307,7 @@ define( // Notify that a drop occurred testModel.composition.push('d'); findOn('mctDrop')( - {}, + mockEvent, 'd', { x: 300, y: 100 } ); @@ -310,12 +315,31 @@ define( // Should have added an element expect(testConfiguration.elements.length).toEqual(4); + // ...and prevented default... + expect(mockEvent.preventDefault).toHaveBeenCalled(); + // Should have triggered commit (provided by // EditRepresenter) with some message. expect(mockScope.commit) .toHaveBeenCalledWith(jasmine.any(String)); }); + it("ignores drops when default has been prevented", function () { + // Avoids redundant drop-handling, WTD-1233 + mockEvent.isDefaultPrevented.andReturn(true); + + // Notify that a drop occurred + testModel.composition.push('d'); + findOn('mctDrop')( + mockEvent, + 'd', + { x: 300, y: 100 } + ); + + // Should NOT have added an element + expect(testConfiguration.elements.length).toEqual(3); + }); + it("unsubscribes when destroyed", function () { // Make an object available findWatch('domainObject')(mockDomainObject); @@ -403,4 +427,4 @@ define( }); }); } -); \ No newline at end of file +); diff --git a/platform/features/layout/test/LayoutControllerSpec.js b/platform/features/layout/test/LayoutControllerSpec.js index 95134c298b..d6cc3d035b 100644 --- a/platform/features/layout/test/LayoutControllerSpec.js +++ b/platform/features/layout/test/LayoutControllerSpec.js @@ -28,6 +28,7 @@ define( describe("The Layout controller", function () { var mockScope, + mockEvent, testModel, testConfiguration, controller; @@ -37,6 +38,10 @@ define( "$scope", [ "$watch", "$on", "commit" ] ); + mockEvent = jasmine.createSpyObj( + 'event', + [ 'preventDefault', 'isDefaultPrevented' ] + ); testModel = { composition: [ "a", "b", "c" ] @@ -144,17 +149,32 @@ define( // Notify that a drop occurred testModel.composition.push('d'); mockScope.$on.mostRecentCall.args[1]( - {}, + mockEvent, 'd', { x: 300, y: 100 } ); expect(testConfiguration.panels.d).toBeDefined(); + expect(mockEvent.preventDefault).toHaveBeenCalled(); // Should have triggered commit (provided by // EditRepresenter) with some message. expect(mockScope.commit) .toHaveBeenCalledWith(jasmine.any(String)); }); + + it("ignores drops when default has been prevented", function () { + // Avoids redundant drop-handling, WTD-1233 + mockEvent.isDefaultPrevented.andReturn(true); + + // Notify that a drop occurred + testModel.composition.push('d'); + mockScope.$on.mostRecentCall.args[1]( + mockEvent, + 'd', + { x: 300, y: 100 } + ); + expect(testConfiguration.panels.d).not.toBeDefined(); + }); }); } -); \ No newline at end of file +);