Skip to content

Commit 09ad12b

Browse files
authored
Modified test to wait for expected telemetry conditions (#8292)
* Modified test to wait for expected telemetry conditions * Revert changes to tsconfig.json * Reordered functions * Fix variable naming * Add deterministic steps to other corresponding test
1 parent bfbd001 commit 09ad12b

2 files changed

Lines changed: 131 additions & 7 deletions

File tree

e2e/appActions.js

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,82 @@ async function expandTreePane(page) {
797797
await expect(page.locator('.l-shell__pane-tree > .l-pane__contents')).toHaveCSS('opacity', '1');
798798
}
799799

800+
/**
801+
* @param {{ page: import('@playwright/test').Page, identifier: import('../../../../../src/api/objects/ObjectAPI').Identifier, expectedValue?: Object }} options
802+
* @returns {Promise<Object>} a promise that will resolve with the parameter value returned by the first subscription callback, or
803+
* the first subscription callback to match the expectedValue if one is provided.
804+
*/
805+
function waitForRawTelemetryValue({ page, identifier, expectedValue }) {
806+
return waitForTelemetryValue({ parseOrFormat: 'parse', ...arguments[0] });
807+
}
808+
809+
/**
810+
* @param {{ page: import('@playwright/test').Page, identifier: import('../../../../../src/api/objects/ObjectAPI').Identifier, expectedValue?: Object }} options
811+
* @returns {Promise<Object>} a promise that will resolve with the parameter value returned by the first subscription callback, or
812+
* the first subscription callback to match the expectedValue if one is provided.
813+
*/
814+
function waitForFormattedTelemetryValue({ page, identifier, expectedValue }) {
815+
return waitForTelemetryValue({ parseOrFormat: 'format', ...arguments[0] });
816+
}
817+
818+
/**
819+
* @param {{ page: import('@playwright/test').Page, identifier: import('../../../../../src/api/objects/ObjectAPI').Identifier, expectedValue?: Object, parseOrFormat: 'parse'|'format' }} options
820+
* @returns {Promise<Object>} a promise that will resolve with the parameter value returned by the first subscription callback, or
821+
* the first subscription callback to match the expectedValue if one is provided.
822+
*/
823+
function waitForTelemetryValue({ page, identifier, expectedValue, parseOrFormat }) {
824+
if (parseOrFormat !== 'parse' && parseOrFormat !== 'format') {
825+
throw new Error("Invalid function invocation. Must be one of 'parse' or 'format'");
826+
}
827+
828+
return page.evaluate(
829+
/**
830+
* @param {{identifier: import('../../../../../src/api/objects/ObjectAPI').Identifier, expectedValue?: Object, parseOrFormat: 'parse'|'format'}} options
831+
* @returns {Promise<Object>}
832+
*/
833+
// eslint-disable-next-line no-shadow
834+
async ({ identifier, expectedValue, parseOrFormat }) => {
835+
// @ts-ignore
836+
const openmct = window.openmct;
837+
const domainObject = await openmct.objects.get(identifier);
838+
const metadata = openmct.telemetry.getMetadata(domainObject);
839+
const valueMetadatum = metadata.getDefaultDisplayValue();
840+
const formatter = openmct.telemetry.getValueFormatter(valueMetadatum);
841+
/**
842+
* @type {() => void}
843+
*/
844+
let unsubscribe;
845+
846+
return new Promise((resolve) => {
847+
unsubscribe = openmct.telemetry.subscribe(domainObject, checkForMatchingTelemetry);
848+
849+
/**
850+
* @param {Object} telemetryDatum
851+
*/
852+
function checkForMatchingTelemetry(telemetryDatum) {
853+
const telemetryValue = formatter[parseOrFormat](telemetryDatum);
854+
if (expectedValue === undefined) {
855+
resolve(telemetryValue);
856+
} else {
857+
if (typeof telemetryValue === 'string' && typeof expectedValue === 'string') {
858+
if (telemetryValue.trim() === expectedValue.trim()) {
859+
resolve(telemetryValue);
860+
}
861+
} else {
862+
if (telemetryValue === expectedValue) {
863+
resolve(telemetryValue);
864+
}
865+
}
866+
}
867+
}
868+
}).finally(() => {
869+
unsubscribe();
870+
});
871+
},
872+
{ identifier, expectedValue, parseOrFormat }
873+
);
874+
}
875+
800876
export {
801877
createDomainObjectWithDefaults,
802878
createExampleTelemetryObject,
@@ -819,5 +895,7 @@ export {
819895
setRealTimeMode,
820896
setStartOffset,
821897
setTimeConductorBounds,
822-
waitForPlotsToRender
898+
waitForFormattedTelemetryValue,
899+
waitForPlotsToRender,
900+
waitForRawTelemetryValue
823901
};

e2e/tests/functional/plugins/styling/conditionWidget.e2e.spec.js

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,20 @@ This test suite is dedicated to tests which verify the basic operations surround
2626
import {
2727
createDomainObjectWithDefaults,
2828
linkParameterToObject,
29-
setRealTimeMode
29+
setRealTimeMode,
30+
waitForFormattedTelemetryValue
3031
} from '../../../../appActions.js';
3132
import { expect, test } from '../../../../pluginFixtures.js';
3233

3334
test.describe('A Condition Widget', () => {
3435
let swg;
36+
/**
37+
* @type {import('../../../../appActions.js').CreatedObjectInfo}
38+
*/
3539
let conditionSet;
40+
/**
41+
* @type {import('../../../../appActions.js').CreatedObjectInfo}
42+
*/
3643
let conditionWidget;
3744

3845
test.beforeEach(async ({ page }) => {
@@ -130,15 +137,35 @@ test.describe('A Condition Widget', () => {
130137
description: 'https://github.com/nasa/openmct/issues/8277'
131138
});
132139

140+
const conditionSetIdentifier = {
141+
namespace: '',
142+
key: conditionSet.uuid
143+
};
144+
133145
const label = page.getByLabel('Test Condition Widget Object View');
134146

135147
await expect(page.getByLabel('Browse bar object name')).toBeVisible();
148+
await waitForFormattedTelemetryValue({
149+
page,
150+
identifier: conditionSetIdentifier
151+
});
152+
136153
await expect(label.getByText('default')).toBeHidden();
154+
await waitForFormattedTelemetryValue({
155+
page,
156+
identifier: conditionSetIdentifier,
157+
expectedValue: '> 0'
158+
});
137159
await expect(label.getByText('> 0')).toBeVisible();
160+
await waitForFormattedTelemetryValue({
161+
page,
162+
identifier: conditionSetIdentifier,
163+
expectedValue: '< 0'
164+
});
138165
await expect(label.getByText('< 0')).toBeVisible();
139166
});
140167

141-
test('Show correct output when a staleness rule is applied', async ({ page }) => {
168+
test('Shows the correct output when a staleness rule is applied', async ({ page }) => {
142169
test.info().annotations.push({
143170
type: 'issue',
144171
description: 'https://github.com/nasa/openmct/issues/8277'
@@ -174,11 +201,30 @@ test.describe('A Condition Widget', () => {
174201

175202
await page.goto(conditionWidget.url);
176203

204+
const conditionSetIdentifier = {
205+
namespace: '',
206+
key: conditionSet.uuid
207+
};
208+
177209
await expect(page.getByLabel('Browse bar object name')).toHaveText('Test Condition Widget');
178210
const label = page.getByLabel('Test Condition Widget Object View');
179-
//TODO Will fix these assertions in a followup
180-
await expect(label.getByText('> 0')).toBeVisible({ timeout: 10_000 });
181-
await expect(label.getByText('< 0')).toBeVisible({ timeout: 10_000 });
182-
await expect(label.getByText('STALE')).toBeVisible({ timeout: 10_000 });
211+
await waitForFormattedTelemetryValue({
212+
page,
213+
identifier: conditionSetIdentifier,
214+
expectedValue: '> 0'
215+
});
216+
await expect(label.getByText('> 0')).toBeVisible();
217+
await waitForFormattedTelemetryValue({
218+
page,
219+
identifier: conditionSetIdentifier,
220+
expectedValue: '< 0'
221+
});
222+
await expect(label.getByText('< 0')).toBeVisible();
223+
await waitForFormattedTelemetryValue({
224+
page,
225+
identifier: conditionSetIdentifier,
226+
expectedValue: 'STALE'
227+
});
228+
await expect(label.getByText('STALE')).toBeVisible();
183229
});
184230
});

0 commit comments

Comments
 (0)