Conditional set output is wrong (#6244)

* Only use default if we've evaluated as default
* Add e2e test for conditional sets
---------

Co-authored-by: Shefali Joshi <simplyrender@gmail.com>
Co-authored-by: Andrew Henry <akhenry@gmail.com>
This commit is contained in:
Scott Bell 2023-03-17 16:58:09 +01:00 committed by GitHub
parent eff0cc96b9
commit 6cb5c47f3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 107 additions and 19 deletions

View File

@ -52,10 +52,9 @@ test.describe.serial('Condition Set CRUD Operations on @localStorage', () => {
//Set object identifier from url //Set object identifier from url
conditionSetUrl = page.url(); conditionSetUrl = page.url();
console.log('conditionSetUrl ' + conditionSetUrl);
getConditionSetIdentifierFromUrl = conditionSetUrl.split('/').pop().split('?')[0]; getConditionSetIdentifierFromUrl = conditionSetUrl.split('/').pop().split('?')[0];
console.debug('getConditionSetIdentifierFromUrl ' + getConditionSetIdentifierFromUrl); console.debug(`getConditionSetIdentifierFromUrl: ${getConditionSetIdentifierFromUrl}`);
await page.close(); await page.close();
}); });
@ -246,4 +245,81 @@ test.describe('Basic Condition Set Use', () => {
await expect(page.getByRole('menuitem', { name: /Plot/ })).toBeVisible(); await expect(page.getByRole('menuitem', { name: /Plot/ })).toBeVisible();
await expect(page.getByRole('menuitem', { name: /Telemetry Table/ })).toBeVisible(); await expect(page.getByRole('menuitem', { name: /Telemetry Table/ })).toBeVisible();
}); });
test('ConditionSet should output blank instead of the default value', async ({ page }) => {
//Navigate to baseURL
await page.goto('./', { waitUntil: 'networkidle' });
//Click the Create button
await page.click('button:has-text("Create")');
// Click the object specified by 'type'
await page.click(`li[role='menuitem']:text("Sine Wave Generator")`);
await page.getByRole('spinbutton', { name: 'Loading Delay (ms)' }).fill('8000');
const nameInput = page.locator('form[name="mctForm"] .first input[type="text"]');
await nameInput.fill("Delayed Sine Wave Generator");
// Click OK button and wait for Navigate event
await Promise.all([
page.waitForLoadState(),
page.click('[aria-label="Save"]'),
// Wait for Save Banner to appear
page.waitForSelector('.c-message-banner__message')
]);
// Create a new condition set
await createDomainObjectWithDefaults(page, {
type: 'Condition Set',
name: "Test Blank Output of Condition Set"
});
// Change the object to edit mode
await page.locator('[title="Edit"]').click();
// Click Add Condition button twice
await page.locator('#addCondition').click();
await page.locator('#addCondition').click();
await page.locator('#conditionCollection').getByRole('textbox').nth(0).fill('First Condition');
await page.locator('#conditionCollection').getByRole('textbox').nth(1).fill('Second Condition');
// Expand the 'My Items' folder in the left tree
await page.locator('.c-tree__item__view-control.c-disclosure-triangle').first().click();
// Add the Sine Wave Generator to the Condition Set and save changes
const treePane = page.getByRole('tree', {
name: 'Main Tree'
});
const sineWaveGeneratorTreeItem = treePane.getByRole('treeitem', { name: "Delayed Sine Wave Generator"});
const conditionCollection = await page.locator('#conditionCollection');
await sineWaveGeneratorTreeItem.dragTo(conditionCollection);
const firstCriterionTelemetry = await page.locator('[aria-label="Criterion Telemetry Selection"] >> nth=0');
firstCriterionTelemetry.selectOption({ label: 'Delayed Sine Wave Generator' });
const secondCriterionTelemetry = await page.locator('[aria-label="Criterion Telemetry Selection"] >> nth=1');
secondCriterionTelemetry.selectOption({ label: 'Delayed Sine Wave Generator' });
const firstCriterionMetadata = await page.locator('[aria-label="Criterion Metadata Selection"] >> nth=0');
firstCriterionMetadata.selectOption({ label: 'Sine' });
const secondCriterionMetadata = await page.locator('[aria-label="Criterion Metadata Selection"] >> nth=1');
secondCriterionMetadata.selectOption({ label: 'Sine' });
const firstCriterionComparison = await page.locator('[aria-label="Criterion Comparison Selection"] >> nth=0');
firstCriterionComparison.selectOption({ label: 'is greater than or equal to' });
const secondCriterionComparison = await page.locator('[aria-label="Criterion Comparison Selection"] >> nth=1');
secondCriterionComparison.selectOption({ label: 'is less than' });
const firstCriterionInput = await page.locator('[aria-label="Criterion Input"] >> nth=0');
await firstCriterionInput.fill("0");
const secondCriterionInput = await page.locator('[aria-label="Criterion Input"] >> nth=1');
await secondCriterionInput.fill("0");
const saveButtonLocator = page.locator('button[title="Save"]');
await saveButtonLocator.click();
await page.getByRole('listitem', { name: 'Save and Finish Editing' }).click();
const outputValue = await page.locator('[aria-label="Current Output Value"]');
await expect(outputValue).toHaveText('---');
});
}); });

