Merge remote-tracking branch 'origin/open751' into open-master
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||
/*global define,Promise,describe,it,expect,xit,beforeEach,waitsFor,jasmine*/
|
||||
|
||||
/**
|
||||
* MergeModelsSpec. Created by vwoeltje on 11/6/14.
|
||||
@@ -11,12 +11,11 @@ define(
|
||||
describe("The plot controller", function () {
|
||||
var mockScope,
|
||||
mockFormatter,
|
||||
mockTelemetry, // mock telemetry controller
|
||||
mockData,
|
||||
mockSubscriber,
|
||||
mockSubscription,
|
||||
mockDomainObject,
|
||||
controller;
|
||||
|
||||
function echo(i) { return i; }
|
||||
|
||||
beforeEach(function () {
|
||||
mockScope = jasmine.createSpyObj(
|
||||
@@ -27,33 +26,32 @@ define(
|
||||
"formatter",
|
||||
[ "formatDomainValue", "formatRangeValue" ]
|
||||
);
|
||||
mockTelemetry = jasmine.createSpyObj(
|
||||
"telemetry",
|
||||
[ "getResponse", "getMetadata" ]
|
||||
);
|
||||
mockData = jasmine.createSpyObj(
|
||||
"data",
|
||||
[ "getPointCount", "getDomainValue", "getRangeValue" ]
|
||||
);
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId", "getModel", "getCapability" ]
|
||||
);
|
||||
|
||||
mockScope.telemetry = mockTelemetry;
|
||||
mockTelemetry.getResponse.andReturn([mockData]);
|
||||
mockData.getPointCount.andReturn(2);
|
||||
mockData.getDomainValue.andCallFake(echo);
|
||||
mockData.getRangeValue.andCallFake(echo);
|
||||
|
||||
controller = new PlotController(mockScope, mockFormatter);
|
||||
});
|
||||
|
||||
it("listens for telemetry updates", function () {
|
||||
expect(mockScope.$on).toHaveBeenCalledWith(
|
||||
"telemetryUpdate",
|
||||
jasmine.any(Function)
|
||||
mockSubscriber = jasmine.createSpyObj(
|
||||
"telemetrySubscriber",
|
||||
["subscribe"]
|
||||
);
|
||||
mockSubscription = jasmine.createSpyObj(
|
||||
"subscription",
|
||||
[
|
||||
"unsubscribe",
|
||||
"getTelemetryObjects",
|
||||
"getMetadata",
|
||||
"getDomainValue",
|
||||
"getRangeValue"
|
||||
]
|
||||
);
|
||||
|
||||
mockSubscriber.subscribe.andReturn(mockSubscription);
|
||||
mockSubscription.getTelemetryObjects.andReturn([mockDomainObject]);
|
||||
mockSubscription.getMetadata.andReturn([{}]);
|
||||
mockSubscription.getDomainValue.andReturn(123);
|
||||
mockSubscription.getRangeValue.andReturn(42);
|
||||
|
||||
controller = new PlotController(mockScope, mockFormatter, mockSubscriber);
|
||||
});
|
||||
|
||||
it("provides plot colors", function () {
|
||||
@@ -66,16 +64,24 @@ define(
|
||||
.not.toEqual(controller.getColor(1));
|
||||
});
|
||||
|
||||
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("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
|
||||
controller.getSubPlots().forEach(function (subplot) {
|
||||
expect(subplot.getDrawingObject().lines)
|
||||
@@ -83,11 +89,10 @@ define(
|
||||
});
|
||||
|
||||
// Make sure there actually are subplots being verified
|
||||
expect(controller.getSubPlots().length > 0)
|
||||
.toBeTruthy();
|
||||
expect(controller.getSubPlots().length > 0).toBeTruthy();
|
||||
|
||||
// Broadcast data
|
||||
mockScope.$on.mostRecentCall.args[1]();
|
||||
mockSubscriber.subscribe.mostRecentCall.args[1]();
|
||||
|
||||
controller.getSubPlots().forEach(function (subplot) {
|
||||
expect(subplot.getDrawingObject().lines)
|
||||
@@ -95,27 +100,39 @@ define(
|
||||
});
|
||||
});
|
||||
|
||||
it("unsubscribes when domain object changes", function () {
|
||||
// Make an object available
|
||||
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
||||
// Verify precondition - shouldn't unsubscribe yet
|
||||
expect(mockSubscription.unsubscribe).not.toHaveBeenCalled();
|
||||
// Remove the domain object
|
||||
mockScope.$watch.mostRecentCall.args[1](undefined);
|
||||
// Should have unsubscribed
|
||||
expect(mockSubscription.unsubscribe).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
it("changes modes depending on number of objects", function () {
|
||||
var expectedWatch = "telemetry.getTelemetryObjects()",
|
||||
watchFunction;
|
||||
// Act like one object is available
|
||||
mockSubscription.getTelemetryObjects.andReturn([
|
||||
mockDomainObject
|
||||
]);
|
||||
|
||||
// Find the watch for telemetry objects, which
|
||||
// should change plot mode options
|
||||
mockScope.$watch.calls.forEach(function (call) {
|
||||
if (call.args[0] === expectedWatch) {
|
||||
watchFunction = call.args[1];
|
||||
}
|
||||
});
|
||||
// Make an object available
|
||||
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
||||
|
||||
watchFunction([mockDomainObject]);
|
||||
expect(controller.getModeOptions().length).toEqual(1);
|
||||
|
||||
watchFunction([
|
||||
// Act like one object is available
|
||||
mockSubscription.getTelemetryObjects.andReturn([
|
||||
mockDomainObject,
|
||||
mockDomainObject,
|
||||
mockDomainObject
|
||||
]);
|
||||
|
||||
// Make an object available
|
||||
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
||||
|
||||
expect(controller.getModeOptions().length).toEqual(2);
|
||||
});
|
||||
|
||||
@@ -151,6 +168,11 @@ define(
|
||||
expect(controller.stepBackPanZoom).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();
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -135,6 +135,22 @@ define(
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
it("provides access to a drawable object", function () {
|
||||
expect(typeof subplot.getDrawingObject()).toEqual('object');
|
||||
});
|
||||
|
||||
it("allows a domain offset to be provided", function () {
|
||||
// Domain object is needed to adjust canvas coordinates
|
||||
// to avoid loss-of-precision associated with converting
|
||||
// to 32 bit floats.
|
||||
subplot.setDomainOffset(3);
|
||||
subplot.update();
|
||||
// Should have adjusted the origin accordingly
|
||||
expect(subplot.getDrawingObject().origin[0])
|
||||
.toEqual(2);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -1,4 +1,4 @@
|
||||
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine,Float32Array*/
|
||||
|
||||
/**
|
||||
* MergeModelsSpec. Created by vwoeltje on 11/6/14.
|
||||
@@ -60,6 +60,13 @@ define(
|
||||
expect(preparer.getDimensions[1]).not.toEqual(0);
|
||||
});
|
||||
|
||||
it("provides buffers", function () {
|
||||
var datas = [makeMockData(0)],
|
||||
preparer = new PlotPreparer(datas);
|
||||
expect(preparer.getBuffers()[0] instanceof Float32Array)
|
||||
.toBeTruthy();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
161
platform/features/plot/test/elements/PlotUpdaterSpec.js
Normal file
161
platform/features/plot/test/elements/PlotUpdaterSpec.js
Normal file
@@ -0,0 +1,161 @@
|
||||
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine,Float32Array*/
|
||||
|
||||
/**
|
||||
* MergeModelsSpec. Created by vwoeltje on 11/6/14.
|
||||
*/
|
||||
define(
|
||||
["../../src/elements/PlotUpdater"],
|
||||
function (PlotUpdater) {
|
||||
"use strict";
|
||||
|
||||
describe("A plot updater", function () {
|
||||
var mockSubscription,
|
||||
testDomain,
|
||||
testRange,
|
||||
testDomainValues,
|
||||
testRangeValues,
|
||||
updater;
|
||||
|
||||
function makeMockDomainObject(id) {
|
||||
var mockDomainObject = jasmine.createSpyObj(
|
||||
"object-" + id,
|
||||
[ "getId", "getCapability", "getModel" ]
|
||||
);
|
||||
mockDomainObject.getId.andReturn(id);
|
||||
return mockDomainObject;
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
var ids = [ 'a', 'b', 'c' ],
|
||||
mockObjects = ids.map(makeMockDomainObject);
|
||||
|
||||
mockSubscription = jasmine.createSpyObj(
|
||||
"subscription",
|
||||
[ "getDomainValue", "getRangeValue", "getTelemetryObjects" ]
|
||||
);
|
||||
testDomain = "testDomain";
|
||||
testRange = "testRange";
|
||||
testDomainValues = { a: 3, b: 7, c: 13 };
|
||||
testRangeValues = { a: 123, b: 456, c: 789 };
|
||||
|
||||
mockSubscription.getTelemetryObjects.andReturn(mockObjects);
|
||||
mockSubscription.getDomainValue.andCallFake(function (mockObject) {
|
||||
return testDomainValues[mockObject.getId()];
|
||||
});
|
||||
mockSubscription.getRangeValue.andCallFake(function (mockObject) {
|
||||
return testRangeValues[mockObject.getId()];
|
||||
});
|
||||
|
||||
updater = new PlotUpdater(
|
||||
mockSubscription,
|
||||
testDomain,
|
||||
testRange,
|
||||
1350 // Smaller max size for easier testing
|
||||
);
|
||||
});
|
||||
|
||||
it("provides one buffer per telemetry object", function () {
|
||||
expect(updater.getBuffers().length).toEqual(3);
|
||||
});
|
||||
|
||||
it("changes buffer count if telemetry object counts change", function () {
|
||||
mockSubscription.getTelemetryObjects
|
||||
.andReturn([makeMockDomainObject('a')]);
|
||||
updater.update();
|
||||
expect(updater.getBuffers().length).toEqual(1);
|
||||
});
|
||||
|
||||
it("maintains a buffer of received telemetry", function () {
|
||||
// Count should be large enough to trigger a buffer resize
|
||||
var count = 750,
|
||||
i;
|
||||
|
||||
// Increment values exposed by subscription
|
||||
function increment() {
|
||||
Object.keys(testDomainValues).forEach(function (k) {
|
||||
testDomainValues[k] += 1;
|
||||
testRangeValues[k] += 1;
|
||||
});
|
||||
}
|
||||
|
||||
// Simulate a lot of telemetry updates
|
||||
for (i = 0; i < count; i += 1) {
|
||||
updater.update();
|
||||
expect(updater.getLength(0)).toEqual(i + 1);
|
||||
expect(updater.getLength(1)).toEqual(i + 1);
|
||||
expect(updater.getLength(2)).toEqual(i + 1);
|
||||
increment();
|
||||
}
|
||||
|
||||
// Domain offset should be lowest domain value
|
||||
expect(updater.getDomainOffset()).toEqual(3);
|
||||
|
||||
// Test against initial values, offset by count,
|
||||
// as was the case during each update
|
||||
for (i = 0; i < count; i += 1) {
|
||||
expect(updater.getBuffers()[0][i * 2])
|
||||
.toEqual(3 + i - 3);
|
||||
expect(updater.getBuffers()[0][i * 2 + 1])
|
||||
.toEqual(123 + i);
|
||||
expect(updater.getBuffers()[1][i * 2])
|
||||
.toEqual(7 + i - 3);
|
||||
expect(updater.getBuffers()[1][i * 2 + 1])
|
||||
.toEqual(456 + i);
|
||||
expect(updater.getBuffers()[2][i * 2])
|
||||
.toEqual(13 + i - 3);
|
||||
expect(updater.getBuffers()[2][i * 2 + 1])
|
||||
.toEqual(789 + i);
|
||||
}
|
||||
});
|
||||
|
||||
it("can handle delayed telemetry object availability", function () {
|
||||
// The case can occur where getTelemetryObjects() returns an
|
||||
// empty array - specifically, while objects are still being
|
||||
// loaded. The updater needs to be able to cope with that
|
||||
// case.
|
||||
var tmp = mockSubscription.getTelemetryObjects();
|
||||
mockSubscription.getTelemetryObjects.andReturn([]);
|
||||
|
||||
// Reinstantiate with the empty subscription
|
||||
updater = new PlotUpdater(
|
||||
mockSubscription,
|
||||
testDomain,
|
||||
testRange
|
||||
);
|
||||
|
||||
// Should have 0 buffers for 0 objects
|
||||
expect(updater.getBuffers().length).toEqual(0);
|
||||
|
||||
// Restore the three objects the test subscription would
|
||||
// normally have.
|
||||
mockSubscription.getTelemetryObjects.andReturn(tmp);
|
||||
updater.update();
|
||||
|
||||
// Should have 3 buffers for 3 objects
|
||||
expect(updater.getBuffers().length).toEqual(3);
|
||||
});
|
||||
|
||||
|
||||
it("shifts buffer upon expansion", function () {
|
||||
// Count should be large enough to hit buffer's max size
|
||||
var count = 1400,
|
||||
i;
|
||||
|
||||
// Initial update; should have 3 in first position
|
||||
// (a's initial domain value)
|
||||
updater.update();
|
||||
expect(updater.getBuffers()[0][1]).toEqual(123);
|
||||
|
||||
// Simulate a lot of telemetry updates
|
||||
for (i = 0; i < count; i += 1) {
|
||||
testDomainValues.a += 1;
|
||||
testRangeValues.a += 1;
|
||||
updater.update();
|
||||
}
|
||||
|
||||
// Value at front of the buffer should have been pushed out
|
||||
expect(updater.getBuffers()[0][1]).not.toEqual(123);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -57,7 +57,7 @@ define(
|
||||
// Prepared telemetry data
|
||||
mockPrepared = jasmine.createSpyObj(
|
||||
"prepared",
|
||||
[ "getDomainOffset", "getOrigin", "getDimensions", "getBuffers" ]
|
||||
[ "getDomainOffset", "getOrigin", "getDimensions", "getBuffers", "getLength" ]
|
||||
);
|
||||
|
||||
mockSubPlotFactory.createSubPlot.andCallFake(createMockSubPlot);
|
||||
@@ -68,6 +68,7 @@ define(
|
||||
mockPrepared.getDomainOffset.andReturn(1234);
|
||||
mockPrepared.getOrigin.andReturn([10, 10]);
|
||||
mockPrepared.getDimensions.andReturn([500, 500]);
|
||||
mockPrepared.getLength.andReturn(3);
|
||||
|
||||
// Clear out drawing objects
|
||||
testDrawingObjects = [];
|
||||
|
||||
@@ -57,7 +57,7 @@ define(
|
||||
// Prepared telemetry data
|
||||
mockPrepared = jasmine.createSpyObj(
|
||||
"prepared",
|
||||
[ "getDomainOffset", "getOrigin", "getDimensions", "getBuffers" ]
|
||||
[ "getDomainOffset", "getOrigin", "getDimensions", "getBuffers", "getLength" ]
|
||||
);
|
||||
|
||||
mockSubPlotFactory.createSubPlot.andCallFake(createMockSubPlot);
|
||||
@@ -68,6 +68,7 @@ define(
|
||||
mockPrepared.getDomainOffset.andReturn(1234);
|
||||
mockPrepared.getOrigin.andReturn([10, 10]);
|
||||
mockPrepared.getDimensions.andReturn([500, 500]);
|
||||
mockPrepared.getLength.andReturn(3);
|
||||
|
||||
// Objects that will be drawn to in sub-plots
|
||||
testDrawingObjects = [];
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"elements/PlotPosition",
|
||||
"elements/PlotPreparer",
|
||||
"elements/PlotTickGenerator",
|
||||
"elements/PlotUpdater",
|
||||
"modes/PlotModeOptions",
|
||||
"modes/PlotOverlayMode",
|
||||
"modes/PlotStackMode"
|
||||
|
||||
Reference in New Issue
Block a user