Merge pull request #625 from nasa/open491

[Create] #491 Apply default context root in Locator when none available from object
This commit is contained in:
Victor Woeltjen 2016-02-05 17:30:22 -08:00
commit 5d4ace64cb
3 changed files with 98 additions and 50 deletions

View File

@ -117,7 +117,8 @@ define([
"implementation": LocatorController, "implementation": LocatorController,
"depends": [ "depends": [
"$scope", "$scope",
"$timeout" "$timeout",
"objectService"
] ]
}, },
{ {

View File

@ -33,7 +33,7 @@ define(
* @memberof platform/commonUI/browse * @memberof platform/commonUI/browse
* @constructor * @constructor
*/ */
function LocatorController($scope, $timeout) { function LocatorController($scope, $timeout, objectService) {
// Populate values needed by the locator control. These are: // Populate values needed by the locator control. These are:
// * rootObject: The top-level object, since we want to show // * rootObject: The top-level object, since we want to show
// the full tree // the full tree
@ -52,6 +52,18 @@ define(
$scope.rootObject = $scope.rootObject =
(context && context.getRoot()) || $scope.rootObject; (context && context.getRoot()) || $scope.rootObject;
}, 0); }, 0);
} else if (!contextRoot){
//If no context root is available, default to the root
// object
$scope.rootObject = undefined;
// Update the displayed tree on a timeout to avoid
// an infinite digest exception.
objectService.getObjects(['ROOT'])
.then(function(objects){
$timeout(function () {
$scope.rootObject = objects.ROOT;
}, 0);
});
} }
$scope.treeModel.selectedObject = domainObject; $scope.treeModel.selectedObject = domainObject;

View File

@ -35,6 +35,8 @@ define(
mockDomainObject, mockDomainObject,
mockRootObject, mockRootObject,
mockContext, mockContext,
mockObjectService,
getObjectsPromise,
controller; controller;
beforeEach(function () { beforeEach(function () {
@ -55,14 +57,29 @@ define(
"context", "context",
[ "getRoot" ] [ "getRoot" ]
); );
mockObjectService = jasmine.createSpyObj(
"objectService",
["getObjects"]
);
getObjectsPromise = jasmine.createSpyObj(
"promise",
["then"]
);
mockDomainObject.getCapability.andReturn(mockContext); mockDomainObject.getCapability.andReturn(mockContext);
mockContext.getRoot.andReturn(mockRootObject); mockContext.getRoot.andReturn(mockRootObject);
mockObjectService.getObjects.andReturn(getObjectsPromise);
mockScope.ngModel = {}; mockScope.ngModel = {};
mockScope.field = "someField"; mockScope.field = "someField";
controller = new LocatorController(mockScope, mockTimeout); controller = new LocatorController(mockScope, mockTimeout, mockObjectService);
});
describe("when context is available", function () {
beforeEach(function () {
mockContext.getRoot.andReturn(mockRootObject);
controller = new LocatorController(mockScope, mockTimeout, mockObjectService);
}); });
it("adds a treeModel to scope", function () { it("adds a treeModel to scope", function () {
@ -121,7 +138,25 @@ define(
expect(mockScope.ngModelController.$setValidity) expect(mockScope.ngModelController.$setValidity)
.toHaveBeenCalledWith(jasmine.any(String), false); .toHaveBeenCalledWith(jasmine.any(String), false);
}); });
});
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);
});
});
}); });
} }
); );