From 10d2794bb7c8d93ba73aa94106bb5b2c55a066b2 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 19 Aug 2016 13:26:11 -0700 Subject: [PATCH] [Locator] Don't reset root unnecessarily ...as this will trigger a refresh of the mct-representation for the tree, which will in turn create a new mct-tree instance, resulting in any expanded/collapsed state being lost. Fixes #1008. --- .../edit/src/creation/LocatorController.js | 2 +- .../test/creation/LocatorControllerSpec.js | 39 ++++++++++++------- 2 files changed, 26 insertions(+), 15 deletions(-) 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); + }); + + }); }); } );