handle arrays and add skeleton tests

This commit is contained in:
Scott Bell 2024-09-05 21:43:35 +02:00
parent dde0d1a64d
commit 80d8babb61
5 changed files with 54 additions and 19 deletions

View File

@ -0,0 +1,43 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2024, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* 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';
test.describe('Comps', () => {
test.beforeEach(async ({ page }) => {
// Open a browser, navigate to the main page, and wait until all networkevents to resolve
await page.goto('./', { waitUntil: 'domcontentloaded' });
});
test('Can add and remove telemetry sources', async ({ page }) => {
// Create the gauge with defaults
const comp = await createDomainObjectWithDefaults(page, { type: 'Derived Telemetry' });
// Create a sine wave generator within the comp
await createDomainObjectWithDefaults(page, {
type: 'Sine Wave Generator',
parent: comp.uuid
});
await page.goto(comp.url);
});
});

View File

@ -21,14 +21,6 @@ export default class CompsManager extends EventEmitter {
this.clearData = this.clearData.bind(this);
}
isValid() {
return this.#domainObject.configuration.comps.valid;
}
setValid(valid) {
this.#domainObject.configuration.comps.valid = valid;
}
#getNextAlphabeticalParameterName() {
const parameters = this.#domainObject.configuration.comps.parameters;
const existingNames = new Set(parameters.map((p) => p.name));
@ -115,7 +107,7 @@ export default class CompsManager extends EventEmitter {
}
isReady() {
return this.isValid() && this.#loaded;
return this.#loaded;
}
async load() {

View File

@ -61,10 +61,6 @@ export default class CompsTelemetryProvider {
this.#openmct,
this.#compsManagerPool
);
if (!specificCompsManager.isValid()) {
resolve([]);
return;
}
specificCompsManager.load().then(() => {
const callbackID = this.#getCallbackID();
const telemetryForComps = specificCompsManager.requestUnderlyingTelemetry();
@ -169,7 +165,8 @@ export default class CompsTelemetryProvider {
} else if (type === 'calculationRequestResult' && this.#requestPromises[callbackID]) {
console.debug('📝 Shared worker request message:', event.data);
if (error) {
this.#requestPromises[callbackID].reject(error);
console.error('📝 Error calculating request:', event.data);
this.#requestPromises[callbackID].resolve([]);
} else {
this.#requestPromises[callbackID].resolve(result);
}

View File

@ -246,7 +246,13 @@ function applyTestData() {
return;
}
const scope = parameters.value.reduce((acc, parameter) => {
acc[parameter.name] = parameter.testValue;
// try to parse the test value as JSON
try {
const parsedValue = JSON.parse(parameter.testValue);
acc[parameter.name] = parsedValue;
} catch (error) {
acc[parameter.name] = parameter.testValue;
}
return acc;
}, {});
try {
@ -254,11 +260,9 @@ function applyTestData() {
const formattedData = getValueFormatter().format(testOutput);
currentTestOutput.value = formattedData;
expressionOutput.value = null;
compsManager.setValid(true);
} catch (error) {
console.error('👎 Error applying test data', error);
currentTestOutput.value = null;
compsManager.setValid(false);
expressionOutput.value = error.message;
}
}

View File

@ -39,8 +39,7 @@ export default function CompsPlugin() {
domainObject.configuration = {
comps: {
expression: '',
parameters: [],
valid: false
parameters: []
}
};
domainObject.composition = [];