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:
Andrew Henry
2018-06-29 17:32:59 -07:00
committed by Pete Richards
parent 013eba744d
commit 433dee0314
305 changed files with 2866 additions and 3324 deletions

View File

@@ -38,8 +38,8 @@ define([
'useCapability'
]) };
testAdaptedObject = { foo: 'bar' };
testContext.domainObject.getModel.andReturn(testModel);
testContext.domainObject.useCapability.andCallFake(function (c) {
testContext.domainObject.getModel.and.returnValue(testModel);
testContext.domainObject.useCapability.and.callFake(function (c) {
return c === 'adapter' && testAdaptedObject;
});
});

View File

@@ -58,13 +58,13 @@ define(
['getCapability', 'useCapability', 'getModel']
);
mockDomainObject.useCapability.andCallFake(function (c, v) {
mockDomainObject.useCapability.and.callFake(function (c, v) {
if (c === 'mutation') {
testModel = v(testModel) || testModel;
return asPromise(true);
}
});
mockDomainObject.getModel.andCallFake(function () {
mockDomainObject.getModel.and.callFake(function () {
return testModel;
});
@@ -82,7 +82,7 @@ define(
it("updates the model with a pausedTime", function () {
testModel.pausedTime = undefined;
mockNow.andReturn(12000);
mockNow.and.returnValue(12000);
action.perform();
expect(testModel.pausedTime).toEqual(12000);
});

View File

@@ -58,13 +58,13 @@ define(
['getCapability', 'useCapability', 'getModel']
);
mockDomainObject.useCapability.andCallFake(function (c, v) {
mockDomainObject.useCapability.and.callFake(function (c, v) {
if (c === 'mutation') {
testModel = v(testModel) || testModel;
return asPromise(true);
}
});
mockDomainObject.getModel.andCallFake(function () {
mockDomainObject.getModel.and.callFake(function () {
return testModel;
});
@@ -76,7 +76,7 @@ define(
it("updates the model with a timestamp", function () {
testModel.pausedTime = 12000;
mockNow.andReturn(12000);
mockNow.and.returnValue(12000);
action.perform();
expect(testModel.timestamp).toEqual(12000);
});

View File

@@ -58,13 +58,13 @@ define(
['getCapability', 'useCapability', 'getModel']
);
mockDomainObject.useCapability.andCallFake(function (c, v) {
mockDomainObject.useCapability.and.callFake(function (c, v) {
if (c === 'mutation') {
testModel = v(testModel) || testModel;
return asPromise(true);
}
});
mockDomainObject.getModel.andCallFake(function () {
mockDomainObject.getModel.and.callFake(function () {
return testModel;
});
@@ -75,7 +75,7 @@ define(
});
it("updates the model with a timestamp", function () {
mockNow.andReturn(12000);
mockNow.and.returnValue(12000);
action.perform();
expect(testModel.timestamp).toEqual(12000);
});

View File

@@ -58,13 +58,13 @@ define(
['getCapability', 'useCapability', 'getModel']
);
mockDomainObject.useCapability.andCallFake(function (c, v) {
mockDomainObject.useCapability.and.callFake(function (c, v) {
if (c === 'mutation') {
testModel = v(testModel) || testModel;
return asPromise(true);
}
});
mockDomainObject.getModel.andCallFake(function () {
mockDomainObject.getModel.and.callFake(function () {
return testModel;
});
@@ -75,7 +75,7 @@ define(
});
it("updates the model with a timestamp", function () {
mockNow.andReturn(12000);
mockNow.and.returnValue(12000);
action.perform();
expect(testModel.timestamp).toEqual(undefined);
});

View File

@@ -38,7 +38,7 @@ define(
mockTicker = jasmine.createSpyObj('ticker', ['listen']);
mockUnticker = jasmine.createSpy('unticker');
mockTicker.listen.andReturn(mockUnticker);
mockTicker.listen.and.returnValue(mockUnticker);
controller = new ClockController(mockScope, mockTicker);
});
@@ -57,17 +57,17 @@ define(
it("unsubscribes to ticks when destroyed", function () {
// Make sure $destroy is being listened for...
expect(mockScope.$on.mostRecentCall.args[0]).toEqual('$destroy');
expect(mockScope.$on.calls.mostRecent().args[0]).toEqual('$destroy');
expect(mockUnticker).not.toHaveBeenCalled();
// ...and makes sure that its listener unsubscribes from ticker
mockScope.$on.mostRecentCall.args[1]();
mockScope.$on.calls.mostRecent().args[1]();
expect(mockUnticker).toHaveBeenCalled();
});
it("formats using the format string from the model", function () {
mockTicker.listen.mostRecentCall.args[0](TEST_TIMESTAMP);
mockScope.$watch.mostRecentCall.args[1]({
mockTicker.listen.calls.mostRecent().args[0](TEST_TIMESTAMP);
mockScope.$watch.calls.mostRecent().args[1]({
"clockFormat": [
"YYYY-DDD hh:mm:ss",
"clock24"
@@ -81,8 +81,8 @@ define(
});
it("formats 12-hour time", function () {
mockTicker.listen.mostRecentCall.args[0](TEST_TIMESTAMP);
mockScope.$watch.mostRecentCall.args[1]({
mockTicker.listen.calls.mostRecent().args[0](TEST_TIMESTAMP);
mockScope.$watch.calls.mostRecent().args[1]({
"clockFormat": [
"YYYY-DDD hh:mm:ss",
"clock12"
@@ -96,9 +96,9 @@ define(
});
it("does not throw exceptions when model is undefined", function () {
mockTicker.listen.mostRecentCall.args[0](TEST_TIMESTAMP);
mockTicker.listen.calls.mostRecent().args[0](TEST_TIMESTAMP);
expect(function () {
mockScope.$watch.mostRecentCall.args[1](undefined);
mockScope.$watch.calls.mostRecent().args[1](undefined);
}).not.toThrow();
});

View File

@@ -37,7 +37,7 @@ define(
mockTicker = jasmine.createSpyObj('ticker', ['listen']);
mockUnticker = jasmine.createSpy('unticker');
mockTicker.listen.andReturn(mockUnticker);
mockTicker.listen.and.returnValue(mockUnticker);
controller = new RefreshingController(mockScope, mockTicker);
});
@@ -52,13 +52,13 @@ define(
['persist', 'refresh']
);
mockDomainObject.getCapability.andCallFake(function (c) {
mockDomainObject.getCapability.and.callFake(function (c) {
return (c === 'persistence') && mockPersistence;
});
mockScope.domainObject = mockDomainObject;
mockTicker.listen.mostRecentCall.args[0](12321);
mockTicker.listen.calls.mostRecent().args[0](12321);
expect(mockPersistence.refresh).toHaveBeenCalled();
expect(mockPersistence.persist).not.toHaveBeenCalled();
});
@@ -70,11 +70,11 @@ define(
it("unsubscribes to ticks when destroyed", function () {
// Make sure $destroy is being listened for...
expect(mockScope.$on.mostRecentCall.args[0]).toEqual('$destroy');
expect(mockScope.$on.calls.mostRecent().args[0]).toEqual('$destroy');
expect(mockUnticker).not.toHaveBeenCalled();
// ...and makes sure that its listener unsubscribes from ticker
mockScope.$on.mostRecentCall.args[1]();
mockScope.$on.calls.mostRecent().args[1]();
expect(mockUnticker).toHaveBeenCalled();
});
});

View File

@@ -40,7 +40,7 @@ define(
controller;
function invokeWatch(expr, value) {
mockScope.$watch.calls.forEach(function (call) {
mockScope.$watch.calls.all().forEach(function (call) {
if (call.args[0] === expr) {
call.args[1](value);
}
@@ -78,13 +78,13 @@ define(
);
mockNow = jasmine.createSpy('now');
mockDomainObject.getCapability.andCallFake(function (c) {
mockDomainObject.getCapability.and.callFake(function (c) {
return (c === 'action') && mockActionCapability;
});
mockDomainObject.getModel.andCallFake(function () {
mockDomainObject.getModel.and.callFake(function () {
return testModel;
});
mockActionCapability.getActions.andCallFake(function (k) {
mockActionCapability.getActions.and.callFake(function (k) {
return [{
'timer.start': mockStart,
'timer.pause': mockPause,
@@ -92,9 +92,9 @@ define(
}[k]];
});
mockStart.getMetadata.andReturn({cssClass: "icon-play", name: "Start"});
mockPause.getMetadata.andReturn({cssClass: "icon-pause", name: "Pause"});
mockStop.getMetadata.andReturn({cssClass: "icon-box", name: "Stop"});
mockStart.getMetadata.and.returnValue({cssClass: "icon-play", name: "Start"});
mockPause.getMetadata.and.returnValue({cssClass: "icon-pause", name: "Pause"});
mockStop.getMetadata.and.returnValue({cssClass: "icon-box", name: "Stop"});
mockScope.domainObject = mockDomainObject;
testModel = {};
@@ -124,8 +124,8 @@ define(
it("displays nothing when there is no target", function () {
// Notify that domain object is available via scope
invokeWatch('domainObject', mockDomainObject);
mockNow.andReturn(TEST_TIMESTAMP);
mockWindow.requestAnimationFrame.mostRecentCall.args[0]();
mockNow.and.returnValue(TEST_TIMESTAMP);
mockWindow.requestAnimationFrame.calls.mostRecent().args[0]();
expect(controller.sign()).toEqual("");
expect(controller.signClass()).toEqual("");
expect(controller.text()).toEqual("");
@@ -137,20 +137,20 @@ define(
// Notify that domain object is available via scope
invokeWatch('domainObject', mockDomainObject);
mockNow.andReturn(TEST_TIMESTAMP + 121000);
mockWindow.requestAnimationFrame.mostRecentCall.args[0]();
mockNow.and.returnValue(TEST_TIMESTAMP + 121000);
mockWindow.requestAnimationFrame.calls.mostRecent().args[0]();
expect(controller.sign()).toEqual("+");
expect(controller.signClass()).toEqual("icon-plus");
expect(controller.text()).toEqual("0D 00:02:01");
mockNow.andReturn(TEST_TIMESTAMP - 121000);
mockWindow.requestAnimationFrame.mostRecentCall.args[0]();
mockNow.and.returnValue(TEST_TIMESTAMP - 121000);
mockWindow.requestAnimationFrame.calls.mostRecent().args[0]();
expect(controller.sign()).toEqual("-");
expect(controller.signClass()).toEqual("icon-minus");
expect(controller.text()).toEqual("0D 00:02:01");
mockNow.andReturn(TEST_TIMESTAMP);
mockWindow.requestAnimationFrame.mostRecentCall.args[0]();
mockNow.and.returnValue(TEST_TIMESTAMP);
mockWindow.requestAnimationFrame.calls.mostRecent().args[0]();
expect(controller.sign()).toEqual("");
expect(controller.signClass()).toEqual("");
expect(controller.text()).toEqual("0D 00:00:00");
@@ -190,27 +190,27 @@ define(
});
it("stops requesting animation frames when destroyed", function () {
var initialCount = mockWindow.requestAnimationFrame.calls.length;
var initialCount = mockWindow.requestAnimationFrame.calls.count();
// First, check that normally new frames keep getting requested
mockWindow.requestAnimationFrame.mostRecentCall.args[0]();
expect(mockWindow.requestAnimationFrame.calls.length)
mockWindow.requestAnimationFrame.calls.mostRecent().args[0]();
expect(mockWindow.requestAnimationFrame.calls.count())
.toEqual(initialCount + 1);
mockWindow.requestAnimationFrame.mostRecentCall.args[0]();
expect(mockWindow.requestAnimationFrame.calls.length)
mockWindow.requestAnimationFrame.calls.mostRecent().args[0]();
expect(mockWindow.requestAnimationFrame.calls.count())
.toEqual(initialCount + 2);
// Now, verify that it stops after $destroy
expect(mockScope.$on.mostRecentCall.args[0])
expect(mockScope.$on.calls.mostRecent().args[0])
.toEqual('$destroy');
mockScope.$on.mostRecentCall.args[1]();
mockScope.$on.calls.mostRecent().args[1]();
// Frames should no longer get requested
mockWindow.requestAnimationFrame.mostRecentCall.args[0]();
expect(mockWindow.requestAnimationFrame.calls.length)
mockWindow.requestAnimationFrame.calls.mostRecent().args[0]();
expect(mockWindow.requestAnimationFrame.calls.count())
.toEqual(initialCount + 2);
mockWindow.requestAnimationFrame.mostRecentCall.args[0]();
expect(mockWindow.requestAnimationFrame.calls.length)
mockWindow.requestAnimationFrame.calls.mostRecent().args[0]();
expect(mockWindow.requestAnimationFrame.calls.count())
.toEqual(initialCount + 2);
});
});

View File

@@ -37,13 +37,13 @@ define(
mockTicker = jasmine.createSpyObj('ticker', ['listen']);
mockUnticker = jasmine.createSpy('unticker');
mockTicker.listen.andReturn(mockUnticker);
mockTicker.listen.and.returnValue(mockUnticker);
indicator = new ClockIndicator(mockTicker, TEST_FORMAT);
});
it("displays the current time", function () {
mockTicker.listen.mostRecentCall.args[0](TEST_TIMESTAMP);
mockTicker.listen.calls.mostRecent().args[0](TEST_TIMESTAMP);
expect(indicator.getText()).toEqual("2015-154 17:56:14 UTC");
});

View File

@@ -46,7 +46,7 @@ define(["../../src/indicators/FollowIndicator"], function (FollowIndicator) {
beforeEach(function () {
testObject = { name: "some timer!" };
mockTimerService.getTimer.andReturn(testObject);
mockTimerService.getTimer.and.returnValue(testObject);
});
it("displays the timer's name", function () {

View File

@@ -37,23 +37,23 @@ define(
mockNow = jasmine.createSpy('now');
mockCallback = jasmine.createSpy('callback');
mockNow.andReturn(TEST_TIMESTAMP);
mockNow.and.returnValue(TEST_TIMESTAMP);
tickerService = new TickerService(mockTimeout, mockNow);
});
it("notifies listeners of clock ticks", function () {
tickerService.listen(mockCallback);
mockNow.andReturn(TEST_TIMESTAMP + 12321);
mockTimeout.mostRecentCall.args[0]();
mockNow.and.returnValue(TEST_TIMESTAMP + 12321);
mockTimeout.calls.mostRecent().args[0]();
expect(mockCallback)
.toHaveBeenCalledWith(TEST_TIMESTAMP + 12321);
});
it("allows listeners to unregister", function () {
tickerService.listen(mockCallback)(); // Unregister immediately
mockNow.andReturn(TEST_TIMESTAMP + 12321);
mockTimeout.mostRecentCall.args[0]();
mockNow.and.returnValue(TEST_TIMESTAMP + 12321);
mockTimeout.calls.mostRecent().args[0]();
expect(mockCallback).not
.toHaveBeenCalledWith(TEST_TIMESTAMP + 12321);
});

View File

@@ -69,7 +69,7 @@ define([
'*',
jasmine.any(Function)
);
mockmct.objects.observe.mostRecentCall.args[2](newTimer);
mockmct.objects.observe.calls.mostRecent().args[2](newTimer);
expect(timerService.getTimer()).toBe(newTimer);
});
});

View File

@@ -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));
});

View File

@@ -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);

View File

@@ -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);

View File

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

View File

@@ -41,7 +41,7 @@ define(
controller = new HyperlinkController(scope);
});
it("knows when it should open a new tab", function () {
scope.domainObject.getModel.andReturn({
scope.domainObject.getModel.and.returnValue({
"displayFormat": "link",
"openNewTab": "newTab",
"showTitle": false
@@ -52,7 +52,7 @@ define(
.toBe(true);
});
it("knows when it is a button", function () {
scope.domainObject.getModel.andReturn({
scope.domainObject.getModel.and.returnValue({
"displayFormat": "button",
"openNewTab": "thisTab",
"showTitle": false
@@ -63,7 +63,7 @@ define(
.toEqual(true);
});
it("knows when it should open in the same tab", function () {
scope.domainObject.getModel.andReturn({
scope.domainObject.getModel.and.returnValue({
"displayFormat": "link",
"openNewTab": "thisTab",
"showTitle": false
@@ -74,7 +74,7 @@ define(
.toBe(false);
});
it("knows when it is a link", function () {
scope.domainObject.getModel.andReturn({
scope.domainObject.getModel.and.returnValue({
"displayFormat": "link",
"openNewTab": "thisTab",
"showTitle": false

View File

@@ -39,7 +39,7 @@ define(
metadata,
prefix,
controller,
hasLoaded,
requestPromise,
mockWindow,
mockElement;
@@ -50,7 +50,7 @@ define(
['getId']
);
newDomainObject = { name: 'foo' };
oldDomainObject.getId.andReturn('testID');
oldDomainObject.getId.and.returnValue('testID');
openmct = {
objects: jasmine.createSpyObj('objectAPI', [
'get'
@@ -73,39 +73,41 @@ define(
'value',
'valuesForHints'
]);
metadata.value.and.returnValue("timestamp");
metadata.valuesForHints.and.returnValue(["value"]);
prefix = "formatted ";
unsubscribe = jasmine.createSpy('unsubscribe');
openmct.telemetry.subscribe.andReturn(unsubscribe);
openmct.time.timeSystem.andReturn({
openmct.telemetry.subscribe.and.returnValue(unsubscribe);
openmct.time.timeSystem.and.returnValue({
key: 'testKey'
});
$scope.domainObject = oldDomainObject;
openmct.objects.get.andReturn(Promise.resolve(newDomainObject));
openmct.telemetry.getMetadata.andReturn(metadata);
openmct.telemetry.getValueFormatter.andCallFake(function (property) {
openmct.objects.get.and.returnValue(Promise.resolve(newDomainObject));
openmct.telemetry.getMetadata.and.returnValue(metadata);
openmct.telemetry.getValueFormatter.and.callFake(function (property) {
var formatter =
jasmine.createSpyObj("formatter-" + property, ['format']);
var isTime = (property === "timestamp");
formatter.format.andCallFake(function (datum) {
formatter.format.and.callFake(function (datum) {
return (isTime ? prefix : "") + datum[property];
});
return formatter;
});
hasLoaded = false;
openmct.telemetry.request.andCallFake(function () {
requestPromise = new Promise(function (resolve) {
setTimeout(function () {
hasLoaded = true;
}, 10);
return Promise.resolve([{
resolve([{
timestamp: 1434600258123,
value: 'some/url'
}]);
}, 10);
});
metadata.value.andReturn("timestamp");
metadata.valuesForHints.andReturn(["value"]);
openmct.telemetry.request.and.returnValue(requestPromise);
mockElement = $(MOCK_ELEMENT_TEMPLATE);
mockWindow = jasmine.createSpyObj('$window', ['requestAnimationFrame']);
mockWindow.requestAnimationFrame.andCallFake(function (f) {
mockWindow.requestAnimationFrame.and.callFake(function (f) {
return f();
});
@@ -123,19 +125,14 @@ define(
bounds;
beforeEach(function () {
waitsFor(function () {
return hasLoaded;
}, 500);
runs(function () {
openmct.time.on.calls.forEach(function (call) {
return requestPromise.then(function () {
openmct.time.on.calls.all().forEach(function (call) {
if (call.args[0] === "bounds") {
boundsListener = call.args[1];
}
});
callback =
openmct.telemetry.subscribe.mostRecentCall.args[1];
openmct.telemetry.subscribe.calls.mostRecent().args[1];
});
});
@@ -209,7 +206,7 @@ define(
it("unsubscribes and unlistens when scope is destroyed", function () {
expect(unsubscribe).not.toHaveBeenCalled();
$scope.$on.calls.forEach(function (call) {
$scope.$on.calls.all().forEach(function (call) {
if (call.args[0] === '$destroy') {
call.args[1]();
}
@@ -222,7 +219,7 @@ define(
it("listens for bounds event and responds to tick and manual change", function () {
var mockBounds = {start: 1434600000000, end: 1434600500000};
expect(openmct.time.on).toHaveBeenCalled();
openmct.telemetry.request.reset();
openmct.telemetry.request.calls.reset();
boundsListener(mockBounds, true);
expect(openmct.telemetry.request).not.toHaveBeenCalled();
boundsListener(mockBounds, false);

View File

@@ -42,7 +42,7 @@ define(
mockElement = jasmine.createSpyObj('element', ['css']);
testImage = {};
mockDocument[0].createElement.andReturn(testImage);
mockDocument[0].createElement.and.returnValue(testImage);
directive = new MCTBackgroundImage(mockDocument);
});
@@ -70,28 +70,28 @@ define(
it("updates images in-order, even when they load out-of-order", function () {
var firstOnload;
mockScope.$watch.mostRecentCall.args[1]("some/url/0");
mockScope.$watch.calls.mostRecent().args[1]("some/url/0");
firstOnload = testImage.onload;
mockScope.$watch.mostRecentCall.args[1]("some/url/1");
mockScope.$watch.calls.mostRecent().args[1]("some/url/1");
// Resolve in a different order
testImage.onload();
firstOnload();
// Should still have taken the more recent value
expect(mockElement.css.mostRecentCall.args).toEqual([
expect(mockElement.css.calls.mostRecent().args).toEqual([
"background-image",
"url('some/url/1')"
]);
});
it("clears the background image when undefined is passed in", function () {
mockScope.$watch.mostRecentCall.args[1]("some/url/0");
mockScope.$watch.calls.mostRecent().args[1]("some/url/0");
testImage.onload();
mockScope.$watch.mostRecentCall.args[1](undefined);
mockScope.$watch.calls.mostRecent().args[1](undefined);
expect(mockElement.css.mostRecentCall.args).toEqual([
expect(mockElement.css.calls.mostRecent().args).toEqual([
"background-image",
"none"
]);
@@ -99,7 +99,7 @@ define(
it("updates filters on change", function () {
var filters = { brightness: 123, contrast: 21 };
mockScope.$watchCollection.calls.forEach(function (call) {
mockScope.$watchCollection.calls.all().forEach(function (call) {
if (call.args[0] === 'filters') {
call.args[1](filters);
}
@@ -111,7 +111,7 @@ define(
});
it("clears filters when none are present", function () {
mockScope.$watchCollection.calls.forEach(function (call) {
mockScope.$watchCollection.calls.all().forEach(function (call) {
if (call.args[0] === 'filters') {
call.args[1](undefined);
}

View File

@@ -45,13 +45,13 @@ define(
'telemetry',
['getMetadata']
);
mockDomainObject.getCapability.andCallFake(function (c) {
mockDomainObject.getCapability.and.callFake(function (c) {
return c === 'telemetry' ? mockTelemetry : undefined;
});
mockDomainObject.getId.andReturn("some-id");
mockDomainObject.getModel.andReturn({ name: "foo" });
mockTelemetry.getMetadata.andReturn(mockMetadata);
mockMetadata.valuesForHints.andReturn(["bar"]);
mockDomainObject.getId.and.returnValue("some-id");
mockDomainObject.getModel.and.returnValue({ name: "foo" });
mockTelemetry.getMetadata.and.returnValue(mockMetadata);
mockMetadata.valuesForHints.and.returnValue(["bar"]);
openmct = { telemetry: mockTelemetry };
@@ -69,7 +69,7 @@ define(
});
it("disallows the imagery view for domain objects without image telemetry", function () {
mockMetadata.valuesForHints.andReturn([]);
mockMetadata.valuesForHints.and.returnValue([]);
expect(policy.allow(testView, mockDomainObject)).toBeFalsy();
});

View File

@@ -34,14 +34,11 @@ define(
var mockScope,
mockQ,
mockDialogService,
mockHandler,
mockFormatter,
mockDomainObject,
mockHandle,
mockEvent,
testGrid,
testModel,
testValues,
testConfiguration,
mockOpenMCT,
mockTelemetryAPI,
@@ -63,7 +60,7 @@ define(
// Utility function; find a $on calls for a given expression.
function findOn(expr) {
var on;
mockScope.$on.calls.forEach(function (call) {
mockScope.$on.calls.all().forEach(function (call) {
if (call.args[0] === expr) {
on = call.args[1];
}
@@ -86,10 +83,6 @@ define(
'$scope',
["$on", "$watch", "$digest", "commit"]
);
mockHandler = jasmine.createSpyObj(
'telemetryHandler',
['handle']
);
mockQ = jasmine.createSpyObj('$q', ['when']);
mockDialogService = jasmine.createSpyObj(
'dialogService',
@@ -99,21 +92,10 @@ define(
'telemetryFormatter',
['format']
);
mockFormatter.format.andCallFake(function (valueMetadata) {
mockFormatter.format.and.callFake(function (valueMetadata) {
return "Formatted " + valueMetadata.value;
});
mockHandle = jasmine.createSpyObj(
'subscription',
[
'unsubscribe',
'getDomainValue',
'getTelemetryObjects',
'getRangeValue',
'getDatum',
'request'
]
);
mockConductor = jasmine.createSpyObj('conductor', [
'on',
'off',
@@ -121,13 +103,13 @@ define(
'timeSystem',
'clock'
]);
mockConductor.bounds.andReturn({});
mockConductor.bounds.and.returnValue({});
mockTimeSystem = {
metadata: {
key: 'key'
}
};
mockConductor.timeSystem.andReturn(mockTimeSystem);
mockConductor.timeSystem.and.returnValue(mockTimeSystem);
mockEvent = jasmine.createSpyObj(
'event',
@@ -144,15 +126,14 @@ define(
'getValueFormatter'
]
);
mockTelemetryAPI.isTelemetryObject.andReturn(true);
mockTelemetryAPI.request.andReturn(Promise.resolve([]));
mockTelemetryAPI.isTelemetryObject.and.returnValue(true);
mockTelemetryAPI.request.and.returnValue(Promise.resolve([]));
testGrid = [123, 456];
testModel = {
composition: ['a', 'b', 'c'],
layoutGrid: testGrid
};
testValues = { a: 10, b: 42, c: 31.42 };
testConfiguration = { elements: [
{ type: "fixed.telemetry", id: 'a', x: 1, y: 1, useGrid: true},
{ type: "fixed.telemetry", id: 'b', x: 1, y: 1, useGrid: true},
@@ -168,8 +149,8 @@ define(
mockCompositionAPI = jasmine.createSpyObj('composition', [
'get'
]);
mockCompositionAPI.get.andReturn(mockCompositionCollection);
mockCompositionCollection.load.andReturn(
mockCompositionAPI.get.and.returnValue(mockCompositionCollection);
mockCompositionCollection.load.and.returnValue(
Promise.resolve(mockChildren)
);
@@ -191,7 +172,7 @@ define(
'domainObject',
['getId', 'getModel', 'getCapability', 'useCapability']
);
mockDomainObject.useCapability.andReturn(mockNewDomainObject);
mockDomainObject.useCapability.and.returnValue(mockNewDomainObject);
mockScope.domainObject = mockDomainObject;
selectable[0] = {
@@ -205,14 +186,14 @@ define(
'off',
'get'
]);
mockSelection.get.andReturn([]);
mockSelection.get.and.returnValue([]);
unlistenFunc = jasmine.createSpy("unlisten");
mockObjects = jasmine.createSpyObj('objects', [
'observe',
'get'
]);
mockObjects.observe.andReturn(unlistenFunc);
mockObjects.observe.and.returnValue(unlistenFunc);
mockOpenMCT = {
time: mockConductor,
@@ -230,11 +211,11 @@ define(
'value',
'values'
]);
mockMetadata.value.andReturn({
mockMetadata.value.and.returnValue({
key: 'value'
});
mockMetadata.valuesForHints.andCallFake(function (hints) {
mockMetadata.valuesForHints.and.callFake(function (hints) {
if (hints === ['domain']) {
return [{
key: 'time'
@@ -250,11 +231,11 @@ define(
'evaluate'
]);
mockLimitEvaluator.evaluate.andReturn({});
mockLimitEvaluator.evaluate.and.returnValue({});
mockTelemetryAPI.getMetadata.andReturn(mockMetadata);
mockTelemetryAPI.limitEvaluator.andReturn(mockLimitEvaluator);
mockTelemetryAPI.getValueFormatter.andReturn(mockFormatter);
mockTelemetryAPI.getMetadata.and.returnValue(mockMetadata);
mockTelemetryAPI.limitEvaluator.and.returnValue(mockLimitEvaluator);
mockTelemetryAPI.getValueFormatter.and.returnValue(mockFormatter);
controller = new FixedController(
mockScope,
@@ -268,17 +249,8 @@ define(
it("subscribes a domain object", function () {
var object = makeMockDomainObject("mock");
var done = false;
controller.getTelemetry(object).then(function () {
done = true;
});
waitsFor(function () {
return done;
});
runs(function () {
return controller.getTelemetry(object).then(function () {
expect(mockTelemetryAPI.subscribe).toHaveBeenCalledWith(
object,
jasmine.any(Function),
@@ -288,29 +260,18 @@ define(
});
it("releases subscription when a domain objects is removed", function () {
var done = false;
var unsubscribe = jasmine.createSpy('unsubscribe');
var unsubscribePromise = new Promise(function (resolve) {
unsubscribe.and.callFake(resolve);
});
var object = makeMockDomainObject("mock");
mockTelemetryAPI.subscribe.andReturn(unsubscribe);
controller.getTelemetry(object).then(function () {
done = true;
});
waitsFor(function () {
return done;
});
runs(function () {
mockTelemetryAPI.subscribe.and.returnValue(unsubscribe);
return controller.getTelemetry(object).then(function () {
controller.onCompositionRemove(object.identifier);
waitsFor(function () {
return unsubscribe.calls.length > 0;
});
runs(function () {
expect(unsubscribe).toHaveBeenCalled();
});
return unsubscribePromise;
}).then(function () {
expect(unsubscribe).toHaveBeenCalled();
});
});
@@ -325,7 +286,7 @@ define(
it("allows elements to be selected", function () {
selectable[0].context.elementProxy = controller.getElements()[1];
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
expect(controller.isElementSelected()).toBe(true);
});
@@ -333,7 +294,7 @@ define(
it("allows selection retrieval", function () {
var elements = controller.getElements();
selectable[0].context.elementProxy = elements[1];
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
expect(controller.getSelectedElement()).toEqual(elements[1]);
});
@@ -341,7 +302,7 @@ define(
it("selects the parent view when selected element is removed", function () {
var elements = controller.getElements();
selectable[0].context.elementProxy = elements[1];
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
controller.remove(elements[1]);
expect($element[0].click).toHaveBeenCalled();
@@ -352,7 +313,7 @@ define(
// Same element (at least by index) should still be selected.
var elements = controller.getElements();
selectable[0].context.elementProxy = elements[1];
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
expect(controller.getSelectedElement()).toEqual(elements[1]);
@@ -377,26 +338,23 @@ define(
key: '12345'
}
};
mockConductor.clock.andReturn({});
mockConductor.clock.and.returnValue({});
controller.elementProxiesById = {};
controller.elementProxiesById['12345'] = [testElement];
controller.elementProxies = [testElement];
controller.subscribeToObject(telemetryObject);
mockTelemetryAPI.subscribe.mostRecentCall.args[1](mockTelemetry);
mockTelemetryAPI.subscribe.calls.mostRecent().args[1](mockTelemetry);
waitsFor(function () {
return controller.digesting === false;
}, "digest to complete", 100);
runs(function () {
return new Promise(function (resolve) {
mockScope.$digest.and.callFake(resolve);
}).then(function () {
// Get elements that controller is now exposing
elements = controller.getElements();
// Formatted values should be available
expect(elements[0].value).toEqual("Formatted 200");
});
});
it("updates elements styles when grid size changes", function () {
@@ -427,7 +385,7 @@ define(
// Notify that a drop occurred
testModel.composition.push('d');
mockObjects.get.andReturn(Promise.resolve([]));
mockObjects.get.and.returnValue(Promise.resolve([]));
findOn('mctDrop')(
mockEvent,
@@ -459,21 +417,12 @@ define(
});
it("unsubscribes when destroyed", function () {
var done = false;
var unsubscribe = jasmine.createSpy('unsubscribe');
var object = makeMockDomainObject("mock");
mockTelemetryAPI.subscribe.andReturn(unsubscribe);
mockTelemetryAPI.subscribe.and.returnValue(unsubscribe);
controller.getTelemetry(object).then(function () {
done = true;
});
waitsFor(function () {
return done;
});
runs(function () {
return controller.getTelemetry(object).then(function () {
expect(unsubscribe).not.toHaveBeenCalled();
// Destroy the scope
findOn('$destroy')();
@@ -489,7 +438,7 @@ define(
it("exposes drag handles", function () {
var handles;
selectable[0].context.elementProxy = controller.getElements()[1];
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
// Should have a non-empty array of handles
handles = controller.handles();
@@ -507,7 +456,7 @@ define(
it("exposes a move handle", function () {
selectable[0].context.elementProxy = controller.getElements()[1];
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
// Should have a move handle
var handle = controller.moveHandle();
@@ -521,7 +470,7 @@ define(
it("updates selection style during drag", function () {
var oldStyle;
selectable[0].context.elementProxy = controller.getElements()[1];
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
// Get style
oldStyle = controller.getSelectedElementStyle();
@@ -545,7 +494,7 @@ define(
jasmine.any(Function)
);
mockScope.$on.mostRecentCall.args[1]();
mockScope.$on.calls.mostRecent().args[1]();
expect(mockOpenMCT.selection.off).toHaveBeenCalledWith(
'change',
@@ -561,7 +510,7 @@ define(
beforeEach(function () {
testBounds = { start: 123, end: 321 };
boundsChangeCallback = mockConductor.on.mostRecentCall.args[1];
boundsChangeCallback = mockConductor.on.calls.mostRecent().args[1];
objectOne = {};
objectTwo = {};
controller.telemetryObjects = [
@@ -569,7 +518,7 @@ define(
objectTwo
];
spyOn(controller, "fetchHistoricalData");
controller.fetchHistoricalData.andCallThrough();
controller.fetchHistoricalData.and.callThrough();
});
it("registers a bounds change listener", function () {
@@ -577,18 +526,18 @@ define(
});
it("requests only a single point", function () {
mockConductor.clock.andReturn(undefined);
mockConductor.clock.and.returnValue(undefined);
boundsChangeCallback(testBounds);
expect(mockTelemetryAPI.request.calls.length).toBe(2);
expect(mockTelemetryAPI.request.calls.count()).toBe(2);
mockTelemetryAPI.request.calls.forEach(function (call) {
mockTelemetryAPI.request.calls.all().forEach(function (call) {
expect(call.args[1].size).toBe(1);
});
});
it("Does not fetch historical data on tick", function () {
boundsChangeCallback(testBounds, true);
expect(mockTelemetryAPI.request.calls.length).toBe(0);
expect(mockTelemetryAPI.request.calls.count()).toBe(0);
});
});
@@ -613,20 +562,18 @@ define(
it("updates displayed values from historical telemetry", function () {
spyOn(controller, "updateView");
controller.updateView.andCallThrough();
controller.updateView.and.callThrough();
mockTelemetryAPI.request.andReturn(Promise.resolve([{
mockTelemetryAPI.request.and.returnValue(Promise.resolve([{
time: 100,
value: testValue
}]));
controller.fetchHistoricalData(mockTelemetryObject);
waitsFor(function () {
return controller.digesting === false;
});
runs(function () {
return new Promise(function (resolve) {
mockScope.$digest.and.callFake(resolve);
}).then(function () {
expect(controller.updateView).toHaveBeenCalled();
expect(controller.getElements()[0].value)
.toEqual("Formatted " + testValue);
@@ -634,7 +581,7 @@ define(
});
it("selects an range value to display, if available", function () {
mockMetadata.valuesForHints.andReturn([
mockMetadata.valuesForHints.and.returnValue([
{
key: 'range',
source: 'range'
@@ -645,8 +592,8 @@ define(
});
it("selects the first non-domain value to display, if no range available", function () {
mockMetadata.valuesForHints.andReturn([]);
mockMetadata.values.andReturn([
mockMetadata.valuesForHints.and.returnValue([]);
mockMetadata.values.and.returnValue([
{
key: 'domain',
source: 'domain',
@@ -667,17 +614,15 @@ define(
});
it("reflects limit status", function () {
mockLimitEvaluator.evaluate.andReturn({cssClass: "alarm-a"});
mockLimitEvaluator.evaluate.and.returnValue({cssClass: "alarm-a"});
controller.updateView(mockTelemetryObject, [{
time: 100,
value: testValue
}]);
waitsFor(function () {
return controller.digesting === false;
});
runs(function () {
return new Promise(function (resolve) {
mockScope.$digest.and.callFake(resolve);
}).then(function () {
// Limit-based CSS classes should be available
expect(controller.getElements()[0].cssClass).toEqual("alarm-a");
});

View File

@@ -37,16 +37,16 @@ define(
'elementHandle',
['x', 'y','getGridSize']
);
mockElementHandle.x.andReturn(6);
mockElementHandle.y.andReturn(8);
mockElementHandle.getGridSize.andReturn(TEST_GRID_SIZE);
mockElementHandle.x.and.returnValue(6);
mockElementHandle.y.and.returnValue(8);
mockElementHandle.getGridSize.and.returnValue(TEST_GRID_SIZE);
mockFixedControl = jasmine.createSpyObj(
'fixedControl',
['updateSelectionStyle', 'mutate']
);
mockFixedControl.updateSelectionStyle.andReturn();
mockFixedControl.mutate.andReturn();
mockFixedControl.updateSelectionStyle.and.returnValue();
mockFixedControl.mutate.and.returnValue();
mockConfigPath = jasmine.createSpy('configPath');
@@ -80,7 +80,7 @@ define(
expect(mockElementHandle.y).toHaveBeenCalledWith(7);
// Should have called updateSelectionStyle once per continueDrag
expect(mockFixedControl.updateSelectionStyle.calls.length).toEqual(2);
expect(mockFixedControl.updateSelectionStyle.calls.count()).toEqual(2);
// Finally, ending drag should mutate
handle.endDrag();

View File

@@ -37,7 +37,7 @@ define(
mockDialogService = jasmine.createSpyObj('dialogService', ['getUserInput']);
mockPromise = jasmine.createSpyObj('promise', ['then']);
mockQ.when.andReturn(mockPromise);
mockQ.when.and.returnValue(mockPromise);
proxy = new FixedProxy(mockCallback, mockQ, mockDialogService);
});
@@ -54,7 +54,7 @@ define(
// Callback should not have been invoked yet
expect(mockCallback).not.toHaveBeenCalled();
// Resolve the promise
mockPromise.then.mostRecentCall.args[0]({});
mockPromise.then.calls.mostRecent().args[0]({});
// Should have fired the callback
expect(mockCallback).toHaveBeenCalledWith({
type: "fixed.box",

View File

@@ -45,14 +45,14 @@ define(
mockCandidateObj = jasmine.createSpyObj('domainObj', [
'getCapability'
]);
mockCandidateObj.getCapability.andReturn(mockCandidate);
mockCandidateObj.getCapability.and.returnValue(mockCandidate);
mockChild.getCapability.andReturn(mockContext);
mockChild.getCapability.and.returnValue(mockContext);
mockCandidate.instanceOf.andCallFake(function (t) {
mockCandidate.instanceOf.and.callFake(function (t) {
return t === candidateType;
});
mockContext.instanceOf.andCallFake(function (t) {
mockContext.instanceOf.and.callFake(function (t) {
return t === contextType;
});

View File

@@ -112,7 +112,7 @@ define(
mockDomainObjectCapability = jasmine.createSpyObj('capability',
['inEditContext', 'listen']
);
mockDomainObjectCapability.listen.andReturn(unlistenFunc);
mockDomainObjectCapability.listen.and.returnValue(unlistenFunc);
mockCompositionCapability = mockPromise(mockCompositionObjects);
@@ -132,12 +132,12 @@ define(
'off',
'get'
]);
mockSelection.get.andReturn(selectable);
mockSelection.get.and.returnValue(selectable);
mockObjects = jasmine.createSpyObj('objects', [
'get'
]);
mockObjects.get.andReturn(mockPromise(mockDomainObject("mockObject")));
mockObjects.get.and.returnValue(mockPromise(mockDomainObject("mockObject")));
mockOpenMCT = {
selection: mockSelection,
objects: mockObjects
@@ -147,17 +147,18 @@ define(
$(document).find('body').append($element);
spyOn($element[0], 'click');
spyOn(mockScope.domainObject, "useCapability").andCallThrough();
spyOn(mockScope.domainObject, "useCapability").and.callThrough();
controller = new LayoutController(mockScope, $element, mockOpenMCT);
spyOn(controller, "layoutPanels").andCallThrough();
spyOn(controller, "layoutPanels").and.callThrough();
spyOn(controller, "commit");
jasmine.Clock.useMock();
jasmine.clock().install();
});
afterEach(function () {
$element.remove();
jasmine.clock().uninstall();
});
@@ -174,7 +175,7 @@ define(
jasmine.any(Function)
);
mockScope.$on.calls[0].args[1]();
mockScope.$on.calls.all()[0].args[1]();
expect(mockOpenMCT.selection.off).toHaveBeenCalledWith(
'change',
@@ -192,7 +193,7 @@ define(
});
it("Retrieves updated composition from composition capability", function () {
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
expect(mockScope.domainObject.useCapability).toHaveBeenCalledWith(
"composition"
);
@@ -208,11 +209,11 @@ define(
secondCompositionCB;
spyOn(mockCompositionCapability, "then");
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
firstCompositionCB = mockCompositionCapability.then.calls[0].args[0];
secondCompositionCB = mockCompositionCapability.then.calls[1].args[0];
firstCompositionCB = mockCompositionCapability.then.calls.all()[0].args[0];
secondCompositionCB = mockCompositionCapability.then.calls.all()[1].args[0];
//Resolve promises in reverse order
secondCompositionCB(secondMockCompositionObjects);
@@ -226,7 +227,7 @@ define(
it("provides styles for frames, from configuration", function () {
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
expect(controller.getFrameStyle("a")).toEqual({
top: "320px",
left: "640px",
@@ -241,7 +242,7 @@ define(
var styleB, styleC;
// b and c do not have configured positions
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
styleB = controller.getFrameStyle("b");
styleC = controller.getFrameStyle("c");
@@ -258,7 +259,7 @@ define(
it("allows panels to be dragged", function () {
// Populate scope
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
// Verify precondition
expect(testConfiguration.panels.b).not.toBeDefined();
@@ -277,7 +278,7 @@ define(
it("invokes commit after drag", function () {
// Populate scope
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
// Do a drag
controller.startDrag("b", [1, 1], [0, 0]);
@@ -300,7 +301,7 @@ define(
expect(testConfiguration.panels.d).not.toBeDefined();
// Notify that a drop occurred
mockScope.$on.mostRecentCall.args[1](
mockScope.$on.calls.mostRecent().args[1](
mockEvent,
'd',
{ x: 300, y: 100 }
@@ -315,7 +316,7 @@ define(
mockEvent.defaultPrevented = true;
// Notify that a drop occurred
mockScope.$on.mostRecentCall.args[1](
mockScope.$on.calls.mostRecent().args[1](
mockEvent,
'd',
{ x: 300, y: 100 }
@@ -330,8 +331,8 @@ define(
testModel.layoutGrid = [1, 1];
// White-boxy; we know which watch is which
mockScope.$watch.calls[0].args[1](testModel.layoutGrid);
mockScope.$watchCollection.calls[0].args[1](testModel.composition);
mockScope.$watch.calls.all()[0].args[1](testModel.layoutGrid);
mockScope.$watchCollection.calls.all()[0].args[1](testModel.composition);
styleB = controller.getFrameStyle("b");
@@ -345,7 +346,7 @@ define(
// Start with a very small frame size
testModel.layoutGrid = [1, 1];
mockScope.$watch.calls[0].args[1](testModel.layoutGrid);
mockScope.$watch.calls.all()[0].args[1](testModel.layoutGrid);
// Add a new object to the composition
mockComposition = ["a", "b", "c", "d"];
@@ -353,7 +354,7 @@ define(
mockCompositionCapability = mockPromise(mockCompositionObjects);
// Notify that a drop occurred
mockScope.$on.mostRecentCall.args[1](
mockScope.$on.calls.mostRecent().args[1](
mockEvent,
'd',
{ x: 300, y: 100 }
@@ -369,14 +370,14 @@ define(
it("updates positions of existing objects on a drop", function () {
var oldStyle;
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
oldStyle = controller.getFrameStyle("b");
expect(oldStyle).toBeDefined();
// ...drop event...
mockScope.$on.mostRecentCall
mockScope.$on.calls.mostRecent()
.args[1](mockEvent, 'b', { x: 300, y: 100 });
expect(controller.getFrameStyle("b"))
@@ -384,16 +385,16 @@ define(
});
it("allows objects to be selected", function () {
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
var childObj = mockCompositionObjects[0];
selectable[0].context.oldItem = childObj;
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
expect(controller.selected(childObj)).toBe(true);
});
it("prevents event bubbling while drag is in progress", function () {
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
var childObj = mockCompositionObjects[0];
// Do a drag
@@ -407,57 +408,57 @@ define(
expect(mockEvent.stopPropagation).toHaveBeenCalled();
// Shoud be able to select another object when dragging is done.
jasmine.Clock.tick(0);
mockEvent.stopPropagation.reset();
jasmine.clock().tick(0);
mockEvent.stopPropagation.calls.reset();
controller.bypassSelection(mockEvent);
expect(mockEvent.stopPropagation).not.toHaveBeenCalled();
});
it("shows frames by default", function () {
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
expect(controller.hasFrame(mockCompositionObjects[0])).toBe(true);
});
it("hyperlinks hide frame by default", function () {
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
expect(controller.hasFrame(mockCompositionObjects[1])).toBe(false);
});
it("selects the parent object when selected object is removed", function () {
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
var childObj = mockCompositionObjects[0];
selectable[0].context.oldItem = childObj;
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
var composition = ["b", "c"];
mockScope.$watchCollection.mostRecentCall.args[1](composition);
mockScope.$watchCollection.calls.mostRecent().args[1](composition);
expect($element[0].click).toHaveBeenCalled();
});
it("allows objects to be drilled-in only when editing", function () {
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
var childObj = mockCompositionObjects[0];
childObj.getCapability().inEditContext.andReturn(false);
childObj.getCapability().inEditContext.and.returnValue(false);
controller.drill(mockEvent, childObj);
expect(controller.isDrilledIn(childObj)).toBe(false);
});
it("allows objects to be drilled-in only if it has sub objects", function () {
mockScope.$watchCollection.mostRecentCall.args[1]();
mockScope.$watchCollection.calls.mostRecent().args[1]();
var childObj = mockCompositionObjects[1];
childObj.getCapability().inEditContext.andReturn(true);
childObj.getCapability().inEditContext.and.returnValue(true);
controller.drill(mockEvent, childObj);
expect(controller.isDrilledIn(childObj)).toBe(false);
});
it("selects a newly-dropped object", function () {
mockScope.$on.mostRecentCall.args[1](
mockScope.$on.calls.mostRecent().args[1](
mockEvent,
'd',
{ x: 300, y: 100 }
@@ -469,7 +470,7 @@ define(
spyOn(testElement[0], 'click');
controller.selectIfNew('some-id', childObj);
jasmine.Clock.tick(0);
jasmine.clock().tick(0);
expect(testElement[0].click).toHaveBeenCalled();
});

View File

@@ -38,10 +38,10 @@ define([
'hasClass',
'parent'
]);
elem.hasClass.andCallFake(function (className) {
elem.hasClass.and.callFake(function (className) {
return classes.indexOf(className) !== -1;
});
elem.parent.andReturn(parentEl);
elem.parent.and.returnValue(parentEl);
var div = document.createElement('div');
div.className = classes.join(' ');
parentEl[0].appendChild(div);
@@ -70,10 +70,10 @@ define([
for (var i = 0; i < 5; i++) {
child = makeElement([], child);
}
$element.parent.andReturn(child);
$element.parent.and.returnValue(child);
$document = [jasmine.createSpyObj('document', ['createElement'])];
$document[0].body = document.createElement('div');
$document[0].createElement.andCallFake(function (tag) {
$document[0].createElement.and.callFake(function (tag) {
return document.createElement(tag);
});
@@ -102,7 +102,7 @@ define([
'$destroy',
jasmine.any(Function)
);
$scope.$on.mostRecentCall.args[1]();
$scope.$on.calls.mostRecent().args[1]();
expect($element.off).toHaveBeenCalledWith(
'click',
jasmine.any(Function)
@@ -113,7 +113,7 @@ define([
[
'a.close', 'a.t-done', '.abs.blocker'
].forEach(function (selector) {
$element.on.mostRecentCall.args[1]();
$element.on.calls.mostRecent().args[1]();
var container = $document[0].body.querySelector('.t-contents');
expect(container.children[0]).toBe(frame[0]);
expect(layoutContainer.children[0]).not.toBe(frame[0]);

View File

@@ -42,8 +42,8 @@ define(
['then']
);
mockDialogService.getUserInput.andReturn(mockPromise);
mockPromise.then.andReturn(mockPromise);
mockDialogService.getUserInput.and.returnValue(mockPromise);
mockPromise.then.and.returnValue(mockPromise);
factory = new ElementFactory(mockDialogService);
});

View File

@@ -39,7 +39,7 @@ define(
useGrid: true
};
mockElementProxy = jasmine.createSpyObj('elementProxy', ['getGridSize']);
mockElementProxy.getGridSize.andReturn(TEST_GRID_SIZE);
mockElementProxy.getGridSize.and.returnValue(TEST_GRID_SIZE);
handle = new LineHandle(testElement, mockElementProxy, 'x', 'y', 'x2', 'y2');
});

View File

@@ -46,9 +46,9 @@ define(
'getMinWidth',
'getMinHeight'
]);
mockElementProxy.getGridSize.andReturn(TEST_GRID_SIZE);
mockElementProxy.getMinWidth.andReturn(TEST_MIN_WIDTH);
mockElementProxy.getMinHeight.andReturn(TEST_MIN_HEIGHT);
mockElementProxy.getGridSize.and.returnValue(TEST_GRID_SIZE);
mockElementProxy.getMinWidth.and.returnValue(TEST_MIN_WIDTH);
mockElementProxy.getMinHeight.and.returnValue(TEST_MIN_HEIGHT);
handle = new ResizeHandle(
mockElementProxy,

View File

@@ -72,11 +72,11 @@ define(
uAM = new UnitAccessorMutator(mockElementProxy);
uAMLine = new UnitAccessorMutator(mockLineProxy);
mockElementProxy.getMinWidth.andReturn(1);
mockElementProxy.getMinHeight.andReturn(1);
mockElementProxy.getMinWidth.and.returnValue(1);
mockElementProxy.getMinHeight.and.returnValue(1);
mockLineProxy.getMinWidth.andReturn(1);
mockLineProxy.getMinHeight.andReturn(1);
mockLineProxy.getMinWidth.and.returnValue(1);
mockLineProxy.getMinHeight.and.returnValue(1);
});
it("allows access to useGrid", function () {

View File

@@ -28,11 +28,12 @@ define(
unlistenFunc,
domainObject,
childObject,
controller,
childModel,
typeCapability,
mutationCapability,
formatService;
formatService,
compositionPromise,
controller;
beforeEach(function () {
unlistenFunc = jasmine.createSpy("unlisten");
@@ -41,17 +42,17 @@ define(
"mutationCapability",
["listen"]
);
mutationCapability.listen.andReturn(unlistenFunc);
mutationCapability.listen.and.returnValue(unlistenFunc);
formatService = jasmine.createSpyObj(
"formatService",
["getFormat"]
);
formatService.getFormat.andReturn(jasmine.createSpyObj(
formatService.getFormat.and.returnValue(jasmine.createSpyObj(
'utc',
["format"]
));
formatService.getFormat().format.andCallFake(function (v) {
formatService.getFormat().format.and.callFake(function (v) {
return "formatted " + v;
});
@@ -59,8 +60,8 @@ define(
"typeCapability",
["getCssClass", "getName"]
);
typeCapability.getCssClass.andReturn("icon-folder");
typeCapability.getName.andReturn("Folder");
typeCapability.getCssClass.and.returnValue("icon-folder");
typeCapability.getName.and.returnValue("Folder");
childModel = jasmine.createSpyObj(
@@ -75,13 +76,11 @@ define(
"childObject",
["getModel", "getCapability"]
);
childObject.getModel.andReturn(
childObject.getModel.and.returnValue(
childModel
);
// childObject.getCapability.andReturn(
// typeCapability
// );
childObject.getCapability.andCallFake(function (arg) {
childObject.getCapability.and.callFake(function (arg) {
if (arg === 'location') {
return '';
} else if (arg === 'type') {
@@ -94,25 +93,21 @@ define(
"domainObject",
["getCapability", "useCapability"]
);
domainObject.useCapability.andReturn(
Promise.resolve([childObject])
);
domainObject.getCapability.andReturn(
compositionPromise = Promise.resolve([childObject]);
domainObject.useCapability.and.returnValue(compositionPromise);
domainObject.getCapability.and.returnValue(
mutationCapability
);
scope = jasmine.createSpyObj(
"$scope",
["$on", "$apply"]
);
scope.domainObject = domainObject;
controller = new ListViewController(scope, formatService);
controller = new ListViewController(scope, formatService);
waitsFor(function () {
return scope.children;
});
return compositionPromise;
});
it("uses the UTC time format", function () {
@@ -120,37 +115,39 @@ define(
});
it("updates the view", function () {
expect(scope.children[0]).toEqual(
{
icon: "icon-folder",
title: "Battery Charge Status",
type: "Folder",
persisted: formatService.getFormat('utc')
.format(childModel.persisted),
modified: formatService.getFormat('utc')
.format(childModel.modified),
asDomainObject: childObject,
location: ''
}
);
var child = scope.children[0];
var testChild = {
icon: "icon-folder",
title: "Battery Charge Status",
type: "Folder",
persisted: formatService.getFormat('utc')
.format(childModel.persisted),
modified: formatService.getFormat('utc')
.format(childModel.modified),
asDomainObject: childObject,
location: '',
action: childObject.getCapability('action')
};
expect(child).toEqual(testChild);
});
it("updates the scope when mutation occurs", function () {
domainObject.useCapability.andReturn(
Promise.resolve([])
);
var applyPromise = new Promise(function (resolve) {
scope.$apply.and.callFake(resolve);
});
domainObject.useCapability.and.returnValue(Promise.resolve([]));
expect(mutationCapability.listen).toHaveBeenCalledWith(jasmine.any(Function));
mutationCapability.listen.mostRecentCall.args[0]();
waitsFor(function () {
return scope.children.length !== 1;
});
runs(function () {
mutationCapability.listen.calls.mostRecent().args[0]();
return applyPromise.then(function () {
expect(scope.children.length).toEqual(0);
expect(scope.$apply).toHaveBeenCalled();
});
expect(scope.$apply).toHaveBeenCalled();
});
it("releases listeners on $destroy", function () {
expect(scope.$on).toHaveBeenCalledWith('$destroy', jasmine.any(Function));
scope.$on.mostRecentCall.args[1]();
scope.$on.calls.mostRecent().args[1]();
expect(unlistenFunc).toHaveBeenCalled();
});

View File

@@ -39,7 +39,7 @@ define(
"gestureService",
["attachGestures"]
);
gestureService.attachGestures.andReturn(
gestureService.attachGestures.and.returnValue(
attachedGesture
);
mctGesture = MCTGesture(gestureService);
@@ -77,7 +77,7 @@ define(
'$destroy',
jasmine.any(Function)
);
scope.$on.mostRecentCall.args[1]();
scope.$on.calls.mostRecent().args[1]();
expect(attachedGesture.destroy).toHaveBeenCalled();
});

View File

@@ -34,7 +34,7 @@ define(
["trustAsResourceUrl"]
);
mockSCE.trustAsResourceUrl.andCallFake(function (v) {
mockSCE.trustAsResourceUrl.and.callFake(function (v) {
return v;
});

View File

@@ -38,8 +38,8 @@ define(
['getModel', 'useCapability', 'getCapability', 'hasCapability']
);
mockModel = {};
mockDomainObject.getModel.andReturn(mockModel);
mockDomainObject.getCapability.andCallFake(function (name) {
mockDomainObject.getModel.and.returnValue(mockModel);
mockDomainObject.getCapability.and.callFake(function (name) {
return name === 'editor' && {
isEditContextRoot: function () {
return true;
@@ -53,7 +53,7 @@ define(
mockAPI = {
telemetry: mockTelemetryAPI
};
mockTelemetryAPI.getValueFormatter.andCallFake(function (metadata) {
mockTelemetryAPI.getValueFormatter.and.callFake(function (metadata) {
var formatter = jasmine.createSpyObj(
'telemetryFormatter:' + metadata.key,
[
@@ -64,8 +64,8 @@ define(
var getter = function (datum) {
return datum[metadata.key];
};
formatter.format.andCallFake(getter);
formatter.parse.andCallFake(getter);
formatter.format.and.callFake(getter);
formatter.parse.and.callFake(getter);
return formatter;
});

View File

@@ -84,7 +84,7 @@ define(
it("discards telemetry data with a time stamp " +
"before specified start bound", function () {
var discarded = discardedCallback.mostRecentCall.args[0];
var discarded = discardedCallback.calls.mostRecent().args[0];
// Expect 5 because as an optimization, the TelemetryCollection
// will not consider telemetry values that exceed the upper

View File

@@ -47,7 +47,7 @@ define(
mockFormat;
function getCallback(target, event) {
return target.calls.filter(function (call) {
return target.calls.all().filter(function (call) {
return call.args[0] === event;
})[0].args[1];
}
@@ -61,7 +61,7 @@ define(
'$watchCollection',
'$digest'
]);
mockScope.$watchCollection.andCallFake(function (event, callback) {
mockScope.$watchCollection.and.callFake(function (event, callback) {
watches[event] = callback;
});
@@ -80,7 +80,7 @@ define(
mockScope.displayHeaders = true;
mockWindow = jasmine.createSpyObj('$window', ['requestAnimationFrame']);
mockWindow.requestAnimationFrame.andCallFake(function (f) {
mockWindow.requestAnimationFrame.and.callFake(function (f) {
return f();
});
@@ -91,7 +91,7 @@ define(
mockFormatService = jasmine.createSpyObj('formatService', [
'getFormat'
]);
mockFormatService.getFormat.andReturn(mockFormat);
mockFormatService.getFormat.and.returnValue(mockFormat);
controller = new MCTTableController(
mockScope,
@@ -101,7 +101,7 @@ define(
mockFormatService,
{time: mockConductor}
);
spyOn(controller, 'setVisibleRows').andCallThrough();
spyOn(controller, 'setVisibleRows').and.callThrough();
});
it('Reacts to changes to filters, headers, and rows', function () {
@@ -186,8 +186,8 @@ define(
mockScope.sortDirection = 'asc';
var toi = moment.utc(testDate).valueOf();
mockFormat.parse.andReturn(toi);
mockFormat.format.andReturn(testDate);
mockFormat.parse.and.returnValue(toi);
mockFormat.format.and.returnValue(testDate);
//mock setting the timeColumns parameter
getCallback(mockScope.$watch, 'timeColumns')(['col2']);
@@ -204,8 +204,8 @@ define(
mockScope.sortDirection = 'desc';
var toi = moment.utc(testDate).valueOf();
mockFormat.parse.andReturn(toi);
mockFormat.format.andReturn(testDate);
mockFormat.parse.and.returnValue(toi);
mockFormat.format.and.returnValue(testDate);
//mock setting the timeColumns parameter
getCallback(mockScope.$watch, 'timeColumns')(['col2']);
@@ -220,9 +220,9 @@ define(
mockScope.sortDirection = 'asc';
var toi = moment.utc(testDate).valueOf();
mockFormat.parse.andReturn(toi);
mockFormat.format.andReturn(testDate);
mockConductor.timeOfInterest.andReturn(toi);
mockFormat.parse.and.returnValue(toi);
mockFormat.format.and.returnValue(testDate);
mockConductor.timeOfInterest.and.returnValue(toi);
//mock setting the timeColumns parameter
getCallback(mockScope.$watch, 'timeColumns')(['col2']);
@@ -230,19 +230,10 @@ define(
//Mock setting the rows on scope
var rowsCallback = getCallback(mockScope.$watch, 'rows');
var setRowsPromise = rowsCallback(rowsAsc);
var promiseResolved = false;
setRowsPromise.then(function () {
promiseResolved = true;
});
waitsFor(function () {
return promiseResolved;
}, "promise to resolve", 100);
runs(function () {
return setRowsPromise.then(function () {
expect(mockScope.toiRowIndex).toBe(2);
});
});
});
@@ -322,7 +313,7 @@ define(
mockScope.exportAsCSV();
expect(mockExportService.exportCSV)
.toHaveBeenCalled();
mockExportService.exportCSV.mostRecentCall.args[0]
mockExportService.exportCSV.calls.mostRecent().args[0]
.forEach(function (row, i) {
Object.keys(row).forEach(function (k) {
expect(row[k]).toEqual(
@@ -389,18 +380,11 @@ define(
var oldRows;
mockScope.rows = testRows;
var setRowsPromise = controller.setRows(testRows);
var promiseResolved = false;
setRowsPromise.then(function () {
promiseResolved = true;
});
oldRows = mockScope.visibleRows;
mockScope.toggleSort('col2');
waitsFor(function () {
return promiseResolved;
}, "promise to resolve", 100);
runs(function () {
return setRowsPromise.then(function () {
expect(mockScope.visibleRows).not.toEqual(oldRows);
});
});

View File

@@ -40,8 +40,8 @@ define(
'getCapability',
'getModel'
]);
mockDomainObject.getCapability.andReturn(mockCapability);
mockDomainObject.getModel.andReturn({});
mockDomainObject.getCapability.and.returnValue(mockCapability);
mockDomainObject.getModel.and.returnValue({});
mockScope = jasmine.createSpyObj('scope', [
'$watchCollection',
@@ -61,12 +61,12 @@ define(
var unlistenFunc = jasmine.createSpy("unlisten");
controller.listeners.push(unlistenFunc);
expect(mockScope.$on).toHaveBeenCalledWith('$destroy', jasmine.any(Function));
mockScope.$on.mostRecentCall.args[1]();
mockScope.$on.calls.mostRecent().args[1]();
expect(unlistenFunc).toHaveBeenCalled();
});
it('Registers a listener for mutation events on the object', function () {
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
expect(mockCapability.listen).toHaveBeenCalled();
});

View File

@@ -43,7 +43,7 @@ define(
mockBounds;
function getCallback(target, event) {
return target.calls.filter(function (call) {
return target.calls.all().filter(function (call) {
return call.args[0] === event;
})[0].args[1];
}
@@ -60,8 +60,8 @@ define(
"off",
"timeSystem"
]);
mockConductor.bounds.andReturn(mockBounds);
mockConductor.clock.andReturn(undefined);
mockConductor.bounds.and.returnValue(mockBounds);
mockConductor.clock.and.returnValue(undefined);
mockDomainObject = jasmine.createSpyObj("domainObject", [
"getModel",
@@ -69,9 +69,9 @@ define(
"useCapability",
"hasCapability"
]);
mockDomainObject.getModel.andReturn({});
mockDomainObject.getId.andReturn("mockId");
mockDomainObject.useCapability.andReturn(true);
mockDomainObject.getModel.and.returnValue({});
mockDomainObject.getId.and.returnValue("mockId");
mockDomainObject.useCapability.and.returnValue(true);
mockCompositionAPI = jasmine.createSpyObj("compositionAPI", [
"get"
@@ -81,7 +81,7 @@ define(
"observe"
]);
unobserve = jasmine.createSpy("unobserve");
mockObjectAPI.observe.andReturn(unobserve);
mockObjectAPI.observe.and.returnValue(unobserve);
mockScope = jasmine.createSpyObj("scope", [
"$on",
@@ -99,9 +99,14 @@ define(
"limitEvaluator",
"getValueFormatter"
]);
mockTelemetryAPI.commonValuesForHints.andReturn([]);
mockTelemetryAPI.request.andReturn(Promise.resolve([]));
mockTelemetryAPI.getValueFormatter.andCallFake(function (metadata) {
mockTelemetryAPI.commonValuesForHints.and.returnValue([]);
mockTelemetryAPI.request.and.returnValue(Promise.resolve([]));
mockTelemetryAPI.getMetadata.and.returnValue({
values: function () {
return [];
}
});
mockTelemetryAPI.getValueFormatter.and.callFake(function (metadata) {
var formatter = jasmine.createSpyObj(
'telemetryFormatter:' + metadata.key,
[
@@ -112,19 +117,15 @@ define(
var getter = function (datum) {
return datum[metadata.key];
};
formatter.format.andCallFake(getter);
formatter.parse.andCallFake(getter);
formatter.format.and.callFake(getter);
formatter.parse.and.callFake(getter);
return formatter;
});
mockTelemetryAPI.getMetadata.andReturn({
values: function () {
return [];
}
});
mockTelemetryAPI.isTelemetryObject.andReturn(false);
mockTelemetryAPI.isTelemetryObject.and.returnValue(false);
mockTimeout = jasmine.createSpy("timeout");
mockTimeout.andReturn(1); // Return something
mockTimeout.and.returnValue(1); // Return something
mockTimeout.cancel = jasmine.createSpy("cancel");
mockAPI = {
@@ -141,7 +142,7 @@ define(
controller.registerChangeListeners();
});
it('object mutation', function () {
var calledObject = mockObjectAPI.observe.mostRecentCall.args[0];
var calledObject = mockObjectAPI.observe.calls.mostRecent().args[0];
expect(mockObjectAPI.observe).toHaveBeenCalled();
expect(calledObject.identifier.key).toEqual(mockDomainObject.getId());
@@ -197,13 +198,13 @@ define(
};
unsubscribe = jasmine.createSpy("unsubscribe");
mockTelemetryAPI.subscribe.andReturn(unsubscribe);
mockTelemetryAPI.subscribe.and.returnValue(unsubscribe);
mockChildren = [mockTelemetryObject];
mockComposition.load.andReturn(Promise.resolve(mockChildren));
mockCompositionAPI.get.andReturn(mockComposition);
mockComposition.load.and.returnValue(Promise.resolve(mockChildren));
mockCompositionAPI.get.and.returnValue(mockComposition);
mockTelemetryAPI.isTelemetryObject.andCallFake(function (obj) {
mockTelemetryAPI.isTelemetryObject.and.callFake(function (obj) {
return obj.identifier.key === mockTelemetryObject.identifier.key;
});
@@ -211,28 +212,13 @@ define(
});
it('fetches historical data for the time period specified by the conductor bounds', function () {
controller.getData().then(function () {
done = true;
});
waitsFor(function () {
return done;
}, "getData to return", 100);
runs(function () {
return controller.getData().then(function () {
expect(mockTelemetryAPI.request).toHaveBeenCalledWith(mockTelemetryObject, mockBounds);
});
});
it('unsubscribes on view destruction', function () {
controller.getData().then(function () {
done = true;
});
waitsFor(function () {
return done;
}, "getData to return", 100);
runs(function () {
return controller.getData().then(function () {
var destroy = getCallback(mockScope.$on, "$destroy");
destroy();
@@ -240,40 +226,19 @@ define(
});
});
it('fetches historical data for the time period specified by the conductor bounds', function () {
controller.getData().then(function () {
done = true;
});
waitsFor(function () {
return done;
}, "getData to return", 100);
runs(function () {
return controller.getData().then(function () {
expect(mockTelemetryAPI.request).toHaveBeenCalledWith(mockTelemetryObject, mockBounds);
});
});
it('fetches data for, and subscribes to parent object if it is a telemetry object', function () {
controller.getData().then(function () {
done = true;
});
waitsFor(function () {
return done;
}, "getData to return", 100);
runs(function () {
return controller.getData().then(function () {
expect(mockTelemetryAPI.subscribe).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Function), {});
expect(mockTelemetryAPI.request).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Object));
});
});
it('fetches data for, and subscribes to parent object if it is a telemetry object', function () {
controller.getData().then(function () {
done = true;
});
waitsFor(function () {
return done;
}, "getData to return", 100);
runs(function () {
return controller.getData().then(function () {
expect(mockTelemetryAPI.subscribe).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Function), {});
expect(mockTelemetryAPI.request).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Object));
});
@@ -289,9 +254,9 @@ define(
{name: "child 4"}
];
mockChildren = mockChildren.concat(mockTelemetryChildren);
mockComposition.load.andReturn(Promise.resolve(mockChildren));
mockComposition.load.and.returnValue(Promise.resolve(mockChildren));
mockTelemetryAPI.isTelemetryObject.andCallFake(function (object) {
mockTelemetryAPI.isTelemetryObject.and.callFake(function (object) {
if (object === mockTelemetryObject) {
return false;
} else {
@@ -299,15 +264,7 @@ define(
}
});
controller.getData().then(function () {
done = true;
});
waitsFor(function () {
return done;
}, "getData to return", 100);
runs(function () {
return controller.getData().then(function () {
mockTelemetryChildren.forEach(function (child) {
expect(mockTelemetryAPI.subscribe).toHaveBeenCalledWith(child, jasmine.any(Function), {});
});
@@ -364,13 +321,13 @@ define(
key: "column1"
};
mockTelemetryAPI.commonValuesForHints.andCallFake(function (metadata, hints) {
mockTelemetryAPI.commonValuesForHints.and.callFake(function (metadata, hints) {
if (_.eq(hints, ["domain"])) {
return domainMetadata;
}
});
mockTelemetryAPI.getMetadata.andReturn({
mockTelemetryAPI.getMetadata.and.returnValue({
values: function () {
return allMetadata;
}
@@ -409,21 +366,21 @@ define(
"column3": 9
}
];
controller.batchSize = 2;
mockTelemetryAPI.request.andReturn(Promise.resolve(mockHistoricalData));
mockTelemetryAPI.request.and.returnValue(Promise.resolve(mockHistoricalData));
controller.getHistoricalData([mockDomainObject]);
waitsFor(function () {
return !!controller.timeoutHandle;
}, "first batch to be processed", 100);
runs(function () {
//Verify that timeout is being used to yield process
expect(mockTimeout).toHaveBeenCalled();
mockTimeout.mostRecentCall.args[0]();
expect(mockTimeout.calls.length).toBe(2);
mockTimeout.mostRecentCall.args[0]();
return new Promise(function (resolve) {
mockTimeout.and.callFake(function () {
resolve();
});
}).then(function () {
mockTimeout.calls.mostRecent().args[0]();
expect(mockTimeout.calls.count()).toBe(2);
mockTimeout.calls.mostRecent().args[0]();
expect(mockScope.rows.length).toBe(3);
});
});
});
@@ -435,7 +392,7 @@ define(
{"column3": "value 3"}
];
spyOn(controller.telemetry, "on").andCallThrough();
spyOn(controller.telemetry, "on").and.callThrough();
controller.registerChangeListeners();
expect(controller.telemetry.on).toHaveBeenCalledWith("discarded", jasmine.any(Function));
@@ -453,10 +410,10 @@ define(
mockScope.rows = [{ a: -1 }];
expectedRows = mockScope.rows.concat(testRows);
spyOn(controller.telemetry, "on").andCallThrough();
spyOn(controller.telemetry, "on").and.callThrough();
controller.registerChangeListeners();
controller.telemetry.on.calls.forEach(function (call) {
controller.telemetry.on.calls.all().forEach(function (call) {
if (call.args[0] === 'added') {
call.args[1](testRows);
}

View File

@@ -54,7 +54,7 @@ define(
['getId', 'getModel', 'getCapability']
);
testModel = { composition: TEST_IDS };
mockDomainObject.getModel.andReturn(testModel);
mockDomainObject.getModel.and.returnValue(testModel);
});
it("returns a corresponding value from the map", function () {

View File

@@ -32,7 +32,8 @@ define(
mockType,
testContext,
testType,
action;
action,
actionPromise;
beforeEach(function () {
mockDomainObject = jasmine.createSpyObj(
@@ -60,11 +61,11 @@ define(
['dismiss']
);
mockNotificationService.notify.andReturn(mockNotification);
mockNotificationService.notify.and.returnValue(mockNotification);
mockDomainObject.hasCapability.andReturn(true);
mockDomainObject.getCapability.andReturn(mockType);
mockType.instanceOf.andCallFake(function (type) {
mockDomainObject.hasCapability.and.returnValue(true);
mockDomainObject.getCapability.and.returnValue(mockType);
mockType.instanceOf.and.callFake(function (type) {
return type === testType;
});
@@ -92,14 +93,12 @@ define(
});
describe("when performed", function () {
var testPromise,
mockCallback;
var testPromise;
beforeEach(function () {
mockCallback = jasmine.createSpy('callback');
// White-boxy; we know most work is delegated
// to the associated Task, so stub out that interaction.
spyOn(action.task, "run").andCallFake(function () {
spyOn(action.task, "run").and.callFake(function () {
return new Promise(function (resolve, reject) {
testPromise = {
resolve: resolve,
@@ -107,7 +106,7 @@ define(
};
});
});
action.perform().then(mockCallback);
actionPromise = action.perform();
});
it("shows a notification", function () {
@@ -122,9 +121,7 @@ define(
describe("and completed", function () {
beforeEach(function () {
testPromise.resolve();
waitsFor(function () {
return mockCallback.calls.length > 0;
});
return actionPromise;
});
it("dismisses the displayed notification", function () {
@@ -144,9 +141,8 @@ define(
beforeEach(function () {
testError = { someProperty: "some value" };
testPromise.reject(testError);
waitsFor(function () {
return mockCallback.calls.length > 0;
});
return actionPromise;
});
it("dismisses the displayed notification", function () {

View File

@@ -47,8 +47,8 @@ define(
]
);
mockDomainObject.getId.andReturn('mock');
mockDomainObject.getModel.andReturn({});
mockDomainObject.getId.and.returnValue('mock');
mockDomainObject.getModel.and.returnValue({});
task = new ExportTimelineAsCSVTask(
mockExportService,
@@ -58,14 +58,9 @@ define(
});
describe("when run", function () {
var mockCallback;
beforeEach(function () {
mockCallback = jasmine.createSpy('callback');
task.run().then(mockCallback);
waitsFor(function () {
return mockCallback.calls.length > 0;
});
return task.run();
});
it("exports to CSV", function () {

View File

@@ -46,7 +46,7 @@ define(
'domainObject',
['getId', 'getModel', 'getCapability']
);
mockDomainObject.getId.andReturn(testId);
mockDomainObject.getId.and.returnValue(testId);
});
it("provides a value mapped from domain object's identifier", function () {

View File

@@ -54,7 +54,7 @@ define(
testIndex = 1;
testMetadata[testIndex].name = testName;
mockDomainObject.useCapability.andCallFake(function (c) {
mockDomainObject.useCapability.and.callFake(function (c) {
return (c === 'metadata') && testMetadata;
});
});

View File

@@ -58,7 +58,7 @@ define(
modes: TEST_IDS
}
};
mockDomainObject.getModel.andReturn(testModel);
mockDomainObject.getModel.and.returnValue(testModel);
});
it("returns a corresponding value from the map", function () {

View File

@@ -39,9 +39,9 @@ define(
'getModel'
]
);
mockDomainObject.getId.andReturn('id-' + index);
mockDomainObject.getModel.andReturn(model);
mockDomainObject.useCapability.andCallFake(function (c) {
mockDomainObject.getId.and.returnValue('id-' + index);
mockDomainObject.getModel.and.returnValue(model);
mockDomainObject.useCapability.and.callFake(function (c) {
return c === 'metadata' && [];
});
return mockDomainObject;
@@ -64,14 +64,14 @@ define(
{ }
].map(makeMockDomainObject);
mockDomainObjects[1].hasCapability.andCallFake(function (c) {
mockDomainObjects[1].hasCapability.and.callFake(function (c) {
return c === 'timespan';
});
mockDomainObjects[1].useCapability.andCallFake(function (c) {
mockDomainObjects[1].useCapability.and.callFake(function (c) {
return c === 'timespan' ? Promise.resolve(mockTimespan) :
c === 'metadata' ? [] : undefined;
});
mockDomainObjects[2].useCapability.andCallFake(function (c) {
mockDomainObjects[2].useCapability.and.callFake(function (c) {
return c === 'metadata' && testMetadata;
});
@@ -82,12 +82,9 @@ define(
var rows;
beforeEach(function () {
exporter.rows().then(function (r) {
return exporter.rows().then(function (r) {
rows = r;
});
waitsFor(function () {
return rows !== undefined;
});
});

View File

@@ -43,17 +43,17 @@ define([
mockRelationships,
model = testModels[id];
mockDomainObject.getId.andReturn(id);
mockDomainObject.getModel.andReturn(model);
mockDomainObject.getId.and.returnValue(id);
mockDomainObject.getModel.and.returnValue(model);
mockDomainObject.hasCapability.andCallFake(function (c) {
mockDomainObject.hasCapability.and.callFake(function (c) {
return c === 'composition' ? !!model.composition :
c === 'relationship' ? !!model.relationships :
false;
});
if (!!model.composition) {
mockDomainObject.useCapability.andCallFake(function (c) {
mockDomainObject.useCapability.and.callFake(function (c) {
return c === 'composition' &&
Promise.resolve(model.composition.map(function (cid) {
return mockDomainObjects[cid];
@@ -66,13 +66,13 @@ define([
'relationship',
['getRelatedObjects']
);
mockRelationships.getRelatedObjects.andCallFake(function (k) {
mockRelationships.getRelatedObjects.and.callFake(function (k) {
var ids = model.relationships[k] || [];
return Promise.resolve(ids.map(function (objId) {
return mockDomainObjects[objId];
}));
});
mockDomainObject.getCapability.andCallFake(function (c) {
mockDomainObject.getCapability.and.callFake(function (c) {
return c === 'relationship' && mockRelationships;
});
}
@@ -105,12 +105,9 @@ define([
}
beforeEach(function () {
traverser.buildObjectList().then(function (objectList) {
return traverser.buildObjectList().then(function (objectList) {
objects = objectList;
});
waitsFor(function () {
return objects !== undefined;
});
});
it("includes the object originally passed in", function () {

View File

@@ -42,12 +42,12 @@ define(
'domainObject',
['useCapability', 'hasCapability']
);
mockTimespan.getStart.andReturn(testTimes.start);
mockTimespan.getEnd.andReturn(testTimes.end);
mockDomainObject.useCapability.andCallFake(function (c) {
mockTimespan.getStart.and.returnValue(testTimes.start);
mockTimespan.getEnd.and.returnValue(testTimes.end);
mockDomainObject.useCapability.and.callFake(function (c) {
return c === 'timespan' && Promise.resolve(mockTimespan);
});
mockDomainObject.hasCapability.andCallFake(function (c) {
mockDomainObject.hasCapability.and.callFake(function (c) {
return c === 'timespan';
});
});
@@ -71,12 +71,9 @@ define(
beforeEach(function () {
value = undefined;
testFormatter = new TimelineFormatter();
column.value(mockDomainObject).then(function (v) {
return column.value(mockDomainObject).then(function (v) {
value = v;
});
waitsFor(function () {
return value !== undefined;
});
});
it("returns a formatted " + bound + " time", function () {

View File

@@ -44,8 +44,8 @@ define(
['getModel', 'getCapability']
);
mockQ.when.andCallFake(asPromise);
mockDomainObject.getModel.andReturn({
mockQ.when.and.callFake(asPromise);
mockDomainObject.getModel.and.returnValue({
start: {
timestamp: 42000,
epoch: "TEST"

View File

@@ -47,7 +47,7 @@ define(
// not intended usage.)
mutatorModel = JSON.parse(JSON.stringify(testModel));
mockMutation = jasmine.createSpyObj("mutation", ["mutate"]);
mockMutation.mutate.andCallFake(function (mutator) {
mockMutation.mutate.and.callFake(function (mutator) {
mutator(mutatorModel);
});
timespan = new ActivityTimespan(testModel, mockMutation);

View File

@@ -42,7 +42,7 @@ define(
}
};
mockDomainObject.getModel.andReturn(testModel);
mockDomainObject.getModel.and.returnValue(testModel);
capability = new CostCapability(mockDomainObject);
});

View File

@@ -37,11 +37,11 @@ define(
['getPointCount', 'getDomainValue', 'getRangeValue']
);
mockGraph.getPointCount.andReturn(points.length * 2);
mockGraph.getDomainValue.andCallFake(function (i) {
mockGraph.getPointCount.and.returnValue(points.length * 2);
mockGraph.getDomainValue.and.callFake(function (i) {
return Math.floor(i / 2) * 100 + 25;
});
mockGraph.getRangeValue.andCallFake(function (i) {
mockGraph.getRangeValue.and.callFake(function (i) {
return points[Math.floor(i / 2) + i % 2];
});

View File

@@ -53,8 +53,8 @@ define(
}
};
mockQ.when.andCallFake(asPromise);
mockDomainObject.getModel.andReturn(testModel);
mockQ.when.and.callFake(asPromise);
mockDomainObject.getModel.and.returnValue(testModel);
capability = new GraphCapability(
mockQ,
@@ -82,7 +82,7 @@ define(
it("provides one graph per resource type", function () {
var mockCallback = jasmine.createSpy('callback');
mockDomainObject.useCapability.andReturn(asPromise([
mockDomainObject.useCapability.and.returnValue(asPromise([
{ key: "abc", start: 0, end: 15 },
{ key: "abc", start: 0, end: 15 },
{ key: "def", start: 4, end: 15 },
@@ -103,7 +103,7 @@ define(
testModel.capacity = 1000;
testModel.startingSOC = 100;
testModel.type = "timeline";
mockDomainObject.useCapability.andReturn(asPromise([
mockDomainObject.useCapability.and.returnValue(asPromise([
{ key: "power", start: 0, end: 15 }
]));
capability.invoke().then(mockCallback);

View File

@@ -64,8 +64,8 @@ define(
['getEnd']
);
mockQ.when.andCallFake(asPromise);
mockQ.all.andCallFake(function (values) {
mockQ.when.and.callFake(asPromise);
mockQ.all.and.callFake(function (values) {
var result = [];
function addResult(v) {
result.push(v);
@@ -76,7 +76,7 @@ define(
values.forEach(promiseResult);
return asPromise(result);
});
mockDomainObject.getModel.andReturn({
mockDomainObject.getModel.and.returnValue({
start: {
timestamp: 42000,
epoch: "TEST"
@@ -85,17 +85,17 @@ define(
timestamp: 12321
}
});
mockDomainObject.useCapability.andCallFake(function (c) {
mockDomainObject.useCapability.and.callFake(function (c) {
if (c === 'composition') {
return asPromise([mockChildA, mockChildB]);
}
});
mockChildA.hasCapability.andReturn(true);
mockChildB.hasCapability.andReturn(true);
mockChildA.useCapability.andCallFake(function (c) {
mockChildA.hasCapability.and.returnValue(true);
mockChildB.hasCapability.and.returnValue(true);
mockChildA.useCapability.and.callFake(function (c) {
return c === 'timespan' && mockTimespanA;
});
mockChildB.useCapability.andCallFake(function (c) {
mockChildB.useCapability.and.callFake(function (c) {
return c === 'timespan' && mockTimespanB;
});
@@ -129,7 +129,7 @@ define(
getEpoch: jasmine.any(Function)
});
// Finally, verify that getEnd recurses
mockCallback.mostRecentCall.args[0].getEnd();
mockCallback.calls.mostRecent().args[0].getEnd();
expect(mockTimespanA.getEnd).toHaveBeenCalled();
expect(mockTimespanB.getEnd).toHaveBeenCalled();
});

View File

@@ -36,7 +36,7 @@ define(
'timespan-' + end,
['getEnd']
);
mockTimespan.getEnd.andReturn(end);
mockTimespan.getEnd.and.returnValue(end);
return mockTimespan;
}
@@ -53,7 +53,7 @@ define(
mockMutation = jasmine.createSpyObj("mutation", ["mutate"]);
mockTimespans = [44000, 65000, 1100].map(makeMockTimespan);
mockMutation.mutate.andCallFake(function (mutator) {
mockMutation.mutate.and.callFake(function (mutator) {
mutator(mutationModel);
});

View File

@@ -108,13 +108,13 @@ define(
relationship: mockRelationship
};
mockQ.when.andCallFake(asPromise);
mockQ.all.andCallFake(allPromises);
mockDomainObject.getModel.andReturn(testModel);
mockDomainObject.getCapability.andCallFake(function (c) {
mockQ.when.and.callFake(asPromise);
mockQ.all.and.callFake(allPromises);
mockDomainObject.getModel.and.returnValue(testModel);
mockDomainObject.getCapability.and.callFake(function (c) {
return testCapabilities[c];
});
mockDomainObject.useCapability.andCallFake(function (c) {
mockDomainObject.useCapability.and.callFake(function (c) {
return testCapabilities[c] && testCapabilities[c].invoke();
});
@@ -142,7 +142,7 @@ define(
});
it("accumulates resources from composition", function () {
mockComposition.invoke.andReturn(asPromise([
mockComposition.invoke.and.returnValue(asPromise([
fakeDomainObject(['abc', 'def']),
fakeDomainObject(['def', 'xyz']),
fakeDomainObject(['abc', 'xyz'])
@@ -155,7 +155,7 @@ define(
});
it("accumulates utilizations from composition", function () {
mockComposition.invoke.andReturn(asPromise([
mockComposition.invoke.and.returnValue(asPromise([
fakeDomainObject(['abc', 'def'], 10, 100),
fakeDomainObject(['def', 'xyz'], 50, 90)
]));
@@ -179,16 +179,16 @@ define(
'timespanCapability',
['invoke']
);
mockComposition.invoke.andReturn(asPromise([]));
mockRelationship.getRelatedObjects.andReturn(asPromise([
mockComposition.invoke.and.returnValue(asPromise([]));
mockRelationship.getRelatedObjects.and.returnValue(asPromise([
fakeDomainObject([], 0, 0, { abc: 5, xyz: 15 })
]));
testCapabilities.timespan = mockTimespanCapability;
mockTimespanCapability.invoke.andReturn(asPromise(mockTimespan));
mockTimespan.getStart.andReturn(42);
mockTimespan.getEnd.andReturn(12321);
mockTimespan.getEpoch.andReturn("TEST");
mockTimespanCapability.invoke.and.returnValue(asPromise(mockTimespan));
mockTimespan.getStart.and.returnValue(42);
mockTimespan.getEnd.and.returnValue(12321);
mockTimespan.getEpoch.and.returnValue("TEST");
capability.invoke().then(mockCallback);
@@ -199,8 +199,8 @@ define(
});
it("provides resource keys from related objects", function () {
mockComposition.invoke.andReturn(asPromise([]));
mockRelationship.getRelatedObjects.andReturn(asPromise([
mockComposition.invoke.and.returnValue(asPromise([]));
mockRelationship.getRelatedObjects.and.returnValue(asPromise([
fakeDomainObject([], 0, 0, { abc: 5, xyz: 15 })
]));

View File

@@ -45,7 +45,7 @@ define(
"fillRect"
]
);
mockCanvas.getContext.andReturn(mock2d);
mockCanvas.getContext.and.returnValue(mock2d);
chart = new Canvas2DChart(mockCanvas);
});
@@ -60,7 +60,7 @@ define(
});
it("does not construct if 2D is unavailable", function () {
mockCanvas.getContext.andReturn(undefined);
mockCanvas.getContext.and.returnValue(undefined);
expect(function () {
return new Canvas2DChart(mockCanvas);
}).toThrow();
@@ -77,7 +77,7 @@ define(
testPoints = 2;
chart.drawLine(testBuffer, testColor, testPoints);
expect(mock2d.beginPath).toHaveBeenCalled();
expect(mock2d.lineTo.calls.length).toEqual(1);
expect(mock2d.lineTo.calls.count()).toEqual(1);
expect(mock2d.stroke).toHaveBeenCalled();
});

View File

@@ -68,11 +68,11 @@ define(
// Echo back names for uniform locations, so we can
// test which of these are set for certain operations.
mockGL.getUniformLocation.andCallFake(function (a, name) {
mockGL.getUniformLocation.and.callFake(function (a, name) {
return name;
});
mockCanvas.getContext.andReturn(mockGL);
mockCanvas.getContext.and.returnValue(mockGL);
glChart = new GLChart(mockCanvas);
});
@@ -83,7 +83,7 @@ define(
});
it("does not construct if WebGL is unavailable", function () {
mockCanvas.getContext.andReturn(undefined);
mockCanvas.getContext.and.returnValue(undefined);
expect(function () {
return new GLChart(mockCanvas);
}).toThrow();

View File

@@ -91,15 +91,15 @@ define(
// Echo back names for uniform locations, so we can
// test which of these are set for certain operations.
mockGL.getUniformLocation.andCallFake(function (a, name) {
mockGL.getUniformLocation.and.callFake(function (a, name) {
return name;
});
mockElement.find.andReturn([mockCanvas]);
mockCanvas.getContext.andCallFake(function (type) {
mockElement.find.and.returnValue([mockCanvas]);
mockCanvas.getContext.and.callFake(function (type) {
return { webgl: mockGL, '2d': mockC2d }[type];
});
mockInterval.andReturn(mockPromise);
mockInterval.and.returnValue(mockPromise);
mctChart = new MCTTimelineChart(mockInterval, mockLog);
});
@@ -121,15 +121,15 @@ define(
it("issues one draw call per line", function () {
mctChart.link(mockScope, mockElement);
mockScope.$watchCollection.mostRecentCall.args[1]({
mockScope.$watchCollection.calls.mostRecent().args[1]({
lines: [{}, {}, {}]
});
expect(mockGL.drawArrays.calls.length).toEqual(3);
expect(mockGL.drawArrays.calls.count()).toEqual(3);
});
it("issues one draw call per box", function () {
mctChart.link(mockScope, mockElement);
mockScope.$watchCollection.mostRecentCall.args[1]({
mockScope.$watchCollection.calls.mostRecent().args[1]({
boxes: [
{ start: [0, 0], end: [1, 1] },
{ start: [0, 0], end: [1, 1] },
@@ -137,12 +137,12 @@ define(
{ start: [0, 0], end: [1, 1] }
]
});
expect(mockGL.drawArrays.calls.length).toEqual(4);
expect(mockGL.drawArrays.calls.count()).toEqual(4);
});
it("does not fail if no draw object is in scope", function () {
mctChart.link(mockScope, mockElement);
expect(mockScope.$watchCollection.mostRecentCall.args[1])
expect(mockScope.$watchCollection.calls.mostRecent().args[1])
.not.toThrow();
});
@@ -164,14 +164,14 @@ define(
mockCanvas.offsetWidth = 150;
mockCanvas.height = 200;
mockCanvas.offsetHeight = 200;
mockInterval.mostRecentCall.args[0]();
mockInterval.calls.mostRecent().args[0]();
// Use clear as an indication that drawing has occurred
expect(mockGL.clear).toHaveBeenCalled();
});
it("warns if no WebGL context is available", function () {
mockCanvas.getContext.andReturn(undefined);
mockCanvas.getContext.and.returnValue(undefined);
mctChart.link(mockScope, mockElement);
expect(mockLog.warn).toHaveBeenCalled();
});
@@ -181,7 +181,7 @@ define(
expect(mockCanvas.addEventListener)
.toHaveBeenCalledWith("webglcontextlost", jasmine.any(Function));
expect(mockCanvas.getContext).not.toHaveBeenCalledWith('2d');
mockCanvas.addEventListener.mostRecentCall.args[1]();
mockCanvas.addEventListener.calls.mostRecent().args[1]();
expect(mockCanvas.getContext).toHaveBeenCalledWith('2d');
});
@@ -205,7 +205,7 @@ define(
expect(mockInterval.cancel).not.toHaveBeenCalled();
// Broadcast a $destroy
mockScope.$on.mostRecentCall.args[1]();
mockScope.$on.calls.mostRecent().args[1]();
// Should have stopped the interval
expect(mockInterval.cancel).toHaveBeenCalledWith(mockPromise);

View File

@@ -69,7 +69,7 @@ define(
}
function fireWatch(expr, value) {
mockScope.$watch.calls.forEach(function (call) {
mockScope.$watch.calls.all().forEach(function (call) {
if (call.args[0] === expr) {
call.args[1](value);
}
@@ -114,23 +114,23 @@ define(
mockScope.domainObject = mockDomainObject;
mockScope.configuration = testConfiguration;
mockQ.when.andCallFake(asPromise);
mockQ.all.andCallFake(allPromises);
mockA.getId.andReturn('a');
mockA.getModel.andReturn(testModels.a);
mockB.getId.andReturn('b');
mockB.getModel.andReturn(testModels.b);
mockA.useCapability.andCallFake(useCapability);
mockB.useCapability.andCallFake(useCapability);
mockA.hasCapability.andReturn(true);
mockB.hasCapability.andReturn(true);
mockA.getCapability.andCallFake(getCapability);
mockB.getCapability.andCallFake(getCapability);
mockSpan.getStart.andReturn(42);
mockSpan.getEnd.andReturn(12321);
mockUtilization.resources.andReturn(['abc', 'xyz']);
mockUtilization.utilization.andReturn(mockPromise);
mockLoader.load.andCallFake(function () {
mockQ.when.and.callFake(asPromise);
mockQ.all.and.callFake(allPromises);
mockA.getId.and.returnValue('a');
mockA.getModel.and.returnValue(testModels.a);
mockB.getId.and.returnValue('b');
mockB.getModel.and.returnValue(testModels.b);
mockA.useCapability.and.callFake(useCapability);
mockB.useCapability.and.callFake(useCapability);
mockA.hasCapability.and.returnValue(true);
mockB.hasCapability.and.returnValue(true);
mockA.getCapability.and.callFake(getCapability);
mockB.getCapability.and.callFake(getCapability);
mockSpan.getStart.and.returnValue(42);
mockSpan.getEnd.and.returnValue(12321);
mockUtilization.resources.and.returnValue(['abc', 'xyz']);
mockUtilization.utilization.and.returnValue(mockPromise);
mockLoader.load.and.callFake(function () {
return asPromise(subgraph(mockA, {
a: mockA,
b: mockB
@@ -160,7 +160,7 @@ define(
var fnWatchCall;
// Find the $watch that was given a function
mockScope.$watch.calls.forEach(function (call) {
mockScope.$watch.calls.all().forEach(function (call) {
if (typeof call.args[0] === 'function') {
// white-box: we know the first call is
// the one we're looking for
@@ -197,17 +197,17 @@ define(
expect(controller.graphs().length).toEqual(0);
// Execute the watch function for graph state
tmp = mockScope.$watch.calls[3].args[0]();
tmp = mockScope.$watch.calls.all()[3].args[0]();
// Change graph state
testConfiguration.graph = { a: true, b: true };
// Verify that this would have triggered a watch
expect(mockScope.$watch.calls[3].args[0]())
expect(mockScope.$watch.calls.all()[3].args[0]())
.not.toEqual(tmp);
// Run the function the watch would have triggered
mockScope.$watch.calls[3].args[1]();
mockScope.$watch.calls.all()[3].args[1]();
// Should have some graphs now
expect(controller.graphs().length).toEqual(2);

View File

@@ -40,9 +40,9 @@ define(
// Verify two-way binding support
it("updates model on changes to entry fields", function () {
// Make sure we're looking at the right watch
expect(mockScope.$watchCollection.calls[0].args[0])
expect(mockScope.$watchCollection.calls.all()[0].args[0])
.toEqual("datetime");
mockScope.$watchCollection.calls[0].args[1]({
mockScope.$watchCollection.calls.all()[0].args[1]({
days: 4,
hours: 12,
minutes: 30,
@@ -55,12 +55,12 @@ define(
it("updates form when model changes", function () {
// Make sure we're looking at the right watch
expect(mockScope.$watchCollection.calls[1].args[0])
expect(mockScope.$watchCollection.calls.all()[1].args[0])
.toEqual(jasmine.any(Function));
// ...and that it's really looking at the field in ngModel
expect(mockScope.$watchCollection.calls[1].args[0]())
expect(mockScope.$watchCollection.calls.all()[1].args[0]())
.toBe(mockScope.ngModel.testField);
mockScope.$watchCollection.calls[1].args[1]({
mockScope.$watchCollection.calls.all()[1].args[1]({
timestamp: ((((((4 * 24) + 12) * 60) + 30) * 60) + 11) * 1000
});
expect(mockScope.datetime).toEqual({

View File

@@ -57,11 +57,11 @@ define(
testScroll = { x: 0, width: 2000 };
mockToPixels = jasmine.createSpy('toPixels');
mockTimespan.getStart.andReturn(100);
mockTimespan.getDuration.andReturn(50);
mockTimespan.getEnd.andReturn(150);
mockTimespan.getStart.and.returnValue(100);
mockTimespan.getDuration.and.returnValue(50);
mockTimespan.getEnd.and.returnValue(150);
mockToPixels.andCallFake(function (t) {
mockToPixels.and.callFake(function (t) {
return t * 10;
});

View File

@@ -57,7 +57,7 @@ define(
mockGraphB = jasmine.createSpyObj('graph-b', ['setBounds']);
// Supply new parameters
mockScope.$watchCollection.mostRecentCall.args[1]({
mockScope.$watchCollection.calls.mostRecent().args[1]({
graphs: [mockGraphA, mockGraphB],
origin: 9,
duration: 144
@@ -71,8 +71,8 @@ define(
it("provides labels for graphs", function () {
var mockGraph = jasmine.createSpyObj('graph', ['minimum', 'maximum']);
mockGraph.minimum.andReturn(12.3412121);
mockGraph.maximum.andReturn(88.7555555);
mockGraph.minimum.and.returnValue(12.3412121);
mockGraph.maximum.and.returnValue(88.7555555);
mockGraph.key = "def";
expect(controller.label(mockGraph)).toEqual({

View File

@@ -46,10 +46,10 @@ define([
]);
mockScope.scroll = { x: 10, width: 1000 };
spyOn(mockmct.time, "on").andCallThrough();
spyOn(mockmct.time, "off").andCallThrough();
spyOn(mockTimerService, "on").andCallThrough();
spyOn(mockTimerService, "off").andCallThrough();
spyOn(mockmct.time, "on").and.callThrough();
spyOn(mockmct.time, "off").and.callThrough();
spyOn(mockTimerService, "on").and.callThrough();
spyOn(mockTimerService, "off").and.callThrough();
controller = new TimelineTOIController(
mockmct,
@@ -96,11 +96,11 @@ define([
beforeEach(function () {
testNow = 333221;
mockScope.zoomController.toPixels
.andCallFake(function (millis) {
.and.callFake(function (millis) {
return millis * 2;
});
mockTimerService.emit('change', mockTimer);
mockTimerService.now.andReturn(testNow);
mockTimerService.now.and.returnValue(testNow);
});
it("reports an x value from the zoomController", function () {
@@ -125,7 +125,7 @@ define([
describe("when follow mode is enabled", function () {
beforeEach(function () {
mockScope.scroll.follow = true;
mockTimerService.now.andReturn(500);
mockTimerService.now.and.returnValue(500);
});
it("zooms on bounds events", function () {

View File

@@ -40,7 +40,7 @@ define(
beforeEach(function () {
mockToMillis = jasmine.createSpy('toMillis');
mockToMillis.andCallFake(function (v) {
mockToMillis.and.callFake(function (v) {
return v * 2 + BILLION;
});
controller = new TimelineTickController();
@@ -69,7 +69,7 @@ define(
it("does rebuild arrays when zoom changes", function () {
var firstValue = controller.labels(800, 300, 100, mockToMillis);
mockToMillis.andCallFake(function (v) {
mockToMillis.and.callFake(function (v) {
return BILLION * 2 + v;
});

View File

@@ -95,24 +95,24 @@ define(
'getDuration'
]);
mockDomainObject.useCapability.andCallFake(function (c) {
mockDomainObject.useCapability.and.callFake(function (c) {
return c === 'timespan' && mockPromise;
});
mockPromise.then.andCallFake(function (callback) {
mockPromise.then.and.callFake(function (callback) {
callback(mockTimespan);
});
mockTimespan.getStart.andReturn(testStart);
mockTimespan.getEnd.andReturn(testEnd);
mockTimespan.getDuration.andReturn(testEnd - testStart);
mockTimespan.getStart.and.returnValue(testStart);
mockTimespan.getEnd.and.returnValue(testEnd);
mockTimespan.getDuration.and.returnValue(testEnd - testStart);
mockScope.scroll = { x: 0, width: 20000 };
mockScope.domainObject = mockDomainObject;
mockScope.$watch.calls.forEach(function (call) {
mockScope.$watch.calls.all().forEach(function (call) {
call.args[1](mockScope[call.args[0]]);
});
mockWindow.requestAnimationFrame.calls.forEach(function (call) {
mockWindow.requestAnimationFrame.calls.all().forEach(function (call) {
call.args[0]();
});
});

View File

@@ -50,9 +50,9 @@ define(
['instanceOf']
);
mockDomainObject.getId.andReturn('test-id');
mockDomainObject.getCapability.andReturn(mockType);
mockType.instanceOf.andCallFake(function (t) {
mockDomainObject.getId.and.returnValue('test-id');
mockDomainObject.getCapability.and.returnValue(mockType);
mockType.instanceOf.and.callFake(function (t) {
return t === testType;
});

View File

@@ -60,10 +60,10 @@ define(
['getId', 'getModel', 'getCapability', 'useCapability']
);
mockDomainObj.getId.andReturn(id);
mockDomainObj.getModel.andReturn({ composition: composition });
mockDomainObj.useCapability.andReturn(asPromise(mockTimespans[id]));
mockDomainObj.getCapability.andCallFake(function (c) {
mockDomainObj.getId.and.returnValue(id);
mockDomainObj.getModel.and.returnValue({ composition: composition });
mockDomainObj.useCapability.and.returnValue(asPromise(mockTimespans[id]));
mockDomainObj.getCapability.and.callFake(function (c) {
return {
mutation: mockMutations[id]
}[c];
@@ -84,9 +84,9 @@ define(
'mutation-' + id,
['mutate']
);
mockTimespans[id].getStart.andReturn(index * 1000);
mockTimespans[id].getDuration.andReturn(4000 + index);
mockTimespans[id].getEnd.andReturn(4000 + index + index * 1000);
mockTimespans[id].getStart.and.returnValue(index * 1000);
mockTimespans[id].getDuration.and.returnValue(4000 + index);
mockTimespans[id].getEnd.and.returnValue(4000 + index + index * 1000);
});
mockLoader = jasmine.createSpyObj('objectLoader', ['load']);
@@ -104,7 +104,7 @@ define(
testConfiguration = {};
mockLoader.load.andReturn(asPromise(
mockLoader.load.and.returnValue(asPromise(
subgraph(mockDomainObject, mockDomainObjects)
));
@@ -193,7 +193,7 @@ define(
it("prevents bulk moves past 0", function () {
// Have a start later; new lowest start is b, at 1000
mockTimespans.a.getStart.andReturn(10000);
mockTimespans.a.getStart.and.returnValue(10000);
handler.move('a', -10000);
// Verify that move was stopped at 0, for b, even though
// move was initiated at a

View File

@@ -42,7 +42,7 @@ define(
);
mockSwimlane.domainObject = mockDomainObject;
mockObjectLoader.load.andReturn(mockPromise);
mockObjectLoader.load.and.returnValue(mockPromise);
populator = new TimelineDragPopulator(mockObjectLoader);
});

View File

@@ -44,19 +44,19 @@ define(
['toMillis', 'toPixels']
);
mockDragHandler.end.andReturn(12321);
mockDragHandler.end.and.returnValue(12321);
// Echo back the value from snapper for most tests
mockSnapHandler.snap.andCallFake(function (ts) {
mockSnapHandler.snap.and.callFake(function (ts) {
return ts;
});
// Double pixels to get millis, for test purposes
mockZoomController.toMillis.andCallFake(function (px) {
mockZoomController.toMillis.and.callFake(function (px) {
return px * 2;
});
mockZoomController.toPixels.andCallFake(function (ms) {
mockZoomController.toPixels.and.callFake(function (ms) {
return ms / 2;
});
@@ -88,7 +88,7 @@ define(
});
it("snaps drags to other end points", function () {
mockSnapHandler.snap.andReturn(42);
mockSnapHandler.snap.and.returnValue(42);
handle.begin();
handle.drag(-10, mockZoomController);
// Should have used snap-to timestamp

View File

@@ -44,21 +44,21 @@ define(
['toMillis', 'toPixels']
);
mockDragHandler.start.andReturn(12321);
mockDragHandler.duration.andReturn(4200);
mockDragHandler.end.andReturn(12321 + 4200);
mockDragHandler.start.and.returnValue(12321);
mockDragHandler.duration.and.returnValue(4200);
mockDragHandler.end.and.returnValue(12321 + 4200);
// Echo back the value from snapper for most tests
mockSnapHandler.snap.andCallFake(function (ts) {
mockSnapHandler.snap.and.callFake(function (ts) {
return ts;
});
// Double pixels to get millis, for test purposes
mockZoomController.toMillis.andCallFake(function (px) {
mockZoomController.toMillis.and.callFake(function (px) {
return px * 2;
});
mockZoomController.toPixels.andCallFake(function (ms) {
mockZoomController.toPixels.and.callFake(function (ms) {
return ms / 2;
});
@@ -100,8 +100,8 @@ define(
);
// Reflect the change from the drag handler
mockDragHandler.start.andReturn(12521);
mockDragHandler.end.andReturn(12521 + 4200);
mockDragHandler.start.and.returnValue(12521);
mockDragHandler.end.and.returnValue(12521 + 4200);
// ....followed by a +100 ms change.
handle.drag(150, mockZoomController);
@@ -112,7 +112,7 @@ define(
});
it("snaps drags to other end points", function () {
mockSnapHandler.snap.andCallFake(function (ts) {
mockSnapHandler.snap.and.callFake(function (ts) {
return ts + 10;
});
handle.begin();
@@ -129,7 +129,7 @@ define(
handle.begin();
expect(mockSnapHandler.snap).not.toHaveBeenCalled();
handle.drag(100, mockZoomController);
expect(mockSnapHandler.snap.calls.length).toEqual(2);
expect(mockSnapHandler.snap.calls.count()).toEqual(2);
});
it("chooses the closest snap-to location", function () {
@@ -139,7 +139,7 @@ define(
// regardless of whether it is the start/end (which
// will vary based on the initial state of this toggle.)
var toggle = false;
mockSnapHandler.snap.andCallFake(function (ts) {
mockSnapHandler.snap.and.callFake(function (ts) {
toggle = !toggle;
return ts + (toggle ? -5 : 10);
});
@@ -151,8 +151,8 @@ define(
);
// Reflect the change from the drag handler
mockDragHandler.start.andReturn(12521 - 5);
mockDragHandler.end.andReturn(12521 + 4200 - 5);
mockDragHandler.start.and.returnValue(12521 - 5);
mockDragHandler.end.and.returnValue(12521 + 4200 - 5);
toggle = true; // Change going-in state
handle.drag(300, mockZoomController);

View File

@@ -37,11 +37,11 @@ define(
['start', 'end', 'ids']
);
mockDragHandler.ids.andReturn(['a', 'b', 'c', 'd']);
mockDragHandler.start.andCallFake(function (id) {
mockDragHandler.ids.and.returnValue(['a', 'b', 'c', 'd']);
mockDragHandler.start.and.callFake(function (id) {
return starts[id];
});
mockDragHandler.end.andCallFake(function (id) {
mockDragHandler.end.and.callFake(function (id) {
return ends[id];
});

View File

@@ -44,19 +44,19 @@ define(
['toMillis', 'toPixels']
);
mockDragHandler.start.andReturn(12321);
mockDragHandler.start.and.returnValue(12321);
// Echo back the value from snapper for most tests
mockSnapHandler.snap.andCallFake(function (ts) {
mockSnapHandler.snap.and.callFake(function (ts) {
return ts;
});
// Double pixels to get millis, for test purposes
mockZoomController.toMillis.andCallFake(function (px) {
mockZoomController.toMillis.and.callFake(function (px) {
return px * 2;
});
mockZoomController.toPixels.andCallFake(function (ms) {
mockZoomController.toPixels.and.callFake(function (ms) {
return ms / 2;
});
@@ -87,7 +87,7 @@ define(
});
it("snaps drags to other end points", function () {
mockSnapHandler.snap.andReturn(42);
mockSnapHandler.snap.and.returnValue(42);
handle.begin();
handle.drag(-10, mockZoomController);
// Should have used snap-to timestamp

View File

@@ -64,15 +64,15 @@ define(
'graph-' + k,
['getPointCount', 'getDomainValue', 'getRangeValue']
);
mockSwimlane.graph.andReturn(true);
mockSwimlane.graph.and.returnValue(true);
mockSwimlane.domainObject = jasmine.createSpyObj(
'domainObject-' + k,
['getCapability', 'hasCapability', 'useCapability', 'getId']
);
mockSwimlane.color.andReturn('#' + k);
mockSwimlane.color.and.returnValue('#' + k);
// Provide just enough information about graphs to support
// determination of which graphs to show
mockSwimlane.domainObject.useCapability.andCallFake(function () {
mockSwimlane.domainObject.useCapability.and.callFake(function () {
var obj = {};
testResources[k].forEach(function (r) {
obj[r] = mockGraph;
@@ -80,16 +80,16 @@ define(
return asPromise(obj);
});
mockSwimlane.domainObject.hasCapability
.andReturn(true);
.and.returnValue(true);
mockSwimlane.domainObject.getId
.andReturn(k);
mockGraph.getPointCount.andReturn(0);
.and.returnValue(k);
mockGraph.getPointCount.and.returnValue(0);
return mockSwimlane;
});
mockQ.when.andCallFake(asPromise);
mockQ.all.andCallFake(allPromises);
mockQ.when.and.callFake(asPromise);
mockQ.all.and.callFake(allPromises);
populator = new TimelineGraphPopulator(mockQ);
});
@@ -105,7 +105,7 @@ define(
});
it("does not include graphs based on swimlane configuration", function () {
mockSwimlanes[2].graph.andReturn(false);
mockSwimlanes[2].graph.and.returnValue(false);
populator.populate(mockSwimlanes);
// Only two unique swimlanes in the other two
expect(populator.get().length).toEqual(2);
@@ -140,7 +140,7 @@ define(
populator.populate(mockSwimlanes);
initialValue = populator.get();
// Change resource graph inclusion...
mockSwimlanes[1].graph.andReturn(false);
mockSwimlanes[1].graph.and.returnValue(false);
populator.populate(mockSwimlanes);
// Now we should get different graphs
expect(populator.get()).not.toBe(initialValue);

View File

@@ -59,10 +59,10 @@ define(
'domainObject-' + k,
['getCapability', 'useCapability']
);
mockDomainObjects[k].useCapability.andReturn(asPromise({
mockDomainObjects[k].useCapability.and.returnValue(asPromise({
testResource: mockGraph
}));
mockGraph.getPointCount.andReturn(i + 2);
mockGraph.getPointCount.and.returnValue(i + 2);
mockGraph.testField = k;
mockGraph.testIndex = i;
@@ -75,7 +75,7 @@ define(
['render', 'decode']
);
mockRenderer.render.andCallFake(function (utilization) {
mockRenderer.render.and.callFake(function (utilization) {
var result = [];
while (result.length < (utilization.testIndex + 2) * 2) {
result.push(Math.floor(result.length / 2));
@@ -88,7 +88,7 @@ define(
return result;
});
mockRenderer.decode.andCallFake(function (color) {
mockRenderer.decode.and.callFake(function (color) {
return testColors[color];
});
@@ -114,7 +114,7 @@ define(
expect(graph.drawingObject.lines).toEqual([
{
color: testColors.a,
buffer: [0, 0, 1, 0],
buffer: [0, 0, 1, -0],
points: 2
},
{
@@ -138,7 +138,7 @@ define(
it("provides a minimum/maximum even with no data", function () {
mockGraphs.forEach(function (mockGraph) {
mockGraph.getPointCount.andReturn(0);
mockGraph.getPointCount.and.returnValue(0);
});
// Create a graph of these utilizations

View File

@@ -49,12 +49,12 @@ define(
'action-' + type,
['perform', 'getMetadata']
);
mockAction.getMetadata.andReturn({ type: type });
mockAction.getMetadata.and.returnValue({ type: type });
return mockAction;
});
mockDomainObject.getCapability.andReturn(mockActionCapability);
mockActionCapability.getActions.andReturn(mockActions);
mockDomainObject.getCapability.and.returnValue(mockActionCapability);
mockActionCapability.getActions.and.returnValue(mockActions);
proxy = new TimelineProxy(mockDomainObject, mockSelection);
});
@@ -90,10 +90,10 @@ define(
);
// Set up mocks
mockSelection.get.andReturn({ domainObject: mockOtherObject });
mockOtherObject.getCapability.andReturn(mockOtherAction);
mockOtherAction.getActions.andReturn([mockAction]);
mockAction.getMetadata.andReturn({ type: 'z' });
mockSelection.get.and.returnValue({ domainObject: mockOtherObject });
mockOtherObject.getCapability.and.returnValue(mockOtherAction);
mockOtherAction.getActions.and.returnValue([mockAction]);
mockAction.getMetadata.and.returnValue({ type: 'z' });
// Invoke add method; should create with selected object
proxy.add('z');

View File

@@ -56,13 +56,13 @@ define(
);
mockPromise = jasmine.createSpyObj('promise', ['then']);
mockSwimlane.domainObject.getCapability.andCallFake(function (c) {
mockSwimlane.domainObject.getCapability.and.callFake(function (c) {
return mockCapabilities[c];
});
mockSwimlane.domainObject.getModel.andReturn(testModel);
mockSwimlane.domainObject.getModel.and.returnValue(testModel);
mockCapabilities.type.instanceOf.andReturn(true);
mockCapabilities.mutation.mutate.andReturn(mockPromise);
mockCapabilities.type.instanceOf.and.returnValue(true);
mockCapabilities.mutation.mutate.and.returnValue(mockPromise);
decorator = new TimelineSwimlaneDecorator(
mockSwimlane,
@@ -109,7 +109,7 @@ define(
decorator.modes(['abc', 'xyz']);
expect(mockCapabilities.mutation.mutate)
.toHaveBeenCalledWith(jasmine.any(Function));
mockCapabilities.mutation.mutate.mostRecentCall.args[0](testModel);
mockCapabilities.mutation.mutate.calls.mostRecent().args[0](testModel);
expect(testModel.relationships.modes).toEqual(['abc', 'xyz']);
});
@@ -117,7 +117,7 @@ define(
decorator.link("http://www.noaa.gov");
expect(mockCapabilities.mutation.mutate)
.toHaveBeenCalledWith(jasmine.any(Function));
mockCapabilities.mutation.mutate.mostRecentCall.args[0](testModel);
mockCapabilities.mutation.mutate.calls.mostRecent().args[0](testModel);
expect(testModel.link).toEqual("http://www.noaa.gov");
});
@@ -133,7 +133,7 @@ define(
testModel.relationships = { modes: testModes };
decorator.modes(testModes2);
expect(mockCapabilities.mutation.mutate).toHaveBeenCalled();
mockCapabilities.mutation.mutate.mostRecentCall.args[0](testModel);
mockCapabilities.mutation.mutate.calls.mostRecent().args[0](testModel);
expect(testModel.relationships.modes).toBe(testModes2);
});
@@ -151,7 +151,7 @@ define(
['perform']
);
mockChild.getCapability.andCallFake(function (c) {
mockChild.getCapability.and.callFake(function (c) {
return c === 'action' ? mockAction : undefined;
});
@@ -173,7 +173,7 @@ define(
it("allows checking for swimlane selection state", function () {
expect(decorator.selected()).toBeFalsy();
mockSelection.get.andReturn(decorator);
mockSelection.get.and.returnValue(decorator);
expect(decorator.selected()).toBeTruthy();
});

View File

@@ -65,8 +65,8 @@ define(
);
mockAction = jasmine.createSpyObj('action', ['perform']);
mockAction.perform.andReturn(mockPromise);
mockPromise.then.andCallFake(function (callback) {
mockAction.perform.and.returnValue(mockPromise);
mockPromise.then.and.callFake(function (callback) {
callback();
});
@@ -77,48 +77,48 @@ define(
mockActionCapability = jasmine.createSpyObj("action", ["perform", "getActions"]);
mockContext = jasmine.createSpyObj('context', ['getParent']);
mockActionCapability.getActions.andReturn([mockAction]);
mockSwimlane.parent.domainObject.getId.andReturn('a');
mockSwimlane.domainObject.getId.andReturn('b');
mockSwimlane.children[0].domainObject.getId.andReturn('c');
mockOtherObject.getId.andReturn('d');
mockActionCapability.getActions.and.returnValue([mockAction]);
mockSwimlane.parent.domainObject.getId.and.returnValue('a');
mockSwimlane.domainObject.getId.and.returnValue('b');
mockSwimlane.children[0].domainObject.getId.and.returnValue('c');
mockOtherObject.getId.and.returnValue('d');
mockSwimlane.domainObject.getCapability.andCallFake(function (c) {
mockSwimlane.domainObject.getCapability.and.callFake(function (c) {
return {
action: mockActionCapability,
editor: mockEditorCapability
}[c];
});
mockSwimlane.parent.domainObject.getCapability.andCallFake(function (c) {
mockSwimlane.parent.domainObject.getCapability.and.callFake(function (c) {
return {
action: mockActionCapability,
editor: mockEditorCapability
}[c];
});
mockOtherObject.getCapability.andCallFake(function (c) {
mockOtherObject.getCapability.and.callFake(function (c) {
return {
action: mockActionCapability,
context: mockContext,
editor: mockEditorCapability
}[c];
});
mockContext.getParent.andReturn(mockOtherObject);
mockContext.getParent.and.returnValue(mockOtherObject);
mockSwimlane.domainObject.hasCapability.andReturn(true);
mockSwimlane.domainObject.hasCapability.and.returnValue(true);
handler = new TimelineSwimlaneDropHandler(mockSwimlane);
});
it("disallows drop outside of edit mode", function () {
mockEditorCapability.inEditContext.andReturn(true);
mockEditorCapability.inEditContext.and.returnValue(true);
// Verify precondition
expect(handler.allowDropIn('d', mockSwimlane.domainObject))
.toBeTruthy();
expect(handler.allowDropAfter('d', mockSwimlane.domainObject))
.toBeTruthy();
// Act as if we're not in edit mode
mockEditorCapability.inEditContext.andReturn(false);
mockEditorCapability.inEditContext.and.returnValue(false);
// Now, they should be disallowed
expect(handler.allowDropIn('d', mockSwimlane.domainObject))
.toBeFalsy();
@@ -149,48 +149,48 @@ define(
it("inserts into when highlighted", function () {
var testModel = { composition: ['c'] };
mockSwimlane.highlight.andReturn(true);
mockSwimlane.highlight.and.returnValue(true);
handler.drop('d', mockOtherObject);
// Should have mutated
expect(mockSwimlane.domainObject.useCapability)
.toHaveBeenCalledWith("mutation", jasmine.any(Function));
// Run the mutator
mockSwimlane.domainObject.useCapability.mostRecentCall
mockSwimlane.domainObject.useCapability.calls.mostRecent()
.args[1](testModel);
expect(testModel.composition).toEqual(['c', 'd']);
});
it("inserts after as a peer when highlighted at the bottom", function () {
var testModel = { composition: ['x', 'b', 'y'] };
mockSwimlane.highlightBottom.andReturn(true);
mockSwimlane.highlightBottom.and.returnValue(true);
mockSwimlane.expanded = false;
handler.drop('d', mockOtherObject);
// Should have mutated
expect(mockSwimlane.parent.domainObject.useCapability)
.toHaveBeenCalledWith("mutation", jasmine.any(Function));
// Run the mutator
mockSwimlane.parent.domainObject.useCapability.mostRecentCall
mockSwimlane.parent.domainObject.useCapability.calls.mostRecent()
.args[1](testModel);
expect(testModel.composition).toEqual(['x', 'b', 'd', 'y']);
});
it("inserts into when highlighted at the bottom and expanded", function () {
var testModel = { composition: ['c'] };
mockSwimlane.highlightBottom.andReturn(true);
mockSwimlane.highlightBottom.and.returnValue(true);
mockSwimlane.expanded = true;
handler.drop('d', mockOtherObject);
// Should have mutated
expect(mockSwimlane.domainObject.useCapability)
.toHaveBeenCalledWith("mutation", jasmine.any(Function));
// Run the mutator
mockSwimlane.domainObject.useCapability.mostRecentCall
mockSwimlane.domainObject.useCapability.calls.mostRecent()
.args[1](testModel);
expect(testModel.composition).toEqual(['d', 'c']);
});
it("inserts after as a peer when highlighted at the bottom and childless", function () {
var testModel = { composition: ['x', 'b', 'y'] };
mockSwimlane.highlightBottom.andReturn(true);
mockSwimlane.highlightBottom.and.returnValue(true);
mockSwimlane.expanded = true;
mockSwimlane.children = [];
handler.drop('d', mockOtherObject);
@@ -198,7 +198,7 @@ define(
expect(mockSwimlane.parent.domainObject.useCapability)
.toHaveBeenCalledWith("mutation", jasmine.any(Function));
// Run the mutator
mockSwimlane.parent.domainObject.useCapability.mostRecentCall
mockSwimlane.parent.domainObject.useCapability.calls.mostRecent()
.args[1](testModel);
expect(testModel.composition).toEqual(['x', 'b', 'd', 'y']);
});
@@ -206,31 +206,28 @@ define(
it("allows reordering within a parent", function () {
var testModel = { composition: ['x', 'b', 'y', 'd'] };
mockSwimlane.highlightBottom.andReturn(true);
mockSwimlane.highlightBottom.and.returnValue(true);
mockSwimlane.expanded = true;
mockSwimlane.children = [];
mockContext.getParent
.andReturn(mockSwimlane.parent.domainObject);
handler.drop('d', mockOtherObject);
mockContext.getParent.and.returnValue(mockSwimlane.parent.domainObject);
waitsFor(function () {
return mockSwimlane.parent.domainObject.useCapability
.calls.length > 0;
});
runs(function () {
mockSwimlane.parent.domainObject.useCapability.mostRecentCall
.args[1](testModel);
return new Promise(function (resolve, reject) {
mockSwimlane.parent.domainObject.useCapability.and.callFake(function (name, callback) {
resolve(callback);
});
handler.drop('d', mockOtherObject);
}).then(function (callback) {
callback(testModel);
expect(testModel.composition).toEqual(['x', 'b', 'd', 'y']);
});
});
it("does not invoke an action when reordering", function () {
mockSwimlane.highlightBottom.andReturn(true);
mockSwimlane.highlightBottom.and.returnValue(true);
mockSwimlane.expanded = true;
mockSwimlane.children = [];
mockContext.getParent
.andReturn(mockSwimlane.parent.domainObject);
.and.returnValue(mockSwimlane.parent.domainObject);
handler.drop('d', mockOtherObject);
expect(mockAction.perform).not.toHaveBeenCalled();
});

View File

@@ -47,9 +47,9 @@ define(
['getId', 'getModel', 'getCapability', 'useCapability']
);
mockDomainObj.getId.andReturn(id);
mockDomainObj.getModel.andReturn({ composition: composition });
mockDomainObj.useCapability.andReturn(asPromise(false));
mockDomainObj.getId.and.returnValue(id);
mockDomainObj.getModel.and.returnValue({ composition: composition });
mockDomainObj.useCapability.and.returnValue(asPromise(false));
return mockDomainObj;
}
@@ -84,7 +84,7 @@ define(
testConfiguration = {};
mockLoader.load.andReturn(asPromise(subgraph(
mockLoader.load.and.returnValue(asPromise(subgraph(
mockDomainObject,
mockDomainObjects
)));
@@ -129,7 +129,7 @@ define(
populator.populate(mockDomainObject);
// Act as if something is already selected
mockSelection.get.andReturn(populator.get()[1]);
mockSelection.get.and.returnValue(populator.get()[1]);
// Verify precondition
expect(mockSelection.select).not.toHaveBeenCalled();
@@ -139,7 +139,7 @@ define(
// Selection should have been preserved
expect(mockSelection.select).toHaveBeenCalled();
expect(mockSelection.select.mostRecentCall.args[0].domainObject)
expect(mockSelection.select.calls.mostRecent().args[0].domainObject)
.toEqual(mockDomainObjects.b);
});

View File

@@ -64,12 +64,12 @@ define(
);
mockActionCapability = jasmine.createSpyObj('action', ['perform']);
mockParentObject.getId.andReturn('test-parent');
mockParentObject.getCapability.andReturn(mockActionCapability);
mockParentObject.useCapability.andReturn(asPromise(mockParentTimespan));
mockParentObject.getModel.andReturn({ name: "Test Parent" });
mockChildObject.getModel.andReturn({ name: "Test Child" });
mockChildObject.useCapability.andReturn(asPromise(mockChildTimespan));
mockParentObject.getId.and.returnValue('test-parent');
mockParentObject.getCapability.and.returnValue(mockActionCapability);
mockParentObject.useCapability.and.returnValue(asPromise(mockParentTimespan));
mockParentObject.getModel.and.returnValue({ name: "Test Parent" });
mockChildObject.getModel.and.returnValue({ name: "Test Child" });
mockChildObject.useCapability.and.returnValue(asPromise(mockChildTimespan));
testConfiguration = { graph: {} };
@@ -149,7 +149,7 @@ define(
});
it("gets colors from the provided assigner", function () {
mockAssigner.get.andReturn("#ABCABC");
mockAssigner.get.and.returnValue("#ABCABC");
expect(parent.color()).toEqual("#ABCABC");
// Verify that id was passed, and no other interactions
expect(mockAssigner.get).toHaveBeenCalledWith('test-parent');
@@ -194,28 +194,28 @@ define(
});
it("detects start/end violations", function () {
mockParentTimespan.getStart.andReturn(42);
mockParentTimespan.getEnd.andReturn(12321);
mockParentTimespan.getStart.and.returnValue(42);
mockParentTimespan.getEnd.and.returnValue(12321);
// First, start with a valid timespan
mockChildTimespan.getStart.andReturn(84);
mockChildTimespan.getEnd.andReturn(100);
mockChildTimespan.getStart.and.returnValue(84);
mockChildTimespan.getEnd.and.returnValue(100);
expect(child.exceeded()).toBeFalsy();
// Start time violation
mockChildTimespan.getStart.andReturn(21);
mockChildTimespan.getStart.and.returnValue(21);
expect(child.exceeded()).toBeTruthy();
// Now both in violation
mockChildTimespan.getEnd.andReturn(20000);
mockChildTimespan.getEnd.and.returnValue(20000);
expect(child.exceeded()).toBeTruthy();
// And just the end
mockChildTimespan.getStart.andReturn(100);
mockChildTimespan.getStart.and.returnValue(100);
expect(child.exceeded()).toBeTruthy();
// Now back to everything's-just-fine
mockChildTimespan.getEnd.andReturn(10000);
mockChildTimespan.getEnd.and.returnValue(10000);
expect(child.exceeded()).toBeFalsy();
});
});

View File

@@ -55,18 +55,18 @@ define(
stopPropagation: jasmine.createSpy()
};
testEvent.dataTransfer.getData.andReturn('abc');
mockDndService.getData.andCallFake(function (key) {
testEvent.dataTransfer.getData.and.returnValue('abc');
mockDndService.getData.and.callFake(function (key) {
return key === SwimlaneDragConstants.TIMELINE_SWIMLANE_DRAG_TYPE ?
mockSwimlane : undefined;
});
mockSwimlane.graph.andReturn(false);
mockSwimlane.graph.and.returnValue(false);
directive = new MCTResourceGraphDrop(mockDndService);
directive.link(mockScope, mockElement, testAttrs);
mockElement.on.calls.forEach(function (call) {
mockElement.on.calls.all().forEach(function (call) {
handlers[call.args[0]] = call.args[1];
});
});
@@ -78,7 +78,7 @@ define(
[false, true].forEach(function (graphing) {
describe("when swimlane graph is " + (graphing ? "" : "not ") + "enabled", function () {
beforeEach(function () {
mockSwimlane.graph.andReturn(graphing);
mockSwimlane.graph.and.returnValue(graphing);
});

View File

@@ -48,7 +48,7 @@ define(
testAttrs = { mctSwimlaneDrag: "someTestExpr" };
// Simulate evaluation of expressions in scope
mockScope.$eval.andCallFake(function (expr) {
mockScope.$eval.and.callFake(function (expr) {
return scopeExprs[expr];
});
@@ -58,7 +58,7 @@ define(
// for testing.
directive.link(mockScope, mockElement, testAttrs);
mockElement.on.calls.forEach(function (call) {
mockElement.on.calls.all().forEach(function (call) {
handlers[call.args[0]] = call.args[1];
});

View File

@@ -64,20 +64,20 @@ define(
["getBoundingClientRect"]
);
mockElement[0].offsetHeight = TEST_HEIGHT;
mockElement[0].getBoundingClientRect.andReturn({ top: TEST_TOP });
mockElement[0].getBoundingClientRect.and.returnValue({ top: TEST_TOP });
// Simulate evaluation of expressions in scope
scopeExprs.mockSwimlane = mockSwimlane;
mockScope.$eval.andCallFake(function (expr) {
mockScope.$eval.and.callFake(function (expr) {
return scopeExprs[expr];
});
mockSwimlane.allowDropIn.andReturn(true);
mockSwimlane.allowDropAfter.andReturn(true);
mockSwimlane.allowDropIn.and.returnValue(true);
mockSwimlane.allowDropAfter.and.returnValue(true);
// Simulate getter-setter behavior
mockSwimlane.highlight.andCallFake(getterSetter(false));
mockSwimlane.highlightBottom.andCallFake(getterSetter(false));
mockSwimlane.highlight.and.callFake(getterSetter(false));
mockSwimlane.highlightBottom.and.callFake(getterSetter(false));
@@ -88,8 +88,8 @@ define(
stopPropagation: jasmine.createSpy()
};
testEvent.dataTransfer.getData.andReturn('abc');
mockDndService.getData.andReturn({ domainObject: 'someDomainObject' });
testEvent.dataTransfer.getData.and.returnValue('abc');
mockDndService.getData.and.returnValue({ domainObject: 'someDomainObject' });
directive = new MCTSwimlaneDrop(mockDndService);
@@ -97,7 +97,7 @@ define(
// for testing.
directive.link(mockScope, mockElement, testAttrs);
mockElement.on.calls.forEach(function (call) {
mockElement.on.calls.all().forEach(function (call) {
handlers[call.args[0]] = call.args[1];
});
@@ -133,7 +133,7 @@ define(
// Near the top
testEvent.pageY = TEST_TOP + TEST_HEIGHT / 10;
mockSwimlane.allowDropIn.andReturn(false);
mockSwimlane.allowDropIn.and.returnValue(false);
handlers.dragover(testEvent);
@@ -145,7 +145,7 @@ define(
// Near the top
testEvent.pageY = TEST_TOP + TEST_HEIGHT - TEST_HEIGHT / 10;
mockSwimlane.allowDropAfter.andReturn(false);
mockSwimlane.allowDropAfter.and.returnValue(false);
handlers.dragover(testEvent);
@@ -165,7 +165,7 @@ define(
});
it("clears highlights when drag leaves", function () {
mockSwimlane.highlight.andReturn(true);
mockSwimlane.highlight.and.returnValue(true);
handlers.dragleave();
expect(mockSwimlane.highlight).toHaveBeenCalledWith(false);
expect(mockSwimlane.highlightBottom).toHaveBeenCalledWith(false);

View File

@@ -57,13 +57,13 @@ define(
['useCapability', 'hasCapability', 'getId']
);
mockDomainObject.getId.andReturn(id);
mockDomainObject.useCapability.andCallFake(function (c) {
mockDomainObject.getId.and.returnValue(id);
mockDomainObject.useCapability.and.callFake(function (c) {
return c === 'composition' ?
asPromise(children.map(lookupObject)) :
undefined;
});
mockDomainObject.hasCapability.andCallFake(function (c) {
mockDomainObject.hasCapability.and.callFake(function (c) {
return (capabilities.indexOf(c) !== -1) || (c === 'composition');
});
mockDomainObjects[id] = mockDomainObject;
@@ -79,8 +79,8 @@ define(
// Provide subset of q's actual behavior which we
// expect object loader to really need
mockQ.when.andCallFake(asPromise);
mockQ.all.andCallFake(function (values) {
mockQ.when.and.callFake(asPromise);
mockQ.all.and.callFake(function (values) {
var result = [];
function addResult(v) {
result.push(v);