Forbid condition sets on bar graphs and add a test (#4434)

* forbid condition sets on bar graph
This commit is contained in:
Scott Bell
2021-12-06 22:49:28 +01:00
committed by GitHub
parent e1e2cf9be8
commit 09b49f31ab
2 changed files with 50 additions and 3 deletions

View File

@ -26,7 +26,7 @@ export default function BarGraphCompositionPolicy(openmct) {
function hasRange(metadata) { function hasRange(metadata) {
const rangeValues = metadata.valuesForHints(['range']); const rangeValues = metadata.valuesForHints(['range']);
return rangeValues.length > 0; return rangeValues && rangeValues.length > 0;
} }
function hasBarGraphTelemetry(domainObject) { function hasBarGraphTelemetry(domainObject) {
@ -41,8 +41,12 @@ export default function BarGraphCompositionPolicy(openmct) {
return { return {
allow: function (parent, child) { allow: function (parent, child) {
if (child.type === 'conditionSet') {
return false;
}
if ((parent.type === BAR_GRAPH_KEY) if ((parent.type === BAR_GRAPH_KEY)
&& (hasBarGraphTelemetry(child) === false) && (!hasBarGraphTelemetry(child))
) { ) {
return false; return false;
} }

View File

@ -283,7 +283,6 @@ describe("the plugin", function () {
}); });
describe("The bar graph composition policy", () => { describe("The bar graph composition policy", () => {
it("allows composition for telemetry that contain at least one range", () => { it("allows composition for telemetry that contain at least one range", () => {
const parent = { const parent = {
"composition": [], "composition": [],
@ -365,6 +364,50 @@ describe("the plugin", function () {
}).toThrow(); }).toThrow();
expect(parent.composition.length).toBe(0); expect(parent.composition.length).toBe(0);
}); });
it("disallows composition for condition sets", () => {
const parent = {
"composition": [],
"configuration": {},
"name": "Some Bar Graph",
"type": "telemetry.plot.bar-graph",
"location": "mine",
"modified": 1631005183584,
"persisted": 1631005183502,
"identifier": {
"namespace": "",
"key": "b78e7e23-f2b8-4776-b1f0-3ff778f5c8a9"
}
};
const testTelemetryObject = {
identifier: {
namespace: "",
key: "test-object"
},
type: "conditionSet",
name: "Test Object",
telemetry: {
values: [{
key: "some-key",
name: "Some attribute",
format: "enum",
hints: {
domain: 1
}
}, {
key: "some-other-key",
name: "Another attribute",
hints: {
range: 1
}
}]
}
};
const composition = openmct.composition.get(parent);
expect(() => {
composition.add(testTelemetryObject);
}).toThrow();
expect(parent.composition.length).toBe(0);
});
}); });
describe('the inspector view', () => { describe('the inspector view', () => {
let mockComposition; let mockComposition;