mirror of
https://github.com/nasa/openmct.git
synced 2025-04-08 20:04:27 +00:00
[Telemetry] Add test casese
Add test cases for general support for handling real-time telemetry, WTD-806.
This commit is contained in:
parent
4d288950fd
commit
ffc122fb5c
@ -5,10 +5,20 @@ define(
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* A telemetry handle acts as a helper in issuing requests for
|
||||
* new telemetry as well as subscribing to real-time updates
|
||||
* for the same telemetry series. This is exposed through the
|
||||
* `telemetryHandler` service.
|
||||
* @param $q Angular's $q, for promises
|
||||
* @param {TelemetrySubscription} subscription a subscription
|
||||
* to supplied telemetry
|
||||
*/
|
||||
function TelemetryHandle($q, subscription) {
|
||||
var seriesMap = {},
|
||||
self = Object.create(subscription);
|
||||
|
||||
// Request a telemetry series for this specific object
|
||||
function requestSeries(telemetryObject, request, callback) {
|
||||
var id = telemetryObject.getId(),
|
||||
telemetry = telemetryObject.getCapability('telemetry');
|
||||
|
@ -6,7 +6,83 @@ define(
|
||||
"use strict";
|
||||
|
||||
describe("A telemetry handle", function () {
|
||||
var mockQ,
|
||||
mockSubscription,
|
||||
mockDomainObject,
|
||||
mockTelemetry,
|
||||
mockSeries,
|
||||
mockCallback,
|
||||
handle;
|
||||
|
||||
function asPromise(v) {
|
||||
return (v || {}).then ? v : {
|
||||
then: function (callback) {
|
||||
return asPromise(callback(v));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
mockQ = jasmine.createSpyObj('$q', ['when', 'all']);
|
||||
mockSubscription = jasmine.createSpyObj(
|
||||
'subscription',
|
||||
['unsubscribe', 'getTelemetryObjects', 'promiseTelemetryObjects']
|
||||
);
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
'domainObject',
|
||||
['getId', 'getCapability']
|
||||
);
|
||||
mockTelemetry = jasmine.createSpyObj(
|
||||
'telemetry',
|
||||
['requestData']
|
||||
);
|
||||
mockSeries = jasmine.createSpyObj(
|
||||
'series',
|
||||
['getPointCount', 'getDomainValue', 'getRangeValue']
|
||||
);
|
||||
mockCallback = jasmine.createSpy('callback');
|
||||
|
||||
// Simulate $q.all, at least for asPromise-provided promises
|
||||
mockQ.all.andCallFake(function (values) {
|
||||
return values.map(function (v) {
|
||||
var r;
|
||||
asPromise(v).then(function (value) { r = value; });
|
||||
return r;
|
||||
});
|
||||
});
|
||||
mockQ.when.andCallFake(asPromise);
|
||||
mockSubscription.getTelemetryObjects
|
||||
.andReturn([mockDomainObject]);
|
||||
mockSubscription.promiseTelemetryObjects
|
||||
.andReturn(asPromise([mockDomainObject]));
|
||||
mockDomainObject.getId.andReturn('testId');
|
||||
mockDomainObject.getCapability.andReturn(mockTelemetry);
|
||||
mockTelemetry.requestData.andReturn(asPromise(mockSeries));
|
||||
|
||||
handle = new TelemetryHandle(mockQ, mockSubscription);
|
||||
});
|
||||
|
||||
it("exposes subscription API", function () {
|
||||
// Should still expose methods from the provided subscription
|
||||
expect(handle.unsubscribe)
|
||||
.toBe(mockSubscription.unsubscribe);
|
||||
expect(handle.getTelemetryObjects)
|
||||
.toBe(mockSubscription.getTelemetryObjects);
|
||||
});
|
||||
|
||||
it("provides an interface for historical requests", function () {
|
||||
handle.request({}, mockCallback);
|
||||
expect(mockCallback).toHaveBeenCalledWith(
|
||||
mockDomainObject,
|
||||
mockSeries
|
||||
);
|
||||
});
|
||||
|
||||
it("provides the latest series for domain objects", function () {
|
||||
handle.request({});
|
||||
expect(handle.getSeries(mockDomainObject))
|
||||
.toEqual(mockSeries);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
@ -6,6 +6,58 @@ define(
|
||||
"use strict";
|
||||
|
||||
describe("The telemetry handler", function () {
|
||||
// TelemetryHandler just provides a factory
|
||||
// for TelemetryHandle, so most real testing
|
||||
// should happen there.
|
||||
var mockQ,
|
||||
mockSubscriber,
|
||||
mockDomainObject,
|
||||
mockCallback,
|
||||
mockSubscription,
|
||||
handler;
|
||||
|
||||
beforeEach(function () {
|
||||
mockQ = jasmine.createSpyObj("$q", ["when"]);
|
||||
mockSubscriber = jasmine.createSpyObj(
|
||||
'telemetrySubscriber',
|
||||
['subscribe']
|
||||
);
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
'domainObject',
|
||||
['getId', 'getCapability']
|
||||
);
|
||||
mockCallback = jasmine.createSpy('callback');
|
||||
mockSubscription = jasmine.createSpyObj(
|
||||
'subscription',
|
||||
[
|
||||
'unsubscribe',
|
||||
'getTelemetryObjects',
|
||||
'getRangeValue',
|
||||
'getDomainValue'
|
||||
]
|
||||
);
|
||||
|
||||
mockSubscriber.subscribe.andReturn(mockSubscription);
|
||||
|
||||
handler = new TelemetryHandler(mockQ, mockSubscriber);
|
||||
});
|
||||
|
||||
it("acts as a factory for subscription objects", function () {
|
||||
var handle = handler.handle(
|
||||
mockDomainObject,
|
||||
mockCallback
|
||||
);
|
||||
// Just verify that this looks like a TelemetrySubscription
|
||||
[
|
||||
"unsubscribe",
|
||||
"getTelemetryObjects",
|
||||
"getRangeValue",
|
||||
"getDomainValue",
|
||||
"request"
|
||||
].forEach(function (method) {
|
||||
expect(handle[method]).toEqual(jasmine.any(Function));
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
@ -184,6 +184,14 @@ define(
|
||||
it("fires callback when telemetry objects are available", function () {
|
||||
expect(mockCallback.calls.length).toEqual(1);
|
||||
});
|
||||
|
||||
it("exposes a promise for telemetry objects", function () {
|
||||
var mockCallback2 = jasmine.createSpy('callback');
|
||||
subscription.promiseTelemetryObjects().then(mockCallback2);
|
||||
|
||||
expect(mockCallback2)
|
||||
.toHaveBeenCalledWith([ mockDomainObject ]);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
Loading…
x
Reference in New Issue
Block a user