mirror of
https://github.com/nasa/openmct.git
synced 2025-01-18 18:57:01 +00:00
[Telemetry] Update specs
Update telemetry bundle specs to account for subscription functionality added to support autoflow tabular views, WTD-614.
This commit is contained in:
parent
cc5cfd95a7
commit
8dd255a06e
@ -8,6 +8,7 @@ define(
|
||||
describe("The telemetry aggregator", function () {
|
||||
var mockQ,
|
||||
mockProviders,
|
||||
mockUnsubscribes,
|
||||
aggregator;
|
||||
|
||||
function mockPromise(value) {
|
||||
@ -20,10 +21,15 @@ define(
|
||||
|
||||
function mockProvider(key, index) {
|
||||
var provider = jasmine.createSpyObj(
|
||||
"provider" + index,
|
||||
[ "requestTelemetry" ]
|
||||
);
|
||||
"provider" + index,
|
||||
[ "requestTelemetry", "subscribe" ]
|
||||
),
|
||||
unsubscribe = jasmine.createSpy("unsubscribe" + index);
|
||||
provider.requestTelemetry.andReturn({ someKey: key });
|
||||
provider.subscribe.andReturn(unsubscribe);
|
||||
|
||||
// Store to verify interactions later
|
||||
mockUnsubscribes[index] = unsubscribe;
|
||||
return provider;
|
||||
}
|
||||
|
||||
@ -31,6 +37,7 @@ define(
|
||||
mockQ = jasmine.createSpyObj("$q", [ "all" ]);
|
||||
mockQ.all.andReturn(mockPromise([]));
|
||||
|
||||
mockUnsubscribes = [];
|
||||
mockProviders = [ "a", "b", "c" ].map(mockProvider);
|
||||
|
||||
aggregator = new TelemetryAggregator(mockQ, mockProviders);
|
||||
@ -74,6 +81,24 @@ define(
|
||||
});
|
||||
});
|
||||
|
||||
it("broadcasts subscriptions from all providers", function () {
|
||||
var mockCallback = jasmine.createSpy("callback"),
|
||||
subscription = aggregator.subscribe(mockCallback);
|
||||
|
||||
// Make sure all providers got subscribed to
|
||||
mockProviders.forEach(function (mockProvider) {
|
||||
expect(mockProvider.subscribe).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Verify that unsubscription gets broadcast too
|
||||
mockUnsubscribes.forEach(function (mockUnsubscribe) {
|
||||
expect(mockUnsubscribe).not.toHaveBeenCalled();
|
||||
});
|
||||
subscription(); // unsubscribe
|
||||
mockUnsubscribes.forEach(function (mockUnsubscribe) {
|
||||
expect(mockUnsubscribe).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ define(
|
||||
mockDomainObject,
|
||||
mockTelemetryService,
|
||||
mockReject,
|
||||
mockUnsubscribe,
|
||||
telemetry;
|
||||
|
||||
|
||||
@ -33,9 +34,10 @@ define(
|
||||
);
|
||||
mockTelemetryService = jasmine.createSpyObj(
|
||||
"telemetryService",
|
||||
[ "requestTelemetry" ]
|
||||
[ "requestTelemetry", "subscribe" ]
|
||||
);
|
||||
mockReject = jasmine.createSpyObj("reject", ["then"]);
|
||||
mockUnsubscribe = jasmine.createSpy("unsubscribe");
|
||||
|
||||
mockInjector.get.andReturn(mockTelemetryService);
|
||||
|
||||
@ -52,6 +54,8 @@ define(
|
||||
|
||||
mockTelemetryService.requestTelemetry
|
||||
.andReturn(mockPromise({}));
|
||||
mockTelemetryService.subscribe
|
||||
.andReturn(mockUnsubscribe);
|
||||
|
||||
// Bubble up...
|
||||
mockReject.then.andReturn(mockReject);
|
||||
@ -127,6 +131,36 @@ define(
|
||||
expect(mockLog.warn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("allows subscriptions to updates", function () {
|
||||
var mockCallback = jasmine.createSpy("callback"),
|
||||
subscription = telemetry.subscribe(mockCallback);
|
||||
|
||||
// Verify subscription to the appropriate object
|
||||
expect(mockTelemetryService.subscribe).toHaveBeenCalledWith(
|
||||
jasmine.any(Function),
|
||||
[{
|
||||
id: "testId", // from domain object
|
||||
source: "testSource",
|
||||
key: "testKey"
|
||||
}]
|
||||
);
|
||||
|
||||
// Check that the callback gets invoked
|
||||
expect(mockCallback).not.toHaveBeenCalled();
|
||||
mockTelemetryService.subscribe.mostRecentCall.args[0]({
|
||||
testSource: { testKey: { someKey: "some value" } }
|
||||
});
|
||||
expect(mockCallback).toHaveBeenCalledWith(
|
||||
{ someKey: "some value" }
|
||||
);
|
||||
|
||||
// Finally, unsubscribe
|
||||
expect(mockUnsubscribe).not.toHaveBeenCalled();
|
||||
subscription(); // should be an unsubscribe function
|
||||
expect(mockUnsubscribe).toHaveBeenCalled();
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
@ -187,6 +187,13 @@ define(
|
||||
.toHaveBeenCalledWith("telemetryUpdate");
|
||||
});
|
||||
|
||||
it("listens for scope destruction to clean up", function () {
|
||||
expect(mockScope.$on).toHaveBeenCalledWith(
|
||||
"$destroy",
|
||||
jasmine.any(Function)
|
||||
);
|
||||
mockScope.$on.mostRecentCall.args[1]();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user