Skip to content

Commit

Permalink
Fixed failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akhenry committed Oct 28, 2016
1 parent 7cc008e commit 099c56c
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ define(
}
};


/**
* Called when form values are changed. Synchronizes the form with
* the time conductor
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ define(['./TimeConductorController'], function (TimeConductorController) {
var mockConductorViewService;
var mockTimeSystems;
var controller;
var mockFormatService;
var mockFormat;

beforeEach(function () {
mockScope = jasmine.createSpyObj("$scope", [
Expand All @@ -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;
Expand Down Expand Up @@ -119,25 +119,26 @@ 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 () {
expect(mockScope.$on).toHaveBeenCalledWith("$destroy", controller.destroy);

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 () {
Expand All @@ -151,14 +152,44 @@ 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);
expect(mockScope.boundsModel.end).toEqual(defaultBounds.end);

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 () {
Expand All @@ -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);

Expand Down Expand Up @@ -225,9 +256,10 @@ define(['./TimeConductorController'], function (TimeConductorController) {
controller = new TimeConductorController(
mockScope,
mockWindow,
mockTimeConductor,
{conductor: mockTimeConductor},
mockConductorViewService,
mockTimeSystemConstructors
mockTimeSystemConstructors,
mockFormatService
);

mockConductorViewService.availableTimeSystems.andReturn(mockTimeSystems);
Expand All @@ -240,9 +272,10 @@ define(['./TimeConductorController'], function (TimeConductorController) {
controller = new TimeConductorController(
mockScope,
mockWindow,
mockTimeConductor,
{conductor: mockTimeConductor},
mockConductorViewService,
mockTimeSystemConstructors
mockTimeSystemConstructors,
mockFormatService
);

mockConductorViewService.availableTimeSystems.andReturn(mockTimeSystems);
Expand All @@ -264,9 +297,10 @@ define(['./TimeConductorController'], function (TimeConductorController) {
controller = new TimeConductorController(
mockScope,
mockWindow,
mockTimeConductor,
{conductor: mockTimeConductor},
mockConductorViewService,
mockTimeSystemConstructors
mockTimeSystemConstructors,
mockFormatService
);

controller.updateBoundsFromForm(formModel);
Expand All @@ -286,9 +320,10 @@ define(['./TimeConductorController'], function (TimeConductorController) {
controller = new TimeConductorController(
mockScope,
mockWindow,
mockTimeConductor,
{conductor: mockTimeConductor},
mockConductorViewService,
mockTimeSystemConstructors
mockTimeSystemConstructors,
mockFormatService
);

controller.updateDeltasFromForm(formModel);
Expand Down Expand Up @@ -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);
});
});

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 13 additions & 2 deletions platform/features/plot/test/PlotControllerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ define(
mockDomainObject,
mockSeries,
mockStatusCapability,
controller;
controller,
mockConductor;

function bind(method, thisObj) {
return function () {
Expand Down Expand Up @@ -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}
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ define(
mockConfiguration,
watches,
mockTableRow,
mockConductor,
controller;

function promise(value) {
Expand Down Expand Up @@ -106,7 +107,8 @@ define(
'getDatum',
'promiseTelemetryObjects',
'getTelemetryObjects',
'request'
'request',
'getMetadata'
]);

// Arbitrary array with non-zero length, contents are not
Expand All @@ -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;
});
Expand Down

0 comments on commit 099c56c

Please sign in to comment.