[Plot] Handle telemetry panels from plot policy (#1732)

* [Plot] Check for telemetry panels

...from plot view policy, and don't try to interrogate them
for telemetry metadata that they will not have.

Fixes #1728

* [Plot] Update test case for policy

...to provide an adapted object with expected properties

* [Plot] Add tests to very plot policy for panels

...to verify fix for #1728
This commit is contained in:
Victor Woeltjen 2017-09-25 14:27:32 -07:00 committed by Pete Richards
parent 8754c438cc
commit 374c363a78
2 changed files with 36 additions and 3 deletions

View File

@ -36,6 +36,13 @@ define(
PlotViewPolicy.prototype.hasNumericTelemetry = function (domainObject) {
var adaptedObject = domainObject.useCapability('adapter');
if (!adaptedObject.telemetry) {
return domainObject.hasCapability('delegation') &&
domainObject.getCapability('delegation')
.doesDelegateCapability('telemetry');
}
var metadata = this.openmct.telemetry.getMetadata(adaptedObject);
var rangeValues = metadata.valuesForHints(['range']);
if (rangeValues.length === 0) {

View File

@ -27,17 +27,19 @@ define(
describe("Plot view policy", function () {
var testView,
mockDomainObject,
testAdaptedObject,
openmct,
telemetryMetadata,
policy;
beforeEach(function () {
testView = { key: "plot" };
testAdaptedObject = { telemetry: {} };
mockDomainObject = jasmine.createSpyObj(
'domainObject',
['useCapability']
['useCapability', 'hasCapability', 'getCapability']
);
mockDomainObject.useCapability.andReturn('adaptedObject');
mockDomainObject.useCapability.andReturn(testAdaptedObject);
openmct = {
telemetry: jasmine.createSpyObj('telemetryAPI', [
'getMetadata'
@ -56,7 +58,7 @@ define(
expect(mockDomainObject.useCapability)
.toHaveBeenCalledWith('adapter');
expect(openmct.telemetry.getMetadata)
.toHaveBeenCalledWith('adaptedObject');
.toHaveBeenCalledWith(testAdaptedObject);
expect(telemetryMetadata.valuesForHints)
.toHaveBeenCalledWith(['range']);
});
@ -87,6 +89,30 @@ define(
expect(policy.allow(testView, mockDomainObject)).toBe(true);
});
it('returns true for telemetry delegators', function () {
delete testAdaptedObject.telemetry;
mockDomainObject.hasCapability.andCallFake(function (c) {
return c === 'delegation';
});
mockDomainObject.getCapability.andReturn(
jasmine.createSpyObj('delegation', [
'doesDelegateCapability'
])
);
mockDomainObject.getCapability('delegation')
.doesDelegateCapability.andCallFake(function (c) {
return c === 'telemetry';
});
expect(policy.allow(testView, mockDomainObject)).toBe(true);
expect(openmct.telemetry.getMetadata).not.toHaveBeenCalled();
});
it('returns true for non-telemetry non-delegators', function () {
delete testAdaptedObject.telemetry;
mockDomainObject.hasCapability.andReturn(false);
expect(policy.allow(testView, mockDomainObject)).toBe(false);
});
it("allows other views", function () {
testView.key = "somethingElse";
expect(policy.allow(testView, mockDomainObject)).toBe(true);