[Plot] Spec for PlotController

Fill in spec for PlotController, which is the primary
handler of logic associated with plot views, transitioned
for WTD-533.
This commit is contained in:
Victor Woeltjen 2014-12-01 18:13:03 -08:00
parent c9300e8611
commit ad802e674e
2 changed files with 178 additions and 9 deletions

View File

@ -84,13 +84,26 @@ define(
tickGenerator.generateRangeTicks(RANGE_TICKS);
}
function plotTelemetry(telemetry) {
var prepared, data;
function setupAxes(metadatas) {
$scope.axes = [
new PlotAxis("domain", metadatas, AXIS_DEFAULTS[0]),
new PlotAxis("range", metadatas, AXIS_DEFAULTS[1])
];
}
function plotTelemetry() {
var prepared, data, telemetry;
telemetry = $scope.telemetry;
if (!telemetry) {
return;
}
if (!$scope.axes) {
setupAxes(telemetry.getMetadata());
}
data = telemetry.getResponse();
prepared = new PlotPreparer(
@ -119,13 +132,6 @@ define(
updateTicks();
}
function setupAxes(metadatas) {
$scope.axes = [
new PlotAxis("domain", metadatas, AXIS_DEFAULTS[0]),
new PlotAxis("range", metadatas, AXIS_DEFAULTS[1])
];
}
function toMousePosition($event) {
var target = $event.target,
bounds = target.getBoundingClientRect();

View File

@ -10,13 +10,43 @@ define(
describe("The plot controller", function () {
var mockScope,
mockTelemetry, // mock telemetry controller
mockData,
mockElement,
controller;
function echo(i) { return i; }
beforeEach(function () {
mockScope = jasmine.createSpyObj(
"$scope",
[ "$watch", "$on" ]
);
mockTelemetry = jasmine.createSpyObj(
"telemetry",
[ "getResponse", "getMetadata" ]
);
mockData = jasmine.createSpyObj(
"data",
[ "getPointCount", "getDomainValue", "getRangeValue" ]
);
mockElement = jasmine.createSpyObj(
"element",
[ "getBoundingClientRect" ]
);
mockScope.telemetry = mockTelemetry;
mockTelemetry.getResponse.andReturn([mockData]);
mockData.getPointCount.andReturn(2);
mockData.getDomainValue.andCallFake(echo);
mockData.getRangeValue.andCallFake(echo);
mockElement.getBoundingClientRect.andReturn({
left: 0,
top: 0,
width: 100,
height: 100
});
controller = new PlotController(mockScope);
});
@ -27,6 +57,139 @@ define(
);
});
it("provides plot colors", function () {
// PlotPalette will have its own tests
expect(controller.getColor(0))
.toEqual(jasmine.any(String));
// Colors should be unique
expect(controller.getColor(0))
.not.toEqual(controller.getColor(1));
});
it("draws lines when telemetry data becomes available", function () {
// Broadcast data
mockScope.$on.mostRecentCall.args[1]();
// Should have put some lines in the drawing scope,
// which the template should pass along to the renderer
expect(mockScope.draw.lines).toBeDefined();
});
it("does not fail if telemetry controller is not in scope", function () {
mockScope.telemetry = undefined;
// Broadcast data
mockScope.$on.mostRecentCall.args[1]();
// Just want to not have an exception
});
it("provides coordinates on hover", function () {
expect(controller.getHoverCoordinates().length).toEqual(0);
controller.hover({
target: mockElement
});
expect(controller.getHoverCoordinates().length).toEqual(2);
});
it("permits marquee zoom", function () {
// Verify pre-condition
expect(controller.isZoomed()).toBeFalsy();
// Simulate a marquee zoom interaction
controller.startMarquee({
target: mockElement,
clientX: 0,
clientY: 10
});
controller.hover({
target: mockElement,
clientX: 0,
clientY: 0
});
controller.endMarquee({
target: mockElement,
clientX: 10,
clientY: 0
});
expect(controller.isZoomed()).toBeTruthy();
});
it("permits unøom", function () {
// Simulate a marquee zoom interaction
controller.startMarquee({
target: mockElement,
clientX: 0,
clientY: 10
});
controller.hover({
target: mockElement,
clientX: 0,
clientY: 0
});
controller.endMarquee({
target: mockElement,
clientX: 10,
clientY: 0
});
// Verify precondition
expect(controller.isZoomed()).toBeTruthy();
// Perform the unzoom
controller.unzoom();
// Should no longer report as zoomed
expect(controller.isZoomed()).toBeFalsy();
});
it("permits unøom", function () {
// Simulate two marquee zooms interaction
[0, 1].forEach(function (n) {
controller.startMarquee({
target: mockElement,
clientX: 0,
clientY: 10 + 10 * n
});
controller.hover({
target: mockElement,
clientX: 0,
clientY: 0
});
controller.endMarquee({
target: mockElement,
clientX: 10 + 10 * n,
clientY: 0
});
});
// Verify precondition
expect(controller.isZoomed()).toBeTruthy();
// Step back...
controller.stepBackPanZoom();
// Should still be zoomed
expect(controller.isZoomed()).toBeTruthy();
// Step back again...
controller.stepBackPanZoom();
// Should no longer report as zoomed
expect(controller.isZoomed()).toBeFalsy();
});
});
}