Merge branch 'master' into persist-on-mutation-825
Conflicts: platform/commonUI/edit/test/actions/EditAndComposeActionSpec.js
This commit is contained in:
@@ -26,7 +26,7 @@ define([
|
||||
"./src/controllers/ElementsController",
|
||||
"./src/controllers/EditObjectController",
|
||||
"./src/directives/MCTBeforeUnload",
|
||||
"./src/actions/LinkAction",
|
||||
"./src/actions/EditAndComposeAction",
|
||||
"./src/actions/EditAction",
|
||||
"./src/actions/PropertiesAction",
|
||||
"./src/actions/RemoveAction",
|
||||
@@ -55,7 +55,7 @@ define([
|
||||
ElementsController,
|
||||
EditObjectController,
|
||||
MCTBeforeUnload,
|
||||
LinkAction,
|
||||
EditAndComposeAction,
|
||||
EditAction,
|
||||
PropertiesAction,
|
||||
RemoveAction,
|
||||
@@ -126,7 +126,7 @@ define([
|
||||
"actions": [
|
||||
{
|
||||
"key": "compose",
|
||||
"implementation": LinkAction
|
||||
"implementation": EditAndComposeAction
|
||||
},
|
||||
{
|
||||
"key": "edit",
|
||||
|
||||
@@ -31,13 +31,14 @@ define(
|
||||
* @memberof platform/commonUI/edit
|
||||
* @implements {Action}
|
||||
*/
|
||||
function LinkAction(context) {
|
||||
function EditAndComposeAction(context) {
|
||||
this.domainObject = (context || {}).domainObject;
|
||||
this.selectedObject = (context || {}).selectedObject;
|
||||
}
|
||||
|
||||
LinkAction.prototype.perform = function () {
|
||||
var self = this;
|
||||
EditAndComposeAction.prototype.perform = function () {
|
||||
var self = this,
|
||||
editAction = this.domainObject.getCapability('action').getActions("edit")[0];
|
||||
|
||||
// Link these objects
|
||||
function doLink() {
|
||||
@@ -46,9 +47,13 @@ define(
|
||||
return composition && composition.add(self.selectedObject);
|
||||
}
|
||||
|
||||
if (editAction) {
|
||||
editAction.perform();
|
||||
}
|
||||
|
||||
return this.selectedObject && doLink();
|
||||
};
|
||||
|
||||
return LinkAction;
|
||||
return EditAndComposeAction;
|
||||
}
|
||||
);
|
||||
@@ -81,17 +81,14 @@ define(
|
||||
var key = action.getMetadata().key,
|
||||
category = (context || {}).category;
|
||||
|
||||
// Only worry about actions in the view-control category
|
||||
if (category === 'view-control') {
|
||||
// Restrict 'edit' to cases where there are editable
|
||||
// views (similarly, restrict 'properties' to when
|
||||
// the converse is true), and where the domain object is not
|
||||
// already being edited.
|
||||
if (key === 'edit') {
|
||||
return this.countEditableViews(context) > 0 && !isEditing(context);
|
||||
} else if (key === 'properties') {
|
||||
return this.countEditableViews(context) < 1 && !isEditing(context);
|
||||
}
|
||||
// Restrict 'edit' to cases where there are editable
|
||||
// views (similarly, restrict 'properties' to when
|
||||
// the converse is true), and where the domain object is not
|
||||
// already being edited.
|
||||
if (key === 'edit') {
|
||||
return this.countEditableViews(context) > 0 && !isEditing(context);
|
||||
} else if (key === 'properties' && category === 'view-control') {
|
||||
return this.countEditableViews(context) < 1 && !isEditing(context);
|
||||
}
|
||||
|
||||
// Like all policies, allow by default.
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
["../../src/actions/LinkAction"],
|
||||
function (LinkAction) {
|
||||
["../../src/actions/EditAndComposeAction"],
|
||||
function (EditAndComposeAction) {
|
||||
|
||||
describe("The Link action", function () {
|
||||
var mockQ,
|
||||
@@ -30,6 +30,8 @@ define(
|
||||
mockParent,
|
||||
mockContext,
|
||||
mockComposition,
|
||||
mockActionCapability,
|
||||
mockEditAction,
|
||||
mockType,
|
||||
actionContext,
|
||||
model,
|
||||
@@ -65,17 +67,22 @@ define(
|
||||
};
|
||||
mockContext = jasmine.createSpyObj("context", [ "getParent" ]);
|
||||
mockComposition = jasmine.createSpyObj("composition", [ "invoke", "add" ]);
|
||||
mockType = jasmine.createSpyObj("type", [ "hasFeature" ]);
|
||||
mockType = jasmine.createSpyObj("type", [ "hasFeature", "getKey" ]);
|
||||
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([]);
|
||||
|
||||
capabilities = {
|
||||
composition: mockComposition,
|
||||
action: mockActionCapability,
|
||||
type: mockType
|
||||
};
|
||||
model = {
|
||||
@@ -87,7 +94,7 @@ define(
|
||||
selectedObject: mockDomainObject
|
||||
};
|
||||
|
||||
action = new LinkAction(actionContext);
|
||||
action = new EditAndComposeAction(actionContext);
|
||||
});
|
||||
|
||||
|
||||
@@ -97,6 +104,21 @@ define(
|
||||
.toHaveBeenCalledWith(mockDomainObject);
|
||||
});
|
||||
|
||||
it("enables edit mode for objects that have an edit action", function () {
|
||||
mockActionCapability.getActions.andReturn([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([]);
|
||||
action.perform();
|
||||
expect(mockEditAction.perform).not.toHaveBeenCalled();
|
||||
expect(mockComposition.add)
|
||||
.toHaveBeenCalledWith(mockDomainObject);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -32,7 +32,8 @@ define(
|
||||
*/
|
||||
function InspectorController($scope, policyService) {
|
||||
var domainObject = $scope.domainObject,
|
||||
typeCapability = domainObject.getCapability('type');
|
||||
typeCapability = domainObject.getCapability('type'),
|
||||
statusListener;
|
||||
|
||||
/**
|
||||
* Filters region parts to only those allowed by region policies
|
||||
@@ -50,6 +51,11 @@ define(
|
||||
$scope.regions = filterRegions(typeCapability.getDefinition().inspector || new InspectorRegion());
|
||||
}
|
||||
|
||||
statusListener = domainObject.getCapability("status").listen(setRegions);
|
||||
$scope.$on("$destroy", function () {
|
||||
statusListener();
|
||||
});
|
||||
|
||||
setRegions();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@ define(
|
||||
mockTypeCapability,
|
||||
mockTypeDefinition,
|
||||
mockPolicyService,
|
||||
mockStatusCapability,
|
||||
capabilities = {},
|
||||
controller;
|
||||
|
||||
beforeEach(function(){
|
||||
@@ -47,19 +49,29 @@ define(
|
||||
'getDefinition'
|
||||
]);
|
||||
mockTypeCapability.getDefinition.andReturn(mockTypeDefinition);
|
||||
capabilities.type = mockTypeCapability;
|
||||
|
||||
mockStatusCapability = jasmine.createSpyObj('statusCapability', [
|
||||
'listen'
|
||||
]);
|
||||
capabilities.status = mockStatusCapability;
|
||||
|
||||
mockDomainObject = jasmine.createSpyObj('domainObject', [
|
||||
'getCapability'
|
||||
]);
|
||||
mockDomainObject.getCapability.andReturn(mockTypeCapability);
|
||||
mockDomainObject.getCapability.andCallFake(function (name) {
|
||||
return capabilities[name];
|
||||
});
|
||||
|
||||
mockPolicyService = jasmine.createSpyObj('policyService', [
|
||||
'allow'
|
||||
]);
|
||||
|
||||
mockScope = {
|
||||
domainObject: mockDomainObject
|
||||
};
|
||||
mockScope = jasmine.createSpyObj('$scope',
|
||||
['$on']
|
||||
);
|
||||
|
||||
mockScope.domainObject = mockDomainObject;
|
||||
});
|
||||
|
||||
it("filters out regions disallowed by region policy", function() {
|
||||
@@ -73,6 +85,25 @@ define(
|
||||
controller = new InspectorController(mockScope, mockPolicyService);
|
||||
expect(mockScope.regions.length).toBe(2);
|
||||
});
|
||||
|
||||
it("Responds to status changes", function() {
|
||||
mockPolicyService.allow.andReturn(true);
|
||||
controller = new InspectorController(mockScope, mockPolicyService);
|
||||
expect(mockScope.regions.length).toBe(2);
|
||||
expect(mockStatusCapability.listen).toHaveBeenCalled();
|
||||
mockPolicyService.allow.andReturn(false);
|
||||
mockStatusCapability.listen.mostRecentCall.args[0]();
|
||||
expect(mockScope.regions.length).toBe(0);
|
||||
});
|
||||
|
||||
it("Unregisters status listener", function() {
|
||||
var mockListener = jasmine.createSpy('listener');
|
||||
mockStatusCapability.listen.andReturn(mockListener);
|
||||
controller = new InspectorController(mockScope, mockPolicyService);
|
||||
expect(mockScope.$on).toHaveBeenCalledWith("$destroy", jasmine.any(Function));
|
||||
mockScope.$on.mostRecentCall.args[1]();
|
||||
expect(mockListener).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user