mirror of
https://github.com/nasa/openmct.git
synced 2025-05-31 22:50:49 +00:00
[Create] #491 Locator is not visible when creating a new object where selected object does not have location
Added additional test for default context Fixed JSLint error
This commit is contained in:
parent
fcae3fd7a9
commit
54653f3914
@ -117,7 +117,8 @@ define([
|
|||||||
"implementation": LocatorController,
|
"implementation": LocatorController,
|
||||||
"depends": [
|
"depends": [
|
||||||
"$scope",
|
"$scope",
|
||||||
"$timeout"
|
"$timeout",
|
||||||
|
"objectService"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -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;
|
||||||
|
@ -35,6 +35,8 @@ define(
|
|||||||
mockDomainObject,
|
mockDomainObject,
|
||||||
mockRootObject,
|
mockRootObject,
|
||||||
mockContext,
|
mockContext,
|
||||||
|
mockObjectService,
|
||||||
|
getObjectsPromise,
|
||||||
controller;
|
controller;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@ -55,73 +57,106 @@ 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 () {
|
||||||
|
|
||||||
it("adds a treeModel to scope", function () {
|
beforeEach(function () {
|
||||||
expect(mockScope.treeModel).toBeDefined();
|
mockContext.getRoot.andReturn(mockRootObject);
|
||||||
});
|
controller = new LocatorController(mockScope, mockTimeout, mockObjectService);
|
||||||
|
});
|
||||||
|
|
||||||
it("watches for changes to treeModel", function () {
|
it("adds a treeModel to scope", function () {
|
||||||
// This is what the embedded tree representation
|
expect(mockScope.treeModel).toBeDefined();
|
||||||
// will be modifying.
|
});
|
||||||
expect(mockScope.$watch).toHaveBeenCalledWith(
|
|
||||||
"treeModel.selectedObject",
|
|
||||||
jasmine.any(Function)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("changes its own model on embedded model updates", function () {
|
it("watches for changes to treeModel", function () {
|
||||||
// Need to pass on selection changes as updates to
|
// This is what the embedded tree representation
|
||||||
// the control's value
|
// will be modifying.
|
||||||
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
expect(mockScope.$watch).toHaveBeenCalledWith(
|
||||||
mockTimeout.mostRecentCall.args[0]();
|
"treeModel.selectedObject",
|
||||||
expect(mockScope.ngModel.someField).toEqual(mockDomainObject);
|
jasmine.any(Function)
|
||||||
expect(mockScope.rootObject).toEqual(mockRootObject);
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// Verify that the capability we expect to have been used
|
it("changes its own model on embedded model updates", function () {
|
||||||
// was used.
|
// Need to pass on selection changes as updates to
|
||||||
expect(mockDomainObject.getCapability)
|
// the control's value
|
||||||
.toHaveBeenCalledWith("context");
|
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
||||||
});
|
mockTimeout.mostRecentCall.args[0]();
|
||||||
|
expect(mockScope.ngModel.someField).toEqual(mockDomainObject);
|
||||||
|
expect(mockScope.rootObject).toEqual(mockRootObject);
|
||||||
|
|
||||||
it("rejects changes which fail validation", function () {
|
// Verify that the capability we expect to have been used
|
||||||
mockScope.structure = { validate: jasmine.createSpy('validate') };
|
// was used.
|
||||||
mockScope.structure.validate.andReturn(false);
|
expect(mockDomainObject.getCapability)
|
||||||
|
.toHaveBeenCalledWith("context");
|
||||||
|
});
|
||||||
|
|
||||||
// Pass selection change
|
it("rejects changes which fail validation", function () {
|
||||||
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
mockScope.structure = { validate: jasmine.createSpy('validate') };
|
||||||
mockTimeout.mostRecentCall.args[0]();
|
mockScope.structure.validate.andReturn(false);
|
||||||
|
|
||||||
expect(mockScope.structure.validate).toHaveBeenCalled();
|
// Pass selection change
|
||||||
// Change should have been rejected
|
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
||||||
expect(mockScope.ngModel.someField).not.toEqual(mockDomainObject);
|
mockTimeout.mostRecentCall.args[0]();
|
||||||
});
|
|
||||||
|
|
||||||
it("treats a lack of a selection as invalid", function () {
|
expect(mockScope.structure.validate).toHaveBeenCalled();
|
||||||
mockScope.ngModelController = jasmine.createSpyObj(
|
// Change should have been rejected
|
||||||
'ngModelController',
|
expect(mockScope.ngModel.someField).not.toEqual(mockDomainObject);
|
||||||
[ '$setValidity' ]
|
});
|
||||||
);
|
|
||||||
|
|
||||||
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
it("treats a lack of a selection as invalid", function () {
|
||||||
mockTimeout.mostRecentCall.args[0]();
|
mockScope.ngModelController = jasmine.createSpyObj(
|
||||||
expect(mockScope.ngModelController.$setValidity)
|
'ngModelController',
|
||||||
.toHaveBeenCalledWith(jasmine.any(String), true);
|
[ '$setValidity' ]
|
||||||
|
);
|
||||||
|
|
||||||
mockScope.$watch.mostRecentCall.args[1](undefined);
|
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
||||||
mockTimeout.mostRecentCall.args[0]();
|
mockTimeout.mostRecentCall.args[0]();
|
||||||
expect(mockScope.ngModelController.$setValidity)
|
expect(mockScope.ngModelController.$setValidity)
|
||||||
.toHaveBeenCalledWith(jasmine.any(String), false);
|
.toHaveBeenCalledWith(jasmine.any(String), true);
|
||||||
});
|
|
||||||
|
|
||||||
|
mockScope.$watch.mostRecentCall.args[1](undefined);
|
||||||
|
mockTimeout.mostRecentCall.args[0]();
|
||||||
|
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);
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user