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

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

View File

@@ -66,11 +66,11 @@ define(
editor: mockEditor
};
mockDomainObject.getCapability.andCallFake(function (name) {
mockDomainObject.getCapability.and.callFake(function (name) {
return capabilities[name];
});
mockDomainObject.hasCapability.andReturn(true);
mockType.hasFeature.andReturn(true);
mockDomainObject.hasCapability.and.returnValue(true);
mockType.hasFeature.and.returnValue(true);
actionContext = { domainObject: mockDomainObject };
@@ -92,9 +92,9 @@ define(
});
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);
mockEditor.isEditContextRoot.andReturn(true);
mockEditor.isEditContextRoot.and.returnValue(true);
expect(EditAction.appliesTo(actionContext)).toBe(false);
});

View File

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

View File

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

View File

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

View File

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

View File

@@ -86,13 +86,13 @@ define(
["info", "error"]
);
mockDomainObject.hasCapability.andReturn(true);
mockDomainObject.getCapability.andCallFake(function (capability) {
mockDomainObject.hasCapability.and.returnValue(true);
mockDomainObject.getCapability.and.callFake(function (capability) {
return capabilities[capability];
});
mockDomainObject.getModel.andReturn({ persisted: 0 });
mockEditorCapability.save.andReturn(mockPromise(true));
mockEditorCapability.isEditContextRoot.andReturn(true);
mockDomainObject.getModel.and.returnValue({ persisted: 0 });
mockEditorCapability.save.and.returnValue(mockPromise(true));
mockEditorCapability.isEditContextRoot.and.returnValue(true);
action = new SaveAndStopEditingAction(dialogService, notificationService, actionContext);
});
@@ -102,18 +102,18 @@ define(
expect(SaveAndStopEditingAction.appliesTo(actionContext)).toBe(true);
expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor");
mockDomainObject.hasCapability.andReturn(false);
mockDomainObject.getCapability.andReturn(undefined);
mockDomainObject.hasCapability.and.returnValue(false);
mockDomainObject.getCapability.and.returnValue(undefined);
expect(SaveAndStopEditingAction.appliesTo(actionContext)).toBe(false);
});
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);
});
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();
expect(mockEditorCapability.save).toHaveBeenCalled();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -41,13 +41,13 @@ define(
['getTrueRoot']
);
mockDomainObject.getId.andReturn('test-id');
mockDomainObject.getCapability.andReturn(mockContext);
mockDomainObject.getId.and.returnValue('test-id');
mockDomainObject.getCapability.and.returnValue(mockContext);
// 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']);
mockRoot.getId.andReturn('root-id');
mockRoot.getId.and.returnValue('root-id');
return mockRoot;
});
@@ -63,7 +63,7 @@ define(
});
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
expect(mockDomainObject.getCapability)
@@ -76,10 +76,10 @@ define(
it("preserves the same root instance to avoid excessive refreshing", function () {
var firstRoot;
// Expose the domain object
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
firstRoot = controller.getRoot();
// Update!
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
// Should still have the same object instance, to avoid
// triggering the watch used by the template we're supporting
expect(controller.getRoot()).toBe(firstRoot);
@@ -90,18 +90,18 @@ define(
it("updates the root when it changes", function () {
var firstRoot;
// Expose the domain object
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
firstRoot = controller.getRoot();
// Change the exposed root
mockContext.getTrueRoot.andCallFake(function () {
mockContext.getTrueRoot.and.callFake(function () {
var mockRoot = jasmine.createSpyObj('root', ['getId']);
mockRoot.getId.andReturn('other-root-id');
mockRoot.getId.and.returnValue('other-root-id');
return mockRoot;
});
// Update!
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
mockScope.$watch.calls.mostRecent().args[1](mockDomainObject);
// Should still have the same object instance, to avoid
// triggering the watch used by the template we're supporting

View File

@@ -63,13 +63,13 @@ define(
mockMutationCapability = jasmine.createSpyObj("mutationCapability", [
"listen"
]);
mockMutationCapability.listen.andReturn(mockUnlisten);
mockMutationCapability.listen.and.returnValue(mockUnlisten);
mockDomainObject = jasmine.createSpyObj("domainObject", [
"getCapability",
"useCapability"
]);
mockDomainObject.useCapability.andReturn(mockCompositionCapability);
mockDomainObject.getCapability.andReturn(mockMutationCapability);
mockDomainObject.useCapability.and.returnValue(mockCompositionCapability);
mockDomainObject.getCapability.and.returnValue(mockMutationCapability);
mockScope = jasmine.createSpyObj("$scope", ['$on']);
mockSelection = jasmine.createSpyObj("selection", [
@@ -77,7 +77,7 @@ define(
'off',
'get'
]);
mockSelection.get.andReturn([]);
mockSelection.get.and.returnValue([]);
mockOpenMCT = {
selection: mockSelection
};
@@ -88,7 +88,7 @@ define(
}
};
spyOn(ElementsController.prototype, 'refreshComposition').andCallThrough();
spyOn(ElementsController.prototype, 'refreshComposition').and.callThrough();
controller = new ElementsController(mockScope, mockOpenMCT);
});
@@ -123,29 +123,29 @@ define(
});
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);
});
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(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 () {
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
expect(mockMutationCapability.listen).toHaveBeenCalled();
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
expect(mockUnlisten).toHaveBeenCalled();
});
@@ -156,7 +156,7 @@ define(
elementProxy: {}
}
};
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
mockOpenMCT.selection.on.calls.mostRecent().args[1](selectable);
expect(mockDomainObject.getCapability).not.toHaveBeenCalledWith('mutation');
});
@@ -167,13 +167,13 @@ define(
firstCompositionCallback,
secondCompositionCallback;
spyOn(mockCompositionCapability, "then").andCallThrough();
spyOn(mockCompositionCapability, "then").and.callThrough();
controller.refreshComposition(mockDomainObject);
controller.refreshComposition(mockDomainObject);
firstCompositionCallback = mockCompositionCapability.then.calls[0].args[0];
secondCompositionCallback = mockCompositionCapability.then.calls[1].args[0];
firstCompositionCallback = mockCompositionCapability.then.calls.all()[0].args[0];
secondCompositionCallback = mockCompositionCapability.then.calls.all()[1].args[0];
secondCompositionCallback(secondMockCompositionObjects);
firstCompositionCallback(mockCompositionObjects);

View File

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

View File

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

View File

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

View File

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

View File

@@ -41,10 +41,10 @@ define(
"property" + name,
["getDefinition", "getValue", "setValue"]
);
mockProperty.getDefinition.andReturn({
mockProperty.getDefinition.and.returnValue({
control: "textfield"
});
mockProperty.getValue.andReturn(name);
mockProperty.getValue.and.returnValue(name);
return mockProperty;
}
@@ -74,12 +74,12 @@ define(
testModel = { someKey: "some value" };
mockType.getKey.andReturn("test");
mockType.getCssClass.andReturn("icon-telemetry");
mockType.getDescription.andReturn("a test type");
mockType.getName.andReturn("Test");
mockType.getInitialModel.andReturn(testModel);
mockType.getProperties.andReturn(mockProperties);
mockType.getKey.and.returnValue("test");
mockType.getCssClass.and.returnValue("icon-telemetry");
mockType.getDescription.and.returnValue("a test type");
mockType.getName.and.returnValue("Test");
mockType.getInitialModel.and.returnValue(testModel);
mockType.getProperties.and.returnValue(mockProperties);
mockDomainObject = jasmine.createSpyObj(
'domainObject',
@@ -87,9 +87,9 @@ define(
);
//Mocking the getCapability('type') call
mockDomainObject.getCapability.andReturn(mockType);
mockDomainObject.useCapability.andReturn();
mockDomainObject.getModel.andReturn(testModel);
mockDomainObject.getCapability.and.returnValue(mockType);
mockDomainObject.useCapability.and.returnValue();
mockDomainObject.getModel.and.returnValue(testModel);
wizard = new CreateWizard(
mockDomainObject,
@@ -147,9 +147,11 @@ define(
"C": "ValueC"
},
compareModel = wizard.createModel(formValue);
//populateObjectFromInput adds a .location attribute that is not added by createModel.
compareModel.location = undefined;
wizard.populateObjectFromInput(formValue);
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 () {
@@ -168,7 +170,7 @@ define(
rows = structure.sections[sections.length - 1].rows,
locationRow = rows[rows.length - 1];
mockDomainObj.getCapability.andReturn(mockOtherType);
mockDomainObj.getCapability.and.returnValue(mockOtherType);
locationRow.validate(mockDomainObj);
// 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 () {
mockType.hasFeature.andReturn(true);
mockType.hasFeature.and.returnValue(true);
expect(policy.allow(mockType)).toBeTruthy();
});
it("disallows creation of types without the creation feature", function () {
mockType.hasFeature.andReturn(false);
mockType.hasFeature.and.returnValue(false);
expect(policy.allow(mockType)).toBeFalsy();
});
});

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -52,8 +52,8 @@ define([
'useCapability'
]);
domainObject.getId.andReturn('anId');
domainObject.getModel.andReturn({name: 'anObject'});
domainObject.getId.and.returnValue('anId');
domainObject.getModel.and.returnValue({name: 'anObject'});
representation = {
key: 'someRepresentation'
@@ -75,7 +75,7 @@ define([
expect(domainObject.useCapability)
.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)
.toEqual({some: 'config'});

View File

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

View File

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

View File

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

View File

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