Update test specs to use Jasmine 3 (#2089)
* Updated Karma and Jasmine versions * Added DOMObserver class. Supports promise-based testing of DOM changes Update asynchronous test specs to use promises or done() instead of waitsFor/runs * Modified ActionCapability to duplicate context object properties as own properties for better object equality comparisons * Global find + replace to fix syntax issues * Fixed various issues caused by non-deterministic runtime order of tests in Jasmine 3. Fixed issues caused by changes to determination of object equality * Addressed review comments * Resolved merge conflicts with master * Fixed style errors * Use spy.calls.count() instead of manually tracking
This commit is contained in:
committed by
Pete Richards
parent
013eba744d
commit
433dee0314
@@ -45,7 +45,7 @@ define([
|
||||
mockFormat;
|
||||
|
||||
function getCallback(target, name) {
|
||||
return target.calls.filter(function (call) {
|
||||
return target.calls.all().filter(function (call) {
|
||||
return call.args[0] === name;
|
||||
})[0].args[1];
|
||||
}
|
||||
@@ -74,7 +74,7 @@ define([
|
||||
"off",
|
||||
"clock"
|
||||
]);
|
||||
mockConductor.bounds.andReturn(mockBounds);
|
||||
mockConductor.bounds.and.returnValue(mockBounds);
|
||||
|
||||
mockFormatService = jasmine.createSpyObj("formatService", [
|
||||
"getFormat"
|
||||
@@ -86,8 +86,8 @@ define([
|
||||
"emit"
|
||||
]);
|
||||
|
||||
spyOn(d3Scale, 'scaleUtc').andCallThrough();
|
||||
spyOn(d3Scale, 'scaleLinear').andCallThrough();
|
||||
spyOn(d3Scale, 'scaleUtc').and.callThrough();
|
||||
spyOn(d3Scale, 'scaleLinear').and.callThrough();
|
||||
|
||||
element = $('<div style="width: 100px;"><div style="width: 100%;"></div></div>');
|
||||
$(document).find('body').append(element);
|
||||
@@ -100,8 +100,8 @@ define([
|
||||
]);
|
||||
|
||||
mockTimeSystem.timeFormat = "mockFormat";
|
||||
mockFormatService.getFormat.andReturn(mockFormat);
|
||||
mockConductor.timeSystem.andReturn(mockTimeSystem);
|
||||
mockFormatService.getFormat.and.returnValue(mockFormat);
|
||||
mockConductor.timeSystem.and.returnValue(mockTimeSystem);
|
||||
mockTimeSystem.isUTCBased = false;
|
||||
});
|
||||
|
||||
@@ -148,19 +148,19 @@ define([
|
||||
it('responds to zoom events', function () {
|
||||
expect(mockConductorViewService.on).toHaveBeenCalledWith("zoom", controller.onZoom);
|
||||
var cb = getCallback(mockConductorViewService.on, "zoom");
|
||||
spyOn(controller, 'setScale').andCallThrough();
|
||||
spyOn(controller, 'setScale').and.callThrough();
|
||||
cb({bounds: {start: 0, end: 100}});
|
||||
expect(controller.setScale).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('adjusts scale on pan', function () {
|
||||
spyOn(controller, 'setScale').andCallThrough();
|
||||
spyOn(controller, 'setScale').and.callThrough();
|
||||
controller.pan(100);
|
||||
expect(controller.setScale).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('emits event on pan', function () {
|
||||
spyOn(controller, 'setScale').andCallThrough();
|
||||
spyOn(controller, 'setScale').and.callThrough();
|
||||
controller.pan(100);
|
||||
expect(mockConductorViewService.emit).toHaveBeenCalledWith("pan", jasmine.any(Object));
|
||||
});
|
||||
|
||||
@@ -32,7 +32,7 @@ define([
|
||||
var conductorTOIController;
|
||||
|
||||
function getNamedCallback(thing, name) {
|
||||
return thing.calls.filter(function (call) {
|
||||
return thing.calls.all().filter(function (call) {
|
||||
return call.args[0] === name;
|
||||
}).map(function (call) {
|
||||
return call.args;
|
||||
@@ -72,35 +72,35 @@ define([
|
||||
start: 0,
|
||||
end: 200
|
||||
};
|
||||
mockConductor.bounds.andReturn(bounds);
|
||||
mockConductor.bounds.and.returnValue(bounds);
|
||||
toiCallback = getNamedCallback(mockConductor.on, "timeOfInterest");
|
||||
});
|
||||
|
||||
it("calculates the correct horizontal offset based on bounds and current TOI", function () {
|
||||
//Expect time of interest position to be 50% of element width
|
||||
mockConductor.timeOfInterest.andReturn(100);
|
||||
mockConductor.timeOfInterest.and.returnValue(100);
|
||||
toiCallback();
|
||||
expect(conductorTOIController.left).toBe(50);
|
||||
|
||||
//Expect time of interest position to be 25% of element width
|
||||
mockConductor.timeOfInterest.andReturn(50);
|
||||
mockConductor.timeOfInterest.and.returnValue(50);
|
||||
toiCallback();
|
||||
expect(conductorTOIController.left).toBe(25);
|
||||
|
||||
//Expect time of interest position to be 0% of element width
|
||||
mockConductor.timeOfInterest.andReturn(0);
|
||||
mockConductor.timeOfInterest.and.returnValue(0);
|
||||
toiCallback();
|
||||
expect(conductorTOIController.left).toBe(0);
|
||||
|
||||
//Expect time of interest position to be 100% of element width
|
||||
mockConductor.timeOfInterest.andReturn(200);
|
||||
mockConductor.timeOfInterest.and.returnValue(200);
|
||||
toiCallback();
|
||||
expect(conductorTOIController.left).toBe(100);
|
||||
});
|
||||
|
||||
it("renders the TOI indicator visible", function () {
|
||||
expect(conductorTOIController.pinned).toBeFalsy();
|
||||
mockConductor.timeOfInterest.andReturn(100);
|
||||
mockConductor.timeOfInterest.and.returnValue(100);
|
||||
toiCallback();
|
||||
expect(conductorTOIController.pinned).toBe(true);
|
||||
});
|
||||
@@ -116,7 +116,7 @@ define([
|
||||
expect(mockConductorViewService.on).toHaveBeenCalledWith("zoom", jasmine.any(Function));
|
||||
|
||||
// Should correspond to horizontal offset of 50%
|
||||
mockConductor.timeOfInterest.andReturn(750);
|
||||
mockConductor.timeOfInterest.and.returnValue(750);
|
||||
var zoomCallback = getNamedCallback(mockConductorViewService.on, "zoom");
|
||||
zoomCallback(mockZoom);
|
||||
expect(conductorTOIController.left).toBe(50);
|
||||
@@ -131,7 +131,7 @@ define([
|
||||
expect(mockConductorViewService.on).toHaveBeenCalledWith("pan", jasmine.any(Function));
|
||||
|
||||
// Should correspond to horizontal offset of 25%
|
||||
mockConductor.timeOfInterest.andReturn(1500);
|
||||
mockConductor.timeOfInterest.and.returnValue(1500);
|
||||
var panCallback = getNamedCallback(mockConductorViewService.on, "pan");
|
||||
panCallback(mockPanBounds);
|
||||
expect(conductorTOIController.left).toBe(25);
|
||||
|
||||
@@ -48,7 +48,7 @@ define(['./TimeConductorController'], function (TimeConductorController) {
|
||||
"off"
|
||||
]
|
||||
);
|
||||
mockTimeConductor.bounds.andReturn({start: undefined, end: undefined});
|
||||
mockTimeConductor.bounds.and.returnValue({start: undefined, end: undefined});
|
||||
|
||||
mockConductorViewService = jasmine.createSpyObj(
|
||||
"ConductorViewService",
|
||||
@@ -62,8 +62,8 @@ define(['./TimeConductorController'], function (TimeConductorController) {
|
||||
"off"
|
||||
]
|
||||
);
|
||||
mockConductorViewService.availableModes.andReturn([]);
|
||||
mockConductorViewService.availableTimeSystems.andReturn([]);
|
||||
mockConductorViewService.availableModes.and.returnValue([]);
|
||||
mockConductorViewService.availableTimeSystems.and.returnValue([]);
|
||||
|
||||
mockFormatService = jasmine.createSpyObj('formatService', [
|
||||
'getFormat'
|
||||
@@ -71,17 +71,17 @@ define(['./TimeConductorController'], function (TimeConductorController) {
|
||||
mockFormat = jasmine.createSpyObj('format', [
|
||||
'format'
|
||||
]);
|
||||
mockFormatService.getFormat.andReturn(mockFormat);
|
||||
mockFormatService.getFormat.and.returnValue(mockFormat);
|
||||
mockLocation = jasmine.createSpyObj('location', [
|
||||
'search'
|
||||
]);
|
||||
mockLocation.search.andReturn({});
|
||||
mockLocation.search.and.returnValue({});
|
||||
|
||||
mockTimeSystems = [];
|
||||
});
|
||||
|
||||
function getListener(target, event) {
|
||||
return target.calls.filter(function (call) {
|
||||
return target.calls.all().filter(function (call) {
|
||||
return call.args[0] === event;
|
||||
})[0].args[1];
|
||||
}
|
||||
@@ -167,7 +167,7 @@ define(['./TimeConductorController'], function (TimeConductorController) {
|
||||
min: 100,
|
||||
max: 10
|
||||
};
|
||||
mockTimeConductor.timeSystem.andReturn(timeSystem);
|
||||
mockTimeConductor.timeSystem.and.returnValue(timeSystem);
|
||||
tsListener(timeSystem);
|
||||
|
||||
expect(mockScope.boundsModel.start).toEqual(defaultBounds.start);
|
||||
@@ -216,7 +216,7 @@ define(['./TimeConductorController'], function (TimeConductorController) {
|
||||
return 1 - Math.pow(rawValue, 1 / 4);
|
||||
}
|
||||
|
||||
mockTimeConductor.timeSystem.andReturn(timeSystem);
|
||||
mockTimeConductor.timeSystem.and.returnValue(timeSystem);
|
||||
//Set zoom defaults
|
||||
tsListener(timeSystem);
|
||||
|
||||
@@ -292,14 +292,14 @@ define(['./TimeConductorController'], function (TimeConductorController) {
|
||||
});
|
||||
|
||||
it("sets the mode on scope", function () {
|
||||
mockConductorViewService.availableTimeSystems.andReturn(mockTimeSystems);
|
||||
mockConductorViewService.availableTimeSystems.and.returnValue(mockTimeSystems);
|
||||
controller.setMode(mode);
|
||||
|
||||
expect(mockScope.modeModel.selectedKey).toEqual(mode);
|
||||
});
|
||||
|
||||
it("sets available time systems on scope when mode changes", function () {
|
||||
mockConductorViewService.availableTimeSystems.andReturn(mockTimeSystems);
|
||||
mockConductorViewService.availableTimeSystems.and.returnValue(mockTimeSystems);
|
||||
controller.setMode(mode);
|
||||
|
||||
expect(mockScope.timeSystemModel.options.length).toEqual(3);
|
||||
@@ -451,8 +451,8 @@ define(['./TimeConductorController'], function (TimeConductorController) {
|
||||
"tc.endDelta": urlDeltas.end,
|
||||
"tc.timeSystem": urlTimeSystem
|
||||
};
|
||||
mockLocation.search.andReturn(mockSearchObject);
|
||||
mockTimeConductor.timeSystem.andReturn(timeSystem);
|
||||
mockLocation.search.and.returnValue(mockSearchObject);
|
||||
mockTimeConductor.timeSystem.and.returnValue(timeSystem);
|
||||
|
||||
controller = new TimeConductorController(
|
||||
mockScope,
|
||||
@@ -493,7 +493,7 @@ define(['./TimeConductorController'], function (TimeConductorController) {
|
||||
});
|
||||
|
||||
it("updates the URL with the bounds", function () {
|
||||
mockConductorViewService.mode.andReturn("fixed");
|
||||
mockConductorViewService.mode.and.returnValue("fixed");
|
||||
controller.changeBounds({start: 500, end: 600});
|
||||
expect(mockLocation.search).toHaveBeenCalledWith("tc.startBound", 500);
|
||||
expect(mockLocation.search).toHaveBeenCalledWith("tc.endBound", 600);
|
||||
|
||||
@@ -40,7 +40,7 @@ define(['./TimeConductorValidation'], function (TimeConductorValidation) {
|
||||
end: 20
|
||||
};
|
||||
|
||||
mockTimeConductor.bounds.andReturn(mockBounds);
|
||||
mockTimeConductor.bounds.and.returnValue(mockBounds);
|
||||
|
||||
});
|
||||
it("Validates start values using Time Conductor", function () {
|
||||
|
||||
Reference in New Issue
Block a user