[Plot] Update plot controller spec

Update plot controller spec to reflect changes introduced
for WTD-751 and WTD-784.
This commit is contained in:
Victor Woeltjen
2015-02-02 16:17:17 -08:00
parent e6f1328d9d
commit 2ea4e7a47a
2 changed files with 72 additions and 27 deletions

View File

@ -85,7 +85,9 @@ define(
// Handle new telemetry data in this plot // Handle new telemetry data in this plot
function updateValues() { function updateValues() {
if (subscription) {
setupModes(subscription.getTelemetryObjects()); setupModes(subscription.getTelemetryObjects());
}
if (updater) { if (updater) {
updater.update(); updater.update();
modeOptions.getModeHandler().plotTelemetry(updater); modeOptions.getModeHandler().plotTelemetry(updater);
@ -105,6 +107,7 @@ define(
true // Lossless true // Lossless
); );
if (subscription) { if (subscription) {
setupModes(subscription.getTelemetryObjects());
setupAxes(subscription.getMetadata()); setupAxes(subscription.getMetadata());
recreateUpdater(); recreateUpdater();
} }
@ -183,6 +186,8 @@ define(
* Check if a request is pending (to show the wait spinner) * Check if a request is pending (to show the wait spinner)
*/ */
isRequestPending: function () { isRequestPending: function () {
// Placeholder; this should reflect request state
// when requesting historical telemetry
return false; return false;
} }
}; };

View File

@ -12,11 +12,10 @@ define(
var mockScope, var mockScope,
mockFormatter, mockFormatter,
mockSubscriber, mockSubscriber,
mockData, mockSubscription,
mockDomainObject, mockDomainObject,
controller; controller;
function echo(i) { return i; }
beforeEach(function () { beforeEach(function () {
mockScope = jasmine.createSpyObj( mockScope = jasmine.createSpyObj(
@ -27,10 +26,6 @@ define(
"formatter", "formatter",
[ "formatDomainValue", "formatRangeValue" ] [ "formatDomainValue", "formatRangeValue" ]
); );
mockData = jasmine.createSpyObj(
"data",
[ "getPointCount", "getDomainValue", "getRangeValue" ]
);
mockDomainObject = jasmine.createSpyObj( mockDomainObject = jasmine.createSpyObj(
"domainObject", "domainObject",
[ "getId", "getModel", "getCapability" ] [ "getId", "getModel", "getCapability" ]
@ -39,10 +34,22 @@ define(
"telemetrySubscriber", "telemetrySubscriber",
["subscribe"] ["subscribe"]
); );
mockSubscription = jasmine.createSpyObj(
"subscription",
[
"unsubscribe",
"getTelemetryObjects",
"getMetadata",
"getDomainValue",
"getRangeValue"
]
);
mockData.getPointCount.andReturn(2); mockSubscriber.subscribe.andReturn(mockSubscription);
mockData.getDomainValue.andCallFake(echo); mockSubscription.getTelemetryObjects.andReturn([mockDomainObject]);
mockData.getRangeValue.andCallFake(echo); mockSubscription.getMetadata.andReturn([{}]);
mockSubscription.getDomainValue.andReturn(123);
mockSubscription.getRangeValue.andReturn(42);
controller = new PlotController(mockScope, mockFormatter, mockSubscriber); controller = new PlotController(mockScope, mockFormatter, mockSubscriber);
}); });
@ -57,7 +64,24 @@ define(
.not.toEqual(controller.getColor(1)); .not.toEqual(controller.getColor(1));
}); });
xit("draws lines when data becomes available", function () { it("subscribes to telemetry when a domain object appears in scope", function () {
// Make sure we're using the right watch here
expect(mockScope.$watch.mostRecentCall.args[0])
.toEqual("domainObject");
// Make an object available
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
// Should have subscribed
expect(mockSubscriber.subscribe).toHaveBeenCalledWith(
mockDomainObject,
jasmine.any(Function),
true // Lossless
);
});
it("draws lines when data becomes available", function () {
// Make an object available
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
// Verify precondition // Verify precondition
controller.getSubPlots().forEach(function (subplot) { controller.getSubPlots().forEach(function (subplot) {
expect(subplot.getDrawingObject().lines) expect(subplot.getDrawingObject().lines)
@ -65,11 +89,10 @@ define(
}); });
// Make sure there actually are subplots being verified // Make sure there actually are subplots being verified
expect(controller.getSubPlots().length > 0) expect(controller.getSubPlots().length > 0).toBeTruthy();
.toBeTruthy();
// Broadcast data // Broadcast data
mockScope.$on.mostRecentCall.args[1](); mockSubscriber.subscribe.mostRecentCall.args[1]();
controller.getSubPlots().forEach(function (subplot) { controller.getSubPlots().forEach(function (subplot) {
expect(subplot.getDrawingObject().lines) expect(subplot.getDrawingObject().lines)
@ -77,27 +100,39 @@ define(
}); });
}); });
it("unsubscribes when domain object changes", function () {
xit("changes modes depending on number of objects", function () { // Make an object available
var expectedWatch = "telemetry.getTelemetryObjects()", mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
watchFunction; // Verify precondition - shouldn't unsubscribe yet
expect(mockSubscription.unsubscribe).not.toHaveBeenCalled();
// Find the watch for telemetry objects, which // Remove the domain object
// should change plot mode options mockScope.$watch.mostRecentCall.args[1](undefined);
mockScope.$watch.calls.forEach(function (call) { // Should have unsubscribed
if (call.args[0] === expectedWatch) { expect(mockSubscription.unsubscribe).toHaveBeenCalled();
watchFunction = call.args[1];
}
}); });
watchFunction([mockDomainObject]);
it("changes modes depending on number of objects", function () {
// Act like one object is available
mockSubscription.getTelemetryObjects.andReturn([
mockDomainObject
]);
// Make an object available
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
expect(controller.getModeOptions().length).toEqual(1); expect(controller.getModeOptions().length).toEqual(1);
watchFunction([ // Act like one object is available
mockSubscription.getTelemetryObjects.andReturn([
mockDomainObject, mockDomainObject,
mockDomainObject, mockDomainObject,
mockDomainObject mockDomainObject
]); ]);
// Make an object available
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
expect(controller.getModeOptions().length).toEqual(2); expect(controller.getModeOptions().length).toEqual(2);
}); });
@ -113,7 +148,7 @@ define(
.toEqual(jasmine.any(String)); .toEqual(jasmine.any(String));
}); });
xit("allows plot mode to be changed", function () { it("allows plot mode to be changed", function () {
expect(function () { expect(function () {
controller.setMode(controller.getMode()); controller.setMode(controller.getMode());
}).not.toThrow(); }).not.toThrow();
@ -133,6 +168,11 @@ define(
expect(controller.stepBackPanZoom).not.toThrow(); expect(controller.stepBackPanZoom).not.toThrow();
expect(controller.unzoom).not.toThrow(); expect(controller.unzoom).not.toThrow();
}); });
it("indicates if a request is pending", function () {
// Placeholder; need to support requesting telemetry
expect(controller.isRequestPending()).toBeFalsy();
});
}); });
} }
); );