mirror of
https://github.com/nasa/openmct.git
synced 2024-12-27 00:31:06 +00:00
[Inspector] Update controller and its tests
Update ObjectInspectorController to first look at ngModel.inspectionObjects before defaulting back to ngModel.selectedObject Updated tests accordingly.
This commit is contained in:
parent
8c811c4a22
commit
b0b87d7fd9
@ -39,15 +39,16 @@ define(
|
||||
$scope.primaryParents = [];
|
||||
$scope.contextutalParents = [];
|
||||
|
||||
// Gets an array of the contextual parents/anscestors of the selected object
|
||||
// Gets an array of the contextual parents/anscestors of the (first) inspected object
|
||||
function getContextualPath() {
|
||||
var currentObj,
|
||||
currentParent,
|
||||
parents = [];
|
||||
|
||||
if ($scope.ngModel && $scope.ngModel.inspectionObjects) {
|
||||
if ($scope.ngModel && $scope.ngModel.inspectionObjects && $scope.ngModel.inspectionObjects[0]) {
|
||||
currentObj = $scope.ngModel.inspectionObjects[0];
|
||||
} else {
|
||||
// Fallback for if the inspection objects are not defined is the selected object
|
||||
currentObj = $scope.ngModel && $scope.ngModel.selectedObject;
|
||||
}
|
||||
|
||||
@ -55,6 +56,7 @@ define(
|
||||
currentObj.hasCapability('context') &&
|
||||
currentObj.getCapability('context').getParent();
|
||||
|
||||
// Loop while this has a parent that is not the root object
|
||||
while (currentParent && currentParent.getModel().type !== 'root' &&
|
||||
currentParent.hasCapability('context')) {
|
||||
// Record this object
|
||||
@ -68,19 +70,22 @@ define(
|
||||
$scope.contextutalParents = parents;
|
||||
}
|
||||
|
||||
// Gets an array of the parents/anscestors of the selected object's
|
||||
// Gets an array of the parents/anscestors of the (first) inspected object's
|
||||
// primary location (locational of original non-link)
|
||||
function getPrimaryPath(current) {
|
||||
var location;
|
||||
|
||||
// If this the the initial call of this recursive function
|
||||
if (!current) {
|
||||
if ($scope.ngModel && $scope.ngModel.inspectionObjects) {
|
||||
// Set the object we are looking at
|
||||
if ($scope.ngModel && $scope.ngModel.inspectionObjects && $scope.ngModel.inspectionObjects[0]) {
|
||||
current = $scope.ngModel.inspectionObjects[0];
|
||||
} else {
|
||||
// Fallback for if the inspection objects are not defined is the selected object
|
||||
current = $scope.ngModel && $scope.ngModel.selectedObject;
|
||||
}
|
||||
|
||||
// And reset the parents array
|
||||
$scope.primaryParents = [];
|
||||
}
|
||||
|
||||
@ -98,41 +103,36 @@ define(
|
||||
|
||||
// Gets the metadata for the selected object
|
||||
function getMetadata() {
|
||||
// We want to get info from the inspectionObjects, but otherwise just use
|
||||
// the selectedObject.
|
||||
if ($scope.ngModel && $scope.ngModel.inspectionObjects &&
|
||||
if ($scope.ngModel &&
|
||||
$scope.ngModel.inspectionObjects &&
|
||||
$scope.ngModel.inspectionObjects[0] &&
|
||||
$scope.ngModel.inspectionObjects[0].hasCapability('metadata')) {
|
||||
// Get metadata from the inspected object
|
||||
$scope.metadata = $scope.ngModel.inspectionObjects[0].useCapability('metadata');
|
||||
} else {
|
||||
// Fallback for if the inspection objects are not defined is the selected object
|
||||
$scope.metadata = $scope.ngModel && $scope.ngModel.selectedObject &&
|
||||
$scope.ngModel.selectedObject.hasCapability('metadata') &&
|
||||
$scope.ngModel.selectedObject.useCapability('metadata');
|
||||
}
|
||||
}
|
||||
|
||||
// Set scope variables when the selected object changes
|
||||
$scope.$watch('ngModel.selectedObject', function () {
|
||||
var isLink = $scope && $scope.ngModel &&
|
||||
$scope.ngModel.selectedObject &&
|
||||
$scope.ngModel.selectedObject.hasCapability('location') &&
|
||||
$scope.ngModel.selectedObject.getCapability('location').isLink();
|
||||
$scope.$watch('ngModel.inspectionObjects', function () {
|
||||
var isLink;
|
||||
|
||||
if (isLink) {
|
||||
getPrimaryPath();
|
||||
getContextualPath();
|
||||
if ($scope && $scope.ngModel &&
|
||||
$scope.ngModel.inspectionObjects &&
|
||||
$scope.ngModel.inspectionObjects[0]) {
|
||||
isLink = $scope.ngModel.inspectionObjects[0].hasCapability('location') &&
|
||||
$scope.ngModel.inspectionObjects[0].getCapability('location').isLink();
|
||||
} else {
|
||||
$scope.primaryParents = [];
|
||||
getContextualPath();
|
||||
// Fallback for if the inspection objects are not defined is the selected object
|
||||
isLink = $scope && $scope.ngModel &&
|
||||
$scope.ngModel.selectedObject &&
|
||||
$scope.ngModel.selectedObject.hasCapability('location') &&
|
||||
$scope.ngModel.selectedObject.getCapability('location').isLink();
|
||||
}
|
||||
|
||||
getMetadata();
|
||||
});
|
||||
|
||||
$scope.$watch('ngModel.inspectionObjects[0]', function () {
|
||||
var isLink = $scope && $scope.ngModel &&
|
||||
$scope.ngModel.inspectionObjects &&
|
||||
$scope.ngModel.inspectionObjects[0].hasCapability('location') &&
|
||||
$scope.ngModel.inspectionObjects[0].getCapability('location').isLink();
|
||||
|
||||
if (isLink) {
|
||||
getPrimaryPath();
|
||||
|
@ -36,7 +36,8 @@ define(
|
||||
mockDomainObject,
|
||||
mockContextCapability,
|
||||
mockLocationCapability,
|
||||
controller;
|
||||
controller,
|
||||
treePosCounter = 0;
|
||||
|
||||
beforeEach(function () {
|
||||
mockScope = jasmine.createSpyObj(
|
||||
@ -45,6 +46,7 @@ define(
|
||||
);
|
||||
mockScope.ngModel = {};
|
||||
mockScope.ngModel.selectedObject = 'mock selected object';
|
||||
mockScope.ngModel.inspectionObjects = [];
|
||||
|
||||
mockObjectService = jasmine.createSpyObj(
|
||||
"objectService",
|
||||
@ -57,10 +59,18 @@ define(
|
||||
mockObjectService.getObjects.andReturn(mockPromise);
|
||||
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"selectedObject",
|
||||
"domainObject",
|
||||
[ "hasCapability", "getCapability", "useCapability", "getModel" ]
|
||||
);
|
||||
mockDomainObject.getModel.andReturn({location: 'somewhere'});
|
||||
mockDomainObject.getModel.andCallFake(function () {
|
||||
// Simulate having a tree by making it take iterations to reach root
|
||||
if (treePosCounter > 5) {
|
||||
return {location: 'somewhere', type: 'root'};
|
||||
} else {
|
||||
treePosCounter += 1;
|
||||
return {location: 'somewhere', type: 'something'};
|
||||
}
|
||||
});
|
||||
mockDomainObject.hasCapability.andReturn(true);
|
||||
|
||||
mockContextCapability = jasmine.createSpyObj(
|
||||
@ -78,15 +88,16 @@ define(
|
||||
return mockContextCapability;
|
||||
}
|
||||
});
|
||||
mockContextCapability.getParent.andReturn(mockDomainObject);
|
||||
|
||||
controller = new ObjectInspectorController(mockScope, mockObjectService);
|
||||
|
||||
// Change the selected object to trigger the watch call
|
||||
mockScope.ngModel.selectedObject = mockDomainObject;
|
||||
// Change the inspected object to trigger the watch call
|
||||
mockScope.ngModel.inspectionObjects[0] = mockDomainObject;
|
||||
});
|
||||
|
||||
it("watches for changes to the selected object", function () {
|
||||
expect(mockScope.$watch).toHaveBeenCalledWith('ngModel.selectedObject', jasmine.any(Function));
|
||||
it("watches for changes to the inspection objects", function () {
|
||||
expect(mockScope.$watch).toHaveBeenCalledWith('ngModel.inspectionObjects', jasmine.any(Function));
|
||||
});
|
||||
|
||||
it("looks for contextual parent objects", function () {
|
||||
@ -94,7 +105,7 @@ define(
|
||||
expect(mockContextCapability.getParent).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("if link, looks for primary parent objects", function () {
|
||||
it("looks for primary parent objects if it is a link", function () {
|
||||
mockLocationCapability.isLink.andReturn(true);
|
||||
|
||||
mockScope.$watch.mostRecentCall.args[1]();
|
||||
@ -107,6 +118,19 @@ define(
|
||||
mockScope.$watch.mostRecentCall.args[1]();
|
||||
expect(mockDomainObject.useCapability).toHaveBeenCalledWith('metadata');
|
||||
});
|
||||
|
||||
it("falls back on the selected object if there are no inspection objects", function () {
|
||||
mockDomainObject.useCapability.reset();
|
||||
|
||||
mockScope.ngModel.selectedObject = mockDomainObject;
|
||||
mockScope.ngModel.inspectionObjects = undefined;
|
||||
|
||||
expect(mockScope.$watch).toHaveBeenCalledWith('ngModel.inspectionObjects', jasmine.any(Function));
|
||||
mockLocationCapability.isLink.andReturn(true);
|
||||
mockScope.$watch.mostRecentCall.args[1]();
|
||||
|
||||
expect(mockDomainObject.useCapability).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
Loading…
Reference in New Issue
Block a user