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,
"depends": [
"$scope",
"$timeout"
"$timeout",
"objectService"
]
},
{

View File

@ -33,7 +33,7 @@ define(
* @memberof platform/commonUI/browse
* @constructor
*/
function LocatorController($scope, $timeout) {
function LocatorController($scope, $timeout, objectService) {
// Populate values needed by the locator control. These are:
// * rootObject: The top-level object, since we want to show
// the full tree
@ -52,6 +52,18 @@ define(
$scope.rootObject =
(context && context.getRoot()) || $scope.rootObject;
}, 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;

View File

@ -35,6 +35,8 @@ define(
mockDomainObject,
mockRootObject,
mockContext,
mockObjectService,
getObjectsPromise,
controller;
beforeEach(function () {
@ -55,14 +57,29 @@ define(
"context",
[ "getRoot" ]
);
mockObjectService = jasmine.createSpyObj(
"objectService",
["getObjects"]
);
getObjectsPromise = jasmine.createSpyObj(
"promise",
["then"]
);
mockDomainObject.getCapability.andReturn(mockContext);
mockContext.getRoot.andReturn(mockRootObject);
mockObjectService.getObjects.andReturn(getObjectsPromise);
mockScope.ngModel = {};
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 () {
@ -121,7 +138,25 @@ define(
expect(mockScope.ngModelController.$setValidity)
.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);
});
});
});
}
);