diff --git a/platform/commonUI/edit/src/creation/LocatorController.js b/platform/commonUI/edit/src/creation/LocatorController.js index 54e5659784..fc0ab6396c 100644 --- a/platform/commonUI/edit/src/creation/LocatorController.js +++ b/platform/commonUI/edit/src/creation/LocatorController.js @@ -50,7 +50,7 @@ define( $scope.rootObject = (context && context.getRoot()) || $scope.rootObject; }, 0); - } else if (!contextRoot) { + } else if (!contextRoot && !$scope.rootObject) { //If no context root is available, default to the root // object $scope.rootObject = undefined; diff --git a/platform/commonUI/edit/test/creation/LocatorControllerSpec.js b/platform/commonUI/edit/test/creation/LocatorControllerSpec.js index ce18b2d1b8..6837ed2a38 100644 --- a/platform/commonUI/edit/test/creation/LocatorControllerSpec.js +++ b/platform/commonUI/edit/test/creation/LocatorControllerSpec.js @@ -138,23 +138,34 @@ define( }); }); describe("when no context is available", function () { - var defaultRoot = "DEFAULT_ROOT"; - - beforeEach(function () { - mockContext.getRoot.andReturn(undefined); - getObjectsPromise.then.andCallFake(function (callback) { - callback({'ROOT': defaultRoot}); - }); - controller = new LocatorController(mockScope, mockTimeout, mockObjectService); - }); - - it("provides a default context where none is available", function () { - mockScope.$watch.mostRecentCall.args[1](mockDomainObject); - mockTimeout.mostRecentCall.args[0](); - expect(mockScope.rootObject).toBe(defaultRoot); + var defaultRoot = "DEFAULT_ROOT"; + beforeEach(function () { + mockContext.getRoot.andReturn(undefined); + getObjectsPromise.then.andCallFake(function (callback) { + callback({'ROOT': defaultRoot}); }); + controller = new LocatorController(mockScope, mockTimeout, mockObjectService); }); + + it("provides a default context where none is available", function () { + mockScope.$watch.mostRecentCall.args[1](mockDomainObject); + mockTimeout.mostRecentCall.args[0](); + expect(mockScope.rootObject).toBe(defaultRoot); + }); + + it("does not issue redundant requests for the root object", function () { + mockScope.$watch.mostRecentCall.args[1](mockDomainObject); + mockTimeout.mostRecentCall.args[0](); + mockScope.$watch.mostRecentCall.args[1](undefined); + mockTimeout.mostRecentCall.args[0](); + mockScope.$watch.mostRecentCall.args[1](mockDomainObject); + mockTimeout.mostRecentCall.args[0](); + expect(mockObjectService.getObjects.calls.length) + .toEqual(1); + }); + + }); }); } );