mirror of
https://github.com/nasa/openmct.git
synced 2025-06-18 23:28:14 +00:00
Forbid condition sets on bar graphs and add a test (#4434)
* forbid condition sets on bar graph
This commit is contained in:
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
Reference in New Issue
Block a user