@@ -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+
800876export {
801877 createDomainObjectWithDefaults ,
802878 createExampleTelemetryObject ,
@@ -819,5 +895,7 @@ export {
819895 setRealTimeMode ,
820896 setStartOffset ,
821897 setTimeConductorBounds ,
822- waitForPlotsToRender
898+ waitForFormattedTelemetryValue ,
899+ waitForPlotsToRender ,
900+ waitForRawTelemetryValue
823901} ;
0 commit comments