mirror of
https://github.com/nasa/openmct.git
synced 2025-01-16 01:40:06 +00:00
[Inspector] Update tests
Updated the object inspector controller spec to test for the different types of locations. #73.
This commit is contained in:
parent
70324a2198
commit
33d88ecce0
@ -84,14 +84,16 @@ define(
|
|||||||
|
|
||||||
// Gets the metadata for the selected object
|
// Gets the metadata for the selected object
|
||||||
function getMetadata() {
|
function getMetadata() {
|
||||||
var sel = $scope.ngModel.selectedObject;
|
$scope.metadata = $scope.ngModel.selectedObject &&
|
||||||
$scope.metadata = sel && sel.hasCapability('metadata') && sel.useCapability('metadata');
|
$scope.ngModel.selectedObject.hasCapability('metadata') &&
|
||||||
|
$scope.ngModel.selectedObject.useCapability('metadata');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set scope variables when the selected object changes
|
// Set scope variables when the selected object changes
|
||||||
$scope.$watch('ngModel.selectedObject', function () {
|
$scope.$watch('ngModel.selectedObject', function () {
|
||||||
var sel = $scope.ngModel.selectedObject;
|
$scope.isLink = $scope.ngModel.selectedObject &&
|
||||||
$scope.isLink = sel && sel.hasCapability('location') && sel.getCapability('location').isLink();
|
$scope.ngModel.selectedObject.hasCapability('location') &&
|
||||||
|
$scope.ngModel.selectedObject.getCapability('location').isLink();
|
||||||
|
|
||||||
if ($scope.isLink) {
|
if ($scope.isLink) {
|
||||||
getPrimaryPath();
|
getPrimaryPath();
|
||||||
|
@ -29,26 +29,16 @@ define(
|
|||||||
function (ObjectInspectorController) {
|
function (ObjectInspectorController) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("The object inspector controller", function () {
|
describe("The object inspector controller ", function () {
|
||||||
var mockScope,
|
var mockScope,
|
||||||
|
mockObjectService,
|
||||||
|
mockPromise,
|
||||||
mockDomainObject,
|
mockDomainObject,
|
||||||
mockContextCapability,
|
mockContextCapability,
|
||||||
|
mockLocationCapability,
|
||||||
controller;
|
controller;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockDomainObject = jasmine.createSpyObj(
|
|
||||||
"selectedObject",
|
|
||||||
[ "hasCapability", "getCapability", "useCapability", "getModel" ]
|
|
||||||
);
|
|
||||||
mockDomainObject.getModel.andReturn({type: 'type 2'});
|
|
||||||
|
|
||||||
mockContextCapability = jasmine.createSpyObj(
|
|
||||||
"context capability",
|
|
||||||
[ "getParent" ]
|
|
||||||
);
|
|
||||||
mockDomainObject.hasCapability.andReturn(true);
|
|
||||||
mockDomainObject.getCapability.andReturn(mockContextCapability);
|
|
||||||
|
|
||||||
mockScope = jasmine.createSpyObj(
|
mockScope = jasmine.createSpyObj(
|
||||||
"$scope",
|
"$scope",
|
||||||
[ "$watch" ]
|
[ "$watch" ]
|
||||||
@ -56,22 +46,64 @@ define(
|
|||||||
mockScope.ngModel = {};
|
mockScope.ngModel = {};
|
||||||
mockScope.ngModel.selectedObject = 'mock selected object';
|
mockScope.ngModel.selectedObject = 'mock selected object';
|
||||||
|
|
||||||
controller = new ObjectInspectorController(mockScope);
|
mockObjectService = jasmine.createSpyObj(
|
||||||
|
"objectService",
|
||||||
|
[ "getObjects" ]
|
||||||
|
);
|
||||||
|
mockPromise = jasmine.createSpyObj(
|
||||||
|
"promise",
|
||||||
|
[ "then" ]
|
||||||
|
);
|
||||||
|
mockObjectService.getObjects.andReturn(mockPromise);
|
||||||
|
|
||||||
|
mockDomainObject = jasmine.createSpyObj(
|
||||||
|
"selectedObject",
|
||||||
|
[ "hasCapability", "getCapability", "useCapability", "getModel" ]
|
||||||
|
);
|
||||||
|
mockDomainObject.getModel.andReturn({location: 'somewhere'});
|
||||||
|
mockDomainObject.hasCapability.andReturn(true);
|
||||||
|
|
||||||
|
mockContextCapability = jasmine.createSpyObj(
|
||||||
|
"context capability",
|
||||||
|
[ "getParent" ]
|
||||||
|
);
|
||||||
|
mockLocationCapability = jasmine.createSpyObj(
|
||||||
|
"location capability",
|
||||||
|
[ "isLink" ]
|
||||||
|
);
|
||||||
|
mockDomainObject.getCapability.andCallFake(function (param) {
|
||||||
|
if (param === 'location') {
|
||||||
|
return mockLocationCapability;
|
||||||
|
} else if (param === 'context') {
|
||||||
|
return mockContextCapability;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
controller = new ObjectInspectorController(mockScope, mockObjectService);
|
||||||
|
|
||||||
// Change the selected object to trigger the watch call
|
// Change the selected object to trigger the watch call
|
||||||
mockScope.ngModel.selectedObject = mockDomainObject;
|
mockScope.ngModel.selectedObject = mockDomainObject;
|
||||||
});
|
});
|
||||||
|
|
||||||
it(" watches for changes to the selected object", function () {
|
it("watches for changes to the selected object", function () {
|
||||||
expect(mockScope.$watch).toHaveBeenCalledWith('ngModel.selectedObject', jasmine.any(Function));
|
expect(mockScope.$watch).toHaveBeenCalledWith('ngModel.selectedObject', jasmine.any(Function));
|
||||||
});
|
});
|
||||||
|
|
||||||
it(" looks for parent objects", function () {
|
it("looks for contextual parent objects", function () {
|
||||||
mockScope.$watch.mostRecentCall.args[1]();
|
mockScope.$watch.mostRecentCall.args[1]();
|
||||||
expect(mockContextCapability.getParent).toHaveBeenCalled();
|
expect(mockContextCapability.getParent).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it(" gets metadata", function () {
|
it("if link, looks for primary parent objects", function () {
|
||||||
|
mockLocationCapability.isLink.andReturn(true);
|
||||||
|
|
||||||
|
mockScope.$watch.mostRecentCall.args[1]();
|
||||||
|
expect(mockDomainObject.getModel).toHaveBeenCalled();
|
||||||
|
expect(mockObjectService.getObjects).toHaveBeenCalled();
|
||||||
|
mockPromise.then.mostRecentCall.args[0]({'somewhere': mockDomainObject});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("gets metadata", function () {
|
||||||
mockScope.$watch.mostRecentCall.args[1]();
|
mockScope.$watch.mostRecentCall.args[1]();
|
||||||
expect(mockDomainObject.useCapability).toHaveBeenCalledWith('metadata');
|
expect(mockDomainObject.useCapability).toHaveBeenCalledWith('metadata');
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user