mirror of
https://github.com/nasa/openmct.git
synced 2024-12-20 21:53:08 +00:00
add tests
This commit is contained in:
parent
59461d6b06
commit
1b186d7596
@ -19,8 +19,8 @@
|
||||
* this source code distribution or the Licensing information page available
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
import { createDomainObjectWithDefaults } from '../../../../appActions.js';
|
||||
import { test } from '../../../../pluginFixtures.js';
|
||||
import { createDomainObjectWithDefaults, setRealTimeMode } from '../../../../appActions.js';
|
||||
import { expect, test } from '../../../../pluginFixtures.js';
|
||||
|
||||
test.describe('Comps', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
@ -28,8 +28,8 @@ test.describe('Comps', () => {
|
||||
await page.goto('./', { waitUntil: 'domcontentloaded' });
|
||||
});
|
||||
|
||||
test('Can add and remove telemetry sources', async ({ page }) => {
|
||||
// Create the gauge with defaults
|
||||
test('Basic Functionality Works', async ({ page }) => {
|
||||
// Create the comps with defaults
|
||||
const comp = await createDomainObjectWithDefaults(page, { type: 'Derived Telemetry' });
|
||||
|
||||
// Create a sine wave generator within the comp
|
||||
@ -38,6 +38,43 @@ test.describe('Comps', () => {
|
||||
parent: comp.uuid
|
||||
});
|
||||
|
||||
// Check that expressions can be edited
|
||||
await page.goto(comp.url);
|
||||
await page.getByLabel('Edit Object').click();
|
||||
await page.getByPlaceholder('Enter an expression').fill('a*2');
|
||||
await page.getByText('Current Output').click();
|
||||
await expect(page.getByText('Expression valid')).toBeVisible();
|
||||
|
||||
// Check that expressions are marked invalid
|
||||
await page.getByLabel('Reference Name Input for a').fill('b');
|
||||
await page.getByText('Current Output').click();
|
||||
await expect(page.getByText('Invalid: Undefined symbol a')).toBeVisible();
|
||||
|
||||
// Check that test data works
|
||||
await page.getByPlaceholder('Enter an expression').fill('b*2');
|
||||
await page.getByLabel('Reference Test Value for b').fill('5');
|
||||
await page.getByLabel('Apply Test Data').click();
|
||||
let testValue = await page.getByLabel('Current Output Value').textContent();
|
||||
expect(testValue).toBe('10');
|
||||
|
||||
// Check that real data works
|
||||
await page.getByLabel('Apply Test Data').click();
|
||||
await setRealTimeMode(page);
|
||||
testValue = await page.getByLabel('Current Output Value').textContent();
|
||||
expect(testValue).not.toBe('10');
|
||||
// should be a number
|
||||
expect(parseFloat(testValue)).not.toBeNaN();
|
||||
|
||||
// Check that the comps are saved
|
||||
await page.getByLabel('Save').click();
|
||||
await page.getByRole('listitem', { name: 'Save and Finish Editing' }).click();
|
||||
const expression = await page.getByLabel('Expression', { exact: true }).textContent();
|
||||
expect(expression).toBe('b*2');
|
||||
|
||||
// Check that comps work after being saved
|
||||
testValue = await page.getByLabel('Current Output Value').textContent();
|
||||
expect(testValue).not.toBe('10');
|
||||
// should be a number
|
||||
expect(parseFloat(testValue)).not.toBeNaN();
|
||||
});
|
||||
});
|
||||
|
@ -119,12 +119,10 @@ export default class CompsManager extends EventEmitter {
|
||||
await Promise.all(this.#telemetryLoadedPromises);
|
||||
this.#telemetryLoadedPromises = [];
|
||||
this.#loaded = true;
|
||||
console.debug('📦 CompsManager: loaded');
|
||||
}
|
||||
}
|
||||
|
||||
async startListeningToUnderlyingTelemetry() {
|
||||
console.debug('🎉 CompsManager: startListeningToUnderlyingTelemetry');
|
||||
this.#loaded = false;
|
||||
Object.keys(this.#telemetryCollections).forEach((keyString) => {
|
||||
if (!this.#telemetryCollections[keyString].loaded) {
|
||||
@ -140,7 +138,6 @@ export default class CompsManager extends EventEmitter {
|
||||
}
|
||||
|
||||
stopListeningToUnderlyingTelemetry() {
|
||||
console.debug('🔇 CompsManager: stopListeningToUnderlyingTelemetry');
|
||||
this.#loaded = false;
|
||||
Object.keys(this.#telemetryCollections).forEach((keyString) => {
|
||||
const specificTelemetryProcessor = this.#telemetryProcessors[keyString];
|
||||
@ -162,7 +159,6 @@ export default class CompsManager extends EventEmitter {
|
||||
this.#composition.on('remove', this.#removeTelemetryObject);
|
||||
await this.#composition.load();
|
||||
}
|
||||
console.debug(`📢 CompsManager: composition loaded`);
|
||||
}
|
||||
|
||||
getFullDataFrame(newTelemetry) {
|
||||
@ -202,7 +198,6 @@ export default class CompsManager extends EventEmitter {
|
||||
}
|
||||
|
||||
#removeTelemetryObject = (telemetryObjectIdentifier) => {
|
||||
console.debug('❌ CompsManager: removeTelemetryObject', telemetryObjectIdentifier);
|
||||
const keyString = this.#openmct.objects.makeKeyString(telemetryObjectIdentifier);
|
||||
delete this.#telemetryObjects[keyString];
|
||||
this.#telemetryCollections[keyString]?.destroy();
|
||||
@ -237,7 +232,6 @@ export default class CompsManager extends EventEmitter {
|
||||
};
|
||||
|
||||
clearData(telemetryLoadedPromise) {
|
||||
console.debug('💨 Clear Data fired, need to wait for all telemetry collections to load');
|
||||
this.#loaded = false;
|
||||
this.#telemetryLoadedPromises.push(telemetryLoadedPromise);
|
||||
}
|
||||
@ -251,7 +245,6 @@ export default class CompsManager extends EventEmitter {
|
||||
}
|
||||
|
||||
#addTelemetryObject = (telemetryObject) => {
|
||||
console.debug(`📢 CompsManager: addTelemetryObject`, telemetryObject);
|
||||
const keyString = this.#openmct.objects.makeKeyString(telemetryObject.identifier);
|
||||
this.#telemetryObjects[keyString] = telemetryObject;
|
||||
this.#telemetryCollections[keyString] =
|
||||
@ -261,7 +254,6 @@ export default class CompsManager extends EventEmitter {
|
||||
this.#telemetryCollections[keyString].on('clear', this.clearData);
|
||||
const telemetryLoadedPromise = this.#telemetryCollections[keyString].load();
|
||||
this.#telemetryLoadedPromises.push(telemetryLoadedPromise);
|
||||
console.debug('📢 CompsManager: loaded telemetry collection', keyString);
|
||||
|
||||
// check to see if we have a corresponding parameter
|
||||
// if not, add one
|
||||
@ -271,7 +263,6 @@ export default class CompsManager extends EventEmitter {
|
||||
if (!parameterExists) {
|
||||
this.addParameter(telemetryObject);
|
||||
}
|
||||
console.debug(`📢 CompsManager: done adding telemetry object`, telemetryObject);
|
||||
};
|
||||
|
||||
static getCompsManager(domainObject, openmct, compsManagerPool) {
|
||||
|
@ -3,10 +3,8 @@ import { evaluate } from 'mathjs';
|
||||
// eslint-disable-next-line no-undef
|
||||
onconnect = function (e) {
|
||||
const port = e.ports[0];
|
||||
console.debug('🧮 Comps Math Worker connected');
|
||||
|
||||
port.onmessage = function (event) {
|
||||
console.debug('🧮 Comps Math Worker message:', event);
|
||||
const { type, callbackID, telemetryForComps, expression, parameters } = event.data;
|
||||
let responseType = 'unknown';
|
||||
let error = null;
|
||||
@ -26,7 +24,6 @@ onconnect = function (e) {
|
||||
}
|
||||
} catch (errorInCalculation) {
|
||||
error = errorInCalculation;
|
||||
console.error('🧮 Comps Math Worker error:', errorInCalculation);
|
||||
}
|
||||
port.postMessage({ type: responseType, callbackID, result, error });
|
||||
};
|
||||
|
@ -79,10 +79,6 @@ export default class CompsTelemetryProvider {
|
||||
callbackID
|
||||
};
|
||||
this.#sharedWorker.port.postMessage(payload);
|
||||
console.debug(
|
||||
'🧮 Comps Telemetry Provider: sending request request (double request!)',
|
||||
payload
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -104,7 +100,6 @@ export default class CompsTelemetryProvider {
|
||||
parameters,
|
||||
callbackID
|
||||
};
|
||||
console.debug('🧮 Comps Telemetry Provider: sending subscription request', payload);
|
||||
this.#sharedWorker.port.postMessage(payload);
|
||||
}
|
||||
|
||||
@ -123,10 +118,6 @@ export default class CompsTelemetryProvider {
|
||||
);
|
||||
specificCompsManager.on('underlyingTelemetryUpdated', boundComputeOnNewTelemetry);
|
||||
specificCompsManager.startListeningToUnderlyingTelemetry();
|
||||
console.debug(
|
||||
`🧮 Comps Telemetry Provider: subscribed to comps. Now have ${Object.keys(this.#subscriptionCallbacks).length} listener`,
|
||||
this.#subscriptionCallbacks
|
||||
);
|
||||
return () => {
|
||||
specificCompsManager.off('underlyingTelemetryUpdated', boundComputeOnNewTelemetry);
|
||||
delete this.#subscriptionCallbacks[callbackID];
|
||||
@ -160,10 +151,8 @@ export default class CompsTelemetryProvider {
|
||||
this.#subscriptionCallbacks[callbackID] &&
|
||||
result.length
|
||||
) {
|
||||
console.debug('📝 Shared worker subscription message:', event.data);
|
||||
this.#subscriptionCallbacks[callbackID](result);
|
||||
} else if (type === 'calculationRequestResult' && this.#requestPromises[callbackID]) {
|
||||
console.debug('📝 Shared worker request message:', event.data);
|
||||
if (error) {
|
||||
console.error('📝 Error calculating request:', event.data);
|
||||
this.#requestPromises[callbackID].resolve([]);
|
||||
|
@ -64,6 +64,7 @@
|
||||
<input
|
||||
v-if="isEditing"
|
||||
v-model="parameter.name"
|
||||
:aria-label="`Reference Name Input for ${parameter.name}`"
|
||||
type="text"
|
||||
class="c-input--md"
|
||||
@change="updateParameters"
|
||||
@ -95,6 +96,7 @@
|
||||
<input
|
||||
v-if="isEditing"
|
||||
v-model="parameter.testValue"
|
||||
:aria-label="`Reference Test Value for ${parameter.name}`"
|
||||
type="text"
|
||||
class="c-input--md"
|
||||
@change="updateParameters"
|
||||
@ -123,7 +125,7 @@
|
||||
@change="updateExpression"
|
||||
></textarea>
|
||||
<div v-else>
|
||||
<div class="c-comps__expression-value">
|
||||
<div class="c-comps__expression-value" aria-label="Expression">
|
||||
{{ expression }}
|
||||
</div>
|
||||
</div>
|
||||
@ -172,7 +174,6 @@ const props = defineProps({
|
||||
});
|
||||
|
||||
onBeforeMount(async () => {
|
||||
console.debug('🚀 CompsView: onMounted with compsManager', compsManager);
|
||||
outputTelemetryCollection = openmct.telemetry.requestCollection(domainObject);
|
||||
outputTelemetryCollection.on('add', telemetryProcessor);
|
||||
outputTelemetryCollection.on('clear', clearData);
|
||||
@ -208,7 +209,6 @@ function reloadParameters(passedDomainObject) {
|
||||
// to defer mutation of our domain object, otherwise we might
|
||||
// mutate an outdated version of the domain object.
|
||||
setTimeout(function () {
|
||||
console.debug('🚀 CompsView: parameter added', passedDomainObject);
|
||||
domainObject.configuration.comps.parameters = passedDomainObject.configuration.comps.parameters;
|
||||
parameters.value = domainObject.configuration.comps.parameters;
|
||||
openmct.objects.mutate(domainObject, `configuration.comps.parameters`, parameters.value);
|
||||
@ -264,7 +264,6 @@ function applyTestData() {
|
||||
currentTestOutput.value = formattedData;
|
||||
expressionOutput.value = null;
|
||||
} catch (error) {
|
||||
console.error('👎 Error applying test data', error);
|
||||
currentTestOutput.value = null;
|
||||
expressionOutput.value = error.message;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user