[Edit Mode] #629 rewriting disabled tests

This commit is contained in:
Henry 2016-05-26 11:35:56 -07:00
parent 5fe759aa91
commit eda1f23df9
2 changed files with 79 additions and 32 deletions

View File

@ -24,12 +24,11 @@ define(
["../../src/actions/CancelAction"], ["../../src/actions/CancelAction"],
function (CancelAction) { function (CancelAction) {
//TODO: Disabled for NEM Beta describe("The Cancel action", function () {
xdescribe("The Cancel action", function () { var mockDomainObject,
var mockLocation, mockParentObject,
mockDomainObject, capabilities = {},
mockEditorCapability, parentCapabilities = {},
mockUrlService,
actionContext, actionContext,
action; action;
@ -42,61 +41,109 @@ define(
} }
beforeEach(function () { beforeEach(function () {
mockLocation = jasmine.createSpyObj(
"$location",
["path"]
);
mockDomainObject = jasmine.createSpyObj( mockDomainObject = jasmine.createSpyObj(
"domainObject", "domainObject",
["getCapability", "hasCapability"] [
"getCapability",
"hasCapability",
"getModel"
]
); );
mockEditorCapability = jasmine.createSpyObj( mockDomainObject.getModel.andReturn({});
mockParentObject = jasmine.createSpyObj(
"parentObject",
[
"getCapability"
]
);
mockParentObject.getCapability.andCallFake(function (name) {
return parentCapabilities[name];
});
capabilities.editor = jasmine.createSpyObj(
"editor", "editor",
["save", "cancel"] ["save", "cancel", "isEditContextRoot"]
); );
mockUrlService = jasmine.createSpyObj( capabilities.action = jasmine.createSpyObj(
"urlService", "actionCapability",
["urlForLocation"] [
"perform"
]
);
capabilities.location = jasmine.createSpyObj(
"locationCapability",
[
"getOriginal"
]
);
capabilities.location.getOriginal.andReturn(mockPromise(mockDomainObject));
capabilities.context = jasmine.createSpyObj(
"contextCapability",
[
"getParent"
]
);
capabilities.context.getParent.andReturn(mockParentObject);
parentCapabilities.action = jasmine.createSpyObj(
"actionCapability",
[
"perform"
]
); );
actionContext = { actionContext = {
domainObject: mockDomainObject domainObject: mockDomainObject
}; };
mockDomainObject.hasCapability.andReturn(true); mockDomainObject.getCapability.andCallFake(function (name) {
mockDomainObject.getCapability.andReturn(mockEditorCapability); return capabilities[name];
mockEditorCapability.cancel.andReturn(mockPromise(true)); });
action = new CancelAction(mockLocation, mockUrlService, actionContext); mockDomainObject.hasCapability.andCallFake(function (name) {
return !!capabilities[name];
});
capabilities.editor.cancel.andReturn(mockPromise(true));
action = new CancelAction(actionContext);
}); });
it("only applies to domain object with an editor capability", function () { it("only applies to domain object that is being edited", function () {
capabilities.editor.isEditContextRoot.andReturn(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);
expect(CancelAction.appliesTo(actionContext)).toBeFalsy();
mockDomainObject.hasCapability.andReturn(false); mockDomainObject.hasCapability.andReturn(false);
mockDomainObject.getCapability.andReturn(undefined);
expect(CancelAction.appliesTo(actionContext)).toBeFalsy(); expect(CancelAction.appliesTo(actionContext)).toBeFalsy();
}); });
it("invokes the editor capability's save functionality when performed", function () { it("invokes the editor capability's cancel functionality when" +
// Verify precondition " performed", function () {
expect(mockEditorCapability.cancel).not.toHaveBeenCalled();
action.perform(); action.perform();
// Should have called cancel // Should have called cancel
expect(mockEditorCapability.cancel).toHaveBeenCalled(); expect(capabilities.editor.cancel).toHaveBeenCalled();
// Definitely shouldn't call save! // Definitely shouldn't call save!
expect(mockEditorCapability.save).not.toHaveBeenCalled(); expect(capabilities.editor.save).not.toHaveBeenCalled();
}); });
it("returns to browse when performed", function () { it("navigates to object if existing", function () {
mockDomainObject.getModel.andReturn({persisted: 1});
action.perform(); action.perform();
expect(mockLocation.path).toHaveBeenCalledWith( expect(capabilities.action.perform).toHaveBeenCalledWith("navigate");
mockUrlService.urlForLocation("browse", mockDomainObject) });
);
it("navigates to parent if new", function () {
mockDomainObject.getModel.andReturn({persisted: undefined});
action.perform();
expect(parentCapabilities.action.perform).toHaveBeenCalledWith("navigate");
}); });
}); });
} }

View File

@ -42,7 +42,7 @@ define(
'parent' 'parent'
]; ];
xdescribe("ConductorRepresenter", function () { describe("ConductorRepresenter", function () {
var mockThrottle, var mockThrottle,
mockConductorService, mockConductorService,
mockCompile, mockCompile,