View File

@ -93,6 +93,11 @@ export default class ConditionManager extends EventEmitter {
); );
this.updateConditionResults({id: id}); this.updateConditionResults({id: id});
this.updateCurrentCondition(latestTimestamp); this.updateCurrentCondition(latestTimestamp);
if (Object.keys(this.telemetryObjects).length === 0) {
// no telemetry objects
this.emit('noTelemetryObjects');
}
} }
initialize() { initialize() {
@ -102,6 +107,11 @@ export default class ConditionManager extends EventEmitter {
this.initCondition(conditionConfiguration, index); this.initCondition(conditionConfiguration, index);
}); });
} }
if (Object.keys(this.telemetryObjects).length === 0) {
// no telemetry objects
this.emit('noTelemetryObjects');
}
} }
updateConditionTelemetryObjects() { updateConditionTelemetryObjects() {

View File

@ -132,6 +132,7 @@
<span class="c-cdef__controls"> <span class="c-cdef__controls">
<select <select
v-model="condition.configuration.trigger" v-model="condition.configuration.trigger"
aria-label="Condition Trigger"
@change="persist" @change="persist"
> >
<option <option

View File

@ -114,15 +114,11 @@ export default {
telemetryObjs: [], telemetryObjs: [],
moveIndex: undefined, moveIndex: undefined,
isDragging: false, isDragging: false,
defaultOutput: undefined,
dragCounter: 0, dragCounter: 0,
currentConditionId: '' currentConditionId: ''
}; };
}, },
watch: { watch: {
defaultOutput(newOutput, oldOutput) {
this.$emit('updateDefaultOutput', newOutput);
},
testData: { testData: {
handler() { handler() {
this.updateTestData(); this.updateTestData();
@ -158,7 +154,7 @@ export default {
this.observeForChanges(); this.observeForChanges();
this.conditionManager = new ConditionManager(this.domainObject, this.openmct); this.conditionManager = new ConditionManager(this.domainObject, this.openmct);
this.conditionManager.on('conditionSetResultUpdated', this.handleConditionSetResultUpdated); this.conditionManager.on('conditionSetResultUpdated', this.handleConditionSetResultUpdated);
this.updateDefaultCondition(); this.conditionManager.on('noTelemetryObjects', this.emitNoTelemetryObjectEvent);
this.stalenessSubscription = {}; this.stalenessSubscription = {};
}, },
methods: { methods: {
@ -166,18 +162,16 @@ export default {
this.currentConditionId = data.conditionId; this.currentConditionId = data.conditionId;
this.$emit('conditionSetResultUpdated', data); this.$emit('conditionSetResultUpdated', data);
}, },
emitNoTelemetryObjectEvent(data) {
this.currentConditionId = '';
this.$emit('noTelemetryObjects');
},
observeForChanges() { observeForChanges() {
this.stopObservingForChanges = this.openmct.objects.observe(this.domainObject, 'configuration.conditionCollection', (newConditionCollection) => { this.stopObservingForChanges = this.openmct.objects.observe(this.domainObject, 'configuration.conditionCollection', (newConditionCollection) => {
//this forces children to re-render //this forces children to re-render
this.conditionCollection = newConditionCollection.map(condition => condition); this.conditionCollection = newConditionCollection.map(condition => condition);
this.updateDefaultCondition();
}); });
}, },
updateDefaultCondition() {
const defaultCondition = this.domainObject.configuration.conditionCollection
.find(conditionConfiguration => conditionConfiguration.isDefault);
this.defaultOutput = defaultCondition.configuration.output;
},
setMoveIndex(index) { setMoveIndex(index) {
this.moveIndex = index; this.moveIndex = index;
this.isDragging = true; this.isDragging = true;

View File

@ -28,12 +28,15 @@
<section class="c-cs__current-output c-section"> <section class="c-cs__current-output c-section">
<div class="c-cs__content c-cs__current-output-value"> <div class="c-cs__content c-cs__current-output-value">
<span class="c-cs__current-output-value__label">Current Output</span> <span class="c-cs__current-output-value__label">Current Output</span>
<span class="c-cs__current-output-value__value"> <span
class="c-cs__current-output-value__value"
aria-label="Current Output Value"
>
<template v-if="currentConditionOutput"> <template v-if="currentConditionOutput">
{{ currentConditionOutput }} {{ currentConditionOutput }}
</template> </template>
<template v-else> <template v-else>
{{ defaultConditionOutput }} ---
</template> </template>
</span> </span>
</div> </div>
@ -51,7 +54,7 @@
:is-editing="isEditing" :is-editing="isEditing"
:test-data="testData" :test-data="testData"
@conditionSetResultUpdated="updateCurrentOutput" @conditionSetResultUpdated="updateCurrentOutput"
@updateDefaultOutput="updateDefaultOutput" @noTelemetryObjects="updateCurrentOutput('---')"
@telemetryUpdated="updateTelemetry" @telemetryUpdated="updateTelemetry"
@telemetryStaleness="handleStaleness" @telemetryStaleness="handleStaleness"
/> />
@ -75,7 +78,6 @@ export default {
data() { data() {
return { return {
currentConditionOutput: '', currentConditionOutput: '',
defaultConditionOutput: '',
telemetryObjs: [], telemetryObjs: [],
testData: {}, testData: {},
staleObjects: [] staleObjects: []

View File

@ -29,6 +29,7 @@
<select <select
ref="telemetrySelect" ref="telemetrySelect"
v-model="criterion.telemetry" v-model="criterion.telemetry"
aria-label="Criterion Telemetry Selection"
@change="updateMetadataOptions" @change="updateMetadataOptions"
> >
<option value="">- Select Telemetry -</option> <option value="">- Select Telemetry -</option>
@ -50,6 +51,7 @@
<select <select
ref="metadataSelect" ref="metadataSelect"
v-model="criterion.metadata" v-model="criterion.metadata"
aria-label="Criterion Metadata Selection"
@change="updateOperations" @change="updateOperations"
> >
<option value="">- Select Field -</option> <option value="">- Select Field -</option>
@ -69,6 +71,7 @@
> >
<select <select
v-model="criterion.operation" v-model="criterion.operation"
aria-label="Criterion Comparison Selection"
@change="updateInputVisibilityAndValues" @change="updateInputVisibilityAndValues"
> >
<option value="">- Select Comparison -</option> <option value="">- Select Comparison -</option>
@ -89,6 +92,7 @@
<input <input
v-model="criterion.input[inputIndex]" v-model="criterion.input[inputIndex]"
class="c-cdef__control__input" class="c-cdef__control__input"
aria-label="Criterion Input"
:type="setInputType" :type="setInputType"
@change="persist" @change="persist"
> >
@ -103,6 +107,7 @@
> >
<select <select
v-model="criterion.input[0]" v-model="criterion.input[0]"
aria-label="Criterion Else Selection"
@change="persist" @change="persist"
> >
<option <option

View File

@ -72,7 +72,7 @@ export default {
this.isEditing = isEditing; this.isEditing = isEditing;
}, },
formatTelemetry(event) { formatTelemetry(event) {
let newFormat = event.currentTarget.value; const newFormat = event.currentTarget.value;
this.openmct.selection.get().forEach(selectionPath => { this.openmct.selection.get().forEach(selectionPath => {
selectionPath[0].context.updateTelemetryFormat(newFormat); selectionPath[0].context.updateTelemetryFormat(newFormat);
}); });

View File

@ -193,7 +193,7 @@ export default {
}, },
telemetryValue() { telemetryValue() {
if (!this.datum) { if (!this.datum) {
return; return '---';
} }
return this.formatter && this.formatter.format(this.datum); return this.formatter && this.formatter.format(this.datum);