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

@ -65,7 +65,7 @@ module.exports = function(config) {
// Test results reporter to use // Test results reporter to use
// Possible values: 'dots', 'progress' // Possible values: 'dots', 'progress'
// Available reporters: https://npmjs.org/browse/keyword/karma-reporter // Available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress', 'coverage', 'html', 'junit'], reporters: ['progress', 'coverage', 'html'],
// Web server port. // Web server port.
port: 9876, port: 9876,
@ -81,7 +81,7 @@ module.exports = function(config) {
// Specify browsers to run tests in. // Specify browsers to run tests in.
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: [ browsers: [
'Chrome' 'ChromeHeadless'
], ],
// Code coverage reporting. // Code coverage reporting.
@ -104,10 +104,6 @@ module.exports = function(config) {
foldAll: false foldAll: false
}, },
junitReporter: {
outputDir: process.env.CIRCLE_TEST_REPORTS || 'dist/reports/junit'
},
// Continuous Integration mode. // Continuous Integration mode.
// If true, Karma captures browsers, runs the tests and exits. // If true, Karma captures browsers, runs the tests and exits.
singleRun: true singleRun: true

View File

@ -32,18 +32,17 @@
"gulp-sass": "^3.1.0", "gulp-sass": "^3.1.0",
"gulp-sourcemaps": "^1.6.0", "gulp-sourcemaps": "^1.6.0",
"html2canvas": "^1.0.0-alpha.12", "html2canvas": "^1.0.0-alpha.12",
"jasmine-core": "^2.3.0", "jasmine-core": "^3.1.0",
"jscs-html-reporter": "^0.1.0", "jscs-html-reporter": "^0.1.0",
"jsdoc": "^3.3.2", "jsdoc": "^3.3.2",
"jshint": "^2.7.0", "jshint": "^2.7.0",
"karma": "^0.13.3", "karma": "^2.0.3",
"karma-chrome-launcher": "^0.1.12", "karma-chrome-launcher": "^2.2.0",
"karma-cli": "0.0.4", "karma-cli": "^1.0.1",
"karma-coverage": "^0.5.3", "karma-coverage": "^1.1.2",
"karma-html-reporter": "^0.2.7", "karma-html-reporter": "^0.2.7",
"karma-jasmine": "^0.1.5", "karma-jasmine": "^1.1.2",
"karma-junit-reporter": "^0.3.8", "karma-requirejs": "^1.1.0",
"karma-requirejs": "^0.2.2",
"lodash": "^3.10.1", "lodash": "^3.10.1",
"markdown-toc": "^0.11.7", "markdown-toc": "^0.11.7",
"marked": "^0.3.5", "marked": "^0.3.5",

View File

@ -19,6 +19,7 @@
* this source code distribution or the Licensing information page available * this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information. * at runtime from the About dialog for additional information.
*****************************************************************************/ *****************************************************************************/
/*global console*/
/** /**
* MCTRepresentationSpec. Created by vwoeltje on 11/6/14. * MCTRepresentationSpec. Created by vwoeltje on 11/6/14.
@ -48,9 +49,19 @@ define(
controller; controller;
function waitsForNavigation() { function waitsForNavigation() {
var calls = mockNavigationService.setNavigation.calls.length; return new Promise(function (resolve) {
waitsFor(function () { mockNavigationService.setNavigation.and.callFake(function (obj) {
return mockNavigationService.setNavigation.calls.length > calls; var returnValue;
try {
returnValue = NavigationService.prototype.setNavigation.call(mockNavigationService, obj);
} catch (err) {
console.error(err);
//Not rejecting because 'setNavigation' has been called, which is what's being tested here.
//Rejecting will fail tests.
}
resolve();
return returnValue;
});
}); });
} }
@ -78,7 +89,7 @@ define(
"urlService", "urlService",
["urlForLocation"] ["urlForLocation"]
); );
mockUrlService.urlForLocation.andCallFake(function (mode, object) { mockUrlService.urlForLocation.and.callFake(function (mode, object) {
if (object === mockDefaultRootObject) { if (object === mockDefaultRootObject) {
return [mode, testDefaultRoot].join('/'); return [mode, testDefaultRoot].join('/');
} }
@ -106,7 +117,7 @@ define(
"removeListener" "removeListener"
].forEach(function (method) { ].forEach(function (method) {
spyOn(mockNavigationService, method) spyOn(mockNavigationService, method)
.andCallThrough(); .and.callThrough();
}); });
mockRootObject = jasmine.createSpyObj( mockRootObject = jasmine.createSpyObj(
"rootObjectContainer", "rootObjectContainer",
@ -124,60 +135,58 @@ define(
"nestedDomainObject", "nestedDomainObject",
["getId", "getCapability", "getModel", "useCapability", "hasCapability"] ["getId", "getCapability", "getModel", "useCapability", "hasCapability"]
); );
mockObjectService.getObjects.andReturn(Promise.resolve({ mockObjectService.getObjects.and.returnValue(Promise.resolve({
ROOT: mockRootObject ROOT: mockRootObject
})); }));
mockRootObject.useCapability.andReturn(Promise.resolve([ mockRootObject.useCapability.and.returnValue(Promise.resolve([
mockOtherDomainObject, mockOtherDomainObject,
mockDefaultRootObject mockDefaultRootObject
])); ]));
mockRootObject.hasCapability.andReturn(true); mockRootObject.hasCapability.and.returnValue(true);
mockDefaultRootObject.useCapability.andReturn(Promise.resolve([ mockDefaultRootObject.useCapability.and.returnValue(Promise.resolve([
mockNextObject mockNextObject
])); ]));
mockDefaultRootObject.hasCapability.andReturn(true); mockDefaultRootObject.hasCapability.and.returnValue(true);
mockOtherDomainObject.hasCapability.andReturn(false); mockOtherDomainObject.hasCapability.and.returnValue(false);
mockNextObject.useCapability.andReturn(undefined); mockNextObject.useCapability.and.returnValue(undefined);
mockNextObject.hasCapability.andReturn(false); mockNextObject.hasCapability.and.returnValue(false);
mockNextObject.getId.andReturn("next"); mockNextObject.getId.and.returnValue("next");
mockDefaultRootObject.getId.andReturn(testDefaultRoot); mockDefaultRootObject.getId.and.returnValue(testDefaultRoot);
instantiateController(); instantiateController();
waitsForNavigation(); return waitsForNavigation();
}); });
it("uses composition to set the navigated object, if there is none", function () { it("uses composition to set the navigated object, if there is none", function () {
instantiateController(); instantiateController();
waitsForNavigation(); return waitsForNavigation().then(function () {
runs(function () {
expect(mockNavigationService.setNavigation) expect(mockNavigationService.setNavigation)
.toHaveBeenCalledWith(mockDefaultRootObject); .toHaveBeenCalledWith(mockDefaultRootObject);
}); });
}); });
it("navigates to a root-level object, even when default path is not found", function () { it("navigates to a root-level object, even when default path is not found", function () {
mockDefaultRootObject.getId mockDefaultRootObject.getId
.andReturn("something-other-than-the-" + testDefaultRoot); .and.returnValue("something-other-than-the-" + testDefaultRoot);
instantiateController(); instantiateController();
waitsForNavigation(); return waitsForNavigation().then(function () {
runs(function () {
expect(mockNavigationService.setNavigation) expect(mockNavigationService.setNavigation)
.toHaveBeenCalledWith(mockDefaultRootObject); .toHaveBeenCalledWith(mockDefaultRootObject);
}); });
});
});
//
it("does not try to override navigation", function () { it("does not try to override navigation", function () {
mockNavigationService.getNavigation.andReturn(mockDefaultRootObject); mockNavigationService.getNavigation.and.returnValue(mockDefaultRootObject);
instantiateController(); instantiateController();
waitsForNavigation(); return waitsForNavigation().then(function () {
expect(mockScope.navigatedObject).toBe(mockDefaultRootObject); expect(mockScope.navigatedObject).toBe(mockDefaultRootObject);
});
}); });
//
it("updates scope when navigated object changes", function () { it("updates scope when navigated object changes", function () {
// Should have registered a listener - call it // Should have registered a listener - call it
mockNavigationService.addListener.mostRecentCall.args[0]( mockNavigationService.addListener.calls.mostRecent().args[0](
mockOtherDomainObject mockOtherDomainObject
); );
expect(mockScope.navigatedObject).toEqual(mockOtherDomainObject); expect(mockScope.navigatedObject).toEqual(mockOtherDomainObject);
@ -189,19 +198,18 @@ define(
"$destroy", "$destroy",
jasmine.any(Function) jasmine.any(Function)
); );
mockScope.$on.mostRecentCall.args[1](); mockScope.$on.calls.mostRecent().args[1]();
// Should remove the listener it added earlier // Should remove the listener it added earlier
expect(mockNavigationService.removeListener).toHaveBeenCalledWith( expect(mockNavigationService.removeListener).toHaveBeenCalledWith(
mockNavigationService.addListener.mostRecentCall.args[0] mockNavigationService.addListener.calls.mostRecent().args[0]
); );
}); });
it("uses route parameters to choose initially-navigated object", function () { it("uses route parameters to choose initially-navigated object", function () {
mockRoute.current.params.ids = testDefaultRoot + "/next"; mockRoute.current.params.ids = testDefaultRoot + "/next";
instantiateController(); instantiateController();
waitsForNavigation(); return waitsForNavigation().then(function () {
runs(function () {
expect(mockScope.navigatedObject).toBe(mockNextObject); expect(mockScope.navigatedObject).toBe(mockNextObject);
expect(mockNavigationService.setNavigation) expect(mockNavigationService.setNavigation)
.toHaveBeenCalledWith(mockNextObject); .toHaveBeenCalledWith(mockNextObject);
@ -214,12 +222,10 @@ define(
// it hits an invalid ID. // it hits an invalid ID.
mockRoute.current.params.ids = testDefaultRoot + "/junk"; mockRoute.current.params.ids = testDefaultRoot + "/junk";
instantiateController(); instantiateController();
waitsForNavigation(); return waitsForNavigation().then(function () {
runs(function () {
expect(mockScope.navigatedObject).toBe(mockDefaultRootObject); expect(mockScope.navigatedObject).toBe(mockDefaultRootObject);
expect(mockNavigationService.setNavigation) expect(mockNavigationService.setNavigation)
.toHaveBeenCalledWith(mockDefaultRootObject); .toHaveBeenCalledWith(mockDefaultRootObject);
}); });
}); });
@ -229,8 +235,7 @@ define(
// should stop at it since remaining IDs cannot be loaded. // should stop at it since remaining IDs cannot be loaded.
mockRoute.current.params.ids = testDefaultRoot + "/next/junk"; mockRoute.current.params.ids = testDefaultRoot + "/next/junk";
instantiateController(); instantiateController();
waitsForNavigation(); return waitsForNavigation().then(function () {
runs(function () {
expect(mockScope.navigatedObject).toBe(mockNextObject); expect(mockScope.navigatedObject).toBe(mockNextObject);
expect(mockNavigationService.setNavigation) expect(mockNavigationService.setNavigation)
.toHaveBeenCalledWith(mockNextObject); .toHaveBeenCalledWith(mockNextObject);
@ -244,11 +249,11 @@ define(
expect(mockRoute.current.pathParams.ids) expect(mockRoute.current.pathParams.ids)
.not .not
.toBe(testDefaultRoot + '/next'); .toBe(testDefaultRoot + '/next');
mockLocation.path.andCallFake(function () { mockLocation.path.and.callFake(function () {
expect(mockRoute.current.pathParams.ids) expect(mockRoute.current.pathParams.ids)
.toBe(testDefaultRoot + '/next'); .toBe(testDefaultRoot + '/next');
}); });
mockNavigationService.addListener.mostRecentCall.args[0]( mockNavigationService.addListener.calls.mostRecent().args[0](
mockNextObject mockNextObject
); );
expect(mockLocation.path).toHaveBeenCalledWith( expect(mockLocation.path).toHaveBeenCalledWith(

View File

@ -20,7 +20,6 @@
* at runtime from the About dialog for additional information. * at runtime from the About dialog for additional information.
*****************************************************************************/ *****************************************************************************/
define( define(
["../src/BrowseObjectController"], ["../src/BrowseObjectController"],
function (BrowseObjectController) { function (BrowseObjectController) {
@ -33,7 +32,7 @@ define(
// Utility function; look for a $watch on scope and fire it // Utility function; look for a $watch on scope and fire it
function fireWatch(expr, value) { function fireWatch(expr, value) {
mockScope.$watch.calls.forEach(function (call) { mockScope.$watch.calls.all().forEach(function (call) {
if (call.args[0] === expr) { if (call.args[0] === expr) {
call.args[1](value); call.args[1](value);
} }
@ -50,7 +49,7 @@ define(
"$location", "$location",
["path", "search"] ["path", "search"]
); );
mockLocation.search.andReturn({}); mockLocation.search.and.returnValue({});
controller = new BrowseObjectController( controller = new BrowseObjectController(
mockScope, mockScope,
@ -65,7 +64,7 @@ define(
// Allows the path index to be checked // Allows the path index to be checked
// prior to setting $route.current // prior to setting $route.current
mockLocation.path.andReturn("/browse/"); mockLocation.path.and.returnValue("/browse/");
}); });
it("sets the active view from query parameters", function () { it("sets the active view from query parameters", function () {
@ -79,10 +78,10 @@ define(
{ key: 'xyz' } { key: 'xyz' }
]; ];
mockDomainObject.useCapability.andCallFake(function (c) { mockDomainObject.useCapability.and.callFake(function (c) {
return (c === 'view') && testViews; return (c === 'view') && testViews;
}); });
mockLocation.search.andReturn({ view: 'def' }); mockLocation.search.and.returnValue({ view: 'def' });
fireWatch('domainObject', mockDomainObject); fireWatch('domainObject', mockDomainObject);
expect(mockScope.representation.selected) expect(mockScope.representation.selected)

View File

@ -50,14 +50,14 @@ define(
"navigationService", "navigationService",
["getNavigation", "addListener"] ["getNavigation", "addListener"]
); );
mockNavigationService.addListener.andReturn(mockNavigationUnlistener); mockNavigationService.addListener.and.returnValue(mockNavigationUnlistener);
mockStatusUnlistener = jasmine.createSpy("statusUnlistener"); mockStatusUnlistener = jasmine.createSpy("statusUnlistener");
mockStatusCapability = jasmine.createSpyObj( mockStatusCapability = jasmine.createSpyObj(
"statusCapability", "statusCapability",
["listen"] ["listen"]
); );
mockStatusCapability.listen.andReturn(mockStatusUnlistener); mockStatusCapability.listen.and.returnValue(mockStatusUnlistener);
mockDomainObject = jasmine.createSpyObj( mockDomainObject = jasmine.createSpyObj(
'domainObject', 'domainObject',
@ -68,13 +68,13 @@ define(
'hasCapability' 'hasCapability'
] ]
); );
mockDomainObject.getId.andReturn("domainObject"); mockDomainObject.getId.and.returnValue("domainObject");
mockDomainObject.getModel.andReturn({}); mockDomainObject.getModel.and.returnValue({});
mockDomainObject.hasCapability.andReturn(true); mockDomainObject.hasCapability.and.returnValue(true);
mockDomainObject.getCapability.andReturn(mockStatusCapability); mockDomainObject.getCapability.and.returnValue(mockStatusCapability);
mockLocation = jasmine.createSpyObj('location', ['search']); mockLocation = jasmine.createSpyObj('location', ['search']);
mockLocation.search.andReturn({}); mockLocation.search.and.returnValue({});
mockAttrs = {}; mockAttrs = {};
@ -84,7 +84,7 @@ define(
it("listens for changes to navigation and attaches a status" + it("listens for changes to navigation and attaches a status" +
" listener", function () { " listener", function () {
expect(mockNavigationService.addListener).toHaveBeenCalledWith(jasmine.any(Function)); expect(mockNavigationService.addListener).toHaveBeenCalledWith(jasmine.any(Function));
mockNavigationService.addListener.mostRecentCall.args[0](mockDomainObject); mockNavigationService.addListener.calls.mostRecent().args[0](mockDomainObject);
expect(mockStatusCapability.listen).toHaveBeenCalledWith(jasmine.any(Function)); expect(mockStatusCapability.listen).toHaveBeenCalledWith(jasmine.any(Function));
}); });
@ -93,8 +93,8 @@ define(
controller.toggle(); controller.toggle();
// test pre-condition that inspector is hidden // test pre-condition that inspector is hidden
expect(controller.visible()).toBe(false); expect(controller.visible()).toBe(false);
mockNavigationService.addListener.mostRecentCall.args[0](mockDomainObject); mockNavigationService.addListener.calls.mostRecent().args[0](mockDomainObject);
mockStatusCapability.listen.mostRecentCall.args[0](["editing"]); mockStatusCapability.listen.calls.mostRecent().args[0](["editing"]);
expect(controller.visible()).toBe(true); expect(controller.visible()).toBe(true);
}); });

View File

@ -60,8 +60,8 @@ define(
mockActionContext.domainObject = mockDomainObject; mockActionContext.domainObject = mockDomainObject;
mockActionContext.event = mockEvent; mockActionContext.event = mockEvent;
mockScope.domainObject = mockDomainObject; mockScope.domainObject = mockDomainObject;
mockDomainObject.getCapability.andReturn(mockContextMenuAction); mockDomainObject.getCapability.and.returnValue(mockContextMenuAction);
mockContextMenuAction.perform.andReturn(jasmine.any(Function)); mockContextMenuAction.perform.and.returnValue(jasmine.any(Function));
controller = new MenuArrowController(mockScope); controller = new MenuArrowController(mockScope);
}); });

View File

@ -39,7 +39,7 @@ define(
mockMutationCapability = jasmine.createSpyObj("mutation", ["mutate"]); mockMutationCapability = jasmine.createSpyObj("mutation", ["mutate"]);
mockTypeCapability = jasmine.createSpyObj("type", ["typeDef", "hasFeature"]); mockTypeCapability = jasmine.createSpyObj("type", ["typeDef", "hasFeature"]);
mockTypeCapability.typeDef = { name: ""}; mockTypeCapability.typeDef = { name: ""};
mockTypeCapability.hasFeature.andCallFake(function (feature) { mockTypeCapability.hasFeature.and.callFake(function (feature) {
return feature === 'creation'; return feature === 'creation';
}); });
@ -52,8 +52,8 @@ define(
name: "Test name" name: "Test name"
}; };
mockDomainObject = jasmine.createSpyObj("domainObject", ["getCapability", "getModel"]); mockDomainObject = jasmine.createSpyObj("domainObject", ["getCapability", "getModel"]);
mockDomainObject.getModel.andReturn(model); mockDomainObject.getModel.and.returnValue(model);
mockDomainObject.getCapability.andCallFake(function (key) { mockDomainObject.getCapability.and.callFake(function (key) {
return mockCapabilities[key]; return mockCapabilities[key];
}); });
@ -62,7 +62,7 @@ define(
}; };
mockCurrentTarget = jasmine.createSpyObj("currentTarget", ["blur", "textContent"]); mockCurrentTarget = jasmine.createSpyObj("currentTarget", ["blur", "textContent"]);
mockCurrentTarget.blur.andReturn(mockCurrentTarget); mockCurrentTarget.blur.and.returnValue(mockCurrentTarget);
mockEvent = { mockEvent = {
which: {}, which: {},
@ -109,7 +109,7 @@ define(
expect(mockMutationCapability.mutate).toHaveBeenCalledWith(jasmine.any(Function)); expect(mockMutationCapability.mutate).toHaveBeenCalledWith(jasmine.any(Function));
mockMutationCapability.mutate.mostRecentCall.args[0](model); mockMutationCapability.mutate.calls.mostRecent().args[0](model);
expect(mockDomainObject.getModel().name).toBe("New name"); expect(mockDomainObject.getModel().name).toBe("New name");
}); });
@ -127,7 +127,7 @@ define(
}); });
it("disallows editting name when object is non-creatable", function () { it("disallows editting name when object is non-creatable", function () {
mockTypeCapability.hasFeature.andReturn(false); mockTypeCapability.hasFeature.and.returnValue(false);
expect(controller.allowEdit()).toBe(false); expect(controller.allowEdit()).toBe(false);

View File

@ -53,8 +53,8 @@ define(
['getId', 'getModel', 'getCapability'] ['getId', 'getModel', 'getCapability']
); );
mockDomainObject.getId.andReturn(id); mockDomainObject.getId.and.returnValue(id);
mockDomainObject.getModel.andReturn({}); mockDomainObject.getModel.and.returnValue({});
return mockDomainObject; return mockDomainObject;
}); });
@ -65,7 +65,7 @@ define(
mockWindow = jasmine.createSpyObj("$window", ["open"]); mockWindow = jasmine.createSpyObj("$window", ["open"]);
mockLocation = jasmine.createSpyObj('location', ['search']); mockLocation = jasmine.createSpyObj('location', ['search']);
mockLocation.search.andReturn({}); mockLocation.search.and.returnValue({});
mockAttrs = {}; mockAttrs = {};
}); });
@ -83,9 +83,9 @@ define(
}); });
it("collapses on navigation changes on portrait-oriented phones", function () { it("collapses on navigation changes on portrait-oriented phones", function () {
mockAgentService.isMobile.andReturn(true); mockAgentService.isMobile.and.returnValue(true);
mockAgentService.isPhone.andReturn(true); mockAgentService.isPhone.and.returnValue(true);
mockAgentService.isPortrait.andReturn(true); mockAgentService.isPortrait.and.returnValue(true);
controller = instantiateController(); controller = instantiateController();
expect(controller.visible()).toBeTruthy(); expect(controller.visible()).toBeTruthy();
@ -102,13 +102,13 @@ define(
}); });
it("sets pane state to false when in location.search", function () { it("sets pane state to false when in location.search", function () {
mockLocation.search.andReturn({'hideTree': true}); mockLocation.search.and.returnValue({'hideTree': true});
expect(instantiateController().visible()).toBe(false); expect(instantiateController().visible()).toBe(false);
expect(mockLocation.search).toHaveBeenCalledWith('hideTree', undefined); expect(mockLocation.search).toHaveBeenCalledWith('hideTree', undefined);
}); });
it("sets state to true when not found in location.search", function () { it("sets state to true when not found in location.search", function () {
mockLocation.search.andReturn({}); mockLocation.search.and.returnValue({});
expect(instantiateController().visible()).toBe(true); expect(instantiateController().visible()).toBe(true);
expect(mockLocation.search).not.toHaveBeenCalledWith('hideTree', undefined); expect(mockLocation.search).not.toHaveBeenCalledWith('hideTree', undefined);
}); });

View File

@ -34,17 +34,6 @@ define([
mockDomainObject, mockDomainObject,
action; action;
function waitForCall() {
var called = false;
waitsFor(function () {
return called;
});
return function () {
called = true;
};
}
beforeEach(function () { beforeEach(function () {
mockNavigationService = jasmine.createSpyObj( mockNavigationService = jasmine.createSpyObj(
"navigationService", "navigationService",
@ -63,26 +52,24 @@ define([
}); });
it("sets navigation if it is allowed", function () { it("sets navigation if it is allowed", function () {
mockNavigationService.shouldNavigate.andReturn(true); mockNavigationService.shouldNavigate.and.returnValue(true);
action.perform() return action.perform()
.then(waitForCall()); .then(function () {
runs(function () { expect(mockNavigationService.setNavigation)
expect(mockNavigationService.setNavigation)
.toHaveBeenCalledWith(mockDomainObject, true); .toHaveBeenCalledWith(mockDomainObject, true);
}); });
}); });
it("does not set navigation if it is not allowed", function () { it("does not set navigation if it is not allowed", function () {
mockNavigationService.shouldNavigate.andReturn(false); mockNavigationService.shouldNavigate.and.returnValue(false);
var onSuccess = jasmine.createSpy('onSuccess'); var onSuccess = jasmine.createSpy('onSuccess');
action.perform() return action.perform()
.then(onSuccess, waitForCall()); .then(onSuccess, function () {
runs(function () { expect(onSuccess).not.toHaveBeenCalled();
expect(onSuccess).not.toHaveBeenCalled(); expect(mockNavigationService.setNavigation)
expect(mockNavigationService.setNavigation) .not
.not .toHaveBeenCalledWith(mockDomainObject);
.toHaveBeenCalledWith(mockDomainObject); });
});
}); });
it("is only applicable when a domain object is in context", function () { it("is only applicable when a domain object is in context", function () {

View File

@ -69,7 +69,7 @@ define(
navigationService.addListener(callback); navigationService.addListener(callback);
navigationService.setNavigation(testObject); navigationService.setNavigation(testObject);
navigationService.setNavigation(testObject); navigationService.setNavigation(testObject);
expect(callback.calls.length).toEqual(1); expect(callback.calls.count()).toEqual(1);
}); });
it("stops notifying listeners after removal", function () { it("stops notifying listeners after removal", function () {

View File

@ -65,34 +65,35 @@ define([
mockActionCapability = jasmine.createSpyObj('action', ['perform']); mockActionCapability = jasmine.createSpyObj('action', ['perform']);
mockEditor = jasmine.createSpyObj('editor', ['isEditContextRoot']); mockEditor = jasmine.createSpyObj('editor', ['isEditContextRoot']);
mockThrottle.andCallFake(function (fn) { mockThrottle.and.callFake(function (fn) {
var mockThrottledFn = var mockThrottledFn =
jasmine.createSpy('throttled-' + mockThrottledFns.length); jasmine.createSpy('throttled-' + mockThrottledFns.length);
mockThrottledFn.andCallFake(fn); mockThrottledFn.and.callFake(fn);
mockThrottledFns.push(mockThrottledFn); mockThrottledFns.push(mockThrottledFn);
return mockThrottledFn; return mockThrottledFn;
}); });
mockTopic.andReturn(mockMutationTopic); mockTopic.and.returnValue(mockMutationTopic);
mockDomainObject.getId.andReturn(testId); mockDomainObject.getId.and.returnValue(testId);
mockDomainObject.getCapability.andCallFake(function (c) { mockDomainObject.getCapability.and.callFake(function (c) {
return { return {
context: mockContext, context: mockContext,
editor: mockEditor editor: mockEditor
}[c]; }[c];
}); });
mockDomainObject.hasCapability.andCallFake(function (c) { mockDomainObject.hasCapability.and.callFake(function (c) {
return !!mockDomainObject.getCapability(c); return !!mockDomainObject.getCapability(c);
}); });
mockParentObject.getCapability.andCallFake(function (c) { mockParentObject.getCapability.and.callFake(function (c) {
return { return {
action: mockActionCapability action: mockActionCapability
}[c]; }[c];
}); });
testParentComposition = []; testParentComposition = [];
mockParentObject.useCapability.andReturn(Promise.resolve(testParentComposition)); mockParentObject.useCapability.and.returnValue(Promise.resolve(testParentComposition));
mockContext.getParent.andReturn(mockParentObject);
mockNavigationService.getNavigation.andReturn(mockDomainObject); mockContext.getParent.and.returnValue(mockParentObject);
mockEditor.isEditContextRoot.andReturn(false); mockNavigationService.getNavigation.and.returnValue(mockDomainObject);
mockEditor.isEditContextRoot.and.returnValue(false);
return new OrphanNavigationHandler( return new OrphanNavigationHandler(
mockThrottle, mockThrottle,
@ -106,7 +107,7 @@ define([
expect(mockMutationTopic.listen) expect(mockMutationTopic.listen)
.toHaveBeenCalledWith(jasmine.any(Function)); .toHaveBeenCalledWith(jasmine.any(Function));
expect(mockThrottledFns.indexOf( expect(mockThrottledFns.indexOf(
mockMutationTopic.listen.mostRecentCall.args[0] mockMutationTopic.listen.calls.mostRecent().args[0]
)).not.toEqual(-1); )).not.toEqual(-1);
}); });
@ -114,7 +115,7 @@ define([
expect(mockNavigationService.addListener) expect(mockNavigationService.addListener)
.toHaveBeenCalledWith(jasmine.any(Function)); .toHaveBeenCalledWith(jasmine.any(Function));
expect(mockThrottledFns.indexOf( expect(mockThrottledFns.indexOf(
mockNavigationService.addListener.mostRecentCall.args[0] mockNavigationService.addListener.calls.mostRecent().args[0]
)).not.toEqual(-1); )).not.toEqual(-1);
}); });
@ -134,28 +135,14 @@ define([
function itNavigatesAsExpected() { function itNavigatesAsExpected() {
if (isOrphan && !isEditRoot) { if (isOrphan && !isEditRoot) {
it("navigates to the parent", function () { it("navigates to the parent", function () {
var done = false; return Promise.resolve().then(function () {
waitsFor(function () {
return done;
});
setTimeout(function () {
done = true;
}, 5);
runs(function () {
expect(mockActionCapability.perform) expect(mockActionCapability.perform)
.toHaveBeenCalledWith('navigate'); .toHaveBeenCalledWith('navigate');
}); });
}); });
} else { } else {
it("does nothing", function () { it("does nothing", function () {
var done = false; return Promise.resolve().then(function () {
waitsFor(function () {
return done;
});
setTimeout(function () {
done = true;
}, 5);
runs(function () {
expect(mockActionCapability.perform) expect(mockActionCapability.perform)
.not.toHaveBeenCalled(); .not.toHaveBeenCalled();
}); });
@ -165,12 +152,12 @@ define([
describe(caseName, function () { describe(caseName, function () {
beforeEach(function () { beforeEach(function () {
mockEditor.isEditContextRoot.andReturn(isEditRoot); mockEditor.isEditContextRoot.and.returnValue(isEditRoot);
}); });
describe("when navigation changes", function () { describe("when navigation changes", function () {
beforeEach(function () { beforeEach(function () {
mockNavigationService.addListener.mostRecentCall mockNavigationService.addListener.calls.mostRecent()
.args[0](mockDomainObject); .args[0](mockDomainObject);
}); });
itNavigatesAsExpected(); itNavigatesAsExpected();
@ -178,7 +165,7 @@ define([
describe("when mutation occurs", function () { describe("when mutation occurs", function () {
beforeEach(function () { beforeEach(function () {
mockMutationTopic.listen.mostRecentCall mockMutationTopic.listen.calls.mostRecent()
.args[0](mockParentObject); .args[0](mockParentObject);
}); });

View File

@ -49,8 +49,8 @@ define(
); );
mockDocument = [{}]; mockDocument = [{}];
mockDomainObject.getModel.andReturn({ name: 'Test name' }); mockDomainObject.getModel.and.returnValue({ name: 'Test name' });
mockNavigationService.getNavigation.andReturn(mockDomainObject); mockNavigationService.getNavigation.and.returnValue(mockDomainObject);
titler = new WindowTitler( titler = new WindowTitler(
mockNavigationService, mockNavigationService,
@ -64,12 +64,12 @@ define(
jasmine.any(Function), jasmine.any(Function),
jasmine.any(Function) jasmine.any(Function)
); );
expect(mockRootScope.$watch.mostRecentCall.args[0]()) expect(mockRootScope.$watch.calls.mostRecent().args[0]())
.toEqual('Test name'); .toEqual('Test name');
}); });
it("sets the title to the name of the navigated object", function () { it("sets the title to the name of the navigated object", function () {
mockRootScope.$watch.mostRecentCall.args[1]("Some name"); mockRootScope.$watch.calls.mostRecent().args[1]("Some name");
expect(mockDocument[0].title).toEqual("Some name"); expect(mockDocument[0].title).toEqual("Some name");
}); });

View File

@ -63,12 +63,12 @@ define(
["find"] ["find"]
); );
mockBody = jasmine.createSpyObj('body', ['on', 'off']); mockBody = jasmine.createSpyObj('body', ['on', 'off']);
mockDocument.find.andReturn(mockBody); mockDocument.find.and.returnValue(mockBody);
mockDeferred.promise = "mock promise"; mockDeferred.promise = "mock promise";
mockQ.defer.andReturn(mockDeferred); mockQ.defer.and.returnValue(mockDeferred);
mockOverlayService.createOverlay.andReturn(mockOverlay); mockOverlayService.createOverlay.and.returnValue(mockOverlay);
dialogService = new DialogService( dialogService = new DialogService(
mockOverlayService, mockOverlayService,
@ -85,7 +85,7 @@ define(
it("allows user input to be canceled", function () { it("allows user input to be canceled", function () {
dialogService.getUserInput({}, { someKey: "some value" }); dialogService.getUserInput({}, { someKey: "some value" });
mockOverlayService.createOverlay.mostRecentCall.args[1].cancel(); mockOverlayService.createOverlay.calls.mostRecent().args[1].cancel();
expect(mockDeferred.reject).toHaveBeenCalled(); expect(mockDeferred.reject).toHaveBeenCalled();
expect(mockDeferred.resolve).not.toHaveBeenCalled(); expect(mockDeferred.resolve).not.toHaveBeenCalled();
}); });
@ -93,7 +93,7 @@ define(
it("passes back the result of user input when confirmed", function () { it("passes back the result of user input when confirmed", function () {
var value = { someKey: 42 }; var value = { someKey: 42 };
dialogService.getUserInput({}, value); dialogService.getUserInput({}, value);
mockOverlayService.createOverlay.mostRecentCall.args[1].confirm(); mockOverlayService.createOverlay.calls.mostRecent().args[1].confirm();
expect(mockDeferred.reject).not.toHaveBeenCalled(); expect(mockDeferred.reject).not.toHaveBeenCalled();
expect(mockDeferred.resolve).toHaveBeenCalledWith(value); expect(mockDeferred.resolve).toHaveBeenCalledWith(value);
}); });
@ -109,7 +109,7 @@ define(
it("can show multiple dialogs if prior ones are dismissed", function () { it("can show multiple dialogs if prior ones are dismissed", function () {
dialogService.getUserInput({}, {}); dialogService.getUserInput({}, {});
expect(mockLog.warn).not.toHaveBeenCalled(); expect(mockLog.warn).not.toHaveBeenCalled();
mockOverlayService.createOverlay.mostRecentCall.args[1].confirm(); mockOverlayService.createOverlay.calls.mostRecent().args[1].confirm();
dialogService.getUserInput({}, {}); dialogService.getUserInput({}, {});
expect(mockLog.warn).not.toHaveBeenCalled(); expect(mockLog.warn).not.toHaveBeenCalled();
expect(mockDeferred.reject).not.toHaveBeenCalled(); expect(mockDeferred.reject).not.toHaveBeenCalled();
@ -148,13 +148,13 @@ define(
it("destroys the event listener when the dialog is cancelled", function () { it("destroys the event listener when the dialog is cancelled", function () {
dialogService.getUserInput({}, {}); dialogService.getUserInput({}, {});
mockOverlayService.createOverlay.mostRecentCall.args[1].cancel(); mockOverlayService.createOverlay.calls.mostRecent().args[1].cancel();
expect(mockBody.off).toHaveBeenCalledWith("keydown", jasmine.any(Function)); expect(mockBody.off).toHaveBeenCalledWith("keydown", jasmine.any(Function));
}); });
it("cancels the dialog when an escape keydown event is triggered", function () { it("cancels the dialog when an escape keydown event is triggered", function () {
dialogService.getUserInput({}, {}); dialogService.getUserInput({}, {});
mockBody.on.mostRecentCall.args[1]({ mockBody.on.calls.mostRecent().args[1]({
keyCode: 27 keyCode: 27
}); });
expect(mockDeferred.reject).toHaveBeenCalled(); expect(mockDeferred.reject).toHaveBeenCalled();
@ -163,7 +163,7 @@ define(
it("ignores non escape keydown events", function () { it("ignores non escape keydown events", function () {
dialogService.getUserInput({}, {}); dialogService.getUserInput({}, {});
mockBody.on.mostRecentCall.args[1]({ mockBody.on.calls.mostRecent().args[1]({
keyCode: 13 keyCode: 13
}); });
expect(mockDeferred.reject).not.toHaveBeenCalled(); expect(mockDeferred.reject).not.toHaveBeenCalled();
@ -197,7 +197,7 @@ define(
"overlay", "overlay",
["dismiss"] ["dismiss"]
); );
mockOverlayService.createOverlay.andReturn(secondMockOverlay); mockOverlayService.createOverlay.and.returnValue(secondMockOverlay);
secondDialogHandle = dialogService.showBlockingMessage(dialogModel); secondDialogHandle = dialogService.showBlockingMessage(dialogModel);
//Dismiss the first dialog. It should only dismiss if it //Dismiss the first dialog. It should only dismiss if it

View File

@ -46,10 +46,10 @@ define(
mockElement = jasmine.createSpyObj("element", ["remove"]); mockElement = jasmine.createSpyObj("element", ["remove"]);
mockScope = jasmine.createSpyObj("scope", ["$destroy"]); mockScope = jasmine.createSpyObj("scope", ["$destroy"]);
mockDocument.find.andReturn(mockBody); mockDocument.find.and.returnValue(mockBody);
mockCompile.andReturn(mockTemplate); mockCompile.and.returnValue(mockTemplate);
mockRootScope.$new.andReturn(mockScope); mockRootScope.$new.and.returnValue(mockScope);
mockTemplate.andReturn(mockElement); mockTemplate.and.returnValue(mockElement);
overlayService = new OverlayService( overlayService = new OverlayService(
mockDocument, mockDocument,
@ -61,7 +61,7 @@ define(
it("prepends an mct-include to create overlays", function () { it("prepends an mct-include to create overlays", function () {
overlayService.createOverlay("test", {}); overlayService.createOverlay("test", {});
expect(mockCompile).toHaveBeenCalled(); expect(mockCompile).toHaveBeenCalled();
expect(mockCompile.mostRecentCall.args[0].indexOf("mct-include")) expect(mockCompile.calls.mostRecent().args[0].indexOf("mct-include"))
.not.toEqual(-1); .not.toEqual(-1);
}); });

View File

@ -49,7 +49,7 @@ define(
"getModel" "getModel"
] ]
); );
mockDomainObject.getModel.andReturn({}); mockDomainObject.getModel.and.returnValue({});
mockParentObject = jasmine.createSpyObj( mockParentObject = jasmine.createSpyObj(
"parentObject", "parentObject",
@ -57,7 +57,7 @@ define(
"getCapability" "getCapability"
] ]
); );
mockParentObject.getCapability.andCallFake(function (name) { mockParentObject.getCapability.and.callFake(function (name) {
return parentCapabilities[name]; return parentCapabilities[name];
}); });
@ -77,14 +77,14 @@ define(
"getOriginal" "getOriginal"
] ]
); );
capabilities.location.getOriginal.andReturn(mockPromise(mockDomainObject)); capabilities.location.getOriginal.and.returnValue(mockPromise(mockDomainObject));
capabilities.context = jasmine.createSpyObj( capabilities.context = jasmine.createSpyObj(
"contextCapability", "contextCapability",
[ [
"getParent" "getParent"
] ]
); );
capabilities.context.getParent.andReturn(mockParentObject); capabilities.context.getParent.and.returnValue(mockParentObject);
parentCapabilities.action = jasmine.createSpyObj( parentCapabilities.action = jasmine.createSpyObj(
"actionCapability", "actionCapability",
@ -97,37 +97,37 @@ define(
domainObject: mockDomainObject domainObject: mockDomainObject
}; };
mockDomainObject.getCapability.andCallFake(function (name) { mockDomainObject.getCapability.and.callFake(function (name) {
return capabilities[name]; return capabilities[name];
}); });
mockDomainObject.hasCapability.andCallFake(function (name) { mockDomainObject.hasCapability.and.callFake(function (name) {
return !!capabilities[name]; return !!capabilities[name];
}); });
capabilities.editor.finish.andReturn(mockPromise(true)); capabilities.editor.finish.and.returnValue(mockPromise(true));
action = new CancelAction(actionContext); action = new CancelAction(actionContext);
}); });
it("only applies to domain object that is being edited", function () { it("only applies to domain object that is being edited", function () {
capabilities.editor.isEditContextRoot.andReturn(true); capabilities.editor.isEditContextRoot.and.returnValue(true);
expect(CancelAction.appliesTo(actionContext)).toBeTruthy(); expect(CancelAction.appliesTo(actionContext)).toBeTruthy();
expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor"); expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor");
capabilities.editor.isEditContextRoot.andReturn(false); capabilities.editor.isEditContextRoot.and.returnValue(false);
expect(CancelAction.appliesTo(actionContext)).toBeFalsy(); expect(CancelAction.appliesTo(actionContext)).toBeFalsy();
mockDomainObject.hasCapability.andReturn(false); mockDomainObject.hasCapability.and.returnValue(false);
expect(CancelAction.appliesTo(actionContext)).toBeFalsy(); expect(CancelAction.appliesTo(actionContext)).toBeFalsy();
}); });
it("invokes the editor capability's cancel functionality when" + it("invokes the editor capability's cancel functionality when" +
" performed", function () { " performed", function () {
mockDomainObject.getModel.andReturn({persisted: 1}); mockDomainObject.getModel.and.returnValue({persisted: 1});
//Return true from navigate action //Return true from navigate action
capabilities.action.perform.andReturn(mockPromise(true)); capabilities.action.perform.and.returnValue(mockPromise(true));
action.perform(); action.perform();
// Should have called finish // Should have called finish
@ -138,15 +138,15 @@ define(
}); });
it("navigates to object if existing using navigate action", function () { it("navigates to object if existing using navigate action", function () {
mockDomainObject.getModel.andReturn({persisted: 1}); mockDomainObject.getModel.and.returnValue({persisted: 1});
//Return true from navigate action //Return true from navigate action
capabilities.action.perform.andReturn(mockPromise(true)); capabilities.action.perform.and.returnValue(mockPromise(true));
action.perform(); action.perform();
expect(capabilities.action.perform).toHaveBeenCalledWith("navigate"); expect(capabilities.action.perform).toHaveBeenCalledWith("navigate");
}); });
it("navigates to parent if new using navigate action", function () { it("navigates to parent if new using navigate action", function () {
mockDomainObject.getModel.andReturn({persisted: undefined}); mockDomainObject.getModel.and.returnValue({persisted: undefined});
action.perform(); action.perform();
expect(parentCapabilities.action.perform).toHaveBeenCalledWith("navigate"); expect(parentCapabilities.action.perform).toHaveBeenCalledWith("navigate");
}); });

View File

@ -66,11 +66,11 @@ define(
editor: mockEditor editor: mockEditor
}; };
mockDomainObject.getCapability.andCallFake(function (name) { mockDomainObject.getCapability.and.callFake(function (name) {
return capabilities[name]; return capabilities[name];
}); });
mockDomainObject.hasCapability.andReturn(true); mockDomainObject.hasCapability.and.returnValue(true);
mockType.hasFeature.andReturn(true); mockType.hasFeature.and.returnValue(true);
actionContext = { domainObject: mockDomainObject }; actionContext = { domainObject: mockDomainObject };
@ -92,9 +92,9 @@ define(
}); });
it("is only applicable to objects not already in edit mode", function () { it("is only applicable to objects not already in edit mode", function () {
mockEditor.isEditContextRoot.andReturn(false); mockEditor.isEditContextRoot.and.returnValue(false);
expect(EditAction.appliesTo(actionContext)).toBe(true); expect(EditAction.appliesTo(actionContext)).toBe(true);
mockEditor.isEditContextRoot.andReturn(true); mockEditor.isEditContextRoot.and.returnValue(true);
expect(EditAction.appliesTo(actionContext)).toBe(false); expect(EditAction.appliesTo(actionContext)).toBe(false);
}); });

View File

@ -71,14 +71,14 @@ define(
mockActionCapability = jasmine.createSpyObj("actionCapability", ["getActions"]); mockActionCapability = jasmine.createSpyObj("actionCapability", ["getActions"]);
mockEditAction = jasmine.createSpyObj("editAction", ["perform"]); mockEditAction = jasmine.createSpyObj("editAction", ["perform"]);
mockDomainObject.getId.andReturn("test"); mockDomainObject.getId.and.returnValue("test");
mockDomainObject.getCapability.andReturn(mockContext); mockDomainObject.getCapability.and.returnValue(mockContext);
mockContext.getParent.andReturn(mockParent); mockContext.getParent.and.returnValue(mockParent);
mockType.hasFeature.andReturn(true); mockType.hasFeature.and.returnValue(true);
mockType.getKey.andReturn("layout"); mockType.getKey.and.returnValue("layout");
mockComposition.invoke.andReturn(mockPromise(true)); mockComposition.invoke.and.returnValue(mockPromise(true));
mockComposition.add.andReturn(mockPromise(true)); mockComposition.add.and.returnValue(mockPromise(true));
mockActionCapability.getActions.andReturn([]); mockActionCapability.getActions.and.returnValue([]);
capabilities = { capabilities = {
composition: mockComposition, composition: mockComposition,
@ -105,14 +105,14 @@ define(
}); });
it("enables edit mode for objects that have an edit action", function () { it("enables edit mode for objects that have an edit action", function () {
mockActionCapability.getActions.andReturn([mockEditAction]); mockActionCapability.getActions.and.returnValue([mockEditAction]);
action.perform(); action.perform();
expect(mockEditAction.perform).toHaveBeenCalled(); expect(mockEditAction.perform).toHaveBeenCalled();
}); });
it("Does not enable edit mode for objects that do not have an" + it("Does not enable edit mode for objects that do not have an" +
" edit action", function () { " edit action", function () {
mockActionCapability.getActions.andReturn([]); mockActionCapability.getActions.and.returnValue([]);
action.perform(); action.perform();
expect(mockEditAction.perform).not.toHaveBeenCalled(); expect(mockEditAction.perform).not.toHaveBeenCalled();
expect(mockComposition.add) expect(mockComposition.add)

View File

@ -71,8 +71,8 @@ define(
} }
}; };
capabilities.type.hasFeature.andReturn(true); capabilities.type.hasFeature.and.returnValue(true);
capabilities.mutation.andReturn(true); capabilities.mutation.and.returnValue(true);
action = new PropertiesAction(dialogService, context); action = new PropertiesAction(dialogService, context);
}); });
@ -80,7 +80,7 @@ define(
it("mutates an object when performed", function () { it("mutates an object when performed", function () {
action.perform(); action.perform();
expect(capabilities.mutation).toHaveBeenCalled(); expect(capabilities.mutation).toHaveBeenCalled();
capabilities.mutation.mostRecentCall.args[0]({}); capabilities.mutation.calls.mostRecent().args[0]({});
}); });
it("does not muate object upon cancel", function () { it("does not muate object upon cancel", function () {

View File

@ -95,13 +95,13 @@ define(
"removeListener" "removeListener"
] ]
); );
mockNavigationService.getNavigation.andReturn(mockDomainObject); mockNavigationService.getNavigation.and.returnValue(mockDomainObject);
mockDomainObject.getId.andReturn("test"); mockDomainObject.getId.and.returnValue("test");
mockDomainObject.getCapability.andReturn(mockContext); mockDomainObject.getCapability.and.returnValue(mockContext);
mockContext.getParent.andReturn(mockParent); mockContext.getParent.and.returnValue(mockParent);
mockType.hasFeature.andReturn(true); mockType.hasFeature.and.returnValue(true);
capabilities = { capabilities = {
mutation: mockMutation, mutation: mockMutation,
@ -119,7 +119,7 @@ define(
it("only applies to objects with parents", function () { it("only applies to objects with parents", function () {
expect(RemoveAction.appliesTo(actionContext)).toBeTruthy(); expect(RemoveAction.appliesTo(actionContext)).toBeTruthy();
mockContext.getParent.andReturn(undefined); mockContext.getParent.and.returnValue(undefined);
expect(RemoveAction.appliesTo(actionContext)).toBeFalsy(); expect(RemoveAction.appliesTo(actionContext)).toBeFalsy();
@ -136,7 +136,7 @@ define(
it("changes composition from its mutation function", function () { it("changes composition from its mutation function", function () {
var mutator, result; var mutator, result;
action.perform(); action.perform();
mutator = mockMutation.invoke.mostRecentCall.args[0]; mutator = mockMutation.invoke.calls.mostRecent().args[0];
result = mutator(model); result = mutator(model);
// Should not have cancelled the mutation // Should not have cancelled the mutation
@ -153,22 +153,22 @@ define(
it("removes parent of object currently navigated to", function () { it("removes parent of object currently navigated to", function () {
// Navigates to child object // Navigates to child object
mockNavigationService.getNavigation.andReturn(mockChildObject); mockNavigationService.getNavigation.and.returnValue(mockChildObject);
// Test is id of object being removed // Test is id of object being removed
// Child object has different id // Child object has different id
mockDomainObject.getId.andReturn("test"); mockDomainObject.getId.and.returnValue("test");
mockChildObject.getId.andReturn("not test"); mockChildObject.getId.and.returnValue("not test");
// Sets context for the child and domainObject // Sets context for the child and domainObject
mockDomainObject.getCapability.andReturn(mockContext); mockDomainObject.getCapability.and.returnValue(mockContext);
mockChildObject.getCapability.andReturn(mockChildContext); mockChildObject.getCapability.and.returnValue(mockChildContext);
// Parents of child and domainObject are set // Parents of child and domainObject are set
mockContext.getParent.andReturn(mockParent); mockContext.getParent.and.returnValue(mockParent);
mockChildContext.getParent.andReturn(mockDomainObject); mockChildContext.getParent.and.returnValue(mockDomainObject);
mockType.hasFeature.andReturn(true); mockType.hasFeature.and.returnValue(true);
action.perform(); action.perform();
@ -178,25 +178,25 @@ define(
it("checks if removing object not in ascendent path (reaches ROOT)", function () { it("checks if removing object not in ascendent path (reaches ROOT)", function () {
// Navigates to grandchild of ROOT // Navigates to grandchild of ROOT
mockNavigationService.getNavigation.andReturn(mockGrandchildObject); mockNavigationService.getNavigation.and.returnValue(mockGrandchildObject);
// domainObject (grandparent) is set as ROOT, child and grandchild // domainObject (grandparent) is set as ROOT, child and grandchild
// are set objects not being removed // are set objects not being removed
mockDomainObject.getId.andReturn("test 1"); mockDomainObject.getId.and.returnValue("test 1");
mockRootObject.getId.andReturn("ROOT"); mockRootObject.getId.and.returnValue("ROOT");
mockChildObject.getId.andReturn("not test 2"); mockChildObject.getId.and.returnValue("not test 2");
mockGrandchildObject.getId.andReturn("not test 3"); mockGrandchildObject.getId.and.returnValue("not test 3");
// Sets context for the grandchild, child, and domainObject // Sets context for the grandchild, child, and domainObject
mockRootObject.getCapability.andReturn(mockRootContext); mockRootObject.getCapability.and.returnValue(mockRootContext);
mockChildObject.getCapability.andReturn(mockChildContext); mockChildObject.getCapability.and.returnValue(mockChildContext);
mockGrandchildObject.getCapability.andReturn(mockGrandchildContext); mockGrandchildObject.getCapability.and.returnValue(mockGrandchildContext);
// Parents of grandchild and child are set // Parents of grandchild and child are set
mockChildContext.getParent.andReturn(mockRootObject); mockChildContext.getParent.and.returnValue(mockRootObject);
mockGrandchildContext.getParent.andReturn(mockChildObject); mockGrandchildContext.getParent.and.returnValue(mockChildObject);
mockType.hasFeature.andReturn(true); mockType.hasFeature.and.returnValue(true);
action.perform(); action.perform();

View File

@ -19,7 +19,7 @@
* this source code distribution or the Licensing information page available * this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information. * at runtime from the About dialog for additional information.
*****************************************************************************/ *****************************************************************************/
/*global describe,it,expect,beforeEach,jasmine,waitsFor,runs*/ /*global describe,it,expect,beforeEach,jasmine*/
define( define(
["../../src/actions/SaveAction"], ["../../src/actions/SaveAction"],
@ -81,13 +81,13 @@ define(
["info", "error"] ["info", "error"]
); );
mockDomainObject.hasCapability.andReturn(true); mockDomainObject.hasCapability.and.returnValue(true);
mockDomainObject.getCapability.andCallFake(function (capability) { mockDomainObject.getCapability.and.callFake(function (capability) {
return capabilities[capability]; return capabilities[capability];
}); });
mockDomainObject.getModel.andReturn({persisted: 0}); mockDomainObject.getModel.and.returnValue({persisted: 0});
mockEditorCapability.save.andReturn(mockPromise(true)); mockEditorCapability.save.and.returnValue(mockPromise(true));
mockEditorCapability.isEditContextRoot.andReturn(true); mockEditorCapability.isEditContextRoot.and.returnValue(true);
action = new SaveAction(mockDialogService, mockNotificationService, actionContext); action = new SaveAction(mockDialogService, mockNotificationService, actionContext);
}); });
@ -96,14 +96,14 @@ define(
expect(SaveAction.appliesTo(actionContext)).toBe(true); expect(SaveAction.appliesTo(actionContext)).toBe(true);
expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor"); expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor");
mockDomainObject.hasCapability.andReturn(false); mockDomainObject.hasCapability.and.returnValue(false);
mockDomainObject.getCapability.andReturn(undefined); mockDomainObject.getCapability.and.returnValue(undefined);
expect(SaveAction.appliesTo(actionContext)).toBe(false); expect(SaveAction.appliesTo(actionContext)).toBe(false);
}); });
it("only applies to domain object that has already been persisted", it("only applies to domain object that has already been persisted",
function () { function () {
mockDomainObject.getModel.andReturn({persisted: undefined}); mockDomainObject.getModel.and.returnValue({persisted: undefined});
expect(SaveAction.appliesTo(actionContext)).toBe(false); expect(SaveAction.appliesTo(actionContext)).toBe(false);
}); });
@ -118,11 +118,11 @@ define(
beforeEach(function () { beforeEach(function () {
mockDialogHandle = jasmine.createSpyObj("dialogHandle", ["dismiss"]); mockDialogHandle = jasmine.createSpyObj("dialogHandle", ["dismiss"]);
mockDialogService.showBlockingMessage.andReturn(mockDialogHandle); mockDialogService.showBlockingMessage.and.returnValue(mockDialogHandle);
}); });
it("shows a dialog while saving", function () { it("shows a dialog while saving", function () {
mockEditorCapability.save.andReturn(new Promise(function () { mockEditorCapability.save.and.returnValue(new Promise(function () {
})); }));
action.perform(); action.perform();
expect(mockDialogService.showBlockingMessage).toHaveBeenCalled(); expect(mockDialogService.showBlockingMessage).toHaveBeenCalled();
@ -137,12 +137,8 @@ define(
it("notifies if saving succeeded", function () { it("notifies if saving succeeded", function () {
var mockCallback = jasmine.createSpy("callback"); var mockCallback = jasmine.createSpy("callback");
mockEditorCapability.save.andReturn(Promise.resolve("success")); mockEditorCapability.save.and.returnValue(Promise.resolve());
action.perform().then(mockCallback); return action.perform().then(mockCallback).then(function () {
waitsFor(function () {
return mockCallback.calls.length > 0;
});
runs(function () {
expect(mockNotificationService.info).toHaveBeenCalled(); expect(mockNotificationService.info).toHaveBeenCalled();
expect(mockNotificationService.error).not.toHaveBeenCalled(); expect(mockNotificationService.error).not.toHaveBeenCalled();
}); });
@ -150,12 +146,8 @@ define(
it("notifies if saving failed", function () { it("notifies if saving failed", function () {
var mockCallback = jasmine.createSpy("callback"); var mockCallback = jasmine.createSpy("callback");
mockEditorCapability.save.andReturn(Promise.reject("some failure reason")); mockEditorCapability.save.and.returnValue(Promise.reject("some failure reason"));
action.perform().then(mockCallback); return action.perform().then(mockCallback).then(function () {
waitsFor(function () {
return mockCallback.calls.length > 0;
});
runs(function () {
expect(mockNotificationService.error).toHaveBeenCalled(); expect(mockNotificationService.error).toHaveBeenCalled();
expect(mockNotificationService.info).not.toHaveBeenCalled(); expect(mockNotificationService.info).not.toHaveBeenCalled();
}); });

View File

@ -86,13 +86,13 @@ define(
["info", "error"] ["info", "error"]
); );
mockDomainObject.hasCapability.andReturn(true); mockDomainObject.hasCapability.and.returnValue(true);
mockDomainObject.getCapability.andCallFake(function (capability) { mockDomainObject.getCapability.and.callFake(function (capability) {
return capabilities[capability]; return capabilities[capability];
}); });
mockDomainObject.getModel.andReturn({ persisted: 0 }); mockDomainObject.getModel.and.returnValue({ persisted: 0 });
mockEditorCapability.save.andReturn(mockPromise(true)); mockEditorCapability.save.and.returnValue(mockPromise(true));
mockEditorCapability.isEditContextRoot.andReturn(true); mockEditorCapability.isEditContextRoot.and.returnValue(true);
action = new SaveAndStopEditingAction(dialogService, notificationService, actionContext); action = new SaveAndStopEditingAction(dialogService, notificationService, actionContext);
}); });
@ -102,18 +102,18 @@ define(
expect(SaveAndStopEditingAction.appliesTo(actionContext)).toBe(true); expect(SaveAndStopEditingAction.appliesTo(actionContext)).toBe(true);
expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor"); expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor");
mockDomainObject.hasCapability.andReturn(false); mockDomainObject.hasCapability.and.returnValue(false);
mockDomainObject.getCapability.andReturn(undefined); mockDomainObject.getCapability.and.returnValue(undefined);
expect(SaveAndStopEditingAction.appliesTo(actionContext)).toBe(false); expect(SaveAndStopEditingAction.appliesTo(actionContext)).toBe(false);
}); });
it("only applies to domain object that has already been persisted", function () { it("only applies to domain object that has already been persisted", function () {
mockDomainObject.getModel.andReturn({ persisted: undefined }); mockDomainObject.getModel.and.returnValue({ persisted: undefined });
expect(SaveAndStopEditingAction.appliesTo(actionContext)).toBe(false); expect(SaveAndStopEditingAction.appliesTo(actionContext)).toBe(false);
}); });
it("does not close the editor before completing the save", function () { it("does not close the editor before completing the save", function () {
mockEditorCapability.save.andReturn(new Promise(function () { mockEditorCapability.save.and.returnValue(new Promise(function () {
})); }));
action.perform(); action.perform();
expect(mockEditorCapability.save).toHaveBeenCalled(); expect(mockEditorCapability.save).toHaveBeenCalled();

View File

@ -19,7 +19,7 @@
* this source code distribution or the Licensing information page available * this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information. * at runtime from the About dialog for additional information.
*****************************************************************************/ *****************************************************************************/
/*global describe,it,expect,beforeEach,jasmine,runs,waitsFor,spyOn*/ /*global describe,it,expect,beforeEach,jasmine,spyOn*/
define( define(
["../../src/actions/SaveAsAction"], ["../../src/actions/SaveAsAction"],
@ -63,12 +63,12 @@ define(
"getId" "getId"
] ]
); );
mockDomainObject.hasCapability.andReturn(true); mockDomainObject.hasCapability.and.returnValue(true);
mockDomainObject.getCapability.andCallFake(function (capability) { mockDomainObject.getCapability.and.callFake(function (capability) {
return capabilities[capability]; return capabilities[capability];
}); });
mockDomainObject.getModel.andReturn({location: 'a', persisted: undefined}); mockDomainObject.getModel.and.returnValue({location: 'a', persisted: undefined});
mockDomainObject.getId.andReturn(0); mockDomainObject.getId.and.returnValue(0);
mockClonedObject = jasmine.createSpyObj( mockClonedObject = jasmine.createSpyObj(
"clonedObject", "clonedObject",
@ -76,7 +76,7 @@ define(
"getId" "getId"
] ]
); );
mockClonedObject.getId.andReturn(1); mockClonedObject.getId.and.returnValue(1);
mockParent = jasmine.createSpyObj( mockParent = jasmine.createSpyObj(
"parentObject", "parentObject",
@ -91,9 +91,9 @@ define(
"editor", "editor",
["save", "finish", "isEditContextRoot"] ["save", "finish", "isEditContextRoot"]
); );
mockEditorCapability.save.andReturn(mockPromise(true)); mockEditorCapability.save.and.returnValue(mockPromise(true));
mockEditorCapability.finish.andReturn(mockPromise(true)); mockEditorCapability.finish.and.returnValue(mockPromise(true));
mockEditorCapability.isEditContextRoot.andReturn(true); mockEditorCapability.isEditContextRoot.and.returnValue(true);
capabilities.editor = mockEditorCapability; capabilities.editor = mockEditorCapability;
mockActionCapability = jasmine.createSpyObj( mockActionCapability = jasmine.createSpyObj(
@ -106,7 +106,7 @@ define(
"objectService", "objectService",
["getObjects"] ["getObjects"]
); );
mockObjectService.getObjects.andReturn(mockPromise({'a': mockParent})); mockObjectService.getObjects.and.returnValue(mockPromise({'a': mockParent}));
mockDialogService = jasmine.createSpyObj( mockDialogService = jasmine.createSpyObj(
"dialogService", "dialogService",
@ -115,7 +115,7 @@ define(
"showBlockingMessage" "showBlockingMessage"
] ]
); );
mockDialogService.getUserInput.andReturn(mockPromise(undefined)); mockDialogService.getUserInput.and.returnValue(mockPromise(undefined));
mockCopyService = jasmine.createSpyObj( mockCopyService = jasmine.createSpyObj(
"copyService", "copyService",
@ -123,7 +123,7 @@ define(
"perform" "perform"
] ]
); );
mockCopyService.perform.andReturn(mockPromise(mockClonedObject)); mockCopyService.perform.and.returnValue(mockPromise(mockClonedObject));
mockNotificationService = jasmine.createSpyObj( mockNotificationService = jasmine.createSpyObj(
"notificationService", "notificationService",
@ -146,10 +146,10 @@ define(
actionContext); actionContext);
spyOn(action, "getObjectService"); spyOn(action, "getObjectService");
action.getObjectService.andReturn(mockObjectService); action.getObjectService.and.returnValue(mockObjectService);
spyOn(action, "createWizard"); spyOn(action, "createWizard");
action.createWizard.andReturn({ action.createWizard.and.returnValue({
getFormStructure: noop, getFormStructure: noop,
getInitialFormValue: noop, getInitialFormValue: noop,
populateObjectFromInput: function () { populateObjectFromInput: function () {
@ -163,8 +163,8 @@ define(
expect(SaveAsAction.appliesTo(actionContext)).toBe(true); expect(SaveAsAction.appliesTo(actionContext)).toBe(true);
expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor"); expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor");
mockDomainObject.hasCapability.andReturn(false); mockDomainObject.hasCapability.and.returnValue(false);
mockDomainObject.getCapability.andReturn(undefined); mockDomainObject.getCapability.and.returnValue(undefined);
expect(SaveAsAction.appliesTo(actionContext)).toBe(false); expect(SaveAsAction.appliesTo(actionContext)).toBe(false);
}); });
@ -173,35 +173,27 @@ define(
expect(SaveAsAction.appliesTo(actionContext)).toBe(true); expect(SaveAsAction.appliesTo(actionContext)).toBe(true);
expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor"); expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor");
mockDomainObject.getModel.andReturn({persisted: 0}); mockDomainObject.getModel.and.returnValue({persisted: 0});
expect(SaveAsAction.appliesTo(actionContext)).toBe(false); expect(SaveAsAction.appliesTo(actionContext)).toBe(false);
}); });
it("uses the editor capability to save the object", function () { it("uses the editor capability to save the object", function () {
mockEditorCapability.save.andReturn(new Promise(function () {})); mockEditorCapability.save.and.returnValue(Promise.resolve());
runs(function () {
action.perform(); return action.perform().then(function () {
}); expect(mockEditorCapability.save).toHaveBeenCalled();
waitsFor(function () {
return mockEditorCapability.save.calls.length > 0;
}, "perform() should call EditorCapability.save");
runs(function () {
expect(mockEditorCapability.finish).not.toHaveBeenCalled();
}); });
}); });
it("uses the editor capability to finish editing the object", function () { it("uses the editor capability to finish editing the object", function () {
runs(function () { return action.perform().then(function () {
action.perform(); expect(mockEditorCapability.finish.calls.count()).toBeGreaterThan(0);
}); });
waitsFor(function () {
return mockEditorCapability.finish.calls.length > 0;
}, "perform() should call EditorCapability.finish");
}); });
it("returns to browse after save", function () { it("returns to browse after save", function () {
spyOn(action, "save"); spyOn(action, "save");
action.save.andReturn(mockPromise(mockDomainObject)); action.save.and.returnValue(mockPromise(mockDomainObject));
action.perform(); action.perform();
expect(mockActionCapability.perform).toHaveBeenCalledWith( expect(mockActionCapability.perform).toHaveBeenCalledWith(
"navigate" "navigate"
@ -218,48 +210,33 @@ define(
beforeEach(function () { beforeEach(function () {
mockDialogHandle = jasmine.createSpyObj("dialogHandle", ["dismiss"]); mockDialogHandle = jasmine.createSpyObj("dialogHandle", ["dismiss"]);
mockDialogService.showBlockingMessage.andReturn(mockDialogHandle); mockDialogService.showBlockingMessage.and.returnValue(mockDialogHandle);
}); });
it("shows a blocking dialog indicating that saving is in progress", function () { it("shows a blocking dialog indicating that saving is in progress", function () {
mockEditorCapability.save.andReturn(new Promise(function () {})); mockEditorCapability.save.and.returnValue(new Promise(function () {}));
action.perform(); action.perform();
expect(mockDialogService.showBlockingMessage).toHaveBeenCalled(); expect(mockDialogService.showBlockingMessage).toHaveBeenCalled();
expect(mockDialogHandle.dismiss).not.toHaveBeenCalled(); expect(mockDialogHandle.dismiss).not.toHaveBeenCalled();
}); });
it("hides the blocking dialog after saving finishes", function () { it("hides the blocking dialog after saving finishes", function () {
var mockCallback = jasmine.createSpy(); return action.perform().then(function () {
action.perform().then(mockCallback); expect(mockDialogService.showBlockingMessage).toHaveBeenCalled();
expect(mockDialogService.showBlockingMessage).toHaveBeenCalled();
waitsFor(function () {
return mockCallback.calls.length > 0;
});
runs(function () {
expect(mockDialogHandle.dismiss).toHaveBeenCalled(); expect(mockDialogHandle.dismiss).toHaveBeenCalled();
}); });
}); });
it("notifies if saving succeeded", function () { it("notifies if saving succeeded", function () {
var mockCallback = jasmine.createSpy(); return action.perform().then(function () {
action.perform().then(mockCallback);
waitsFor(function () {
return mockCallback.calls.length > 0;
});
runs(function () {
expect(mockNotificationService.info).toHaveBeenCalled(); expect(mockNotificationService.info).toHaveBeenCalled();
expect(mockNotificationService.error).not.toHaveBeenCalled(); expect(mockNotificationService.error).not.toHaveBeenCalled();
}); });
}); });
it("notifies if saving failed", function () { it("notifies if saving failed", function () {
mockCopyService.perform.andReturn(Promise.reject("some failure reason")); mockCopyService.perform.and.returnValue(Promise.reject("some failure reason"));
var mockCallback = jasmine.createSpy(); action.perform().then(function () {
action.perform().then(mockCallback);
waitsFor(function () {
return mockCallback.calls.length > 0;
});
runs(function () {
expect(mockNotificationService.error).toHaveBeenCalled(); expect(mockNotificationService.error).toHaveBeenCalled();
expect(mockNotificationService.info).not.toHaveBeenCalled(); expect(mockNotificationService.info).not.toHaveBeenCalled();
}); });

View File

@ -60,8 +60,8 @@ define(
"cancel" "cancel"
] ]
); );
mockTransactionService.commit.andReturn(fastPromise()); mockTransactionService.commit.and.returnValue(fastPromise());
mockTransactionService.cancel.andReturn(fastPromise()); mockTransactionService.cancel.and.returnValue(fastPromise());
mockTransactionService.isActive = jasmine.createSpy('isActive'); mockTransactionService.isActive = jasmine.createSpy('isActive');
mockStatusCapability = jasmine.createSpyObj( mockStatusCapability = jasmine.createSpyObj(
@ -76,23 +76,23 @@ define(
"contextCapability", "contextCapability",
["getParent"] ["getParent"]
); );
mockContextCapability.getParent.andReturn(mockParentObject); mockContextCapability.getParent.and.returnValue(mockParentObject);
capabilities = { capabilities = {
context: mockContextCapability, context: mockContextCapability,
status: mockStatusCapability status: mockStatusCapability
}; };
mockDomainObject.hasCapability.andCallFake(function (name) { mockDomainObject.hasCapability.and.callFake(function (name) {
return capabilities[name] !== undefined; return capabilities[name] !== undefined;
}); });
mockDomainObject.getCapability.andCallFake(function (name) { mockDomainObject.getCapability.and.callFake(function (name) {
return capabilities[name]; return capabilities[name];
}); });
mockParentObject.getCapability.andReturn(mockParentStatus); mockParentObject.getCapability.and.returnValue(mockParentStatus);
mockParentObject.hasCapability.andReturn(false); mockParentObject.hasCapability.and.returnValue(false);
capability = new EditorCapability( capability = new EditorCapability(
mockTransactionService, mockTransactionService,
@ -112,18 +112,18 @@ define(
it("uses editing status to determine editing context root", function () { it("uses editing status to determine editing context root", function () {
capability.edit(); capability.edit();
mockStatusCapability.get.andReturn(false); mockStatusCapability.get.and.returnValue(false);
expect(capability.isEditContextRoot()).toBe(false); expect(capability.isEditContextRoot()).toBe(false);
mockStatusCapability.get.andReturn(true); mockStatusCapability.get.and.returnValue(true);
expect(capability.isEditContextRoot()).toBe(true); expect(capability.isEditContextRoot()).toBe(true);
}); });
it("inEditingContext returns true if parent object is being" + it("inEditingContext returns true if parent object is being" +
" edited", function () { " edited", function () {
mockStatusCapability.get.andReturn(false); mockStatusCapability.get.and.returnValue(false);
mockParentStatus.get.andReturn(false); mockParentStatus.get.and.returnValue(false);
expect(capability.inEditContext()).toBe(false); expect(capability.inEditContext()).toBe(false);
mockParentStatus.get.andReturn(true); mockParentStatus.get.and.returnValue(true);
expect(capability.inEditContext()).toBe(true); expect(capability.inEditContext()).toBe(true);
}); });
@ -142,7 +142,7 @@ define(
describe("finish", function () { describe("finish", function () {
beforeEach(function () { beforeEach(function () {
mockTransactionService.isActive.andReturn(true); mockTransactionService.isActive.and.returnValue(true);
capability.edit(); capability.edit();
capability.finish(); capability.finish();
}); });
@ -156,7 +156,7 @@ define(
describe("finish", function () { describe("finish", function () {
beforeEach(function () { beforeEach(function () {
mockTransactionService.isActive.andReturn(false); mockTransactionService.isActive.and.returnValue(false);
capability.edit(); capability.edit();
}); });
@ -175,15 +175,15 @@ define(
var model = {}; var model = {};
beforeEach(function () { beforeEach(function () {
mockDomainObject.getModel.andReturn(model); mockDomainObject.getModel.and.returnValue(model);
capability.edit(); capability.edit();
capability.finish(); capability.finish();
}); });
it("returns true if the object has been modified since it" + it("returns true if the object has been modified since it" +
" was last persisted", function () { " was last persisted", function () {
mockTransactionService.size.andReturn(0); mockTransactionService.size.and.returnValue(0);
expect(capability.dirty()).toBe(false); expect(capability.dirty()).toBe(false);
mockTransactionService.size.andReturn(1); mockTransactionService.size.and.returnValue(1);
expect(capability.dirty()).toBe(true); expect(capability.dirty()).toBe(true);
}); });
}); });

View File

@ -37,7 +37,7 @@ define(
mockQ = {}; mockQ = {};
mockTransactionService = {}; mockTransactionService = {};
mockCapabilityService = jasmine.createSpyObj("capabilityService", ["getCapabilities"]); mockCapabilityService = jasmine.createSpyObj("capabilityService", ["getCapabilities"]);
mockCapabilityService.getCapabilities.andReturn({ mockCapabilityService.getCapabilities.and.returnValue({
persistence: function () {} persistence: function () {}
}); });

View File

@ -47,7 +47,7 @@ define(
testId = "test-id"; testId = "test-id";
mockQ = jasmine.createSpyObj("$q", ["when"]); mockQ = jasmine.createSpyObj("$q", ["when"]);
mockQ.when.andCallFake(function (val) { mockQ.when.and.callFake(function (val) {
return fastPromise(val); return fastPromise(val);
}); });
mockTransactionManager = jasmine.createSpyObj( mockTransactionManager = jasmine.createSpyObj(
@ -58,15 +58,15 @@ define(
"persistenceCapability", "persistenceCapability",
["persist", "refresh", "getSpace"] ["persist", "refresh", "getSpace"]
); );
mockPersistence.persist.andReturn(fastPromise()); mockPersistence.persist.and.returnValue(fastPromise());
mockPersistence.refresh.andReturn(fastPromise()); mockPersistence.refresh.and.returnValue(fastPromise());
mockDomainObject = jasmine.createSpyObj( mockDomainObject = jasmine.createSpyObj(
"domainObject", "domainObject",
["getModel", "getId"] ["getModel", "getId"]
); );
mockDomainObject.getModel.andReturn({persisted: 1}); mockDomainObject.getModel.and.returnValue({persisted: 1});
mockDomainObject.getId.andReturn(testId); mockDomainObject.getId.and.returnValue(testId);
capability = new TransactionalPersistenceCapability( capability = new TransactionalPersistenceCapability(
mockQ, mockQ,
@ -78,24 +78,24 @@ define(
it("if no transaction is active, passes through to persistence" + it("if no transaction is active, passes through to persistence" +
" provider", function () { " provider", function () {
mockTransactionManager.isActive.andReturn(false); mockTransactionManager.isActive.and.returnValue(false);
capability.persist(); capability.persist();
expect(mockPersistence.persist).toHaveBeenCalled(); expect(mockPersistence.persist).toHaveBeenCalled();
}); });
it("if transaction is active, persist and cancel calls are" + it("if transaction is active, persist and cancel calls are" +
" queued", function () { " queued", function () {
mockTransactionManager.isActive.andReturn(true); mockTransactionManager.isActive.and.returnValue(true);
capability.persist(); capability.persist();
expect(mockTransactionManager.addToTransaction).toHaveBeenCalled(); expect(mockTransactionManager.addToTransaction).toHaveBeenCalled();
mockTransactionManager.addToTransaction.mostRecentCall.args[1](); mockTransactionManager.addToTransaction.calls.mostRecent().args[1]();
expect(mockPersistence.persist).toHaveBeenCalled(); expect(mockPersistence.persist).toHaveBeenCalled();
mockTransactionManager.addToTransaction.mostRecentCall.args[2](); mockTransactionManager.addToTransaction.calls.mostRecent().args[2]();
expect(mockPersistence.refresh).toHaveBeenCalled(); expect(mockPersistence.refresh).toHaveBeenCalled();
}); });
it("wraps getSpace", function () { it("wraps getSpace", function () {
mockPersistence.getSpace.andReturn('foo'); mockPersistence.getSpace.and.returnValue('foo');
expect(capability.getSpace()).toEqual('foo'); expect(capability.getSpace()).toEqual('foo');
}); });

View File

@ -38,7 +38,7 @@ define(
jasmine.createSpyObj("mockSaveAction", ["getMetadata", "perform"]) jasmine.createSpyObj("mockSaveAction", ["getMetadata", "perform"])
]; ];
mockedSaveActions.forEach(function (action) { mockedSaveActions.forEach(function (action) {
action.getMetadata.andReturn(mockSaveActionMetadata); action.getMetadata.and.returnValue(mockSaveActionMetadata);
}); });
return mockedSaveActions; return mockedSaveActions;
} else if (actionContext.category === "conclude-editing") { } else if (actionContext.category === "conclude-editing") {
@ -54,14 +54,14 @@ define(
beforeEach(function () { beforeEach(function () {
mockActions = jasmine.createSpyObj("action", ["getActions"]); mockActions = jasmine.createSpyObj("action", ["getActions"]);
mockActions.getActions.andCallFake(fakeGetActions); mockActions.getActions.and.callFake(fakeGetActions);
mockScope = jasmine.createSpyObj("$scope", ["$watch"]); mockScope = jasmine.createSpyObj("$scope", ["$watch"]);
mockScope.action = mockActions; mockScope.action = mockActions;
controller = new EditActionController(mockScope); controller = new EditActionController(mockScope);
}); });
function makeControllerUpdateActions() { function makeControllerUpdateActions() {
mockScope.$watch.mostRecentCall.args[1](); mockScope.$watch.calls.mostRecent().args[1]();
} }
it("watches scope that may change applicable actions", function () { it("watches scope that may change applicable actions", function () {

View File

@ -61,17 +61,17 @@ define(
mockLocation = jasmine.createSpyObj('$location', mockLocation = jasmine.createSpyObj('$location',
["search"] ["search"]
); );
mockLocation.search.andReturn({"view": "fixed"}); mockLocation.search.and.returnValue({"view": "fixed"});
mockNavigationService = jasmine.createSpyObj('navigationService', mockNavigationService = jasmine.createSpyObj('navigationService',
["checkBeforeNavigation"] ["checkBeforeNavigation"]
); );
removeCheck = jasmine.createSpy('removeCheck'); removeCheck = jasmine.createSpy('removeCheck');
mockNavigationService.checkBeforeNavigation.andReturn(removeCheck); mockNavigationService.checkBeforeNavigation.and.returnValue(removeCheck);
mockObject.getId.andReturn("test"); mockObject.getId.and.returnValue("test");
mockObject.getModel.andReturn({ name: "Test object" }); mockObject.getModel.and.returnValue({ name: "Test object" });
mockObject.getCapability.andCallFake(function (key) { mockObject.getCapability.and.callFake(function (key) {
return mockCapabilities[key]; return mockCapabilities[key];
}); });
@ -81,10 +81,10 @@ define(
{ key: 'xyz' } { key: 'xyz' }
]; ];
mockObject.useCapability.andCallFake(function (c) { mockObject.useCapability.and.callFake(function (c) {
return (c === 'view') && testViews; return (c === 'view') && testViews;
}); });
mockLocation.search.andReturn({ view: 'def' }); mockLocation.search.and.returnValue({ view: 'def' });
mockScope.domainObject = mockObject; mockScope.domainObject = mockObject;
@ -99,17 +99,17 @@ define(
expect(mockNavigationService.checkBeforeNavigation) expect(mockNavigationService.checkBeforeNavigation)
.toHaveBeenCalledWith(jasmine.any(Function)); .toHaveBeenCalledWith(jasmine.any(Function));
var checkFn = mockNavigationService.checkBeforeNavigation.mostRecentCall.args[0]; var checkFn = mockNavigationService.checkBeforeNavigation.calls.mostRecent().args[0];
mockEditorCapability.isEditContextRoot.andReturn(false); mockEditorCapability.isEditContextRoot.and.returnValue(false);
mockEditorCapability.dirty.andReturn(false); mockEditorCapability.dirty.and.returnValue(false);
expect(checkFn()).toBe("Continuing will cause the loss of any unsaved changes."); expect(checkFn()).toBe("Continuing will cause the loss of any unsaved changes.");
mockEditorCapability.isEditContextRoot.andReturn(true); mockEditorCapability.isEditContextRoot.and.returnValue(true);
expect(checkFn()).toBe("Continuing will cause the loss of any unsaved changes."); expect(checkFn()).toBe("Continuing will cause the loss of any unsaved changes.");
mockEditorCapability.dirty.andReturn(true); mockEditorCapability.dirty.and.returnValue(true);
expect(checkFn()) expect(checkFn())
.toBe("Continuing will cause the loss of any unsaved changes."); .toBe("Continuing will cause the loss of any unsaved changes.");
@ -119,7 +119,7 @@ define(
expect(mockScope.$on) expect(mockScope.$on)
.toHaveBeenCalledWith("$destroy", jasmine.any(Function)); .toHaveBeenCalledWith("$destroy", jasmine.any(Function));
mockScope.$on.mostRecentCall.args[1](); mockScope.$on.calls.mostRecent().args[1]();
expect(mockEditorCapability.finish).toHaveBeenCalled(); expect(mockEditorCapability.finish).toHaveBeenCalled();
expect(removeCheck).toHaveBeenCalled(); expect(removeCheck).toHaveBeenCalled();

View File

@ -41,13 +41,13 @@ define(
['getTrueRoot'] ['getTrueRoot']
); );
mockDomainObject.getId.andReturn('test-id'); mockDomainObject.getId.and.returnValue('test-id');
mockDomainObject.getCapability.andReturn(mockContext); mockDomainObject.getCapability.and.returnValue(mockContext);
// Return a new instance of the root object each time // Return a new instance of the root object each time
mockContext.getTrueRoot.andCallFake(function () { mockContext.getTrueRoot.and.callFake(function () {
var mockRoot = jasmine.createSpyObj('root', ['getId']); var mockRoot = jasmine.createSpyObj('root', ['getId']);
mockRoot.getId.andReturn('root-id'); mockRoot.getId.and.returnValue('root-id');
return mockRoot; return mockRoot;
}); });
@ -63,7 +63,7 @@ define(
}); });
it("exposes the root object found via the object's context capability", function () { it("exposes the root object found via the object's context capability", function () {
mockScope.$watch.mostRecentCall.args[1](mockDomainObject); mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
// Verify that the correct capability was used // Verify that the correct capability was used
expect(mockDomainObject.getCapability) expect(mockDomainObject.getCapability)
@ -76,10 +76,10 @@ define(
it("preserves the same root instance to avoid excessive refreshing", function () { it("preserves the same root instance to avoid excessive refreshing", function () {
var firstRoot; var firstRoot;
// Expose the domain object // Expose the domain object
mockScope.$watch.mostRecentCall.args[1](mockDomainObject); mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
firstRoot = controller.getRoot(); firstRoot = controller.getRoot();
// Update! // Update!
mockScope.$watch.mostRecentCall.args[1](mockDomainObject); mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
// Should still have the same object instance, to avoid // Should still have the same object instance, to avoid
// triggering the watch used by the template we're supporting // triggering the watch used by the template we're supporting
expect(controller.getRoot()).toBe(firstRoot); expect(controller.getRoot()).toBe(firstRoot);
@ -90,18 +90,18 @@ define(
it("updates the root when it changes", function () { it("updates the root when it changes", function () {
var firstRoot; var firstRoot;
// Expose the domain object // Expose the domain object
mockScope.$watch.mostRecentCall.args[1](mockDomainObject); mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
firstRoot = controller.getRoot(); firstRoot = controller.getRoot();
// Change the exposed root // Change the exposed root
mockContext.getTrueRoot.andCallFake(function () { mockContext.getTrueRoot.and.callFake(function () {
var mockRoot = jasmine.createSpyObj('root', ['getId']); var mockRoot = jasmine.createSpyObj('root', ['getId']);
mockRoot.getId.andReturn('other-root-id'); mockRoot.getId.and.returnValue('other-root-id');
return mockRoot; return mockRoot;
}); });
// Update! // Update!
mockScope.$watch.mostRecentCall.args[1](mockDomainObject); mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
// Should still have the same object instance, to avoid // Should still have the same object instance, to avoid
// triggering the watch used by the template we're supporting // triggering the watch used by the template we're supporting

View File

@ -63,13 +63,13 @@ define(
mockMutationCapability = jasmine.createSpyObj("mutationCapability", [ mockMutationCapability = jasmine.createSpyObj("mutationCapability", [
"listen" "listen"
]); ]);
mockMutationCapability.listen.andReturn(mockUnlisten); mockMutationCapability.listen.and.returnValue(mockUnlisten);
mockDomainObject = jasmine.createSpyObj("domainObject", [ mockDomainObject = jasmine.createSpyObj("domainObject", [
"getCapability", "getCapability",
"useCapability" "useCapability"
]); ]);
mockDomainObject.useCapability.andReturn(mockCompositionCapability); mockDomainObject.useCapability.and.returnValue(mockCompositionCapability);
mockDomainObject.getCapability.andReturn(mockMutationCapability); mockDomainObject.getCapability.and.returnValue(mockMutationCapability);
mockScope = jasmine.createSpyObj("$scope", ['$on']); mockScope = jasmine.createSpyObj("$scope", ['$on']);
mockSelection = jasmine.createSpyObj("selection", [ mockSelection = jasmine.createSpyObj("selection", [
@ -77,7 +77,7 @@ define(
'off', 'off',
'get' 'get'
]); ]);
mockSelection.get.andReturn([]); mockSelection.get.and.returnValue([]);
mockOpenMCT = { mockOpenMCT = {
selection: mockSelection selection: mockSelection
}; };
@ -88,7 +88,7 @@ define(
} }
}; };
spyOn(ElementsController.prototype, 'refreshComposition').andCallThrough(); spyOn(ElementsController.prototype, 'refreshComposition').and.callThrough();
controller = new ElementsController(mockScope, mockOpenMCT); controller = new ElementsController(mockScope, mockOpenMCT);
}); });
@ -123,29 +123,29 @@ define(
}); });
it("refreshes composition on selection", function () { it("refreshes composition on selection", function () {
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable); mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
expect(ElementsController.prototype.refreshComposition).toHaveBeenCalledWith(mockDomainObject); expect(ElementsController.prototype.refreshComposition).toHaveBeenCalledWith(mockDomainObject);
}); });
it("listens on mutation and refreshes composition", function () { it("listens on mutation and refreshes composition", function () {
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable); mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
expect(mockDomainObject.getCapability).toHaveBeenCalledWith('mutation'); expect(mockDomainObject.getCapability).toHaveBeenCalledWith('mutation');
expect(mockMutationCapability.listen).toHaveBeenCalled(); expect(mockMutationCapability.listen).toHaveBeenCalled();
expect(ElementsController.prototype.refreshComposition.calls.length).toBe(1); expect(ElementsController.prototype.refreshComposition.calls.count()).toBe(1);
mockMutationCapability.listen.mostRecentCall.args[0](mockDomainObject); mockMutationCapability.listen.calls.mostRecent().args[0](mockDomainObject);
expect(ElementsController.prototype.refreshComposition.calls.length).toBe(2); expect(ElementsController.prototype.refreshComposition.calls.count()).toBe(2);
}); });
it("cleans up mutation listener when selection changes", function () { it("cleans up mutation listener when selection changes", function () {
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable); mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
expect(mockMutationCapability.listen).toHaveBeenCalled(); expect(mockMutationCapability.listen).toHaveBeenCalled();
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable); mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
expect(mockUnlisten).toHaveBeenCalled(); expect(mockUnlisten).toHaveBeenCalled();
}); });
@ -156,7 +156,7 @@ define(
elementProxy: {} elementProxy: {}
} }
}; };
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable); mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
expect(mockDomainObject.getCapability).not.toHaveBeenCalledWith('mutation'); expect(mockDomainObject.getCapability).not.toHaveBeenCalledWith('mutation');
}); });
@ -167,13 +167,13 @@ define(
firstCompositionCallback, firstCompositionCallback,
secondCompositionCallback; secondCompositionCallback;
spyOn(mockCompositionCapability, "then").andCallThrough(); spyOn(mockCompositionCapability, "then").and.callThrough();
controller.refreshComposition(mockDomainObject); controller.refreshComposition(mockDomainObject);
controller.refreshComposition(mockDomainObject); controller.refreshComposition(mockDomainObject);
firstCompositionCallback = mockCompositionCapability.then.calls[0].args[0]; firstCompositionCallback = mockCompositionCapability.then.calls.all()[0].args[0];
secondCompositionCallback = mockCompositionCapability.then.calls[1].args[0]; secondCompositionCallback = mockCompositionCapability.then.calls.all()[1].args[0];
secondCompositionCallback(secondMockCompositionObjects); secondCompositionCallback(secondMockCompositionObjects);
firstCompositionCallback(mockCompositionObjects); firstCompositionCallback(mockCompositionObjects);

View File

@ -51,9 +51,9 @@ define(
"hasFeature" "hasFeature"
] ]
); );
mockType.hasFeature.andReturn(true); mockType.hasFeature.and.returnValue(true);
mockType.getName.andReturn(name); mockType.getName.and.returnValue(name);
mockType.getKey.andReturn(name); mockType.getKey.and.returnValue(name);
return mockType; return mockType;
} }
@ -77,7 +77,7 @@ define(
mockTypeMap[type.getKey()] = type; mockTypeMap[type.getKey()] = type;
}); });
mockTypeService.getType.andCallFake(function (key) { mockTypeService.getType.and.callFake(function (key) {
return mockTypeMap[key]; return mockTypeMap[key];
}); });

View File

@ -49,8 +49,8 @@ define(
"hasFeature" "hasFeature"
] ]
); );
mockType.hasFeature.andReturn(true); mockType.hasFeature.and.returnValue(true);
mockType.getName.andReturn(name); mockType.getName.and.returnValue(name);
return mockType; return mockType;
} }
@ -74,11 +74,11 @@ define(
return mockPolicyMap[type.getName()]; return mockPolicyMap[type.getName()];
}; };
mockPolicyService.allow.andCallFake(function (category, type) { mockPolicyService.allow.and.callFake(function (category, type) {
return category === "creation" && mockCreationPolicy(type) ? true : false; return category === "creation" && mockCreationPolicy(type) ? true : false;
}); });
mockTypeService.listTypes.andReturn(mockTypes); mockTypeService.listTypes.and.returnValue(mockTypes);
provider = new CreateActionProvider( provider = new CreateActionProvider(
mockTypeService, mockTypeService,

View File

@ -77,10 +77,10 @@ define(
"useCapability" "useCapability"
] ]
); );
mockDomainObject.hasCapability.andCallFake(function (name) { mockDomainObject.hasCapability.and.callFake(function (name) {
return !!capabilities[name]; return !!capabilities[name];
}); });
mockDomainObject.getCapability.andCallFake(function (name) { mockDomainObject.getCapability.and.callFake(function (name) {
return capabilities[name]; return capabilities[name];
}); });
mockSaveAction = jasmine.createSpyObj( mockSaveAction = jasmine.createSpyObj(
@ -117,14 +117,14 @@ define(
mockContext = { mockContext = {
domainObject: mockParent domainObject: mockParent
}; };
mockParent.useCapability.andReturn(mockDomainObject); mockParent.useCapability.and.returnValue(mockDomainObject);
mockType.getKey.andReturn("test"); mockType.getKey.and.returnValue("test");
mockType.getCssClass.andReturn("icon-telemetry"); mockType.getCssClass.and.returnValue("icon-telemetry");
mockType.getDescription.andReturn("a test type"); mockType.getDescription.and.returnValue("a test type");
mockType.getName.andReturn("Test"); mockType.getName.and.returnValue("Test");
mockType.getProperties.andReturn([]); mockType.getProperties.and.returnValue([]);
mockType.getInitialModel.andReturn({}); mockType.getInitialModel.and.returnValue({});
action = new CreateAction( action = new CreateAction(
mockType, mockType,
@ -144,7 +144,7 @@ define(
describe("the perform function", function () { describe("the perform function", function () {
var promise = jasmine.createSpyObj("promise", ["then"]); var promise = jasmine.createSpyObj("promise", ["then"]);
beforeEach(function () { beforeEach(function () {
capabilities.action.getActions.andReturn([mockEditAction]); capabilities.action.getActions.and.returnValue([mockEditAction]);
}); });
it("uses the instantiation capability when performed", function () { it("uses the instantiation capability when performed", function () {
@ -159,30 +159,30 @@ define(
it("uses the save-as action if object does not have an edit action" + it("uses the save-as action if object does not have an edit action" +
" available", function () { " available", function () {
capabilities.action.getActions.andReturn([]); capabilities.action.getActions.and.returnValue([]);
capabilities.action.perform.andReturn(mockPromise(undefined)); capabilities.action.perform.and.returnValue(mockPromise(undefined));
capabilities.editor.save.andReturn(promise); capabilities.editor.save.and.returnValue(promise);
action.perform(); action.perform();
expect(capabilities.action.perform).toHaveBeenCalledWith("save-as"); expect(capabilities.action.perform).toHaveBeenCalledWith("save-as");
}); });
describe("uses to editor capability", function () { describe("uses to editor capability", function () {
beforeEach(function () { beforeEach(function () {
capabilities.action.getActions.andReturn([]); capabilities.action.getActions.and.returnValue([]);
capabilities.action.perform.andReturn(promise); capabilities.action.perform.and.returnValue(promise);
capabilities.editor.save.andReturn(promise); capabilities.editor.save.and.returnValue(promise);
}); });
it("to save the edit if user saves dialog", function () { it("to save the edit if user saves dialog", function () {
action.perform(); action.perform();
expect(promise.then).toHaveBeenCalled(); expect(promise.then).toHaveBeenCalled();
promise.then.mostRecentCall.args[0](); promise.then.calls.mostRecent().args[0]();
expect(capabilities.editor.save).toHaveBeenCalled(); expect(capabilities.editor.save).toHaveBeenCalled();
}); });
it("to finish the edit if user cancels dialog", function () { it("to finish the edit if user cancels dialog", function () {
action.perform(); action.perform();
promise.then.mostRecentCall.args[1](); promise.then.calls.mostRecent().args[1]();
expect(capabilities.editor.finish).toHaveBeenCalled(); expect(capabilities.editor.finish).toHaveBeenCalled();
}); });
}); });

View File

@ -49,10 +49,10 @@ define(
it("populates the scope with create actions", function () { it("populates the scope with create actions", function () {
mockScope.action = mockActions; mockScope.action = mockActions;
mockActions.getActions.andReturn(["a", "b", "c"]); mockActions.getActions.and.returnValue(["a", "b", "c"]);
// Call the watch // Call the watch
mockScope.$watch.mostRecentCall.args[1](); mockScope.$watch.calls.mostRecent().args[1]();
// Should have grouped and ungrouped actions in scope now // Should have grouped and ungrouped actions in scope now
expect(mockScope.createActions.length).toEqual(3); expect(mockScope.createActions.length).toEqual(3);

View File

@ -41,10 +41,10 @@ define(
"property" + name, "property" + name,
["getDefinition", "getValue", "setValue"] ["getDefinition", "getValue", "setValue"]
); );
mockProperty.getDefinition.andReturn({ mockProperty.getDefinition.and.returnValue({
control: "textfield" control: "textfield"
}); });
mockProperty.getValue.andReturn(name); mockProperty.getValue.and.returnValue(name);
return mockProperty; return mockProperty;
} }
@ -74,12 +74,12 @@ define(
testModel = { someKey: "some value" }; testModel = { someKey: "some value" };
mockType.getKey.andReturn("test"); mockType.getKey.and.returnValue("test");
mockType.getCssClass.andReturn("icon-telemetry"); mockType.getCssClass.and.returnValue("icon-telemetry");
mockType.getDescription.andReturn("a test type"); mockType.getDescription.and.returnValue("a test type");
mockType.getName.andReturn("Test"); mockType.getName.and.returnValue("Test");
mockType.getInitialModel.andReturn(testModel); mockType.getInitialModel.and.returnValue(testModel);
mockType.getProperties.andReturn(mockProperties); mockType.getProperties.and.returnValue(mockProperties);
mockDomainObject = jasmine.createSpyObj( mockDomainObject = jasmine.createSpyObj(
'domainObject', 'domainObject',
@ -87,9 +87,9 @@ define(
); );
//Mocking the getCapability('type') call //Mocking the getCapability('type') call
mockDomainObject.getCapability.andReturn(mockType); mockDomainObject.getCapability.and.returnValue(mockType);
mockDomainObject.useCapability.andReturn(); mockDomainObject.useCapability.and.returnValue();
mockDomainObject.getModel.andReturn(testModel); mockDomainObject.getModel.and.returnValue(testModel);
wizard = new CreateWizard( wizard = new CreateWizard(
mockDomainObject, mockDomainObject,
@ -147,9 +147,11 @@ define(
"C": "ValueC" "C": "ValueC"
}, },
compareModel = wizard.createModel(formValue); compareModel = wizard.createModel(formValue);
//populateObjectFromInput adds a .location attribute that is not added by createModel.
compareModel.location = undefined;
wizard.populateObjectFromInput(formValue); wizard.populateObjectFromInput(formValue);
expect(mockDomainObject.useCapability).toHaveBeenCalledWith('mutation', jasmine.any(Function)); expect(mockDomainObject.useCapability).toHaveBeenCalledWith('mutation', jasmine.any(Function));
expect(mockDomainObject.useCapability.mostRecentCall.args[1]()).toEqual(compareModel); expect(mockDomainObject.useCapability.calls.mostRecent().args[1]()).toEqual(compareModel);
}); });
it("validates selection types using policy", function () { it("validates selection types using policy", function () {
@ -168,7 +170,7 @@ define(
rows = structure.sections[sections.length - 1].rows, rows = structure.sections[sections.length - 1].rows,
locationRow = rows[rows.length - 1]; locationRow = rows[rows.length - 1];
mockDomainObj.getCapability.andReturn(mockOtherType); mockDomainObj.getCapability.and.returnValue(mockOtherType);
locationRow.validate(mockDomainObj); locationRow.validate(mockDomainObj);
// Should check policy to see if the user-selected location // Should check policy to see if the user-selected location

View File

@ -38,12 +38,12 @@ define(
}); });
it("allows creation of types with the creation feature", function () { it("allows creation of types with the creation feature", function () {
mockType.hasFeature.andReturn(true); mockType.hasFeature.and.returnValue(true);
expect(policy.allow(mockType)).toBeTruthy(); expect(policy.allow(mockType)).toBeTruthy();
}); });
it("disallows creation of types without the creation feature", function () { it("disallows creation of types without the creation feature", function () {
mockType.hasFeature.andReturn(false); mockType.hasFeature.and.returnValue(false);
expect(policy.allow(mockType)).toBeFalsy(); expect(policy.allow(mockType)).toBeFalsy();
}); });
}); });

View File

@ -103,33 +103,33 @@ define(
["persist", "getSpace"] ["persist", "getSpace"]
); );
mockParentObject.getCapability.andCallFake(function (key) { mockParentObject.getCapability.and.callFake(function (key) {
return mockCapabilities[key]; return mockCapabilities[key];
}); });
mockParentObject.useCapability.andCallFake(function (key, value) { mockParentObject.useCapability.and.callFake(function (key, value) {
return mockCapabilities[key].invoke(value); return mockCapabilities[key].invoke(value);
}); });
mockParentObject.getId.andReturn('parentId'); mockParentObject.getId.and.returnValue('parentId');
mockNewObject.getId.andReturn('newId'); mockNewObject.getId.and.returnValue('newId');
mockNewObject.getCapability.andCallFake(function (c) { mockNewObject.getCapability.and.callFake(function (c) {
return c === 'persistence' ? return c === 'persistence' ?
mockNewPersistenceCapability : undefined; mockNewPersistenceCapability : undefined;
}); });
mockPersistenceCapability.persist mockPersistenceCapability.persist
.andReturn(mockPromise(true)); .and.returnValue(mockPromise(true));
mockNewPersistenceCapability.persist mockNewPersistenceCapability.persist
.andReturn(mockPromise(true)); .and.returnValue(mockPromise(true));
mockMutationCapability.invoke.andReturn(mockPromise(true)); mockMutationCapability.invoke.and.returnValue(mockPromise(true));
mockPersistenceCapability.getSpace.andReturn("testSpace"); mockPersistenceCapability.getSpace.and.returnValue("testSpace");
mockCompositionCapability.invoke.andReturn( mockCompositionCapability.invoke.and.returnValue(
mockPromise([mockNewObject]) mockPromise([mockNewObject])
); );
mockCompositionCapability.add.andReturn(mockPromise(true)); mockCompositionCapability.add.and.returnValue(mockPromise(true));
mockCreationCapability.instantiate.andReturn(mockNewObject); mockCreationCapability.instantiate.and.returnValue(mockNewObject);
mockCreationCapability.invoke.andCallFake(function (model) { mockCreationCapability.invoke.and.callFake(function (model) {
return mockCreationCapability.instantiate(model); return mockCreationCapability.instantiate(model);
}); });
@ -163,10 +163,10 @@ define(
mockCallback = jasmine.createSpy('callback'); mockCallback = jasmine.createSpy('callback');
// Act as if the object had been created // Act as if the object had been created
mockCompositionCapability.add.andCallFake(function (id) { mockCompositionCapability.add.and.callFake(function (id) {
mockDomainObject.getId.andReturn(id); mockDomainObject.getId.and.returnValue(id);
mockCompositionCapability.invoke mockCompositionCapability.invoke
.andReturn(mockPromise([mockDomainObject])); .and.returnValue(mockPromise([mockDomainObject]));
return mockPromise(mockDomainObject); return mockPromise(mockDomainObject);
}); });
@ -200,7 +200,7 @@ define(
// created object - this is an error. // created object - this is an error.
var model = { someKey: "some value" }; var model = { someKey: "some value" };
mockCompositionCapability.add.andReturn(mockPromise(false)); mockCompositionCapability.add.and.returnValue(mockPromise(false));
creationService.createObject(model, mockParentObject); creationService.createObject(model, mockParentObject);

View File

@ -64,9 +64,9 @@ define(
["then"] ["then"]
); );
mockDomainObject.getCapability.andReturn(mockContext); mockDomainObject.getCapability.and.returnValue(mockContext);
mockContext.getRoot.andReturn(mockRootObject); mockContext.getRoot.and.returnValue(mockRootObject);
mockObjectService.getObjects.andReturn(getObjectsPromise); mockObjectService.getObjects.and.returnValue(getObjectsPromise);
mockScope.ngModel = {}; mockScope.ngModel = {};
mockScope.field = "someField"; mockScope.field = "someField";
@ -76,7 +76,7 @@ define(
describe("when context is available", function () { describe("when context is available", function () {
beforeEach(function () { beforeEach(function () {
mockContext.getRoot.andReturn(mockRootObject); mockContext.getRoot.and.returnValue(mockRootObject);
controller = new LocatorController(mockScope, mockTimeout, mockObjectService); controller = new LocatorController(mockScope, mockTimeout, mockObjectService);
}); });
@ -96,8 +96,8 @@ define(
it("changes its own model on embedded model updates", function () { it("changes its own model on embedded model updates", function () {
// Need to pass on selection changes as updates to // Need to pass on selection changes as updates to
// the control's value // the control's value
mockScope.$watch.mostRecentCall.args[1](mockDomainObject); mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
mockTimeout.mostRecentCall.args[0](); mockTimeout.calls.mostRecent().args[0]();
expect(mockScope.ngModel.someField).toEqual(mockDomainObject); expect(mockScope.ngModel.someField).toEqual(mockDomainObject);
expect(mockScope.rootObject).toEqual(mockRootObject); expect(mockScope.rootObject).toEqual(mockRootObject);
@ -109,11 +109,11 @@ define(
it("rejects changes which fail validation", function () { it("rejects changes which fail validation", function () {
mockScope.structure = { validate: jasmine.createSpy('validate') }; mockScope.structure = { validate: jasmine.createSpy('validate') };
mockScope.structure.validate.andReturn(false); mockScope.structure.validate.and.returnValue(false);
// Pass selection change // Pass selection change
mockScope.$watch.mostRecentCall.args[1](mockDomainObject); mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
mockTimeout.mostRecentCall.args[0](); mockTimeout.calls.mostRecent().args[0]();
expect(mockScope.structure.validate).toHaveBeenCalled(); expect(mockScope.structure.validate).toHaveBeenCalled();
// Change should have been rejected // Change should have been rejected
@ -126,13 +126,13 @@ define(
['$setValidity'] ['$setValidity']
); );
mockScope.$watch.mostRecentCall.args[1](mockDomainObject); mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
mockTimeout.mostRecentCall.args[0](); mockTimeout.calls.mostRecent().args[0]();
expect(mockScope.ngModelController.$setValidity) expect(mockScope.ngModelController.$setValidity)
.toHaveBeenCalledWith(jasmine.any(String), true); .toHaveBeenCalledWith(jasmine.any(String), true);
mockScope.$watch.mostRecentCall.args[1](undefined); mockScope.$watch.calls.mostRecent().args[1](undefined);
mockTimeout.mostRecentCall.args[0](); mockTimeout.calls.mostRecent().args[0]();
expect(mockScope.ngModelController.$setValidity) expect(mockScope.ngModelController.$setValidity)
.toHaveBeenCalledWith(jasmine.any(String), false); .toHaveBeenCalledWith(jasmine.any(String), false);
}); });
@ -141,27 +141,27 @@ define(
var defaultRoot = "DEFAULT_ROOT"; var defaultRoot = "DEFAULT_ROOT";
beforeEach(function () { beforeEach(function () {
mockContext.getRoot.andReturn(undefined); mockContext.getRoot.and.returnValue(undefined);
getObjectsPromise.then.andCallFake(function (callback) { getObjectsPromise.then.and.callFake(function (callback) {
callback({'ROOT': defaultRoot}); callback({'ROOT': defaultRoot});
}); });
controller = new LocatorController(mockScope, mockTimeout, mockObjectService); controller = new LocatorController(mockScope, mockTimeout, mockObjectService);
}); });
it("provides a default context where none is available", function () { it("provides a default context where none is available", function () {
mockScope.$watch.mostRecentCall.args[1](mockDomainObject); mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
mockTimeout.mostRecentCall.args[0](); mockTimeout.calls.mostRecent().args[0]();
expect(mockScope.rootObject).toBe(defaultRoot); expect(mockScope.rootObject).toBe(defaultRoot);
}); });
it("does not issue redundant requests for the root object", function () { it("does not issue redundant requests for the root object", function () {
mockScope.$watch.mostRecentCall.args[1](mockDomainObject); mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
mockTimeout.mostRecentCall.args[0](); mockTimeout.calls.mostRecent().args[0]();
mockScope.$watch.mostRecentCall.args[1](undefined); mockScope.$watch.calls.mostRecent().args[1](undefined);
mockTimeout.mostRecentCall.args[0](); mockTimeout.calls.mostRecent().args[0]();
mockScope.$watch.mostRecentCall.args[1](mockDomainObject); mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
mockTimeout.mostRecentCall.args[0](); mockTimeout.calls.mostRecent().args[0]();
expect(mockObjectService.getObjects.calls.length) expect(mockObjectService.getObjects.calls.count())
.toEqual(1); .toEqual(1);
}); });

View File

@ -58,10 +58,10 @@ define(
mockEditAction = jasmine.createSpyObj('edit', ['getMetadata']); mockEditAction = jasmine.createSpyObj('edit', ['getMetadata']);
mockPropertiesAction = jasmine.createSpyObj('edit', ['getMetadata']); mockPropertiesAction = jasmine.createSpyObj('edit', ['getMetadata']);
mockDomainObject.getCapability.andCallFake(function (capability) { mockDomainObject.getCapability.and.callFake(function (capability) {
return capabilities[capability]; return capabilities[capability];
}); });
mockDomainObject.hasCapability.andCallFake(function (capability) { mockDomainObject.hasCapability.and.callFake(function (capability) {
return !!capabilities[capability]; return !!capabilities[capability];
}); });
@ -71,13 +71,13 @@ define(
plotView = { key: "plot", editable: false }; plotView = { key: "plot", editable: false };
testViews = []; testViews = [];
mockDomainObject.useCapability.andCallFake(function (c) { mockDomainObject.useCapability.and.callFake(function (c) {
// Provide test views, only for the view capability // Provide test views, only for the view capability
return c === 'view' && testViews; return c === 'view' && testViews;
}); });
mockEditAction.getMetadata.andReturn({ key: 'edit' }); mockEditAction.getMetadata.and.returnValue({ key: 'edit' });
mockPropertiesAction.getMetadata.andReturn({ key: 'properties' }); mockPropertiesAction.getMetadata.and.returnValue({ key: 'properties' });
testContext = { testContext = {
domainObject: mockDomainObject, domainObject: mockDomainObject,
@ -111,20 +111,20 @@ define(
it("disallows the edit action when object is already being" + it("disallows the edit action when object is already being" +
" edited", function () { " edited", function () {
testViews = [editableView]; testViews = [editableView];
mockEditorCapability.isEditContextRoot.andReturn(true); mockEditorCapability.isEditContextRoot.and.returnValue(true);
expect(policy.allow(mockEditAction, testContext)).toBe(false); expect(policy.allow(mockEditAction, testContext)).toBe(false);
}); });
it("allows editing of panels in plot view", function () { it("allows editing of panels in plot view", function () {
testViews = [plotView]; testViews = [plotView];
mockTypeCapability.getKey.andReturn('telemetry.panel'); mockTypeCapability.getKey.and.returnValue('telemetry.panel');
expect(policy.allow(mockEditAction, testContext)).toBe(true); expect(policy.allow(mockEditAction, testContext)).toBe(true);
}); });
it("disallows editing of plot view when object not a panel type", function () { it("disallows editing of plot view when object not a panel type", function () {
testViews = [plotView]; testViews = [plotView];
mockTypeCapability.getKey.andReturn('something.else'); mockTypeCapability.getKey.and.returnValue('something.else');
expect(policy.allow(mockEditAction, testContext)).toBe(false); expect(policy.allow(mockEditAction, testContext)).toBe(false);
}); });

View File

@ -41,20 +41,20 @@ define(
mockEditorCapability = jasmine.createSpyObj("editorCapability", ["isEditContextRoot", "inEditContext"]); mockEditorCapability = jasmine.createSpyObj("editorCapability", ["isEditContextRoot", "inEditContext"]);
navigatedObject = jasmine.createSpyObj("navigatedObject", ["hasCapability", "getCapability"]); navigatedObject = jasmine.createSpyObj("navigatedObject", ["hasCapability", "getCapability"]);
navigatedObject.getCapability.andReturn(mockEditorCapability); navigatedObject.getCapability.and.returnValue(mockEditorCapability);
navigatedObject.hasCapability.andReturn(false); navigatedObject.hasCapability.and.returnValue(false);
mockDomainObject = jasmine.createSpyObj("domainObject", ["hasCapability", "getCapability"]); mockDomainObject = jasmine.createSpyObj("domainObject", ["hasCapability", "getCapability"]);
mockDomainObject.hasCapability.andReturn(false); mockDomainObject.hasCapability.and.returnValue(false);
mockDomainObject.getCapability.andReturn(mockEditorCapability); mockDomainObject.getCapability.and.returnValue(mockEditorCapability);
navigationService = jasmine.createSpyObj("navigationService", ["getNavigation"]); navigationService = jasmine.createSpyObj("navigationService", ["getNavigation"]);
navigationService.getNavigation.andReturn(navigatedObject); navigationService.getNavigation.and.returnValue(navigatedObject);
metadata = {key: "move"}; metadata = {key: "move"};
mockAction = jasmine.createSpyObj("action", ["getMetadata"]); mockAction = jasmine.createSpyObj("action", ["getMetadata"]);
mockAction.getMetadata.andReturn(metadata); mockAction.getMetadata.and.returnValue(metadata);
context = {domainObject: mockDomainObject}; context = {domainObject: mockDomainObject};
@ -67,8 +67,8 @@ define(
it('Allows "window" action when navigated object in edit mode,' + it('Allows "window" action when navigated object in edit mode,' +
' but selected object not in edit mode ', function () { ' but selected object not in edit mode ', function () {
navigatedObject.hasCapability.andReturn(true); navigatedObject.hasCapability.and.returnValue(true);
mockEditorCapability.isEditContextRoot.andReturn(true); mockEditorCapability.isEditContextRoot.and.returnValue(true);
metadata.key = "window"; metadata.key = "window";
expect(policy.allow(mockAction, context)).toBe(true); expect(policy.allow(mockAction, context)).toBe(true);
}); });
@ -79,12 +79,12 @@ define(
var mockParent = jasmine.createSpyObj("parentObject", ["hasCapability"]), var mockParent = jasmine.createSpyObj("parentObject", ["hasCapability"]),
mockContextCapability = jasmine.createSpyObj("contextCapability", ["getParent"]); mockContextCapability = jasmine.createSpyObj("contextCapability", ["getParent"]);
mockParent.hasCapability.andReturn(true); mockParent.hasCapability.and.returnValue(true);
mockContextCapability.getParent.andReturn(mockParent); mockContextCapability.getParent.and.returnValue(mockParent);
navigatedObject.hasCapability.andReturn(true); navigatedObject.hasCapability.and.returnValue(true);
mockDomainObject.getCapability.andReturn(mockContextCapability); mockDomainObject.getCapability.and.returnValue(mockContextCapability);
mockDomainObject.hasCapability.andCallFake(function (capability) { mockDomainObject.hasCapability.and.callFake(function (capability) {
switch (capability) { switch (capability) {
case "editor": return false; case "editor": return false;
case "context": return true; case "context": return true;
@ -97,19 +97,19 @@ define(
it('Disallows "move" action when navigated object in edit mode,' + it('Disallows "move" action when navigated object in edit mode,' +
' but selected object not in edit mode ', function () { ' but selected object not in edit mode ', function () {
navigatedObject.hasCapability.andReturn(true); navigatedObject.hasCapability.and.returnValue(true);
mockEditorCapability.isEditContextRoot.andReturn(true); mockEditorCapability.isEditContextRoot.and.returnValue(true);
mockEditorCapability.inEditContext.andReturn(false); mockEditorCapability.inEditContext.and.returnValue(false);
metadata.key = "move"; metadata.key = "move";
expect(policy.allow(mockAction, context)).toBe(false); expect(policy.allow(mockAction, context)).toBe(false);
}); });
it('Disallows copy action when navigated object and' + it('Disallows copy action when navigated object and' +
' selected object in edit mode', function () { ' selected object in edit mode', function () {
navigatedObject.hasCapability.andReturn(true); navigatedObject.hasCapability.and.returnValue(true);
mockDomainObject.hasCapability.andReturn(true); mockDomainObject.hasCapability.and.returnValue(true);
mockEditorCapability.isEditContextRoot.andReturn(true); mockEditorCapability.isEditContextRoot.and.returnValue(true);
mockEditorCapability.inEditContext.andReturn(true); mockEditorCapability.inEditContext.and.returnValue(true);
metadata.key = "copy"; metadata.key = "copy";
expect(policy.allow(mockAction, context)).toBe(false); expect(policy.allow(mockAction, context)).toBe(false);

View File

@ -54,11 +54,11 @@ define(
mockPropertiesAction = jasmine.createSpyObj('properties', ['getMetadata']); mockPropertiesAction = jasmine.createSpyObj('properties', ['getMetadata']);
mockOtherAction = jasmine.createSpyObj('other', ['getMetadata']); mockOtherAction = jasmine.createSpyObj('other', ['getMetadata']);
mockEditAction.getMetadata.andReturn({ key: 'edit' }); mockEditAction.getMetadata.and.returnValue({ key: 'edit' });
mockPropertiesAction.getMetadata.andReturn({ key: 'properties' }); mockPropertiesAction.getMetadata.and.returnValue({ key: 'properties' });
mockOtherAction.getMetadata.andReturn({key: 'other'}); mockOtherAction.getMetadata.and.returnValue({key: 'other'});
mockDomainObject.getId.andReturn('test:testId'); mockDomainObject.getId.and.returnValue('test:testId');
testContext = { testContext = {
domainObject: mockDomainObject, domainObject: mockDomainObject,
@ -69,7 +69,7 @@ define(
}); });
it("Applies to edit action", function () { it("Applies to edit action", function () {
mockObjectAPI.getProvider.andReturn({}); mockObjectAPI.getProvider.and.returnValue({});
expect(mockObjectAPI.getProvider).not.toHaveBeenCalled(); expect(mockObjectAPI.getProvider).not.toHaveBeenCalled();
policy.allow(mockEditAction, testContext); policy.allow(mockEditAction, testContext);
@ -77,7 +77,7 @@ define(
}); });
it("Applies to properties action", function () { it("Applies to properties action", function () {
mockObjectAPI.getProvider.andReturn({}); mockObjectAPI.getProvider.and.returnValue({});
expect(mockObjectAPI.getProvider).not.toHaveBeenCalled(); expect(mockObjectAPI.getProvider).not.toHaveBeenCalled();
policy.allow(mockPropertiesAction, testContext); policy.allow(mockPropertiesAction, testContext);
@ -85,7 +85,7 @@ define(
}); });
it("does not apply to other actions", function () { it("does not apply to other actions", function () {
mockObjectAPI.getProvider.andReturn({}); mockObjectAPI.getProvider.and.returnValue({});
expect(mockObjectAPI.getProvider).not.toHaveBeenCalled(); expect(mockObjectAPI.getProvider).not.toHaveBeenCalled();
policy.allow(mockOtherAction, testContext); policy.allow(mockOtherAction, testContext);
@ -93,10 +93,10 @@ define(
}); });
it("Tests object provider for editability", function () { it("Tests object provider for editability", function () {
mockObjectAPI.getProvider.andReturn({}); mockObjectAPI.getProvider.and.returnValue({});
expect(policy.allow(mockEditAction, testContext)).toBe(false); expect(policy.allow(mockEditAction, testContext)).toBe(false);
expect(mockObjectAPI.getProvider).toHaveBeenCalled(); expect(mockObjectAPI.getProvider).toHaveBeenCalled();
mockObjectAPI.getProvider.andReturn({save: function () {}}); mockObjectAPI.getProvider.and.returnValue({save: function () {}});
expect(policy.allow(mockEditAction, testContext)).toBe(true); expect(policy.allow(mockEditAction, testContext)).toBe(true);
}); });
}); });

View File

@ -35,12 +35,12 @@ define(
'domainObject', 'domainObject',
['hasCapability', 'getCapability'] ['hasCapability', 'getCapability']
); );
mockDomainObject.getCapability.andReturn({ mockDomainObject.getCapability.and.returnValue({
inEditContext: function () { inEditContext: function () {
return true; return true;
} }
}); });
mockDomainObject.hasCapability.andCallFake(function (c) { mockDomainObject.hasCapability.and.callFake(function (c) {
return (c === 'editor') && testMode; return (c === 'editor') && testMode;
}); });

View File

@ -52,8 +52,8 @@ define([
'useCapability' 'useCapability'
]); ]);
domainObject.getId.andReturn('anId'); domainObject.getId.and.returnValue('anId');
domainObject.getModel.andReturn({name: 'anObject'}); domainObject.getModel.and.returnValue({name: 'anObject'});
representation = { representation = {
key: 'someRepresentation' key: 'someRepresentation'
@ -75,7 +75,7 @@ define([
expect(domainObject.useCapability) expect(domainObject.useCapability)
.toHaveBeenCalledWith('mutation', jasmine.any(Function)); .toHaveBeenCalledWith('mutation', jasmine.any(Function));
var mutateValue = domainObject.useCapability.calls[0].args[1](); var mutateValue = domainObject.useCapability.calls.all()[0].args[1]();
expect(mutateValue.configuration.someRepresentation) expect(mutateValue.configuration.someRepresentation)
.toEqual({some: 'config'}); .toEqual({some: 'config'});

View File

@ -41,13 +41,13 @@ define(
beforeEach(function () { beforeEach(function () {
mockOpenMCT = jasmine.createSpy('openmct', ['objects']); mockOpenMCT = jasmine.createSpy('openmct', ['objects']);
mockObjects = jasmine.createSpyObj('objects', ['observe']); mockObjects = jasmine.createSpyObj('objects', ['observe']);
mockObjects.observe.andReturn(); mockObjects.observe.and.returnValue();
mockOpenMCT.objects = mockObjects; mockOpenMCT.objects = mockObjects;
mockScope = jasmine.createSpyObj("$scope", [ mockScope = jasmine.createSpyObj("$scope", [
"$watchCollection", "$watchCollection",
"$on" "$on"
]); ]);
mockScope.$watchCollection.andReturn(); mockScope.$watchCollection.and.returnValue();
mockDomainObject = jasmine.createSpyObj("domainObject", [ mockDomainObject = jasmine.createSpyObj("domainObject", [
'identifier' 'identifier'
]); ]);

View File

@ -44,10 +44,10 @@ define(
testId = 'test-id'; testId = 'test-id';
mockPromise = jasmine.createSpyObj('promise', ['then']); mockPromise = jasmine.createSpyObj('promise', ['then']);
mockOnCommit.andReturn(mockPromise); mockOnCommit.and.returnValue(mockPromise);
mockOnCancel.andReturn(mockPromise); mockOnCancel.and.returnValue(mockPromise);
mockTransactionService.addToTransaction.andCallFake(function () { mockTransactionService.addToTransaction.and.callFake(function () {
var mockRemove = var mockRemove =
jasmine.createSpy('remove-' + mockRemoves.length); jasmine.createSpy('remove-' + mockRemoves.length);
mockRemoves.push(mockRemove); mockRemoves.push(mockRemove);
@ -59,7 +59,7 @@ define(
it("delegates isActive calls", function () { it("delegates isActive calls", function () {
[false, true].forEach(function (state) { [false, true].forEach(function (state) {
mockTransactionService.isActive.andReturn(state); mockTransactionService.isActive.and.returnValue(state);
expect(manager.isActive()).toBe(state); expect(manager.isActive()).toBe(state);
}); });
}); });
@ -84,12 +84,12 @@ define(
it("invokes passed-in callbacks from its own callbacks", function () { it("invokes passed-in callbacks from its own callbacks", function () {
expect(mockOnCommit).not.toHaveBeenCalled(); expect(mockOnCommit).not.toHaveBeenCalled();
mockTransactionService.addToTransaction mockTransactionService.addToTransaction
.mostRecentCall.args[0](); .calls.mostRecent().args[0]();
expect(mockOnCommit).toHaveBeenCalled(); expect(mockOnCommit).toHaveBeenCalled();
expect(mockOnCancel).not.toHaveBeenCalled(); expect(mockOnCancel).not.toHaveBeenCalled();
mockTransactionService.addToTransaction mockTransactionService.addToTransaction
.mostRecentCall.args[1](); .calls.mostRecent().args[1]();
expect(mockOnCancel).toHaveBeenCalled(); expect(mockOnCancel).toHaveBeenCalled();
}); });
@ -99,7 +99,7 @@ define(
jasmine.createSpy(), jasmine.createSpy(),
jasmine.createSpy() jasmine.createSpy()
); );
expect(mockTransactionService.addToTransaction.calls.length) expect(mockTransactionService.addToTransaction.calls.count())
.toEqual(1); .toEqual(1);
}); });
@ -109,7 +109,7 @@ define(
jasmine.createSpy(), jasmine.createSpy(),
jasmine.createSpy() jasmine.createSpy()
); );
expect(mockTransactionService.addToTransaction.calls.length) expect(mockTransactionService.addToTransaction.calls.count())
.toEqual(2); .toEqual(2);
}); });

View File

@ -40,7 +40,7 @@ define(
beforeEach(function () { beforeEach(function () {
mockQ = jasmine.createSpyObj("$q", ["all"]); mockQ = jasmine.createSpyObj("$q", ["all"]);
mockQ.all.andReturn(fastPromise()); mockQ.all.and.returnValue(fastPromise());
mockLog = jasmine.createSpyObj("$log", ["error"]); mockLog = jasmine.createSpyObj("$log", ["error"]);
transactionService = new TransactionService(mockQ, mockLog); transactionService = new TransactionService(mockQ, mockLog);
}); });

View File

@ -92,7 +92,7 @@ define(
describe("and an exception is encountered during commit", function () { describe("and an exception is encountered during commit", function () {
beforeEach(function () { beforeEach(function () {
mockCommit.andCallFake(function () { mockCommit.and.callFake(function () {
throw new Error("test error"); throw new Error("test error");
}); });
transaction.commit(); transaction.commit();

View File

@ -46,12 +46,12 @@ define([
splashElement.className = 'some-class-name'; splashElement.className = 'some-class-name';
$document.querySelectorAll.andReturn([splashElement]); $document.querySelectorAll.and.returnValue([splashElement]);
}); });
describe('when element exists', function () { describe('when element exists', function () {
beforeEach(function () { beforeEach(function () {
$document.querySelectorAll.andReturn([splashElement]); $document.querySelectorAll.and.returnValue([splashElement]);
return new SplashScreenManager([$document]); return new SplashScreenManager([$document]);
}); });
@ -69,14 +69,14 @@ define([
.not .not
.toHaveBeenCalled(); .toHaveBeenCalled();
splashElement.addEventListener.mostRecentCall.args[1](); splashElement.addEventListener.calls.mostRecent().args[1]();
expect(splashElement.parentNode.removeChild) expect(splashElement.parentNode.removeChild)
.toHaveBeenCalledWith(splashElement); .toHaveBeenCalledWith(splashElement);
}); });
}); });
it('does not error when element doesn\'t exist', function () { it('does not error when element doesn\'t exist', function () {
$document.querySelectorAll.andReturn([]); $document.querySelectorAll.and.returnValue([]);
function run() { function run() {
return new SplashScreenManager([$document]); return new SplashScreenManager([$document]);

View File

@ -52,14 +52,14 @@ define(
mockHead = jasmine.createSpyObj("head", ["append"]); mockHead = jasmine.createSpyObj("head", ["append"]);
mockElement = jasmine.createSpyObj("link", ["setAttribute"]); mockElement = jasmine.createSpyObj("link", ["setAttribute"]);
mockDocument.find.andReturn(mockHead); mockDocument.find.and.returnValue(mockHead);
mockPlainDocument.createElement.andReturn(mockElement); mockPlainDocument.createElement.and.returnValue(mockElement);
loader = new StyleSheetLoader(testStyleSheets, mockDocument); loader = new StyleSheetLoader(testStyleSheets, mockDocument);
}); });
it("appends one link per stylesheet extension", function () { it("appends one link per stylesheet extension", function () {
expect(mockHead.append.calls.length) expect(mockHead.append.calls.count())
.toEqual(testStyleSheets.length); .toEqual(testStyleSheets.length);
}); });

View File

@ -34,7 +34,7 @@ define(
"action" + index, "action" + index,
["perform", "getMetadata"] ["perform", "getMetadata"]
); );
action.getMetadata.andReturn(metadata); action.getMetadata.and.returnValue(metadata);
return action; return action;
} }
@ -61,7 +61,7 @@ define(
mockScope.action = mockActions; mockScope.action = mockActions;
mockScope.parameters = { category: "test" }; mockScope.parameters = { category: "test" };
mockActions.getActions.andReturn([ mockActions.getActions.and.returnValue([
{ group: "a", someKey: 0 }, { group: "a", someKey: 0 },
{ group: "a", someKey: 1 }, { group: "a", someKey: 1 },
{ group: "b", someKey: 2 }, { group: "b", someKey: 2 },
@ -74,7 +74,7 @@ define(
].map(mockAction)); ].map(mockAction));
// Call the watch // Call the watch
mockScope.$watch.mostRecentCall.args[1](); mockScope.$watch.calls.mostRecent().args[1]();
// Should have grouped and ungrouped actions in scope now // Should have grouped and ungrouped actions in scope now
expect(mockScope.groups.length).toEqual(2); expect(mockScope.groups.length).toEqual(2);
@ -85,7 +85,7 @@ define(
it("provides empty arrays when no action capability is available", function () { it("provides empty arrays when no action capability is available", function () {
// Call the watch // Call the watch
mockScope.$watch.mostRecentCall.args[1](); mockScope.$watch.calls.mostRecent().args[1]();
expect(mockScope.groups.length).toEqual(0); expect(mockScope.groups.length).toEqual(0);
expect(mockScope.ungrouped.length).toEqual(0); expect(mockScope.ungrouped.length).toEqual(0);

View File

@ -79,9 +79,9 @@ define(
it("deactivates and detaches listener on document click", function () { it("deactivates and detaches listener on document click", function () {
var callback, timeout; var callback, timeout;
controller.setState(true); controller.setState(true);
callback = mockDocument.on.mostRecentCall.args[1]; callback = mockDocument.on.calls.mostRecent().args[1];
callback(); callback();
timeout = mockTimeout.mostRecentCall.args[0]; timeout = mockTimeout.calls.mostRecent().args[0];
timeout(); timeout();
expect(controller.isActive()).toEqual(false); expect(controller.isActive()).toEqual(false);
expect(mockDocument.off).toHaveBeenCalledWith("mouseup", callback); expect(mockDocument.off).toHaveBeenCalledWith("mouseup", callback);

View File

@ -47,10 +47,10 @@ define(
mockScope.action = mockActions; mockScope.action = mockActions;
mockScope.parameters = { category: "test" }; mockScope.parameters = { category: "test" };
mockActions.getActions.andReturn(["a", "b", "c"]); mockActions.getActions.and.returnValue(["a", "b", "c"]);
// Call the watch // Call the watch
mockScope.$watch.mostRecentCall.args[1](); mockScope.$watch.calls.mostRecent().args[1]();
// Should have grouped and ungrouped actions in scope now // Should have grouped and ungrouped actions in scope now
expect(mockScope.menuActions.length).toEqual(3); expect(mockScope.menuActions.length).toEqual(3);

View File

@ -33,7 +33,7 @@ define(
controller; controller;
function fireWatch(expr, value) { function fireWatch(expr, value) {
mockScope.$watch.calls.forEach(function (call) { mockScope.$watch.calls.all().forEach(function (call) {
if (call.args[0] === expr) { if (call.args[0] === expr) {
call.args[1](value); call.args[1](value);
} }
@ -50,15 +50,15 @@ define(
'format' 'format'
]); ]);
mockFormatService.getFormat.andReturn(mockFormat); mockFormatService.getFormat.and.returnValue(mockFormat);
mockFormat.validate.andCallFake(function (text) { mockFormat.validate.and.callFake(function (text) {
return moment.utc(text, TEST_FORMAT).isValid(); return moment.utc(text, TEST_FORMAT).isValid();
}); });
mockFormat.parse.andCallFake(function (text) { mockFormat.parse.and.callFake(function (text) {
return moment.utc(text, TEST_FORMAT).valueOf(); return moment.utc(text, TEST_FORMAT).valueOf();
}); });
mockFormat.format.andCallFake(function (value) { mockFormat.format.and.callFake(function (value) {
return moment.utc(value).format(TEST_FORMAT); return moment.utc(value).format(TEST_FORMAT);
}); });
@ -159,8 +159,8 @@ define(
var newText = "2015-3-3 01:02:04", var newText = "2015-3-3 01:02:04",
oldValue = mockScope.ngModel.testField; oldValue = mockScope.ngModel.testField;
mockFormat.validate.andReturn(true); mockFormat.validate.and.returnValue(true);
mockFormat.parse.andReturn(42); mockFormat.parse.and.returnValue(42);
mockScope.textValue = newText; mockScope.textValue = newText;
fireWatch("textValue", newText); fireWatch("textValue", newText);
@ -176,7 +176,7 @@ define(
}); });
it("throws an error for unknown formats", function () { it("throws an error for unknown formats", function () {
mockFormatService.getFormat.andReturn(undefined); mockFormatService.getFormat.and.returnValue(undefined);
expect(function () { expect(function () {
fireWatch("structure.format", "some-format"); fireWatch("structure.format", "some-format");
}).toThrow(); }).toThrow();
@ -187,9 +187,9 @@ define(
testText = "some text"; testText = "some text";
beforeEach(function () { beforeEach(function () {
mockFormat.validate.andReturn(true); mockFormat.validate.and.returnValue(true);
mockFormat.parse.andReturn(testValue); mockFormat.parse.and.returnValue(testValue);
mockFormat.format.andReturn(testText); mockFormat.format.and.returnValue(testText);
}); });
it("parses user input", function () { it("parses user input", function () {

View File

@ -30,7 +30,7 @@ define(
controller; controller;
function fireWatch(expr, value) { function fireWatch(expr, value) {
mockScope.$watch.calls.forEach(function (call) { mockScope.$watch.calls.all().forEach(function (call) {
if (call.args[0] === expr) { if (call.args[0] === expr) {
call.args[1](value); call.args[1](value);
} }
@ -38,7 +38,7 @@ define(
} }
function fireWatchCollection(expr, value) { function fireWatchCollection(expr, value) {
mockScope.$watchCollection.calls.forEach(function (call) { mockScope.$watchCollection.calls.all().forEach(function (call) {
if (call.args[0] === expr) { if (call.args[0] === expr) {
call.args[1](value); call.args[1](value);
} }

View File

@ -53,7 +53,7 @@ define(
expect(mockScope.ngModel) expect(mockScope.ngModel)
.not.toHaveBeenCalledWith("some new value"); .not.toHaveBeenCalledWith("some new value");
// Fire the matching watcher // Fire the matching watcher
mockScope.$watch.calls.forEach(function (call) { mockScope.$watch.calls.all().forEach(function (call) {
if (call.args[0] === "getterSetter.value") { if (call.args[0] === "getterSetter.value") {
call.args[1](mockScope.getterSetter.value); call.args[1](mockScope.getterSetter.value);
} }
@ -64,11 +64,11 @@ define(
}); });
it("updates internal state when external changes are detected", function () { it("updates internal state when external changes are detected", function () {
mockScope.ngModel.andReturn("some other new value"); mockScope.ngModel.and.returnValue("some other new value");
// Verify precondition // Verify precondition
expect(mockScope.getterSetter.value).toBeUndefined(); expect(mockScope.getterSetter.value).toBeUndefined();
// Fire the matching watcher // Fire the matching watcher
mockScope.$watch.calls.forEach(function (call) { mockScope.$watch.calls.all().forEach(function (call) {
if (call.args[0] === "ngModel()") { if (call.args[0] === "ngModel()") {
call.args[1]("some other new value"); call.args[1]("some other new value");
} }

View File

@ -50,14 +50,14 @@ define(
"promise", "promise",
["then"] ["then"]
); );
mockObjectService.getObjects.andReturn(mockPromise); mockObjectService.getObjects.and.returnValue(mockPromise);
mockDomainObject = jasmine.createSpyObj( mockDomainObject = jasmine.createSpyObj(
"selectedObject", "selectedObject",
["hasCapability", "getCapability", "useCapability", "getModel"] ["hasCapability", "getCapability", "useCapability", "getModel"]
); );
mockDomainObject.getModel.andReturn({location: 'somewhere'}); mockDomainObject.getModel.and.returnValue({location: 'somewhere'});
mockDomainObject.hasCapability.andReturn(true); mockDomainObject.hasCapability.and.returnValue(true);
mockContextCapability = jasmine.createSpyObj( mockContextCapability = jasmine.createSpyObj(
"context capability", "context capability",
@ -68,7 +68,7 @@ define(
["isLink"] ["isLink"]
); );
mockDomainObject.getCapability.andCallFake(function (param) { mockDomainObject.getCapability.and.callFake(function (param) {
if (param === 'location') { if (param === 'location') {
return mockLocationCapability; return mockLocationCapability;
} else if (param === 'context') { } else if (param === 'context') {
@ -91,21 +91,21 @@ define(
}); });
it("looks for contextual parent objects", function () { it("looks for contextual parent objects", function () {
mockScope.$watch.mostRecentCall.args[1](); mockScope.$watch.calls.mostRecent().args[1]();
expect(mockContextCapability.getParent).toHaveBeenCalled(); expect(mockContextCapability.getParent).toHaveBeenCalled();
}); });
it("if link, looks for primary parent objects", function () { it("if link, looks for primary parent objects", function () {
mockLocationCapability.isLink.andReturn(true); mockLocationCapability.isLink.and.returnValue(true);
mockScope.$watch.mostRecentCall.args[1](); mockScope.$watch.calls.mostRecent().args[1]();
expect(mockDomainObject.getModel).toHaveBeenCalled(); expect(mockDomainObject.getModel).toHaveBeenCalled();
expect(mockObjectService.getObjects).toHaveBeenCalled(); expect(mockObjectService.getObjects).toHaveBeenCalled();
mockPromise.then.mostRecentCall.args[0]({'somewhere': mockDomainObject}); mockPromise.then.calls.mostRecent().args[0]({'somewhere': mockDomainObject});
}); });
it("gets metadata", function () { it("gets metadata", function () {
mockScope.$watch.mostRecentCall.args[1](); mockScope.$watch.calls.mostRecent().args[1]();
expect(mockDomainObject.useCapability).toHaveBeenCalledWith('metadata'); expect(mockDomainObject.useCapability).toHaveBeenCalledWith('metadata');
}); });
}); });

View File

@ -45,7 +45,7 @@ define(
'object-' + id, 'object-' + id,
['getId'] ['getId']
); );
mockObject.getId.andReturn(id); mockObject.getId.and.returnValue(id);
return mockObject; return mockObject;
} }
@ -72,8 +72,8 @@ define(
mockDomainObjects[id] = makeMockObject(id); mockDomainObjects[id] = makeMockObject(id);
}); });
mockDomainObject.getCapability.andReturn(mockType); mockDomainObject.getCapability.and.returnValue(mockType);
mockObjectService.getObjects.andReturn(promiseOf(mockDomainObjects)); mockObjectService.getObjects.and.returnValue(promiseOf(mockDomainObjects));
mockScope.field = "testField"; mockScope.field = "testField";
mockScope.ngModel = {}; mockScope.ngModel = {};
@ -91,27 +91,27 @@ define(
it("watches for changes in selection in left-hand tree", function () { it("watches for changes in selection in left-hand tree", function () {
var testObject = { a: 123, b: 456 }; var testObject = { a: 123, b: 456 };
// This test is sensitive to ordering of watch calls // This test is sensitive to ordering of watch calls
expect(mockScope.$watch.calls.length).toEqual(1); expect(mockScope.$watch.calls.count()).toEqual(1);
// Make sure we're watching the correct object // Make sure we're watching the correct object
controller.treeModel.selectedObject = testObject; controller.treeModel.selectedObject = testObject;
expect(mockScope.$watch.calls[0].args[0]()).toBe(testObject); expect(mockScope.$watch.calls.all()[0].args[0]()).toBe(testObject);
}); });
it("watches for changes in controlled property", function () { it("watches for changes in controlled property", function () {
var testValue = ["a", "b", 1, 2]; var testValue = ["a", "b", 1, 2];
// This test is sensitive to ordering of watch calls // This test is sensitive to ordering of watch calls
expect(mockScope.$watchCollection.calls.length).toEqual(1); expect(mockScope.$watchCollection.calls.count()).toEqual(1);
// Make sure we're watching the correct object // Make sure we're watching the correct object
mockScope.ngModel = { testField: testValue }; mockScope.ngModel = { testField: testValue };
expect(mockScope.$watchCollection.calls[0].args[0]()).toBe(testValue); expect(mockScope.$watchCollection.calls.all()[0].args[0]()).toBe(testValue);
}); });
it("rejects selection of incorrect types", function () { it("rejects selection of incorrect types", function () {
mockScope.structure = { type: "someType" }; mockScope.structure = { type: "someType" };
mockType.instanceOf.andReturn(false); mockType.instanceOf.and.returnValue(false);
controller.treeModel.selectedObject = mockDomainObject; controller.treeModel.selectedObject = mockDomainObject;
// Fire the watch // Fire the watch
mockScope.$watch.calls[0].args[1](mockDomainObject); mockScope.$watch.calls.all()[0].args[1](mockDomainObject);
// Should have cleared the selection // Should have cleared the selection
expect(controller.treeModel.selectedObject).toBeUndefined(); expect(controller.treeModel.selectedObject).toBeUndefined();
// Verify interaction (that instanceOf got a useful argument) // Verify interaction (that instanceOf got a useful argument)
@ -120,10 +120,10 @@ define(
it("permits selection of matching types", function () { it("permits selection of matching types", function () {
mockScope.structure = { type: "someType" }; mockScope.structure = { type: "someType" };
mockType.instanceOf.andReturn(true); mockType.instanceOf.and.returnValue(true);
controller.treeModel.selectedObject = mockDomainObject; controller.treeModel.selectedObject = mockDomainObject;
// Fire the watch // Fire the watch
mockScope.$watch.calls[0].args[1](mockDomainObject); mockScope.$watch.calls.all()[0].args[1](mockDomainObject);
// Should have preserved the selection // Should have preserved the selection
expect(controller.treeModel.selectedObject).toEqual(mockDomainObject); expect(controller.treeModel.selectedObject).toEqual(mockDomainObject);
// Verify interaction (that instanceOf got a useful argument) // Verify interaction (that instanceOf got a useful argument)
@ -133,11 +133,11 @@ define(
it("loads objects when the underlying list changes", function () { it("loads objects when the underlying list changes", function () {
var testIds = ["abc", "def", "xyz"]; var testIds = ["abc", "def", "xyz"];
// This test is sensitive to ordering of watch calls // This test is sensitive to ordering of watch calls
expect(mockScope.$watchCollection.calls.length).toEqual(1); expect(mockScope.$watchCollection.calls.count()).toEqual(1);
// Make sure we're watching the correct object // Make sure we're watching the correct object
mockScope.ngModel = { testField: testIds }; mockScope.ngModel = { testField: testIds };
// Fire the watch // Fire the watch
mockScope.$watchCollection.calls[0].args[1](testIds); mockScope.$watchCollection.calls.all()[0].args[1](testIds);
// Should have loaded the corresponding objects // Should have loaded the corresponding objects
expect(mockObjectService.getObjects).toHaveBeenCalledWith(testIds); expect(mockObjectService.getObjects).toHaveBeenCalledWith(testIds);
}); });
@ -169,8 +169,8 @@ define(
controller.select(mockDomainObjects.def); controller.select(mockDomainObjects.def);
controller.select(mockDomainObjects.abc); controller.select(mockDomainObjects.abc);
// Fire the watch for the id changes... // Fire the watch for the id changes...
mockScope.$watchCollection.calls[0].args[1]( mockScope.$watchCollection.calls.all()[0].args[1](
mockScope.$watchCollection.calls[0].args[0]() mockScope.$watchCollection.calls.all()[0].args[0]()
); );
// Should have loaded and exposed those objects // Should have loaded and exposed those objects
expect(controller.selected()).toEqual( expect(controller.selected()).toEqual(

View File

@ -39,7 +39,7 @@ define(
controller; controller;
function fireWatch(expr, value) { function fireWatch(expr, value) {
mockScope.$watch.calls.forEach(function (call) { mockScope.$watch.calls.all().forEach(function (call) {
if (call.args[0] === expr) { if (call.args[0] === expr) {
call.args[1](value); call.args[1](value);
} }
@ -47,7 +47,7 @@ define(
} }
function fireWatchCollection(expr, value) { function fireWatchCollection(expr, value) {
mockScope.$watchCollection.calls.forEach(function (call) { mockScope.$watchCollection.calls.all().forEach(function (call) {
if (call.args[0] === expr) { if (call.args[0] === expr) {
call.args[1](value); call.args[1](value);
} }
@ -73,9 +73,9 @@ define(
["validate", "format", "parse"] ["validate", "format", "parse"]
); );
mockFormatService.getFormat.andReturn(mockFormat); mockFormatService.getFormat.and.returnValue(mockFormat);
mockFormat.format.andCallFake(function (value) { mockFormat.format.and.callFake(function (value) {
return moment.utc(value).format("YYYY-MM-DD HH:mm:ss"); return moment.utc(value).format("YYYY-MM-DD HH:mm:ss");
}); });
@ -300,7 +300,7 @@ define(
}); });
it("throws an error for unknown formats", function () { it("throws an error for unknown formats", function () {
mockFormatService.getFormat.andReturn(undefined); mockFormatService.getFormat.and.returnValue(undefined);
expect(function () { expect(function () {
fireWatch("parameters.format", "some-format"); fireWatch("parameters.format", "some-format");
}).toThrow(); }).toThrow();

View File

@ -62,7 +62,7 @@ define(
// Expansion is tracked on a timeout, because too // Expansion is tracked on a timeout, because too
// much expansion can result in an unstable digest. // much expansion can result in an unstable digest.
expect(mockTimeout).toHaveBeenCalled(); expect(mockTimeout).toHaveBeenCalled();
mockTimeout.mostRecentCall.args[0](); mockTimeout.calls.mostRecent().args[0]();
expect(controller.hasBeenExpanded()).toBeTruthy(); expect(controller.hasBeenExpanded()).toBeTruthy();
controller.trackExpansion(); controller.trackExpansion();
@ -77,7 +77,7 @@ define(
), ),
obj = new TestObject("test-object", mockContext); obj = new TestObject("test-object", mockContext);
mockContext.getPath.andReturn([obj]); mockContext.getPath.and.returnValue([obj]);
// Verify precondition // Verify precondition
expect(controller.isSelected()).toBeFalsy(); expect(controller.isSelected()).toBeFalsy();
@ -86,7 +86,7 @@ define(
mockScope.domainObject = obj; mockScope.domainObject = obj;
// Invoke the watch with the new selection // Invoke the watch with the new selection
mockScope.$watch.calls[0].args[1](obj); mockScope.$watch.calls.all()[0].args[1](obj);
expect(controller.isSelected()).toBeTruthy(); expect(controller.isSelected()).toBeTruthy();
}); });
@ -103,9 +103,9 @@ define(
parent = new TestObject("parent", mockParentContext), parent = new TestObject("parent", mockParentContext),
child = new TestObject("child", mockChildContext); child = new TestObject("child", mockChildContext);
mockChildContext.getParent.andReturn(parent); mockChildContext.getParent.and.returnValue(parent);
mockChildContext.getPath.andReturn([parent, child]); mockChildContext.getPath.and.returnValue([parent, child]);
mockParentContext.getPath.andReturn([parent]); mockParentContext.getPath.and.returnValue([parent]);
// Set up such that we are on, but not at the end of, a path // Set up such that we are on, but not at the end of, a path
mockScope.ngModel = { selectedObject: child }; mockScope.ngModel = { selectedObject: child };
@ -113,13 +113,13 @@ define(
mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]); mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]);
// Invoke the watch with the new selection // Invoke the watch with the new selection
mockScope.$watch.calls[0].args[1](child); mockScope.$watch.calls.all()[0].args[1](child);
// Expansion is tracked on a timeout, because too // Expansion is tracked on a timeout, because too
// much expansion can result in an unstable digest. // much expansion can result in an unstable digest.
// Trigger that timeout. // Trigger that timeout.
expect(mockTimeout).toHaveBeenCalled(); expect(mockTimeout).toHaveBeenCalled();
mockTimeout.mostRecentCall.args[0](); mockTimeout.calls.mostRecent().args[0]();
expect(mockScope.toggle.setState).toHaveBeenCalledWith(true); expect(mockScope.toggle.setState).toHaveBeenCalledWith(true);
expect(controller.hasBeenExpanded()).toBeTruthy(); expect(controller.hasBeenExpanded()).toBeTruthy();
@ -139,9 +139,9 @@ define(
parent = new TestObject("parent", mockParentContext), parent = new TestObject("parent", mockParentContext),
child = new TestObject("child", mockChildContext); child = new TestObject("child", mockChildContext);
mockChildContext.getParent.andReturn(parent); mockChildContext.getParent.and.returnValue(parent);
mockChildContext.getPath.andReturn([child, child]); mockChildContext.getPath.and.returnValue([child, child]);
mockParentContext.getPath.andReturn([parent]); mockParentContext.getPath.and.returnValue([parent]);
// Set up such that we are on, but not at the end of, a path // Set up such that we are on, but not at the end of, a path
mockScope.ngModel = { selectedObject: child }; mockScope.ngModel = { selectedObject: child };
@ -149,7 +149,7 @@ define(
mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]); mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]);
// Invoke the watch with the new selection // Invoke the watch with the new selection
mockScope.$watch.calls[0].args[1](child); mockScope.$watch.calls.all()[0].args[1](child);
// Expansion is tracked on a timeout, because too // Expansion is tracked on a timeout, because too
// much expansion can result in an unstable digest. // much expansion can result in an unstable digest.
@ -172,9 +172,9 @@ define(
parent = new TestObject("parent", mockParentContext), parent = new TestObject("parent", mockParentContext),
child = new TestObject("child", undefined); child = new TestObject("child", undefined);
mockChildContext.getParent.andReturn(parent); mockChildContext.getParent.and.returnValue(parent);
mockChildContext.getPath.andReturn([parent, child]); mockChildContext.getPath.and.returnValue([parent, child]);
mockParentContext.getPath.andReturn([parent]); mockParentContext.getPath.and.returnValue([parent]);
// Set up such that we are on, but not at the end of, a path // Set up such that we are on, but not at the end of, a path
mockScope.ngModel = { selectedObject: child }; mockScope.ngModel = { selectedObject: child };
@ -182,7 +182,7 @@ define(
mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]); mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]);
// Invoke the watch with the new selection // Invoke the watch with the new selection
mockScope.$watch.calls[0].args[1](child); mockScope.$watch.calls.all()[0].args[1](child);
expect(mockScope.toggle.setState).not.toHaveBeenCalled(); expect(mockScope.toggle.setState).not.toHaveBeenCalled();
expect(controller.hasBeenExpanded()).toBeFalsy(); expect(controller.hasBeenExpanded()).toBeFalsy();

View File

@ -35,7 +35,7 @@ define(
beforeEach(function () { beforeEach(function () {
mockScope = jasmine.createSpyObj("$scope", ["$watch"]); mockScope = jasmine.createSpyObj("$scope", ["$watch"]);
mockTimeout = jasmine.createSpy("$timeout"); mockTimeout = jasmine.createSpy("$timeout");
mockTimeout.andCallFake(function (cb) { mockTimeout.and.callFake(function (cb) {
cb(); cb();
}); });
mockScope.ngModel = {}; mockScope.ngModel = {};
@ -60,11 +60,11 @@ define(
{ key: "c", name: "View C" }, { key: "c", name: "View C" },
{ key: "d", name: "View D" } { key: "d", name: "View D" }
]; ];
mockScope.$watch.mostRecentCall.args[1](views); mockScope.$watch.calls.mostRecent().args[1](views);
mockScope.ngModel.selected = views[1]; mockScope.ngModel.selected = views[1];
// Change the set of applicable views // Change the set of applicable views
mockScope.$watch.mostRecentCall.args[1]([ mockScope.$watch.calls.mostRecent().args[1]([
{ key: "a", name: "View A" }, { key: "a", name: "View A" },
{ key: "b", name: "View B" }, { key: "b", name: "View B" },
{ key: "x", name: "View X" } { key: "x", name: "View X" }
@ -81,11 +81,11 @@ define(
{ key: "c", name: "View C" }, { key: "c", name: "View C" },
{ key: "d", name: "View D" } { key: "d", name: "View D" }
]; ];
mockScope.$watch.mostRecentCall.args[1](views); mockScope.$watch.calls.mostRecent().args[1](views);
mockScope.ngModel.selected = views[1]; mockScope.ngModel.selected = views[1];
// Change the set of applicable views // Change the set of applicable views
mockScope.$watch.mostRecentCall.args[1]([ mockScope.$watch.calls.mostRecent().args[1]([
{ key: "a", name: "View A" }, { key: "a", name: "View A" },
{ key: "c", name: "View C" }, { key: "c", name: "View C" },
{ key: "x", name: "View X" } { key: "x", name: "View X" }
@ -102,7 +102,7 @@ define(
expect(mockTimeout).not.toHaveBeenCalled(); expect(mockTimeout).not.toHaveBeenCalled();
// Invoke the watch for set of views // Invoke the watch for set of views
mockScope.$watch.mostRecentCall.args[1]([]); mockScope.$watch.calls.mostRecent().args[1]([]);
// Should have run on a timeout // Should have run on a timeout
expect(mockTimeout).toHaveBeenCalled(); expect(mockTimeout).toHaveBeenCalled();

View File

@ -66,9 +66,9 @@ define(
height: 75 height: 75
}; };
mockElement[0] = mockPlainEl; mockElement[0] = mockPlainEl;
mockPlainEl.getBoundingClientRect.andReturn(testRect); mockPlainEl.getBoundingClientRect.and.returnValue(testRect);
mockDocument.find.andReturn(mockBody); mockDocument.find.and.returnValue(mockBody);
mctClickElsewhere = new MCTClickElsewhere(mockDocument); mctClickElsewhere = new MCTClickElsewhere(mockDocument);
mctClickElsewhere.link(mockScope, mockElement, testAttrs); mctClickElsewhere.link(mockScope, mockElement, testAttrs);
@ -80,14 +80,14 @@ define(
it("detaches listeners when destroyed", function () { it("detaches listeners when destroyed", function () {
expect(mockBody.off).not.toHaveBeenCalled(); expect(mockBody.off).not.toHaveBeenCalled();
mockScope.$on.calls.forEach(function (call) { mockScope.$on.calls.all().forEach(function (call) {
if (call.args[0] === '$destroy') { if (call.args[0] === '$destroy') {
call.args[1](); call.args[1]();
} }
}); });
expect(mockBody.off).toHaveBeenCalled(); expect(mockBody.off).toHaveBeenCalled();
expect(mockBody.off.mostRecentCall.args) expect(mockBody.off.calls.mostRecent().args)
.toEqual(mockBody.on.mostRecentCall.args); .toEqual(mockBody.on.calls.mostRecent().args);
}); });
it("listens for mousedown on the document's body", function () { it("listens for mousedown on the document's body", function () {
@ -97,7 +97,7 @@ define(
describe("when a click occurs outside the element's bounds", function () { describe("when a click occurs outside the element's bounds", function () {
beforeEach(function () { beforeEach(function () {
mockBody.on.mostRecentCall.args[1](testEvent( mockBody.on.calls.mostRecent().args[1](testEvent(
testRect.left + testRect.width + 10, testRect.left + testRect.width + 10,
testRect.top + testRect.height + 10 testRect.top + testRect.height + 10
)); ));
@ -105,7 +105,7 @@ define(
it("triggers an evaluation of its related Angular expression", function () { it("triggers an evaluation of its related Angular expression", function () {
expect(mockScope.$apply).toHaveBeenCalled(); expect(mockScope.$apply).toHaveBeenCalled();
mockScope.$apply.mostRecentCall.args[0](); mockScope.$apply.calls.mostRecent().args[0]();
expect(mockScope.$eval) expect(mockScope.$eval)
.toHaveBeenCalledWith(testAttrs.mctClickElsewhere); .toHaveBeenCalledWith(testAttrs.mctClickElsewhere);
}); });
@ -113,7 +113,7 @@ define(
describe("when a click occurs within the element's bounds", function () { describe("when a click occurs within the element's bounds", function () {
beforeEach(function () { beforeEach(function () {
mockBody.on.mostRecentCall.args[1](testEvent( mockBody.on.calls.mostRecent().args[1](testEvent(
testRect.left + testRect.width / 2, testRect.left + testRect.width / 2,
testRect.top + testRect.height / 2 testRect.top + testRect.height / 2
)); ));

View File

@ -61,8 +61,8 @@ define(
mctDragUp: "ending a drag" mctDragUp: "ending a drag"
}; };
mockDocument.find.andReturn(mockBody); mockDocument.find.and.returnValue(mockBody);
mockAgentService.isMobile.andReturn(true); mockAgentService.isMobile.and.returnValue(true);
mctDrag = new MCTDrag(mockDocument, mockAgentService); mctDrag = new MCTDrag(mockDocument, mockAgentService);
mctDrag.link(mockScope, mockElement, testAttrs); mctDrag.link(mockScope, mockElement, testAttrs);
@ -84,7 +84,7 @@ define(
it("invokes mctDragDown when dragging begins", function () { it("invokes mctDragDown when dragging begins", function () {
var event = testEvent(42, 60); var event = testEvent(42, 60);
mockElement.on.mostRecentCall.args[1](event); mockElement.on.calls.mostRecent().args[1](event);
expect(mockScope.$eval).toHaveBeenCalledWith( expect(mockScope.$eval).toHaveBeenCalledWith(
testAttrs.mctDragDown, testAttrs.mctDragDown,
{ delta: [0, 0], $event: event } { delta: [0, 0], $event: event }
@ -92,7 +92,7 @@ define(
}); });
it("listens for touchmove after dragging begins", function () { it("listens for touchmove after dragging begins", function () {
mockElement.on.mostRecentCall.args[1](testEvent(42, 60)); mockElement.on.calls.mostRecent().args[1](testEvent(42, 60));
expect(mockBody.on).toHaveBeenCalledWith( expect(mockBody.on).toHaveBeenCalledWith(
"touchmove", "touchmove",
jasmine.any(Function) jasmine.any(Function)
@ -106,10 +106,10 @@ define(
it("invokes mctDrag expression during drag", function () { it("invokes mctDrag expression during drag", function () {
var event; var event;
mockElement.on.mostRecentCall.args[1](testEvent(42, 60)); mockElement.on.calls.mostRecent().args[1](testEvent(42, 60));
// Find and invoke the touchmove listener // Find and invoke the touchmove listener
mockBody.on.calls.forEach(function (call) { mockBody.on.calls.all().forEach(function (call) {
if (call.args[0] === 'touchmove') { if (call.args[0] === 'touchmove') {
call.args[1](event = testEvent(52, 200)); call.args[1](event = testEvent(52, 200));
} }
@ -125,16 +125,16 @@ define(
it("invokes mctDragUp expression after drag", function () { it("invokes mctDragUp expression after drag", function () {
var event; var event;
mockElement.on.mostRecentCall.args[1](testEvent(42, 60)); mockElement.on.calls.mostRecent().args[1](testEvent(42, 60));
// Find and invoke the touchmove listener // Find and invoke the touchmove listener
mockBody.on.calls.forEach(function (call) { mockBody.on.calls.all().forEach(function (call) {
if (call.args[0] === 'touchmove') { if (call.args[0] === 'touchmove') {
call.args[1](testEvent(52, 200)); call.args[1](testEvent(52, 200));
} }
}); });
// Find and invoke the touchmove listener // Find and invoke the touchmove listener
mockBody.on.calls.forEach(function (call) { mockBody.on.calls.all().forEach(function (call) {
if (call.args[0] === 'touchend') { if (call.args[0] === 'touchend') {
call.args[1](event = testEvent(40, 71)); call.args[1](event = testEvent(40, 71));
} }
@ -189,8 +189,8 @@ define(
mctDragUp: "ending a drag" mctDragUp: "ending a drag"
}; };
mockDocument.find.andReturn(mockBody); mockDocument.find.and.returnValue(mockBody);
mockAgentService.isMobile.andReturn(false); mockAgentService.isMobile.and.returnValue(false);
mctDrag = new MCTDrag(mockDocument, mockAgentService); mctDrag = new MCTDrag(mockDocument, mockAgentService);
mctDrag.link(mockScope, mockElement, testAttrs); mctDrag.link(mockScope, mockElement, testAttrs);
@ -212,7 +212,7 @@ define(
it("invokes mctDragDown when dragging begins", function () { it("invokes mctDragDown when dragging begins", function () {
var event = testEvent(42, 60); var event = testEvent(42, 60);
mockElement.on.mostRecentCall.args[1](event); mockElement.on.calls.mostRecent().args[1](event);
expect(mockScope.$eval).toHaveBeenCalledWith( expect(mockScope.$eval).toHaveBeenCalledWith(
testAttrs.mctDragDown, testAttrs.mctDragDown,
{ delta: [0, 0], $event: event } { delta: [0, 0], $event: event }
@ -220,7 +220,7 @@ define(
}); });
it("listens for mousemove after dragging begins", function () { it("listens for mousemove after dragging begins", function () {
mockElement.on.mostRecentCall.args[1](testEvent(42, 60)); mockElement.on.calls.mostRecent().args[1](testEvent(42, 60));
expect(mockBody.on).toHaveBeenCalledWith( expect(mockBody.on).toHaveBeenCalledWith(
"mousemove", "mousemove",
jasmine.any(Function) jasmine.any(Function)
@ -234,10 +234,10 @@ define(
it("invokes mctDrag expression during drag", function () { it("invokes mctDrag expression during drag", function () {
var event; var event;
mockElement.on.mostRecentCall.args[1](testEvent(42, 60)); mockElement.on.calls.mostRecent().args[1](testEvent(42, 60));
// Find and invoke the mousemove listener // Find and invoke the mousemove listener
mockBody.on.calls.forEach(function (call) { mockBody.on.calls.all().forEach(function (call) {
if (call.args[0] === 'mousemove') { if (call.args[0] === 'mousemove') {
call.args[1](event = testEvent(52, 200)); call.args[1](event = testEvent(52, 200));
} }
@ -253,16 +253,16 @@ define(
it("invokes mctDragUp expression after drag", function () { it("invokes mctDragUp expression after drag", function () {
var event; var event;
mockElement.on.mostRecentCall.args[1](testEvent(42, 60)); mockElement.on.calls.mostRecent().args[1](testEvent(42, 60));
// Find and invoke the mousemove listener // Find and invoke the mousemove listener
mockBody.on.calls.forEach(function (call) { mockBody.on.calls.all().forEach(function (call) {
if (call.args[0] === 'mousemove') { if (call.args[0] === 'mousemove') {
call.args[1](testEvent(52, 200)); call.args[1](testEvent(52, 200));
} }
}); });
// Find and invoke the mousemove listener // Find and invoke the mousemove listener
mockBody.on.calls.forEach(function (call) { mockBody.on.calls.all().forEach(function (call) {
if (call.args[0] === 'mouseup') { if (call.args[0] === 'mouseup') {
call.args[1](event = testEvent(40, 71)); call.args[1](event = testEvent(40, 71));
} }

View File

@ -78,14 +78,14 @@ define(
height: 75 height: 75
}; };
mockCompile.andCallFake(function () { mockCompile.and.callFake(function () {
var mockFn = jasmine.createSpy(); var mockFn = jasmine.createSpy();
mockFn.andReturn(mockNewElement); mockFn.and.returnValue(mockNewElement);
return mockFn; return mockFn;
}); });
mockElement.parent.andReturn([mockParentEl]); mockElement.parent.and.returnValue([mockParentEl]);
mockParentEl.getBoundingClientRect.andReturn(testRect); mockParentEl.getBoundingClientRect.and.returnValue(testRect);
mockPopupService.display.andReturn(mockPopup); mockPopupService.display.and.returnValue(mockPopup);
mctPopup = new MCTPopup(mockCompile, mockPopupService); mctPopup = new MCTPopup(mockCompile, mockPopupService);
@ -113,14 +113,14 @@ define(
it("displays transcluded content", function () { it("displays transcluded content", function () {
var mockClone = var mockClone =
jasmine.createSpyObj('clone', JQLITE_METHODS); jasmine.createSpyObj('clone', JQLITE_METHODS);
mockTransclude.mostRecentCall.args[0](mockClone); mockTransclude.calls.mostRecent().args[0](mockClone);
expect(mockNewElement.append) expect(mockNewElement.append)
.toHaveBeenCalledWith(mockClone); .toHaveBeenCalledWith(mockClone);
}); });
it("is removed when its containing scope is destroyed", function () { it("is removed when its containing scope is destroyed", function () {
expect(mockPopup.dismiss).not.toHaveBeenCalled(); expect(mockPopup.dismiss).not.toHaveBeenCalled();
mockScope.$on.calls.forEach(function (call) { mockScope.$on.calls.all().forEach(function (call) {
if (call.args[0] === '$destroy') { if (call.args[0] === '$destroy') {
call.args[1](); call.args[1]();
} }

View File

@ -73,7 +73,7 @@ define(
); );
// Fire the timeout // Fire the timeout
mockTimeout.mostRecentCall.args[0](); mockTimeout.calls.mostRecent().args[0]();
// Should have triggered an evaluation of mctResize // Should have triggered an evaluation of mctResize
// with the new width & height // with the new width & height
@ -91,56 +91,56 @@ define(
.toHaveBeenCalledWith("$destroy", jasmine.any(Function)); .toHaveBeenCalledWith("$destroy", jasmine.any(Function));
// Should have scheduled the first timeout // Should have scheduled the first timeout
expect(mockTimeout.calls.length).toEqual(1); expect(mockTimeout.calls.count()).toEqual(1);
// Fire the timeout // Fire the timeout
mockTimeout.mostRecentCall.args[0](); mockTimeout.calls.mostRecent().args[0]();
// Should have scheduled another timeout // Should have scheduled another timeout
expect(mockTimeout.calls.length).toEqual(2); expect(mockTimeout.calls.count()).toEqual(2);
// Broadcast a destroy event // Broadcast a destroy event
mockScope.$on.mostRecentCall.args[1](); mockScope.$on.calls.mostRecent().args[1]();
testElement.offsetWidth = 300; testElement.offsetWidth = 300;
testElement.offsetHeight = 350; testElement.offsetHeight = 350;
mockScope.$eval.reset(); mockScope.$eval.calls.reset();
// Fire the timeout // Fire the timeout
mockTimeout.mostRecentCall.args[0](); mockTimeout.calls.mostRecent().args[0]();
// Should NOT have scheduled another timeout // Should NOT have scheduled another timeout
expect(mockTimeout.calls.length).toEqual(2); expect(mockTimeout.calls.count()).toEqual(2);
expect(mockScope.$eval).not.toHaveBeenCalled(); expect(mockScope.$eval).not.toHaveBeenCalled();
}); });
it("triggers a digest cycle when size changes", function () { it("triggers a digest cycle when size changes", function () {
var applyCount; var applyCount;
mctResize.link(mockScope, [testElement], testAttrs); mctResize.link(mockScope, [testElement], testAttrs);
applyCount = mockScope.$apply.calls.length; applyCount = mockScope.$apply.calls.count();
// Change the element's apparent size // Change the element's apparent size
testElement.offsetWidth = 300; testElement.offsetWidth = 300;
testElement.offsetHeight = 350; testElement.offsetHeight = 350;
// Fire the timeout // Fire the timeout
mockTimeout.mostRecentCall.args[0](); mockTimeout.calls.mostRecent().args[0]();
// No more apply calls // No more apply calls
expect(mockScope.$apply.calls.length) expect(mockScope.$apply.calls.count())
.toBeGreaterThan(applyCount); .toBeGreaterThan(applyCount);
}); });
it("does not trigger a digest cycle when size does not change", function () { it("does not trigger a digest cycle when size does not change", function () {
var applyCount; var applyCount;
mctResize.link(mockScope, [testElement], testAttrs); mctResize.link(mockScope, [testElement], testAttrs);
applyCount = mockScope.$apply.calls.length; applyCount = mockScope.$apply.calls.count();
// Fire the timeout // Fire the timeout
mockTimeout.mostRecentCall.args[0](); mockTimeout.calls.mostRecent().args[0]();
// No more apply calls // No more apply calls
expect(mockScope.$apply.calls.length).toEqual(applyCount); expect(mockScope.$apply.calls.count()).toEqual(applyCount);
}); });
}); });

View File

@ -49,7 +49,7 @@ define(
mockElement = [{ testProperty: 42 }]; mockElement = [{ testProperty: 42 }];
mockElement.on = jasmine.createSpy('on'); mockElement.on = jasmine.createSpy('on');
mockParse.andReturn(mockParsed); mockParse.and.returnValue(mockParsed);
testAttrs = {}; testAttrs = {};
testAttrs[ATTRIBUTE] = EXPRESSION; testAttrs[ATTRIBUTE] = EXPRESSION;
@ -76,7 +76,7 @@ define(
jasmine.any(Function) jasmine.any(Function)
); );
// Should have been only watch (other tests need this to be true) // Should have been only watch (other tests need this to be true)
expect(mockScope.$watch.calls.length).toEqual(1); expect(mockScope.$watch.calls.count()).toEqual(1);
}); });
it("listens for scroll events", function () { it("listens for scroll events", function () {
@ -85,7 +85,7 @@ define(
jasmine.any(Function) jasmine.any(Function)
); );
// Should have been only listener (other tests need this to be true) // Should have been only listener (other tests need this to be true)
expect(mockElement.on.calls.length).toEqual(1); expect(mockElement.on.calls.count()).toEqual(1);
}); });
it("publishes initial scroll state", function () { it("publishes initial scroll state", function () {
@ -94,13 +94,13 @@ define(
}); });
it("updates scroll state when scope changes", function () { it("updates scroll state when scope changes", function () {
mockScope.$watch.mostRecentCall.args[1](64); mockScope.$watch.calls.mostRecent().args[1](64);
expect(mockElement[0].testProperty).toEqual(64); expect(mockElement[0].testProperty).toEqual(64);
}); });
it("updates scope when scroll state changes", function () { it("updates scope when scroll state changes", function () {
mockElement[0].testProperty = 12321; mockElement[0].testProperty = 12321;
mockElement.on.mostRecentCall.args[1]({ target: mockElement[0] }); mockElement.on.calls.mostRecent().args[1]({ target: mockElement[0] });
expect(mockParsed.assign).toHaveBeenCalledWith(mockScope, 12321); expect(mockParsed.assign).toHaveBeenCalledWith(mockScope, 12321);
expect(mockScope.$apply).toHaveBeenCalledWith(EXPRESSION); expect(mockScope.$apply).toHaveBeenCalledWith(EXPRESSION);
}); });

View File

@ -49,7 +49,7 @@ define(
mockInterval.cancel = jasmine.createSpy('mockCancel'); mockInterval.cancel = jasmine.createSpy('mockCancel');
mockParsed = jasmine.createSpy('parsed'); mockParsed = jasmine.createSpy('parsed');
mockParsed.assign = jasmine.createSpy('assign'); mockParsed.assign = jasmine.createSpy('assign');
mockParse.andReturn(mockParsed); mockParse.and.returnValue(mockParsed);
mockWindow.localStorage = { mockWindow.localStorage = {
store: {}, store: {},
@ -84,7 +84,7 @@ define(
controller; controller;
function fireOn(eventType) { function fireOn(eventType) {
mockScope.$on.calls.forEach(function (call) { mockScope.$on.calls.all().forEach(function (call) {
if (call.args[0] === eventType) { if (call.args[0] === eventType) {
call.args[1](); call.args[1]();
} }
@ -106,12 +106,12 @@ define(
mockSecondPane = mockSecondPane =
jasmine.createSpyObj('secondPane', JQLITE_METHODS); jasmine.createSpyObj('secondPane', JQLITE_METHODS);
mockElement.children.andReturn(mockChildren); mockElement.children.and.returnValue(mockChildren);
mockElement[0] = { mockElement[0] = {
offsetWidth: 12321, offsetWidth: 12321,
offsetHeight: 45654 offsetHeight: 45654
}; };
mockChildren.eq.andCallFake(function (i) { mockChildren.eq.and.callFake(function (i) {
return [mockFirstPane, mockSplitter, mockSecondPane][i]; return [mockFirstPane, mockSplitter, mockSecondPane][i];
}); });
mockFirstPane[0] = { offsetWidth: 123, offsetHeight: 456 }; mockFirstPane[0] = { offsetWidth: 123, offsetHeight: 456 };
@ -135,7 +135,7 @@ define(
}); });
it("sets an interval which does not trigger digests", function () { it("sets an interval which does not trigger digests", function () {
expect(mockInterval.mostRecentCall.args[3]).toBe(false); expect(mockInterval.calls.mostRecent().args[3]).toBe(false);
}); });
it("exposes its splitter's initial position", function () { it("exposes its splitter's initial position", function () {
@ -202,7 +202,7 @@ define(
expect(controller.position()).not.toEqual( expect(controller.position()).not.toEqual(
mockFirstPane[0].offsetWidth mockFirstPane[0].offsetWidth
); );
mockInterval.mostRecentCall.args[0](); mockInterval.calls.mostRecent().args[0]();
expect(controller.position()).toEqual( expect(controller.position()).toEqual(
mockFirstPane[0].offsetWidth mockFirstPane[0].offsetWidth
); );

View File

@ -78,8 +78,8 @@ define(
beforeEach(function () { beforeEach(function () {
testPosition = 12321; testPosition = 12321;
mockSplitPane.position.andReturn(testPosition); mockSplitPane.position.and.returnValue(testPosition);
mockSplitPane.anchor.andReturn({ mockSplitPane.anchor.and.returnValue({
orientation: 'vertical', orientation: 'vertical',
reversed: false reversed: false
}); });

View File

@ -38,8 +38,8 @@ define([
'getCapability', 'getCapability',
'hasCapability' 'hasCapability'
]); ]);
mockDomainObject.getId.andReturn(id); mockDomainObject.getId.and.returnValue(id);
mockDomainObject.getModel.andReturn({}); mockDomainObject.getModel.and.returnValue({});
return mockDomainObject; return mockDomainObject;
} }
@ -51,8 +51,8 @@ define([
mockParse = jasmine.createSpy('$parse'); mockParse = jasmine.createSpy('$parse');
mockExpr = jasmine.createSpy('expr'); mockExpr = jasmine.createSpy('expr');
mockExpr.assign = jasmine.createSpy('assign'); mockExpr.assign = jasmine.createSpy('assign');
mockParse.andReturn(mockExpr); mockParse.and.returnValue(mockExpr);
spyOn(TreeView.prototype, 'observe').andCallThrough(); spyOn(TreeView.prototype, 'observe').and.callThrough();
mctTree = new MCTTree(mockParse, mockGestureService); mctTree = new MCTTree(mockParse, mockGestureService);
}); });
@ -118,7 +118,7 @@ define([
it("does not trigger $apply during $watches", function () { it("does not trigger $apply during $watches", function () {
mockScope.mctObject = makeMockDomainObject('root'); mockScope.mctObject = makeMockDomainObject('root');
mockScope.mctMode = makeMockDomainObject('selection'); mockScope.mctMode = makeMockDomainObject('selection');
mockScope.$watch.calls.forEach(function (call) { mockScope.$watch.calls.all().forEach(function (call) {
call.args[1](mockScope[call.args[0]]); call.args[1](mockScope[call.args[0]]);
}); });
expect(mockScope.$apply).not.toHaveBeenCalled(); expect(mockScope.$apply).not.toHaveBeenCalled();
@ -129,7 +129,7 @@ define([
return; return;
} }
// White-boxy; we know this is the setter for the tree's value // White-boxy; we know this is the setter for the tree's value
var treeValueFn = TreeView.prototype.observe.calls[0].args[0]; var treeValueFn = TreeView.prototype.observe.calls.all()[0].args[0];
mockScope.mctObject = makeMockDomainObject('root'); mockScope.mctObject = makeMockDomainObject('root');
mockScope.mctMode = makeMockDomainObject('selection'); mockScope.mctMode = makeMockDomainObject('selection');

View File

@ -41,7 +41,7 @@ define(
'remove' 'remove'
]); ]);
mockDocument.find.andCallFake(function (query) { mockDocument.find.and.callFake(function (query) {
return query === 'body' && mockBody; return query === 'body' && mockBody;
}); });

View File

@ -60,25 +60,25 @@ define(
// The mockContext is set a path // The mockContext is set a path
// for the mockDomainObject // for the mockDomainObject
mockContext.getPath.andReturn( mockContext.getPath.and.returnValue(
[mockDomainObject] [mockDomainObject]
); );
// view capability used with the testviews made // view capability used with the testviews made
mockDomainObject.useCapability.andCallFake(function (c) { mockDomainObject.useCapability.and.callFake(function (c) {
return (c === 'view') && testViews; return (c === 'view') && testViews;
}); });
// context capability used with the mockContext created // context capability used with the mockContext created
// so the variables including context in the urlFor are // so the variables including context in the urlFor are
// initialized and reached // initialized and reached
mockDomainObject.getCapability.andCallFake(function (c) { mockDomainObject.getCapability.and.callFake(function (c) {
return c === 'context' && mockContext; return c === 'context' && mockContext;
}); });
// Uses the mockLocation to get the current // Uses the mockLocation to get the current
// "mock" website's view // "mock" website's view
mockLocation.search.andReturn({ view: 'def' }); mockLocation.search.and.returnValue({ view: 'def' });
urlService = new UrlService(mockLocation); urlService = new UrlService(mockLocation);
}); });

View File

@ -46,15 +46,15 @@ define([
'useCapability' 'useCapability'
] ]
); );
mockDomainObj.getId.andReturn(id); mockDomainObj.getId.and.returnValue(id);
mockDomainObj.getModel.andReturn(model); mockDomainObj.getModel.and.returnValue(model);
mockDomainObj.hasCapability.andCallFake(function (c) { mockDomainObj.hasCapability.and.callFake(function (c) {
return !!(capabilities[c]); return !!(capabilities[c]);
}); });
mockDomainObj.getCapability.andCallFake(function (c) { mockDomainObj.getCapability.and.callFake(function (c) {
return capabilities[c]; return capabilities[c];
}); });
mockDomainObj.useCapability.andCallFake(function (c) { mockDomainObj.useCapability.and.callFake(function (c) {
return capabilities[c] && capabilities[c].invoke(); return capabilities[c] && capabilities[c].invoke();
}); });
return mockDomainObj; return mockDomainObj;
@ -68,11 +68,11 @@ define([
mockGestureHandle = jasmine.createSpyObj('gestures', ['destroy']); mockGestureHandle = jasmine.createSpyObj('gestures', ['destroy']);
mockGestureService.attachGestures.andReturn(mockGestureHandle); mockGestureService.attachGestures.and.returnValue(mockGestureHandle);
mockMutation = jasmine.createSpyObj('mutation', ['listen']); mockMutation = jasmine.createSpyObj('mutation', ['listen']);
mockUnlisten = jasmine.createSpy('unlisten'); mockUnlisten = jasmine.createSpy('unlisten');
mockMutation.listen.andReturn(mockUnlisten); mockMutation.listen.and.returnValue(mockUnlisten);
testCapabilities = { mutation: mockMutation }; testCapabilities = { mutation: mockMutation };
@ -102,7 +102,7 @@ define([
var mockStatus = var mockStatus =
jasmine.createSpyObj('status', ['listen', 'list']); jasmine.createSpyObj('status', ['listen', 'list']);
mockStatus.list.andReturn([]); mockStatus.list.and.returnValue([]);
return { return {
context: jasmine.createSpyObj('context', ['getPath']), context: jasmine.createSpyObj('context', ['getPath']),
@ -113,16 +113,6 @@ define([
}; };
} }
function waitForCompositionCallback() {
var calledBack = false;
testCapabilities.composition.invoke().then(function () {
calledBack = true;
});
waitsFor(function () {
return calledBack;
});
}
beforeEach(function () { beforeEach(function () {
mockComposition = ['a', 'b', 'c'].map(function (id) { mockComposition = ['a', 'b', 'c'].map(function (id) {
var testCaps = makeGenericCapabilities(), var testCaps = makeGenericCapabilities(),
@ -130,7 +120,7 @@ define([
makeMockDomainObject(id, {}, testCaps); makeMockDomainObject(id, {}, testCaps);
testCaps.context.getPath testCaps.context.getPath
.andReturn([mockDomainObject, mockChild]); .and.returnValue([mockDomainObject, mockChild]);
return mockChild; return mockChild;
}); });
@ -138,10 +128,10 @@ define([
testCapabilities.composition = testCapabilities.composition =
jasmine.createSpyObj('composition', ['invoke']); jasmine.createSpyObj('composition', ['invoke']);
testCapabilities.composition.invoke testCapabilities.composition.invoke
.andReturn(Promise.resolve(mockComposition)); .and.returnValue(Promise.resolve(mockComposition));
treeView.model(mockDomainObject); treeView.model(mockDomainObject);
waitForCompositionCallback(); return testCapabilities.composition.invoke();
}); });
it("adds one node per composition element", function () { it("adds one node per composition element", function () {
@ -158,8 +148,8 @@ define([
beforeEach(function () { beforeEach(function () {
mockComposition.pop(); mockComposition.pop();
testCapabilities.mutation.listen testCapabilities.mutation.listen
.mostRecentCall.args[0](mockDomainObject.getModel()); .calls.mostRecent().args[0](mockDomainObject.getModel());
waitForCompositionCallback(); return testCapabilities.composition.invoke();
}); });
it("continues to show one node per composition element", function () { it("continues to show one node per composition element", function () {
@ -219,38 +209,30 @@ define([
mockNewChild = mockNewChild =
makeMockDomainObject('d', {}, newCapabilities), makeMockDomainObject('d', {}, newCapabilities),
mockGrandchild = mockGrandchild =
makeMockDomainObject('gc', {}, gcCapabilities), makeMockDomainObject('gc', {}, gcCapabilities);
calledBackInner = false;
newCapabilities.composition = newCapabilities.composition =
jasmine.createSpyObj('composition', ['invoke']); jasmine.createSpyObj('composition', ['invoke']);
newCapabilities.composition.invoke newCapabilities.composition.invoke
.andReturn(Promise.resolve([mockGrandchild])); .and.returnValue(Promise.resolve([mockGrandchild]));
mockComposition.push(mockNewChild); mockComposition.push(mockNewChild);
newCapabilities.context.getPath.andReturn([ newCapabilities.context.getPath.and.returnValue([
mockDomainObject, mockDomainObject,
mockNewChild mockNewChild
]); ]);
gcCapabilities.context.getPath.andReturn([ gcCapabilities.context.getPath.and.returnValue([
mockDomainObject, mockDomainObject,
mockNewChild, mockNewChild,
mockGrandchild mockGrandchild
]); ]);
testCapabilities.mutation.listen testCapabilities.mutation.listen
.mostRecentCall.args[0](mockDomainObject); .calls.mostRecent().args[0](mockDomainObject);
waitForCompositionCallback();
runs(function () { return testCapabilities.composition.invoke().then(function () {
// Select the innermost object to force expansion,
// such that we can verify the subtree is present.
treeView.value(mockGrandchild); treeView.value(mockGrandchild);
newCapabilities.composition.invoke().then(function () { return newCapabilities.composition.invoke();
calledBackInner = true;
});
});
waitsFor(function () {
return calledBackInner;
}); });
}); });
@ -268,8 +250,8 @@ define([
testStatuses = ['foo']; testStatuses = ['foo'];
mockStatus.list.andReturn(testStatuses); mockStatus.list.and.returnValue(testStatuses);
mockStatus.listen.mostRecentCall.args[0](testStatuses); mockStatus.listen.calls.mostRecent().args[0](testStatuses);
}); });
it("reflects the status change in the tree", function () { it("reflects the status change in the tree", function () {

View File

@ -45,7 +45,7 @@ define(
mockTimeout = jasmine.createSpy('$timeout'); mockTimeout = jasmine.createSpy('$timeout');
mockDocument = jasmine.createSpyObj('$document', ['find']); mockDocument = jasmine.createSpyObj('$document', ['find']);
mockBody = jasmine.createSpyObj('body', ['on', 'off', 'scope', 'css', 'unbind']); mockBody = jasmine.createSpyObj('body', ['on', 'off', 'scope', 'css', 'unbind']);
mockDocument.find.andReturn(mockBody); mockDocument.find.and.returnValue(mockBody);
mockAgentService = jasmine.createSpyObj('agentService', ['isMobile', 'isPhone']); mockAgentService = jasmine.createSpyObj('agentService', ['isMobile', 'isPhone']);
mockInfoService = jasmine.createSpyObj( mockInfoService = jasmine.createSpyObj(
'infoService', 'infoService',
@ -68,14 +68,14 @@ define(
testMetadata = [{ name: "Test name", value: "Test value" }]; testMetadata = [{ name: "Test name", value: "Test value" }];
mockHide = jasmine.createSpy('hide'); mockHide = jasmine.createSpy('hide');
mockDomainObject.getModel.andReturn({ name: "Test Object" }); mockDomainObject.getModel.and.returnValue({ name: "Test Object" });
mockDomainObject.useCapability.andCallFake(function (c) { mockDomainObject.useCapability.and.callFake(function (c) {
return (c === 'metadata') ? testMetadata : undefined; return (c === 'metadata') ? testMetadata : undefined;
}); });
mockElement.scope.andReturn(mockScope); mockElement.scope.and.returnValue(mockScope);
mockScope.$on.andReturn(mockOff); mockScope.$on.and.returnValue(mockOff);
mockInfoService.display.andReturn(mockHide); mockInfoService.display.and.returnValue(mockHide);
mockAgentService.isMobile.andReturn(true); mockAgentService.isMobile.and.returnValue(true);
gesture = new InfoButtonGesture( gesture = new InfoButtonGesture(
mockDocument, mockDocument,
mockAgentService, mockAgentService,
@ -83,7 +83,7 @@ define(
mockElement, mockElement,
mockDomainObject mockDomainObject
); );
fireGesture = mockElement.on.mostRecentCall.args[1]; fireGesture = mockElement.on.calls.mostRecent().args[1];
}); });
it("expect click on the representation", function () { it("expect click on the representation", function () {
@ -106,7 +106,7 @@ define(
// Get the touch start on the body // Get the touch start on the body
// and fire the dismiss gesture // and fire the dismiss gesture
fireDismissGesture = mockBody.on.mostRecentCall.args[1]; fireDismissGesture = mockBody.on.calls.mostRecent().args[1];
fireDismissGesture(mockEvent); fireDismissGesture(mockEvent);
// Expect Body to have been touched, event.preventDefault() // Expect Body to have been touched, event.preventDefault()
// to be called, then the mockBody listener to be detached // to be called, then the mockBody listener to be detached

View File

@ -39,7 +39,7 @@ define(
gesture; gesture;
function fireEvent(evt, value) { function fireEvent(evt, value) {
mockElement.on.calls.forEach(function (call) { mockElement.on.calls.all().forEach(function (call) {
if (call.args[0] === evt) { if (call.args[0] === evt) {
call.args[1](value); call.args[1](value);
} }
@ -68,14 +68,14 @@ define(
mockPromise = jasmine.createSpyObj('promise', ['then']); mockPromise = jasmine.createSpyObj('promise', ['then']);
mockHide = jasmine.createSpy('hide'); mockHide = jasmine.createSpy('hide');
mockDomainObject.getModel.andReturn({ name: "Test Object" }); mockDomainObject.getModel.and.returnValue({ name: "Test Object" });
mockDomainObject.useCapability.andCallFake(function (c) { mockDomainObject.useCapability.and.callFake(function (c) {
return (c === 'metadata') ? testMetadata : undefined; return (c === 'metadata') ? testMetadata : undefined;
}); });
mockElement.scope.andReturn(mockScope); mockElement.scope.and.returnValue(mockScope);
mockScope.$on.andReturn(mockOff); mockScope.$on.and.returnValue(mockOff);
mockTimeout.andReturn(mockPromise); mockTimeout.and.returnValue(mockPromise);
mockInfoService.display.andReturn(mockHide); mockInfoService.display.and.returnValue(mockHide);
gesture = new InfoGesture( gesture = new InfoGesture(
mockTimeout, mockTimeout,
@ -96,7 +96,7 @@ define(
fireEvent("mouseenter", { clientX: 1977, clientY: 42 }); fireEvent("mouseenter", { clientX: 1977, clientY: 42 });
expect(mockTimeout) expect(mockTimeout)
.toHaveBeenCalledWith(jasmine.any(Function), testDelay); .toHaveBeenCalledWith(jasmine.any(Function), testDelay);
mockTimeout.mostRecentCall.args[0](); mockTimeout.calls.mostRecent().args[0]();
expect(mockInfoService.display).toHaveBeenCalledWith( expect(mockInfoService.display).toHaveBeenCalledWith(
jasmine.any(String), jasmine.any(String),
"Test Object", "Test Object",
@ -114,7 +114,7 @@ define(
it("hides a shown bubble when mouse leaves", function () { it("hides a shown bubble when mouse leaves", function () {
fireEvent("mouseenter", { clientX: 1977, clientY: 42 }); fireEvent("mouseenter", { clientX: 1977, clientY: 42 });
mockTimeout.mostRecentCall.args[0](); mockTimeout.calls.mostRecent().args[0]();
expect(mockHide).not.toHaveBeenCalled(); // verify precondition expect(mockHide).not.toHaveBeenCalled(); // verify precondition
fireEvent("mouseleave", {}); fireEvent("mouseleave", {});
expect(mockHide).toHaveBeenCalled(); expect(mockHide).toHaveBeenCalled();
@ -124,7 +124,7 @@ define(
fireEvent("mouseenter", { clientX: 1977, clientY: 42 }); fireEvent("mouseenter", { clientX: 1977, clientY: 42 });
fireEvent("mousemove", { clientX: 1999, clientY: 11 }); fireEvent("mousemove", { clientX: 1999, clientY: 11 });
fireEvent("mousemove", { clientX: 1984, clientY: 11 }); fireEvent("mousemove", { clientX: 1984, clientY: 11 });
mockTimeout.mostRecentCall.args[0](); mockTimeout.calls.mostRecent().args[0]();
// Should have displayed at the latest observed mouse position // Should have displayed at the latest observed mouse position
expect(mockInfoService.display).toHaveBeenCalledWith( expect(mockInfoService.display).toHaveBeenCalledWith(
jasmine.any(String), jasmine.any(String),
@ -136,7 +136,7 @@ define(
it("hides shown bubbles when destroyed", function () { it("hides shown bubbles when destroyed", function () {
fireEvent("mouseenter", { clientX: 1977, clientY: 42 }); fireEvent("mouseenter", { clientX: 1977, clientY: 42 });
mockTimeout.mostRecentCall.args[0](); mockTimeout.calls.mostRecent().args[0]();
expect(mockHide).not.toHaveBeenCalled(); // verify precondition expect(mockHide).not.toHaveBeenCalled(); // verify precondition
gesture.destroy(); gesture.destroy();
expect(mockHide).toHaveBeenCalled(); expect(mockHide).toHaveBeenCalled();
@ -145,7 +145,7 @@ define(
it("detaches listeners when destroyed", function () { it("detaches listeners when destroyed", function () {
fireEvent("mouseenter", { clientX: 1977, clientY: 42 }); fireEvent("mouseenter", { clientX: 1977, clientY: 42 });
gesture.destroy(); gesture.destroy();
mockElement.on.calls.forEach(function (call) { mockElement.on.calls.all().forEach(function (call) {
expect(mockElement.off).toHaveBeenCalledWith( expect(mockElement.off).toHaveBeenCalledWith(
call.args[0], call.args[0],
call.args[1] call.args[1]

View File

@ -53,19 +53,19 @@ define(
mockScope = jasmine.createSpyObj("scope", ["$destroy"]); mockScope = jasmine.createSpyObj("scope", ["$destroy"]);
mockElements = []; mockElements = [];
mockPopupService.display.andReturn(mockPopup); mockPopupService.display.and.returnValue(mockPopup);
mockCompile.andCallFake(function () { mockCompile.and.callFake(function () {
var mockCompiledTemplate = jasmine.createSpy('template'), var mockCompiledTemplate = jasmine.createSpy('template'),
mockElement = jasmine.createSpyObj('element', [ mockElement = jasmine.createSpyObj('element', [
'css', 'css',
'remove', 'remove',
'append' 'append'
]); ]);
mockCompiledTemplate.andReturn(mockElement); mockCompiledTemplate.and.returnValue(mockElement);
mockElements.push(mockElement); mockElements.push(mockElement);
return mockCompiledTemplate; return mockCompiledTemplate;
}); });
mockRootScope.$new.andReturn(mockScope); mockRootScope.$new.and.returnValue(mockScope);
service = new InfoService( service = new InfoService(
mockCompile, mockCompile,
@ -92,7 +92,7 @@ define(
}); });
it("when on phone device, positions at bottom", function () { it("when on phone device, positions at bottom", function () {
mockAgentService.isPhone.andReturn(true); mockAgentService.isPhone.and.returnValue(true);
service = new InfoService( service = new InfoService(
mockCompile, mockCompile,
mockRootScope, mockRootScope,
@ -119,10 +119,10 @@ define(
].join('-'); ].join('-');
beforeEach(function () { beforeEach(function () {
mockPopup.goesUp.andReturn(goesUp); mockPopup.goesUp.and.returnValue(goesUp);
mockPopup.goesDown.andReturn(!goesUp); mockPopup.goesDown.and.returnValue(!goesUp);
mockPopup.goesLeft.andReturn(goesLeft); mockPopup.goesLeft.and.returnValue(goesLeft);
mockPopup.goesRight.andReturn(!goesLeft); mockPopup.goesRight.and.returnValue(!goesLeft);
service.display('', '', {}, [10, 10]); service.display('', '', {}, [10, 10]);
}); });

View File

@ -60,11 +60,11 @@ define(
'body', 'body',
['addClass'] ['addClass']
); );
mockDocument.find.andCallFake(function (sel) { mockDocument.find.and.callFake(function (sel) {
return sel === 'body' && mockBody; return sel === 'body' && mockBody;
}); });
AGENT_SERVICE_METHODS.forEach(function (m) { AGENT_SERVICE_METHODS.forEach(function (m) {
mockAgentService[m].andReturn(false); mockAgentService[m].and.returnValue(false);
}); });
}); });
@ -78,7 +78,7 @@ define(
beforeEach(function () { beforeEach(function () {
trueMethods.forEach(function (m) { trueMethods.forEach(function (m) {
mockAgentService[m].andReturn(true); mockAgentService[m].and.returnValue(true);
}); });
classifier = new DeviceClassifier( classifier = new DeviceClassifier(
mockAgentService, mockAgentService,

View File

@ -43,10 +43,10 @@ define(
}); });
it("detects when a device is a desktop device", function () { it("detects when a device is a desktop device", function () {
mockAgentService.isMobile.andReturn(false); mockAgentService.isMobile.and.returnValue(false);
expect(DeviceMatchers.desktop(mockAgentService)) expect(DeviceMatchers.desktop(mockAgentService))
.toBe(true); .toBe(true);
mockAgentService.isMobile.andReturn(true); mockAgentService.isMobile.and.returnValue(true);
expect(DeviceMatchers.desktop(mockAgentService)) expect(DeviceMatchers.desktop(mockAgentService))
.toBe(false); .toBe(false);
}); });
@ -65,10 +65,10 @@ define(
"touch" "touch"
].forEach(function (deviceType) { ].forEach(function (deviceType) {
it("detects when a device is a " + deviceType + " device", function () { it("detects when a device is a " + deviceType + " device", function () {
mockAgentService[method(deviceType)].andReturn(true); mockAgentService[method(deviceType)].and.returnValue(true);
expect(DeviceMatchers[deviceType](mockAgentService)) expect(DeviceMatchers[deviceType](mockAgentService))
.toBe(true); .toBe(true);
mockAgentService[method(deviceType)].andReturn(false); mockAgentService[method(deviceType)].and.returnValue(false);
expect(DeviceMatchers[deviceType](mockAgentService)) expect(DeviceMatchers[deviceType](mockAgentService))
.toBe(false); .toBe(false);
}); });

View File

@ -47,12 +47,12 @@ define(
mockElement = jasmine.createSpyObj(name, JQLITE_METHODS); mockElement = jasmine.createSpyObj(name, JQLITE_METHODS);
mockClone = jasmine.createSpyObj(name, JQLITE_METHODS); mockClone = jasmine.createSpyObj(name, JQLITE_METHODS);
mockTransclude.andCallFake(function (fn) { mockTransclude.and.callFake(function (fn) {
fn(mockClone); fn(mockClone);
}); });
// Look desktop-like by default // Look desktop-like by default
mockAgentService.isLandscape.andReturn(true); mockAgentService.isLandscape.and.returnValue(true);
testAttrs = {}; testAttrs = {};
@ -85,40 +85,40 @@ define(
link(); link();
expectExclusion(); expectExclusion();
mockAgentService.isMobile.andReturn(true); mockAgentService.isMobile.and.returnValue(true);
link(); link();
expectInclusion(); expectInclusion();
}); });
it("restricts element inclusion for tablet devices", function () { it("restricts element inclusion for tablet devices", function () {
testAttrs.mctDevice = "tablet"; testAttrs.mctDevice = "tablet";
mockAgentService.isMobile.andReturn(true); mockAgentService.isMobile.and.returnValue(true);
link(); link();
expectExclusion(); expectExclusion();
mockAgentService.isTablet.andReturn(true); mockAgentService.isTablet.and.returnValue(true);
link(); link();
expectInclusion(); expectInclusion();
}); });
it("restricts element inclusion for phone devices", function () { it("restricts element inclusion for phone devices", function () {
testAttrs.mctDevice = "phone"; testAttrs.mctDevice = "phone";
mockAgentService.isMobile.andReturn(true); mockAgentService.isMobile.and.returnValue(true);
link(); link();
expectExclusion(); expectExclusion();
mockAgentService.isPhone.andReturn(true); mockAgentService.isPhone.and.returnValue(true);
link(); link();
expectInclusion(); expectInclusion();
}); });
it("restricts element inclusion for desktop devices", function () { it("restricts element inclusion for desktop devices", function () {
testAttrs.mctDevice = "desktop"; testAttrs.mctDevice = "desktop";
mockAgentService.isMobile.andReturn(true); mockAgentService.isMobile.and.returnValue(true);
link(); link();
expectExclusion(); expectExclusion();
mockAgentService.isMobile.andReturn(false); mockAgentService.isMobile.and.returnValue(false);
link(); link();
expectInclusion(); expectInclusion();
}); });
@ -128,19 +128,19 @@ define(
link(); link();
expectExclusion(); expectExclusion();
mockAgentService.isPortrait.andReturn(true); mockAgentService.isPortrait.and.returnValue(true);
link(); link();
expectInclusion(); expectInclusion();
}); });
it("restricts element inclusion for landscape orientation", function () { it("restricts element inclusion for landscape orientation", function () {
testAttrs.mctDevice = "landscape"; testAttrs.mctDevice = "landscape";
mockAgentService.isLandscape.andReturn(false); mockAgentService.isLandscape.and.returnValue(false);
mockAgentService.isPortrait.andReturn(true); mockAgentService.isPortrait.and.returnValue(true);
link(); link();
expectExclusion(); expectExclusion();
mockAgentService.isLandscape.andReturn(true); mockAgentService.isLandscape.and.returnValue(true);
link(); link();
expectInclusion(); expectInclusion();
}); });
@ -153,13 +153,13 @@ define(
// Neither portrait nor mobile, not called // Neither portrait nor mobile, not called
expectExclusion(); expectExclusion();
mockAgentService.isPortrait.andReturn(true); mockAgentService.isPortrait.and.returnValue(true);
link(); link();
// Was portrait, but not mobile, so no // Was portrait, but not mobile, so no
expectExclusion(); expectExclusion();
mockAgentService.isMobile.andReturn(true); mockAgentService.isMobile.and.returnValue(true);
link(); link();
expectInclusion(); expectInclusion();
}); });

View File

@ -52,8 +52,8 @@ define(
expect(mockScope.showNotificationsList).toBeDefined(); expect(mockScope.showNotificationsList).toBeDefined();
mockScope.showNotificationsList(); mockScope.showNotificationsList();
expect(mockDialogService.getDialogResponse).toHaveBeenCalled(); expect(mockDialogService.getDialogResponse).toHaveBeenCalled();
expect(mockDialogService.getDialogResponse.mostRecentCall.args[0]).toBe('overlay-message-list'); expect(mockDialogService.getDialogResponse.calls.mostRecent().args[0]).toBe('overlay-message-list');
expect(mockDialogService.getDialogResponse.mostRecentCall.args[1].dialog).toBeDefined(); expect(mockDialogService.getDialogResponse.calls.mostRecent().args[1].dialog).toBeDefined();
}); });
}); });
} }

View File

@ -37,14 +37,14 @@ define(
errorModel; errorModel;
function elapseTimeout() { function elapseTimeout() {
mockTimeout.mostRecentCall.args[0](); mockTimeout.calls.mostRecent().args[0]();
} }
beforeEach(function () { beforeEach(function () {
mockTimeout = jasmine.createSpy("$timeout"); mockTimeout = jasmine.createSpy("$timeout");
mockTopicFunction = jasmine.createSpy("topic"); mockTopicFunction = jasmine.createSpy("topic");
mockTopicObject = jasmine.createSpyObj("topicObject", ["listen", "notify"]); mockTopicObject = jasmine.createSpyObj("topicObject", ["listen", "notify"]);
mockTopicFunction.andReturn(mockTopicObject); mockTopicFunction.and.returnValue(mockTopicObject);
mockAutoDismiss = mockMinimizeTimeout = 1000; mockAutoDismiss = mockMinimizeTimeout = 1000;
notificationService = new NotificationService(mockTimeout, mockTopicFunction, mockAutoDismiss, mockMinimizeTimeout); notificationService = new NotificationService(mockTimeout, mockTopicFunction, mockAutoDismiss, mockMinimizeTimeout);
@ -72,7 +72,7 @@ define(
expect(mockTopicObject.listen).toHaveBeenCalled(); expect(mockTopicObject.listen).toHaveBeenCalled();
notification.dismiss(); notification.dismiss();
expect(mockTopicObject.notify).toHaveBeenCalled(); expect(mockTopicObject.notify).toHaveBeenCalled();
mockTopicObject.listen.mostRecentCall.args[0](); mockTopicObject.listen.calls.mostRecent().args[0]();
expect(dismissListener).toHaveBeenCalled(); expect(dismissListener).toHaveBeenCalled();
}); });
@ -132,7 +132,7 @@ define(
}); });
it("keeps alert notifications active if the caller disables auto-dismiss", function () { it("keeps alert notifications active if the caller disables auto-dismiss", function () {
mockTimeout.andCallFake(function (callback, time) { mockTimeout.and.callFake(function (callback, time) {
callback(); callback();
}); });
alertModel.autoDismiss = false; alertModel.autoDismiss = false;
@ -143,7 +143,7 @@ define(
}); });
it("keeps alert notifications active if the caller ignores auto-dismiss", function () { it("keeps alert notifications active if the caller ignores auto-dismiss", function () {
mockTimeout.andCallFake(function (callback, time) { mockTimeout.and.callFake(function (callback, time) {
callback(); callback();
}); });
var notification = notificationService.alert(alertModel); var notification = notificationService.alert(alertModel);
@ -165,7 +165,7 @@ define(
}); });
it("keeps error notifications active if the caller disables auto-dismiss", function () { it("keeps error notifications active if the caller disables auto-dismiss", function () {
mockTimeout.andCallFake(function (callback, time) { mockTimeout.and.callFake(function (callback, time) {
callback(); callback();
}); });
errorModel.autoDismiss = false; errorModel.autoDismiss = false;
@ -176,7 +176,7 @@ define(
}); });
it("keeps error notifications active if the caller ignores auto-dismiss", function () { it("keeps error notifications active if the caller ignores auto-dismiss", function () {
mockTimeout.andCallFake(function (callback, time) { mockTimeout.and.callFake(function (callback, time) {
callback(); callback();
}); });
var notification = notificationService.error(errorModel); var notification = notificationService.error(errorModel);

View File

@ -46,26 +46,26 @@ define(
mockDomainObject = jasmine.createSpyObj("domainObject", [ mockDomainObject = jasmine.createSpyObj("domainObject", [
"hasCapability", "getCapability" "hasCapability", "getCapability"
]); ]);
mockDomainObject.hasCapability.andReturn(true); mockDomainObject.hasCapability.and.returnValue(true);
mockDomainObject.getCapability.andReturn(mockEditorCapability); mockDomainObject.getCapability.and.returnValue(mockEditorCapability);
}); });
it("includes only browse region parts for object not in edit mode", function () { it("includes only browse region parts for object not in edit mode", function () {
mockEditorCapability.inEditContext.andReturn(false); mockEditorCapability.inEditContext.and.returnValue(false);
expect(editableRegionPolicy.allow(mockBrowseRegionPart, mockDomainObject)).toBe(true); expect(editableRegionPolicy.allow(mockBrowseRegionPart, mockDomainObject)).toBe(true);
expect(editableRegionPolicy.allow(mockEditRegionPart, mockDomainObject)).toBe(false); expect(editableRegionPolicy.allow(mockEditRegionPart, mockDomainObject)).toBe(false);
}); });
it("includes only edit region parts for object in edit mode", function () { it("includes only edit region parts for object in edit mode", function () {
mockEditorCapability.inEditContext.andReturn(true); mockEditorCapability.inEditContext.and.returnValue(true);
expect(editableRegionPolicy.allow(mockBrowseRegionPart, mockDomainObject)).toBe(false); expect(editableRegionPolicy.allow(mockBrowseRegionPart, mockDomainObject)).toBe(false);
expect(editableRegionPolicy.allow(mockEditRegionPart, mockDomainObject)).toBe(true); expect(editableRegionPolicy.allow(mockEditRegionPart, mockDomainObject)).toBe(true);
}); });
it("includes region parts with no mode specification", function () { it("includes region parts with no mode specification", function () {
mockEditorCapability.inEditContext.andReturn(false); mockEditorCapability.inEditContext.and.returnValue(false);
expect(editableRegionPolicy.allow(mockAllModesRegionPart, mockDomainObject)).toBe(true); expect(editableRegionPolicy.allow(mockAllModesRegionPart, mockDomainObject)).toBe(true);
mockEditorCapability.inEditContext.andReturn(true); mockEditorCapability.inEditContext.and.returnValue(true);
expect(editableRegionPolicy.allow(mockAllModesRegionPart, mockDomainObject)).toBe(true); expect(editableRegionPolicy.allow(mockAllModesRegionPart, mockDomainObject)).toBe(true);
}); });

View File

@ -46,7 +46,7 @@ define(
mockDomainObject = jasmine.createSpyObj('domainObject', [ mockDomainObject = jasmine.createSpyObj('domainObject', [
'getCapability' 'getCapability'
]); ]);
mockDomainObject.getCapability.andReturn(mockTypeDef); mockDomainObject.getCapability.and.returnValue(mockTypeDef);
mockScope = jasmine.createSpyObj('$scope', mockScope = jasmine.createSpyObj('$scope',
['$on', 'selection'] ['$on', 'selection']
@ -63,7 +63,7 @@ define(
'off', 'off',
'get' 'get'
]); ]);
mockSelection.get.andReturn(selectable); mockSelection.get.and.returnValue(selectable);
mockInspectorViews = jasmine.createSpyObj('inspectorViews', ['get']); mockInspectorViews = jasmine.createSpyObj('inspectorViews', ['get']);
mockOpenMCT = { mockOpenMCT = {
@ -73,7 +73,7 @@ define(
container = jasmine.createSpy('container', ['innerHTML']); container = jasmine.createSpy('container', ['innerHTML']);
$document[0] = jasmine.createSpyObj("$document", ['querySelectorAll']); $document[0] = jasmine.createSpyObj("$document", ['querySelectorAll']);
$document[0].querySelectorAll.andReturn([container]); $document[0].querySelectorAll.and.returnValue([container]);
controller = new InspectorController(mockScope, mockOpenMCT, $document); controller = new InspectorController(mockScope, mockOpenMCT, $document);
}); });
@ -89,10 +89,10 @@ define(
var mockItem = jasmine.createSpyObj('domainObject', [ var mockItem = jasmine.createSpyObj('domainObject', [
'getCapability' 'getCapability'
]); ]);
mockItem.getCapability.andReturn(mockTypeDef); mockItem.getCapability.and.returnValue(mockTypeDef);
selectable[0].context.oldItem = mockItem; selectable[0].context.oldItem = mockItem;
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable); mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
expect(controller.selectedItem()).toEqual(mockItem); expect(controller.selectedItem()).toEqual(mockItem);
}); });
@ -103,7 +103,7 @@ define(
jasmine.any(Function) jasmine.any(Function)
); );
mockScope.$on.calls[0].args[1](); mockScope.$on.calls.all()[0].args[1]();
expect(mockOpenMCT.selection.off).toHaveBeenCalledWith( expect(mockOpenMCT.selection.off).toHaveBeenCalledWith(
'change', 'change',

View File

@ -40,7 +40,7 @@ define(
); );
mockTypes = ['a', 'b'].map(function (type) { mockTypes = ['a', 'b'].map(function (type) {
var mockType = jasmine.createSpyObj('type-' + type, ['getKey']); var mockType = jasmine.createSpyObj('type-' + type, ['getKey']);
mockType.getKey.andReturn(type); mockType.getKey.and.returnValue(type);
return mockType; return mockType;
}); });
mockDomainObjects = ['a', 'b'].map(function (id, index) { mockDomainObjects = ['a', 'b'].map(function (id, index) {
@ -48,8 +48,8 @@ define(
'domainObject-' + id, 'domainObject-' + id,
['getId', 'getCapability'] ['getId', 'getCapability']
); );
mockDomainObject.getId.andReturn(id); mockDomainObject.getId.and.returnValue(id);
mockDomainObject.getCapability.andCallFake(function (c) { mockDomainObject.getCapability.and.callFake(function (c) {
return c === 'type' && mockTypes[index]; return c === 'type' && mockTypes[index];
}); });
return mockDomainObject; return mockDomainObject;
@ -62,8 +62,8 @@ define(
selectedObject: mockDomainObjects[1] selectedObject: mockDomainObjects[1]
}; };
mockAction.getMetadata.andReturn(testContext); mockAction.getMetadata.and.returnValue(testContext);
mockInjector.get.andCallFake(function (service) { mockInjector.get.and.callFake(function (service) {
return service === 'policyService' && mockPolicyService; return service === 'policyService' && mockPolicyService;
}); });
@ -71,9 +71,9 @@ define(
}); });
it("defers to composition policy", function () { it("defers to composition policy", function () {
mockPolicyService.allow.andReturn(false); mockPolicyService.allow.and.returnValue(false);
expect(policy.allow(mockAction, testContext)).toBeFalsy(); expect(policy.allow(mockAction, testContext)).toBeFalsy();
mockPolicyService.allow.andReturn(true); mockPolicyService.allow.and.returnValue(true);
expect(policy.allow(mockAction, testContext)).toBeTruthy(); expect(policy.allow(mockAction, testContext)).toBeTruthy();
expect(mockPolicyService.allow).toHaveBeenCalledWith( expect(mockPolicyService.allow).toHaveBeenCalledWith(
@ -85,7 +85,7 @@ define(
it("allows actions other than compose", function () { it("allows actions other than compose", function () {
testContext.key = 'somethingElse'; testContext.key = 'somethingElse';
mockPolicyService.allow.andReturn(false); mockPolicyService.allow.and.returnValue(false);
expect(policy.allow(mockAction, testContext)).toBeTruthy(); expect(policy.allow(mockAction, testContext)).toBeTruthy();
}); });
}); });

View File

@ -19,9 +19,9 @@ define(
}); });
it("only allows composition for types which will have a composition property", function () { it("only allows composition for types which will have a composition property", function () {
mockType.getInitialModel.andReturn({}); mockType.getInitialModel.and.returnValue({});
expect(policy.allow(mockObject)).toBeFalsy(); expect(policy.allow(mockObject)).toBeFalsy();
mockType.getInitialModel.andReturn({ composition: [] }); mockType.getInitialModel.and.returnValue({ composition: [] });
expect(policy.allow(mockObject)).toBeTruthy(); expect(policy.allow(mockObject)).toBeTruthy();
}); });
}); });

View File

@ -41,7 +41,7 @@ define(
it("only allows composition for types which can be created/modified", function () { it("only allows composition for types which can be created/modified", function () {
expect(policy.allow(mockObject)).toBeFalsy(); expect(policy.allow(mockObject)).toBeFalsy();
mockType.hasFeature.andReturn(true); mockType.hasFeature.and.returnValue(true);
expect(policy.allow(mockObject)).toBeTruthy(); expect(policy.allow(mockObject)).toBeTruthy();
expect(mockType.hasFeature).toHaveBeenCalledWith('creation'); expect(mockType.hasFeature).toHaveBeenCalledWith('creation');
}); });

View File

@ -40,8 +40,8 @@ define(
'type A-- the particular kind', 'type A-- the particular kind',
['getKey', 'getDefinition'] ['getKey', 'getDefinition']
); );
typeA.getKey.andReturn('a'); typeA.getKey.and.returnValue('a');
typeA.getDefinition.andReturn({ typeA.getDefinition.and.returnValue({
contains: ['a'] contains: ['a']
}); });
@ -50,8 +50,8 @@ define(
'type B-- anything goes', 'type B-- anything goes',
['getKey', 'getDefinition'] ['getKey', 'getDefinition']
); );
typeB.getKey.andReturn('b'); typeB.getKey.and.returnValue('b');
typeB.getDefinition.andReturn({ typeB.getDefinition.and.returnValue({
contains: ['a', 'b'] contains: ['a', 'b']
}); });
@ -59,8 +59,8 @@ define(
'type C-- distinguishing and interested in telemetry', 'type C-- distinguishing and interested in telemetry',
['getKey', 'getDefinition'] ['getKey', 'getDefinition']
); );
typeC.getKey.andReturn('c'); typeC.getKey.and.returnValue('c');
typeC.getDefinition.andReturn({ typeC.getDefinition.and.returnValue({
contains: [{has: 'telemetry'}] contains: [{has: 'telemetry'}]
}); });
@ -75,17 +75,17 @@ define(
describe('enforces simple containment rules', function () { describe('enforces simple containment rules', function () {
it('allows when type matches', function () { it('allows when type matches', function () {
mockParentObject.getCapability.andReturn(typeA); mockParentObject.getCapability.and.returnValue(typeA);
mockChildObject.getCapability.andReturn(typeA); mockChildObject.getCapability.and.returnValue(typeA);
expect(policy.allow(mockParentObject, mockChildObject)) expect(policy.allow(mockParentObject, mockChildObject))
.toBeTruthy(); .toBeTruthy();
mockParentObject.getCapability.andReturn(typeB); mockParentObject.getCapability.and.returnValue(typeB);
expect(policy.allow(mockParentObject, mockChildObject)) expect(policy.allow(mockParentObject, mockChildObject))
.toBeTruthy(); .toBeTruthy();
mockChildObject.getCapability.andReturn(typeB); mockChildObject.getCapability.and.returnValue(typeB);
expect(policy.allow(mockParentObject, mockChildObject)) expect(policy.allow(mockParentObject, mockChildObject))
.toBeTruthy(); .toBeTruthy();
}); });
@ -93,12 +93,12 @@ define(
it('disallows when type doesn\'t match', function () { it('disallows when type doesn\'t match', function () {
mockParentObject.getCapability.andReturn(typeA); mockParentObject.getCapability.and.returnValue(typeA);
mockChildObject.getCapability.andReturn(typeB); mockChildObject.getCapability.and.returnValue(typeB);
expect(policy.allow(mockParentObject, mockChildObject)) expect(policy.allow(mockParentObject, mockChildObject))
.toBeFalsy(); .toBeFalsy();
mockChildObject.getCapability.andReturn(typeC); mockChildObject.getCapability.and.returnValue(typeC);
expect(policy.allow(mockParentObject, mockChildObject)) expect(policy.allow(mockParentObject, mockChildObject))
.toBeFalsy(); .toBeFalsy();
}); });
@ -107,9 +107,9 @@ define(
describe('enforces capability-based containment rules', function () { describe('enforces capability-based containment rules', function () {
it('allows when object has capability', function () { it('allows when object has capability', function () {
mockParentObject.getCapability.andReturn(typeC); mockParentObject.getCapability.and.returnValue(typeC);
mockChildObject.hasCapability.andReturn(true); mockChildObject.hasCapability.and.returnValue(true);
expect(policy.allow(mockParentObject, mockChildObject)) expect(policy.allow(mockParentObject, mockChildObject))
.toBeTruthy(); .toBeTruthy();
expect(mockChildObject.hasCapability) expect(mockChildObject.hasCapability)
@ -117,9 +117,9 @@ define(
}); });
it('skips when object doesn\'t have capability', function () { it('skips when object doesn\'t have capability', function () {
mockChildObject.hasCapability.andReturn(false); mockChildObject.hasCapability.and.returnValue(false);
mockParentObject.getCapability.andReturn(typeC); mockParentObject.getCapability.and.returnValue(typeC);
expect(policy.allow(mockParentObject, mockChildObject)) expect(policy.allow(mockParentObject, mockChildObject))
.toBeFalsy(); .toBeFalsy();

View File

@ -44,15 +44,15 @@ define(
'getCapability', 'getCapability',
'getId' 'getId'
]); ]);
mockParent.hasCapability.andReturn(true); mockParent.hasCapability.and.returnValue(true);
mockParent.getId.andReturn('someNamespace:someId'); mockParent.getId.and.returnValue('someNamespace:someId');
mockChild = {}; mockChild = {};
mockEditorCapability = jasmine.createSpyObj('domainObject', [ mockEditorCapability = jasmine.createSpyObj('domainObject', [
'isEditContextRoot' 'isEditContextRoot'
]); ]);
mockParent.getCapability.andReturn(mockEditorCapability); mockParent.getCapability.and.returnValue(mockEditorCapability);
objectAPI.getProvider.andReturn({ objectAPI.getProvider.and.returnValue({
save: function () {} save: function () {}
}); });
persistableCompositionPolicy = new PersistableCompositionPolicy(mockOpenMCT); persistableCompositionPolicy = new PersistableCompositionPolicy(mockOpenMCT);
@ -64,18 +64,18 @@ define(
// - openMct.objects.getProvider // - openMct.objects.getProvider
it("Does not allow composition for objects that are not persistable", function () { it("Does not allow composition for objects that are not persistable", function () {
mockEditorCapability.isEditContextRoot.andReturn(false); mockEditorCapability.isEditContextRoot.and.returnValue(false);
expect(persistableCompositionPolicy.allow(mockParent, mockChild)).toBe(true); expect(persistableCompositionPolicy.allow(mockParent, mockChild)).toBe(true);
objectAPI.getProvider.andReturn({}); objectAPI.getProvider.and.returnValue({});
expect(persistableCompositionPolicy.allow(mockParent, mockChild)).toBe(false); expect(persistableCompositionPolicy.allow(mockParent, mockChild)).toBe(false);
}); });
it("Always allows composition of objects in edit mode to support object creation", function () { it("Always allows composition of objects in edit mode to support object creation", function () {
mockEditorCapability.isEditContextRoot.andReturn(true); mockEditorCapability.isEditContextRoot.and.returnValue(true);
expect(persistableCompositionPolicy.allow(mockParent, mockChild)).toBe(true); expect(persistableCompositionPolicy.allow(mockParent, mockChild)).toBe(true);
expect(objectAPI.getProvider).not.toHaveBeenCalled(); expect(objectAPI.getProvider).not.toHaveBeenCalled();
mockEditorCapability.isEditContextRoot.andReturn(false); mockEditorCapability.isEditContextRoot.and.returnValue(false);
expect(persistableCompositionPolicy.allow(mockParent, mockChild)).toBe(true); expect(persistableCompositionPolicy.allow(mockParent, mockChild)).toBe(true);
expect(objectAPI.getProvider).toHaveBeenCalled(); expect(objectAPI.getProvider).toHaveBeenCalled();
}); });

View File

@ -24,8 +24,8 @@
* Module defining ActionCapability. Created by vwoeltje on 11/10/14. * Module defining ActionCapability. Created by vwoeltje on 11/10/14.
*/ */
define( define(
[], ['lodash'],
function () { function (_) {
/** /**
* The ActionCapability allows applicable Actions to be retrieved and * The ActionCapability allows applicable Actions to be retrieved and
@ -74,10 +74,14 @@ define(
// Get all actions which are valid in this context; // Get all actions which are valid in this context;
// this simply redirects to the action service, // this simply redirects to the action service,
// but additionally adds a domainObject field. // but additionally adds a domainObject field.
var baseContext = typeof context === 'string' ? var baseContext;
{ key: context } : (context || {}), if (typeof context === 'string') {
actionContext = Object.create(baseContext); baseContext = { key: context };
} else {
baseContext = context || {};
}
var actionContext = _.extend({}, baseContext);
actionContext.domainObject = this.domainObject; actionContext.domainObject = this.domainObject;
return this.actionService.getActions(actionContext); return this.actionService.getActions(actionContext);

View File

@ -33,7 +33,7 @@ define(
function createMockActionProvider(actions, i) { function createMockActionProvider(actions, i) {
var spy = jasmine.createSpyObj("agg" + i, ["getActions"]); var spy = jasmine.createSpyObj("agg" + i, ["getActions"]);
spy.getActions.andReturn(actions); spy.getActions.and.returnValue(actions);
return spy; return spy;
} }

View File

@ -52,7 +52,7 @@ define(
["getId", "getModel", "getCapability", "hasCapability", "useCapability"] ["getId", "getModel", "getCapability", "hasCapability", "useCapability"]
); );
mockActionService.getActions.andReturn([mockAction, {}]); mockActionService.getActions.and.returnValue([mockAction, {}]);
capability = new ActionCapability( capability = new ActionCapability(
mockQ, mockQ,
@ -77,8 +77,8 @@ define(
it("promises the result of performed actions", function () { it("promises the result of performed actions", function () {
var mockPromise = jasmine.createSpyObj("promise", ["then"]); var mockPromise = jasmine.createSpyObj("promise", ["then"]);
mockQ.when.andReturn(mockPromise); mockQ.when.and.returnValue(mockPromise);
mockAction.perform.andReturn("the action's result"); mockAction.perform.and.returnValue("the action's result");
// Verify precondition // Verify precondition
expect(mockAction.perform).not.toHaveBeenCalled(); expect(mockAction.perform).not.toHaveBeenCalled();

View File

@ -176,7 +176,7 @@ define(
it("reports the error's message", function () { it("reports the error's message", function () {
expect( expect(
mockLog.error.mostRecentCall.args[0].indexOf(errorText) mockLog.error.calls.mostRecent().args[0].indexOf(errorText)
).not.toEqual(-1); ).not.toEqual(-1);
}); });

View File

@ -47,7 +47,7 @@ define(
["error", "warn", "info", "debug"] ["error", "warn", "info", "debug"]
); );
mockActionService.getActions.andReturn([mockAction]); mockActionService.getActions.and.returnValue([mockAction]);
decorator = new LoggingActionDecorator( decorator = new LoggingActionDecorator(
mockLog, mockLog,

View File

@ -72,7 +72,7 @@ define(
} }
}; };
mockObjectService.getObjects.andReturn(mockPromise([])); mockObjectService.getObjects.and.returnValue(mockPromise([]));
composition = new CompositionCapability( composition = new CompositionCapability(
mockInjector, mockInjector,
@ -90,7 +90,7 @@ define(
it("requests ids found in model's composition from the object service", function () { it("requests ids found in model's composition from the object service", function () {
var ids = ["a", "b", "c", "xyz"]; var ids = ["a", "b", "c", "xyz"];
mockDomainObject.getModel.andReturn({ composition: ids }); mockDomainObject.getModel.and.returnValue({ composition: ids });
composition.invoke(); composition.invoke();
@ -101,9 +101,9 @@ define(
var result, var result,
mockChild = jasmine.createSpyObj("child", DOMAIN_OBJECT_METHODS); mockChild = jasmine.createSpyObj("child", DOMAIN_OBJECT_METHODS);
mockDomainObject.getModel.andReturn({ composition: ["x"] }); mockDomainObject.getModel.and.returnValue({ composition: ["x"] });
mockObjectService.getObjects.andReturn(mockPromise({x: mockChild})); mockObjectService.getObjects.and.returnValue(mockPromise({x: mockChild}));
mockChild.getCapability.andReturn(undefined); mockChild.getCapability.and.returnValue(undefined);
composition.invoke().then(function (c) { composition.invoke().then(function (c) {
result = c; result = c;
@ -119,12 +119,12 @@ define(
testModel = { composition: [] }, testModel = { composition: [] },
mockChild = jasmine.createSpyObj("child", DOMAIN_OBJECT_METHODS); mockChild = jasmine.createSpyObj("child", DOMAIN_OBJECT_METHODS);
mockDomainObject.getModel.andReturn(testModel); mockDomainObject.getModel.and.returnValue(testModel);
mockObjectService.getObjects.andReturn(mockPromise({a: mockChild})); mockObjectService.getObjects.and.returnValue(mockPromise({a: mockChild}));
mockChild.getCapability.andReturn(undefined); mockChild.getCapability.and.returnValue(undefined);
mockChild.getId.andReturn('a'); mockChild.getId.and.returnValue('a');
mockDomainObject.useCapability.andCallFake(function (key, mutator) { mockDomainObject.useCapability.and.callFake(function (key, mutator) {
if (key === 'mutation') { if (key === 'mutation') {
mutator(testModel); mutator(testModel);
return mockPromise(true); return mockPromise(true);
@ -149,12 +149,12 @@ define(
testModel = { composition: ['a'] }, testModel = { composition: ['a'] },
mockChild = jasmine.createSpyObj("child", DOMAIN_OBJECT_METHODS); mockChild = jasmine.createSpyObj("child", DOMAIN_OBJECT_METHODS);
mockDomainObject.getModel.andReturn(testModel); mockDomainObject.getModel.and.returnValue(testModel);
mockObjectService.getObjects.andReturn(mockPromise({a: mockChild})); mockObjectService.getObjects.and.returnValue(mockPromise({a: mockChild}));
mockChild.getCapability.andReturn(undefined); mockChild.getCapability.and.returnValue(undefined);
mockChild.getId.andReturn('a'); mockChild.getId.and.returnValue('a');
mockDomainObject.useCapability.andCallFake(function (key, mutator) { mockDomainObject.useCapability.and.callFake(function (key, mutator) {
if (key === 'mutation') { if (key === 'mutation') {
mutator(testModel); mutator(testModel);
return mockPromise(true); return mockPromise(true);
@ -180,12 +180,12 @@ define(
testModel = { composition: ['a', 'b', 'c'] }, testModel = { composition: ['a', 'b', 'c'] },
mockChild = jasmine.createSpyObj("child", DOMAIN_OBJECT_METHODS); mockChild = jasmine.createSpyObj("child", DOMAIN_OBJECT_METHODS);
mockDomainObject.getModel.andReturn(testModel); mockDomainObject.getModel.and.returnValue(testModel);
mockObjectService.getObjects.andReturn(mockPromise({a: mockChild})); mockObjectService.getObjects.and.returnValue(mockPromise({a: mockChild}));
mockChild.getCapability.andReturn(undefined); mockChild.getCapability.and.returnValue(undefined);
mockChild.getId.andReturn('a'); mockChild.getId.and.returnValue('a');
mockDomainObject.useCapability.andCallFake(function (key, mutator) { mockDomainObject.useCapability.and.callFake(function (key, mutator) {
if (key === 'mutation') { if (key === 'mutation') {
mutator(testModel); mutator(testModel);
return mockPromise(true); return mockPromise(true);

View File

@ -48,10 +48,10 @@ define(
mockGrandparent = jasmine.createSpyObj("grandparent", DOMAIN_OBJECT_METHODS); mockGrandparent = jasmine.createSpyObj("grandparent", DOMAIN_OBJECT_METHODS);
mockContext = jasmine.createSpyObj("context", ["getParent", "getRoot", "getPath"]); mockContext = jasmine.createSpyObj("context", ["getParent", "getRoot", "getPath"]);
mockParent.getCapability.andReturn(mockContext); mockParent.getCapability.and.returnValue(mockContext);
mockContext.getParent.andReturn(mockGrandparent); mockContext.getParent.and.returnValue(mockGrandparent);
mockContext.getRoot.andReturn(mockGrandparent); mockContext.getRoot.and.returnValue(mockGrandparent);
mockContext.getPath.andReturn([mockGrandparent, mockParent]); mockContext.getPath.and.returnValue([mockGrandparent, mockParent]);
context = new ContextCapability(mockParent, mockDomainObject); context = new ContextCapability(mockParent, mockDomainObject);
}); });
@ -69,7 +69,7 @@ define(
}); });
it("treats ancestors with no context capability as deepest ancestors", function () { it("treats ancestors with no context capability as deepest ancestors", function () {
mockParent.getCapability.andReturn(undefined); mockParent.getCapability.and.returnValue(undefined);
expect(context.getPath()).toEqual([mockParent, mockDomainObject]); expect(context.getPath()).toEqual([mockParent, mockDomainObject]);
expect(context.getRoot()).toEqual(mockParent); expect(context.getRoot()).toEqual(mockParent);
}); });

View File

@ -49,8 +49,8 @@ define(
model = { someKey: "some value" }; model = { someKey: "some value" };
mockDomainObject.getCapability.andReturn("some capability"); mockDomainObject.getCapability.and.returnValue("some capability");
mockDomainObject.getModel.andReturn(model); mockDomainObject.getModel.and.returnValue(model);
contextualDomainObject = new ContextualDomainObject( contextualDomainObject = new ContextualDomainObject(
mockDomainObject, mockDomainObject,

View File

@ -49,6 +49,8 @@ define(
} }
beforeEach(function () { beforeEach(function () {
KeylessCapability.key = undefined;
mockLog = jasmine.createSpyObj( mockLog = jasmine.createSpyObj(
"$log", "$log",
["error", "warn", "info", "debug"] ["error", "warn", "info", "debug"]

View File

@ -49,16 +49,16 @@ define(
['getId', 'getCapability', 'getModel'] ['getId', 'getCapability', 'getModel']
); );
mockInjector.get.andCallFake(function (key) { mockInjector.get.and.callFake(function (key) {
return { return {
'instantiate': mockInstantiate 'instantiate': mockInstantiate
}[key]; }[key];
}); });
mockIdentifierService.parse.andReturn(mockIdentifier); mockIdentifierService.parse.and.returnValue(mockIdentifier);
mockIdentifierService.generate.andReturn("some-id"); mockIdentifierService.generate.and.returnValue("some-id");
mockNow = jasmine.createSpy(); mockNow = jasmine.createSpy();
mockNow.andReturn(1234321); mockNow.and.returnValue(1234321);
instantiation = new InstantiationCapability( instantiation = new InstantiationCapability(
mockInjector, mockInjector,
@ -81,7 +81,7 @@ define(
'useCapability', 'useCapability',
'hasCapability' 'hasCapability'
]), testModel = { someKey: "some value" }; ]), testModel = { someKey: "some value" };
mockInstantiate.andReturn(mockDomainObj); mockInstantiate.and.returnValue(mockDomainObj);
instantiation.instantiate(testModel); instantiation.instantiate(testModel);
expect(mockInstantiate) expect(mockInstantiate)
.toHaveBeenCalledWith({ .toHaveBeenCalledWith({

View File

@ -58,18 +58,18 @@ define(
'property-' + k, 'property-' + k,
['getValue', 'getDefinition'] ['getValue', 'getDefinition']
); );
mockProperty.getValue.andReturn("Value " + k); mockProperty.getValue.and.returnValue("Value " + k);
mockProperty.getDefinition.andReturn({ name: "Property " + k}); mockProperty.getDefinition.and.returnValue({ name: "Property " + k});
return mockProperty; return mockProperty;
}); });
testModel = { name: "" }; testModel = { name: "" };
mockDomainObject.getId.andReturn("Test id"); mockDomainObject.getId.and.returnValue("Test id");
mockDomainObject.getModel.andReturn(testModel); mockDomainObject.getModel.and.returnValue(testModel);
mockDomainObject.getCapability.andCallFake(getCapability); mockDomainObject.getCapability.and.callFake(getCapability);
mockDomainObject.useCapability.andCallFake(getCapability); mockDomainObject.useCapability.and.callFake(getCapability);
mockType.getProperties.andReturn(mockProperties); mockType.getProperties.and.returnValue(mockProperties);
mockType.getName.andReturn("Test type"); mockType.getName.and.returnValue("Test type");
metadata = new MetadataCapability(mockDomainObject); metadata = new MetadataCapability(mockDomainObject);
}); });

View File

@ -48,7 +48,7 @@ define(
testModel = { number: 6 }; testModel = { number: 6 };
topic = new Topic(); topic = new Topic();
mockNow = jasmine.createSpy('now'); mockNow = jasmine.createSpy('now');
mockNow.andReturn(12321); mockNow.and.returnValue(12321);
mutation = new MutationCapability( mutation = new MutationCapability(
topic, topic,
mockNow, mockNow,
@ -105,7 +105,7 @@ define(
m.number = 8; m.number = 8;
}); });
expect(mockCallback).toHaveBeenCalled(); expect(mockCallback).toHaveBeenCalled();
expect(mockCallback.mostRecentCall.args[0].number) expect(mockCallback.calls.mostRecent().args[0].number)
.toEqual(8); .toEqual(8);
}); });
@ -130,7 +130,7 @@ define(
m.number = 8; m.number = 8;
}); });
expect(mockCallback).toHaveBeenCalled(); expect(mockCallback).toHaveBeenCalled();
expect(mockCallback.mostRecentCall.args[0].number) expect(mockCallback.calls.mostRecent().args[0].number)
.toEqual(8); .toEqual(8);
}); });
}); });

View File

@ -95,15 +95,15 @@ define(
useCapability: jasmine.createSpy() useCapability: jasmine.createSpy()
}; };
// Simulate mutation capability // Simulate mutation capability
mockDomainObject.useCapability.andCallFake(function (capability, mutator) { mockDomainObject.useCapability.and.callFake(function (capability, mutator) {
if (capability === 'mutation') { if (capability === 'mutation') {
model = mutator(model) || model; model = mutator(model) || model;
} }
}); });
mockIdentifierService.parse.andReturn(mockIdentifier); mockIdentifierService.parse.and.returnValue(mockIdentifier);
mockIdentifier.getSpace.andReturn(SPACE); mockIdentifier.getSpace.and.returnValue(SPACE);
mockIdentifier.getKey.andReturn(key); mockIdentifier.getKey.and.returnValue(key);
mockQ.when.andCallFake(asPromise); mockQ.when.and.callFake(asPromise);
persistence = new PersistenceCapability( persistence = new PersistenceCapability(
mockCacheService, mockCacheService,
mockPersistenceService, mockPersistenceService,
@ -116,8 +116,8 @@ define(
describe("successful persistence", function () { describe("successful persistence", function () {
beforeEach(function () { beforeEach(function () {
mockPersistenceService.updateObject.andReturn(happyPromise); mockPersistenceService.updateObject.and.returnValue(happyPromise);
mockPersistenceService.createObject.andReturn(happyPromise); mockPersistenceService.createObject.and.returnValue(happyPromise);
}); });
it("creates unpersisted objects with the persistence service", function () { it("creates unpersisted objects with the persistence service", function () {
// Verify precondition; no call made during constructor // Verify precondition; no call made during constructor
@ -158,7 +158,7 @@ define(
it("refreshes the domain object model from persistence", function () { it("refreshes the domain object model from persistence", function () {
var refreshModel = {someOtherKey: "some other value"}; var refreshModel = {someOtherKey: "some other value"};
model.persisted = 1; model.persisted = 1;
mockPersistenceService.readObject.andReturn(asPromise(refreshModel)); mockPersistenceService.readObject.and.returnValue(asPromise(refreshModel));
persistence.refresh(); persistence.refresh();
expect(model).toEqual(refreshModel); expect(model).toEqual(refreshModel);
}); });
@ -178,7 +178,7 @@ define(
} }
}; };
beforeEach(function () { beforeEach(function () {
mockPersistenceService.createObject.andReturn(sadPromise); mockPersistenceService.createObject.and.returnValue(sadPromise);
}); });
it("rejects on falsey persistence result", function () { it("rejects on falsey persistence result", function () {
persistence.persist(); persistence.persist();

View File

@ -69,7 +69,7 @@ define(
} }
}; };
mockObjectService.getObjects.andReturn(mockPromise([])); mockObjectService.getObjects.and.returnValue(mockPromise([]));
relationship = new RelationshipCapability( relationship = new RelationshipCapability(
mockInjector, mockInjector,
@ -87,7 +87,7 @@ define(
it("requests ids found in model's composition from the object service", function () { it("requests ids found in model's composition from the object service", function () {
var ids = ["a", "b", "c", "xyz"]; var ids = ["a", "b", "c", "xyz"];
mockDomainObject.getModel.andReturn({ relationships: { xyz: ids } }); mockDomainObject.getModel.and.returnValue({ relationships: { xyz: ids } });
relationship.getRelatedObjects('xyz'); relationship.getRelatedObjects('xyz');
@ -95,7 +95,7 @@ define(
}); });
it("provides a list of relationship types", function () { it("provides a list of relationship types", function () {
mockDomainObject.getModel.andReturn({ relationships: { mockDomainObject.getModel.and.returnValue({ relationships: {
abc: ['a', 'b'], abc: ['a', 'b'],
def: "not an array, should be ignored", def: "not an array, should be ignored",
xyz: [] xyz: []
@ -107,14 +107,14 @@ define(
// Lookups can be expensive, so this capability // Lookups can be expensive, so this capability
// should have some self-caching // should have some self-caching
mockDomainObject.getModel mockDomainObject.getModel
.andReturn({ relationships: { xyz: ['a'] } }); .and.returnValue({ relationships: { xyz: ['a'] } });
// Call twice; response should be the same object instance // Call twice; response should be the same object instance
expect(relationship.getRelatedObjects('xyz')) expect(relationship.getRelatedObjects('xyz'))
.toBe(relationship.getRelatedObjects('xyz')); .toBe(relationship.getRelatedObjects('xyz'));
// Should have only made one call // Should have only made one call
expect(mockObjectService.getObjects.calls.length) expect(mockObjectService.getObjects.calls.count())
.toEqual(1); .toEqual(1);
}); });
@ -125,7 +125,7 @@ define(
testModel = { relationships: { xyz: ['a'] } }; testModel = { relationships: { xyz: ['a'] } };
mockDomainObject.getModel.andReturn(testModel); mockDomainObject.getModel.and.returnValue(testModel);
// Call twice, but as if modification had occurred in between // Call twice, but as if modification had occurred in between
relationship.getRelatedObjects('xyz'); relationship.getRelatedObjects('xyz');
@ -133,7 +133,7 @@ define(
relationship.getRelatedObjects('xyz'); relationship.getRelatedObjects('xyz');
// Should have only made one call // Should have only made one call
expect(mockObjectService.getObjects.calls.length) expect(mockObjectService.getObjects.calls.count())
.toEqual(2); .toEqual(2);
}); });

View File

@ -67,7 +67,7 @@ define(
a: { someKey: "some value" }, a: { someKey: "some value" },
b: { someOtherKey: "some other value" } b: { someOtherKey: "some other value" }
}; };
mockModelService.getModels.andReturn(asPromise(testModels)); mockModelService.getModels.and.returnValue(asPromise(testModels));
decorator = new CachingModelDecorator( decorator = new CachingModelDecorator(
new ModelCacheService(), new ModelCacheService(),
mockModelService mockModelService
@ -80,19 +80,19 @@ define(
}); });
it("does not try to reload cached models", function () { it("does not try to reload cached models", function () {
mockModelService.getModels.andReturn(asPromise({ a: testModels.a })); mockModelService.getModels.and.returnValue(asPromise({ a: testModels.a }));
decorator.getModels(['a']); decorator.getModels(['a']);
mockModelService.getModels.andReturn(asPromise(testModels)); mockModelService.getModels.and.returnValue(asPromise(testModels));
decorator.getModels(['a', 'b']); decorator.getModels(['a', 'b']);
expect(mockModelService.getModels).not.toHaveBeenCalledWith(['a', 'b']); expect(mockModelService.getModels).not.toHaveBeenCalledWith(['a', 'b']);
expect(mockModelService.getModels.mostRecentCall.args[0]).toEqual(['b']); expect(mockModelService.getModels.calls.mostRecent().args[0]).toEqual(['b']);
}); });
it("does not call its wrapped model service if not needed", function () { it("does not call its wrapped model service if not needed", function () {
decorator.getModels(['a', 'b']); decorator.getModels(['a', 'b']);
expect(mockModelService.getModels.calls.length).toEqual(1); expect(mockModelService.getModels.calls.count()).toEqual(1);
decorator.getModels(['a', 'b']).then(mockCallback); decorator.getModels(['a', 'b']).then(mockCallback);
expect(mockModelService.getModels.calls.length).toEqual(1); expect(mockModelService.getModels.calls.count()).toEqual(1);
// Verify that we still got back our models, even though // Verify that we still got back our models, even though
// no new call to the wrapped service was made // no new call to the wrapped service was made
expect(mockCallback).toHaveBeenCalledWith(testModels); expect(mockCallback).toHaveBeenCalledWith(testModels);
@ -105,9 +105,9 @@ define(
promiseB = fakePromise(); promiseB = fakePromise();
// Issue two calls before those promises resolve // Issue two calls before those promises resolve
mockModelService.getModels.andReturn(promiseA); mockModelService.getModels.and.returnValue(promiseA);
decorator.getModels(['a']); decorator.getModels(['a']);
mockModelService.getModels.andReturn(promiseB); mockModelService.getModels.and.returnValue(promiseB);
decorator.getModels(['a']).then(mockCallback); decorator.getModels(['a']).then(mockCallback);
// Then resolve those promises. Note that we're whiteboxing here // Then resolve those promises. Note that we're whiteboxing here
@ -119,9 +119,9 @@ define(
}); });
// Ensure that we have a pointer-identical instance // Ensure that we have a pointer-identical instance
expect(mockCallback.mostRecentCall.args[0].a) expect(mockCallback.calls.mostRecent().args[0].a)
.toEqual({ someNewKey: "some other value" }); .toEqual({ someNewKey: "some other value" });
expect(mockCallback.mostRecentCall.args[0].a) expect(mockCallback.calls.mostRecent().args[0].a)
.toBe(testModels.a); .toBe(testModels.a);
}); });
@ -132,9 +132,9 @@ define(
promiseB = fakePromise(); promiseB = fakePromise();
// Issue two calls before those promises resolve // Issue two calls before those promises resolve
mockModelService.getModels.andReturn(promiseA); mockModelService.getModels.and.returnValue(promiseA);
decorator.getModels(['a']); decorator.getModels(['a']);
mockModelService.getModels.andReturn(promiseB); mockModelService.getModels.and.returnValue(promiseB);
decorator.getModels(['a']).then(mockCallback); decorator.getModels(['a']).then(mockCallback);
// Some model providers might erroneously add undefined values // Some model providers might erroneously add undefined values
@ -147,7 +147,7 @@ define(
}); });
// Should still have gotten the model // Should still have gotten the model
expect(mockCallback.mostRecentCall.args[0].a) expect(mockCallback.calls.mostRecent().args[0].a)
.toEqual({ someNewKey: "some other value" }); .toEqual({ someNewKey: "some other value" });
}); });

Some files were not shown because too many files have changed in this diff Show More