Fixed failing tests

This commit is contained in:
Henry 2016-10-28 16:46:06 -07:00
parent 7cc008ed01
commit 099c56c407
6 changed files with 123 additions and 47 deletions

View File

@ -197,7 +197,6 @@ define(
}
};
/**
* Called when form values are changed. Synchronizes the form with
* the time conductor
@ -318,7 +317,6 @@ define(
var zoomDefaults = this.conductor.timeSystem().defaults().zoom;
var timeSpan = Math.pow((1 - sliderValue), 4) * (zoomDefaults.min - zoomDefaults.max);
var zoom = this.conductorViewService.zoom(timeSpan);
this.$scope.boundsModel.start = zoom.bounds.start;

View File

@ -28,6 +28,8 @@ define(['./TimeConductorController'], function (TimeConductorController) {
var mockConductorViewService;
var mockTimeSystems;
var controller;
var mockFormatService;
var mockFormat;
beforeEach(function () {
mockScope = jasmine.createSpyObj("$scope", [
@ -52,34 +54,32 @@ define(['./TimeConductorController'], function (TimeConductorController) {
"availableModes",
"mode",
"availableTimeSystems",
"deltas"
"deltas",
"deltas",
"on",
"off"
]
);
mockConductorViewService.availableModes.andReturn([]);
mockConductorViewService.availableTimeSystems.andReturn([]);
mockFormatService = jasmine.createSpyObj('formatService',[
'getFormat'
]);
mockFormat = jasmine.createSpyObj('format', [
'format'
]);
mockFormatService.getFormat.andReturn(mockFormat);
mockTimeSystems = [];
});
function getListener(name) {
return mockTimeConductor.on.calls.filter(function (call) {
return call.args[0] === name;
function getListener(target, event) {
return target.calls.filter(function (call) {
return call.args[0] === event;
})[0].args[1];
}
describe("", function () {
beforeEach(function () {
controller = new TimeConductorController(
mockScope,
mockWindow,
mockTimeConductor,
mockConductorViewService,
mockTimeSystems
);
});
});
describe("when time conductor state changes", function () {
var mockFormat;
var mockDeltaFormat;
@ -119,17 +119,18 @@ define(['./TimeConductorController'], function (TimeConductorController) {
controller = new TimeConductorController(
mockScope,
mockWindow,
mockTimeConductor,
{conductor: mockTimeConductor},
mockConductorViewService,
mockTimeSystems
mockTimeSystems,
mockFormatService
);
tsListener = getListener("timeSystem");
tsListener = getListener(mockTimeConductor.on, "timeSystem");
});
it("listens for changes to conductor state", function () {
expect(mockTimeConductor.on).toHaveBeenCalledWith("timeSystem", controller.changeTimeSystem);
expect(mockTimeConductor.on).toHaveBeenCalledWith("bounds", controller.setFormFromBounds);
expect(mockTimeConductor.on).toHaveBeenCalledWith("bounds", controller.changeBounds);
});
it("deregisters conductor listens when scope is destroyed", function () {
@ -137,7 +138,7 @@ define(['./TimeConductorController'], function (TimeConductorController) {
controller.destroy();
expect(mockTimeConductor.off).toHaveBeenCalledWith("timeSystem", controller.changeTimeSystem);
expect(mockTimeConductor.off).toHaveBeenCalledWith("bounds", controller.setFormFromBounds);
expect(mockTimeConductor.off).toHaveBeenCalledWith("bounds", controller.changeBounds);
});
it("when time system changes, sets time system on scope", function () {
@ -151,7 +152,11 @@ define(['./TimeConductorController'], function (TimeConductorController) {
});
it("when time system changes, sets defaults on scope", function () {
expect(tsListener).toBeDefined();
mockDefaults.zoom = {
min: 100,
max: 10
};
mockTimeConductor.timeSystem.andReturn(timeSystem);
tsListener(timeSystem);
expect(mockScope.boundsModel.start).toEqual(defaultBounds.start);
@ -159,6 +164,32 @@ define(['./TimeConductorController'], function (TimeConductorController) {
expect(mockScope.boundsModel.startDelta).toEqual(defaultDeltas.start);
expect(mockScope.boundsModel.endDelta).toEqual(defaultDeltas.end);
expect(mockScope.timeSystemModel.minZoom).toBe(mockDefaults.zoom.min);
expect(mockScope.timeSystemModel.maxZoom).toBe(mockDefaults.zoom.max);
});
it("when bounds change, sets the correct zoom slider value", function() {
var bounds = {
start: 0,
end: 50
};
mockDefaults.zoom = {
min: 100,
max: 0
};
function exponentializer (rawValue){
return 1 - Math.pow(rawValue, 1 / 4);
}
mockTimeConductor.timeSystem.andReturn(timeSystem);
//Set zoom defaults
tsListener(timeSystem);
controller.changeBounds(bounds);
expect(controller.currentZoom).toEqual(exponentializer(0.5));
});
it("when bounds change, sets them on scope", function () {
@ -167,7 +198,7 @@ define(['./TimeConductorController'], function (TimeConductorController) {
end: 2
};
var boundsListener = getListener("bounds");
var boundsListener = getListener(mockTimeConductor.on, "bounds");
expect(boundsListener).toBeDefined();
boundsListener(bounds);
@ -225,9 +256,10 @@ define(['./TimeConductorController'], function (TimeConductorController) {
controller = new TimeConductorController(
mockScope,
mockWindow,
mockTimeConductor,
{conductor: mockTimeConductor},
mockConductorViewService,
mockTimeSystemConstructors
mockTimeSystemConstructors,
mockFormatService
);
mockConductorViewService.availableTimeSystems.andReturn(mockTimeSystems);
@ -240,9 +272,10 @@ define(['./TimeConductorController'], function (TimeConductorController) {
controller = new TimeConductorController(
mockScope,
mockWindow,
mockTimeConductor,
{conductor: mockTimeConductor},
mockConductorViewService,
mockTimeSystemConstructors
mockTimeSystemConstructors,
mockFormatService
);
mockConductorViewService.availableTimeSystems.andReturn(mockTimeSystems);
@ -264,9 +297,10 @@ define(['./TimeConductorController'], function (TimeConductorController) {
controller = new TimeConductorController(
mockScope,
mockWindow,
mockTimeConductor,
{conductor: mockTimeConductor},
mockConductorViewService,
mockTimeSystemConstructors
mockTimeSystemConstructors,
mockFormatService
);
controller.updateBoundsFromForm(formModel);
@ -286,9 +320,10 @@ define(['./TimeConductorController'], function (TimeConductorController) {
controller = new TimeConductorController(
mockScope,
mockWindow,
mockTimeConductor,
{conductor: mockTimeConductor},
mockConductorViewService,
mockTimeSystemConstructors
mockTimeSystemConstructors,
mockFormatService
);
controller.updateDeltasFromForm(formModel);
@ -321,14 +356,35 @@ define(['./TimeConductorController'], function (TimeConductorController) {
controller = new TimeConductorController(
mockScope,
mockWindow,
mockTimeConductor,
{conductor: mockTimeConductor},
mockConductorViewService,
mockTimeSystems
mockTimeSystems,
mockFormatService
);
controller.selectTimeSystemByKey('testTimeSystem');
expect(mockTimeConductor.timeSystem).toHaveBeenCalledWith(timeSystem, defaultBounds);
});
it("updates form bounds during pan events", function() {
var testBounds = {
start: 10,
end: 20
};
expect(controller.$scope.boundsModel.start).not.toBe(testBounds.start);
expect(controller.$scope.boundsModel.end).not.toBe(testBounds.end);
// use registered CB instead
// controller.onPan(testBounds);
expect(controller.conductorViewService.on).toHaveBeenCalledWith("pan",
controller.onPan);
getListener(controller.conductorViewService.on, "pan")(testBounds);
expect(controller.$scope.boundsModel.start).toBe(testBounds.start);
expect(controller.$scope.boundsModel.end).toBe(testBounds.end);
});
});
});

View File

@ -87,7 +87,7 @@ define(['./TimeConductorViewService'], function (TimeConductorViewService) {
it("At a minimum supports fixed mode", function () {
var mockTimeSystems = [mockConstructor(basicTimeSystem)];
viewService = new TimeConductorViewService(mockTimeConductor, mockTimeSystems);
viewService = new TimeConductorViewService({conductor: mockTimeConductor}, mockTimeSystems);
var availableModes = viewService.availableModes();
expect(availableModes.fixed).toBeDefined();
@ -102,7 +102,7 @@ define(['./TimeConductorViewService'], function (TimeConductorViewService) {
};
tickingTimeSystem.tickSources.andReturn([mockRealtimeTickSource]);
viewService = new TimeConductorViewService(mockTimeConductor, mockTimeSystems);
viewService = new TimeConductorViewService({conductor: mockTimeConductor}, mockTimeSystems);
var availableModes = viewService.availableModes();
expect(availableModes.realtime).toBeDefined();
@ -117,7 +117,7 @@ define(['./TimeConductorViewService'], function (TimeConductorViewService) {
};
tickingTimeSystem.tickSources.andReturn([mockLADTickSource]);
viewService = new TimeConductorViewService(mockTimeConductor, mockTimeSystems);
viewService = new TimeConductorViewService({conductor: mockTimeConductor}, mockTimeSystems);
var availableModes = viewService.availableModes();
expect(availableModes.lad).toBeDefined();
@ -132,7 +132,7 @@ define(['./TimeConductorViewService'], function (TimeConductorViewService) {
"destroy"
]);
viewService = new TimeConductorViewService(mockTimeConductor, mockTimeSystems);
viewService = new TimeConductorViewService({conductor: mockTimeConductor}, mockTimeSystems);
viewService.currentMode = oldMode;
viewService.mode('fixed');
expect(oldMode.destroy).toHaveBeenCalled();
@ -149,7 +149,7 @@ define(['./TimeConductorViewService'], function (TimeConductorViewService) {
};
tickingTimeSystem.tickSources.andReturn([mockRealtimeTickSource]);
viewService = new TimeConductorViewService(mockTimeConductor, mockTimeSystems);
viewService = new TimeConductorViewService({conductor: mockTimeConductor}, mockTimeSystems);
//Set time system to one known to support realtime mode
mockTimeConductor.timeSystem.andReturn(tickingTimeSystem);
@ -169,7 +169,7 @@ define(['./TimeConductorViewService'], function (TimeConductorViewService) {
};
tickingTimeSystem.tickSources.andReturn([mockRealtimeTickSource]);
viewService = new TimeConductorViewService(mockTimeConductor, mockTimeSystems);
viewService = new TimeConductorViewService({conductor: mockTimeConductor}, mockTimeSystems);
//Set time system to one known to not support realtime mode
mockTimeConductor.timeSystem.andReturn(basicTimeSystem);

View File

@ -22,7 +22,7 @@
define(['./TimeOfInterestController'], function (TimeOfInterestController) {
ddescribe("The time of interest controller", function () {
describe("The time of interest controller", function () {
var controller;
var mockScope;
var mockConductor;

View File

@ -40,7 +40,8 @@ define(
mockDomainObject,
mockSeries,
mockStatusCapability,
controller;
controller,
mockConductor;
function bind(method, thisObj) {
return function () {
@ -120,13 +121,23 @@ define(
mockHandle.getRangeValue.andReturn(42);
mockScope.domainObject = mockDomainObject;
mockConductor = jasmine.createSpyObj('conductor', [
'on',
'off',
'bounds',
'timeSystem',
'timeOfInterest'
]);
controller = new PlotController(
mockScope,
mockElement,
mockExportImageService,
mockFormatter,
mockHandler,
mockThrottle
mockThrottle,
undefined,
{conductor: mockConductor}
);
});

View File

@ -36,6 +36,7 @@ define(
mockConfiguration,
watches,
mockTableRow,
mockConductor,
controller;
function promise(value) {
@ -106,7 +107,8 @@ define(
'getDatum',
'promiseTelemetryObjects',
'getTelemetryObjects',
'request'
'request',
'getMetadata'
]);
// Arbitrary array with non-zero length, contents are not
@ -115,13 +117,22 @@ define(
mockTelemetryHandle.promiseTelemetryObjects.andReturn(promise(undefined));
mockTelemetryHandle.getDatum.andReturn({});
mockTelemetryHandle.request.andReturn(promise(undefined));
mockTelemetryHandle.getMetadata.andReturn([]);
mockTelemetryHandler = jasmine.createSpyObj('telemetryHandler', [
'handle'
]);
mockTelemetryHandler.handle.andReturn(mockTelemetryHandle);
controller = new TableController(mockScope, mockTelemetryHandler, mockTelemetryFormatter);
mockConductor = jasmine.createSpyObj('conductor', [
'on',
'off',
'bounds',
'timeSystem',
'timeOfInterest'
]);
controller = new TableController(mockScope, mockTelemetryHandler, mockTelemetryFormatter, {conductor: mockConductor});
controller.table = mockTable;
controller.handle = mockTelemetryHandle;
});