Updates conditionSet composition policy to allow only telemetry since we're no longer using composition for condition domain objects

This commit is contained in:
Joshi 2020-01-13 14:59:45 -08:00
parent 37650487f7
commit 8bbd7898bb
3 changed files with 45 additions and 20 deletions

View File

@ -24,9 +24,7 @@ export default function ConditionSetCompositionPolicy(openmct) {
return { return {
allow: function (parent, child) { allow: function (parent, child) {
let parentType = parent.type; let parentType = parent.type;
let childType = child.type; if (parentType === 'conditionSet' && !openmct.telemetry.isTelemetryObject(child)) {
if (parentType === 'conditionSet' && childType !== 'condition') {
return false; return false;
} }

View File

@ -21,43 +21,67 @@
*****************************************************************************/ *****************************************************************************/
import ConditionSetCompositionPolicy from './ConditionSetCompositionPolicy'; import ConditionSetCompositionPolicy from './ConditionSetCompositionPolicy';
import { createOpenMct } from "testTools";
describe('ConditionSetCompositionPolicy', () => { fdescribe('ConditionSetCompositionPolicy', () => {
let policy; let policy;
let testTelemetryObject;
let openmct = {};
let parentDomainObject; let parentDomainObject;
let childDomainObject;
let composition; let composition;
beforeEach(function () { beforeAll(function () {
policy = new ConditionSetCompositionPolicy(); testTelemetryObject = {
identifier:{ namespace: "", key: "test-object"},
type: "test-object",
name: "Test Object",
telemetry: {
values: [{
key: "some-key",
name: "Some attribute",
hints: {
domain: 1
}
}, {
key: "some-other-key",
name: "Another attribute",
hints: {
range: 1
}
}]
}
};
openmct.objects = jasmine.createSpyObj('objects', ['get', 'makeKeyString']);
openmct.objects.get.and.returnValue(testTelemetryObject);
openmct.objects.makeKeyString.and.returnValue(testTelemetryObject.identifier.key);
openmct.telemetry = jasmine.createSpyObj('telemetry', ['isTelemetryObject']);
policy = new ConditionSetCompositionPolicy(openmct);
parentDomainObject = {}; parentDomainObject = {};
childDomainObject = {};
composition = {}; composition = {};
}); });
it('returns true for object types that are not conditionSets', function () { it('returns true for object types that are not conditionSets', function () {
parentDomainObject.type = 'random'; parentDomainObject.type = 'random';
childDomainObject.type = ''; openmct.telemetry.isTelemetryObject.and.returnValue(false);
expect(policy.allow(parentDomainObject, childDomainObject)).toBe(true); expect(policy.allow(parentDomainObject, {})).toBe(true);
}); });
it('returns false for object types that are not conditions when parent is a conditionSet', function () { it('returns false for object types that are not telemetry objects when parent is a conditionSet', function () {
parentDomainObject.type = 'conditionSet'; parentDomainObject.type = 'conditionSet';
childDomainObject.type = ''; openmct.telemetry.isTelemetryObject.and.returnValue(false);
expect(policy.allow(parentDomainObject, childDomainObject)).toBe(false); expect(policy.allow(parentDomainObject, {})).toBe(false);
}); });
it('returns true for object types that are conditions when parent is a conditionSet', function () { it('returns true for object types that are telemetry objects when parent is a conditionSet', function () {
parentDomainObject.type = 'conditionSet'; parentDomainObject.type = 'conditionSet';
childDomainObject.type = 'condition'; openmct.telemetry.isTelemetryObject.and.returnValue(true);
expect(policy.allow(parentDomainObject, childDomainObject)).toBe(true); expect(policy.allow(parentDomainObject, testTelemetryObject)).toBe(true);
}); });
it('returns true for object types that are conditions when parent is not a conditionSet', function () { it('returns true for object types that are telemetry objects when parent is not a conditionSet', function () {
parentDomainObject.type = 'random'; parentDomainObject.type = 'random';
childDomainObject.type = 'condition'; openmct.telemetry.isTelemetryObject.and.returnValue(true);
expect(policy.allow(parentDomainObject, childDomainObject)).toBe(true); expect(policy.allow(parentDomainObject, testTelemetryObject)).toBe(true);
}); });
}); });

View File

@ -20,6 +20,7 @@
* at runtime from the About dialog for additional information. * at runtime from the About dialog for additional information.
*****************************************************************************/ *****************************************************************************/
import ConditionSetViewProvider from './ConditionSetViewProvider.js'; import ConditionSetViewProvider from './ConditionSetViewProvider.js';
import ConditionSetCompositionPolicy from "@/plugins/condition/ConditionSetCompositionPolicy";
export default function ConditionPlugin() { export default function ConditionPlugin() {
@ -45,6 +46,8 @@ export default function ConditionPlugin() {
} }
}); });
openmct.composition.addPolicy(new ConditionSetCompositionPolicy(openmct).allow);
openmct.objectViews.addProvider(new ConditionSetViewProvider(openmct)); openmct.objectViews.addProvider(new ConditionSetViewProvider(openmct));
} }