[Events] Controller test correction

Test for the RT Event List controller now
actually works. #26.
This commit is contained in:
Sarah Hale 2015-06-29 13:09:00 -07:00
parent 4c6b3c7a13
commit 6616dedf63
2 changed files with 68 additions and 28 deletions

View File

@ -65,7 +65,7 @@ define(
columns = []; columns = [];
columns.push(new DomainColumn(telemetryFormatter)); columns.push(new DomainColumn(telemetryFormatter, telemetryHandler.getMetadata()));
columns.push(new RangeColumn()); columns.push(new RangeColumn());
headers = columns.map(function (column) { headers = columns.map(function (column) {

View File

@ -30,14 +30,19 @@ define(
"use strict"; "use strict";
describe("The real time event list controller", function () { describe("The real time event list controller", function () {
var mockScope, var mockDomainObject,
//mockTelemetry, mockScope,
mockTelemetryHandler, mockTelemetryHandler,
mockHandle, mockHandle,
mockTelemetryFormatter, mockTelemetryFormatter,
mockColumn,
controller; controller;
beforeEach(function () { beforeEach(function () {
mockDomainObject = jasmine.createSpyObj(
"domainObject",
[ "getId", "getModel", "getCapability" ]
);
mockScope = jasmine.createSpyObj( mockScope = jasmine.createSpyObj(
"$scope", "$scope",
[ "$on", "$watch" ] [ "$on", "$watch" ]
@ -48,48 +53,83 @@ define(
); );
mockHandle = jasmine.createSpyObj( mockHandle = jasmine.createSpyObj(
"handle", "handle",
["getDomainValue", "getRangeValue"] ["getDomainValue", "getRangeValue", "getTelemetryObjects", "unsubscribe"]
); );
mockTelemetryFormatter = jasmine.createSpyObj( mockTelemetryFormatter = jasmine.createSpyObj(
"formatter", "formatter",
["formatDomainValue", "formatRangeValue"] ["formatDomainValue", "formatRangeValue"]
); );
mockColumn = jasmine.createSpyObj(
"column",
["getValue"]
);
controller = new RTEventListController(mockScope, mockTelemetryHandler, mockTelemetryFormatter); controller = new RTEventListController(mockScope, mockTelemetryHandler, mockTelemetryFormatter);
// Add some data into the table mockHandle.getDomainValue.andReturn("domain value");
controller.setUpColumns([{id: 'a'}, {id: 'b'}]); mockHandle.getRangeValue.andReturn("range value");
}
mockTelemetryHandler.handle.andReturn(mockHandle);
mockHandle.getTelemetryObjects.andReturn([mockDomainObject]);
// Subscribe to the RT telemetry
// second argument of: $scope.$watch("domainObject", makeSubscription);
////// TODO: Maybe use some instead of forEach?
mockScope.$watch.calls.forEach(function (c) {
// There are two possible calls of $watch, so we need to filter
// through the calls to get the correct kind
if (c.args[0] === 'domainObject') {
c.args[1]();
}
});
// callback, passed into telemetry handler
mockTelemetryHandler.handle.mostRecentCall.args[1]();
// Update the telemetry objects
// second argument of: $scope.$watch(getTelemetryObjects, updateObjects);
mockScope.$watch.calls.forEach(function (c) {
// There are two possible calls of $watch, so we need to filter
// through the calls to get the correct kind
if (c.args[0] !== 'domainObject') {
c.args[1]([mockDomainObject]);
}
});
});
it("provides a domain and a range column", function () {
// Should have two columns with these headers
expect(controller.headers()).toEqual(["Time", "Message"]);
}); });
it("listens for telemetry data updates", function () { it("listens for telemetry data updates", function () {
expect(mockScope.$on).toHaveBeenCalledWith( // Of the two possible $watch calls, this corresponds to
"telemetryUpdate", // $scope.$watch(getTelemetryObjects, updateObjects);
jasmine.any(Function)
);
});
it("watches for telemetry controller changes", function () {
expect(mockScope.$watch).toHaveBeenCalledWith( expect(mockScope.$watch).toHaveBeenCalledWith(
"telemetry", jasmine.any(Function),
jasmine.any(Function) jasmine.any(Function)
); );
}); });
it("provides a domain and a range column", function () { it("makes telemetry subscriptions", function () {
// Should have two columns // Of the two possible $watch calls, this corresponds to
expect(controller.rows()[0].length).toEqual([]); // $scope.$watch("domainObject", makeSubscription);
expect(mockScope.$watch).toHaveBeenCalledWith(
// And they should have these headers "domainObject",
expect(controller.headers()).toEqual(["Time", "Message"]); jasmine.any(Function)
);
}); });
it("does not throw if telemetry controller is undefined", function () { it("releases telemetry subscriptions on destruction", function () {
// Just a general robustness check // Call the second argument of
mockScope.telemetry = undefined; // $scope.$on("$destroy", releaseSubscription);
expect(mockScope.$watch.mostRecentCall.args[1]) mockScope.$on.mostRecentCall.args[1]();
.not.toThrow();
expect(mockScope.$on).toHaveBeenCalledWith(
"$destroy",
jasmine.any(Function)
);
}); });
}); });
} }