Merge remote-tracking branch 'github-open/open97' into open-master
This commit is contained in:
@@ -36,20 +36,11 @@ define(
|
||||
function LinkAction(context) {
|
||||
this.domainObject = (context || {}).domainObject;
|
||||
this.selectedObject = (context || {}).selectedObject;
|
||||
this.selectedId = this.selectedObject && this.selectedObject.getId();
|
||||
}
|
||||
|
||||
LinkAction.prototype.perform = function () {
|
||||
var self = this;
|
||||
|
||||
// Add this domain object's identifier
|
||||
function addId(model) {
|
||||
if (Array.isArray(model.composition) &&
|
||||
model.composition.indexOf(self.selectedId) < 0) {
|
||||
model.composition.push(self.selectedId);
|
||||
}
|
||||
}
|
||||
|
||||
// Persist changes to the domain object
|
||||
function doPersist() {
|
||||
var persistence =
|
||||
@@ -59,11 +50,13 @@ define(
|
||||
|
||||
// Link these objects
|
||||
function doLink() {
|
||||
return self.domainObject.useCapability("mutation", addId)
|
||||
.then(doPersist);
|
||||
var composition = self.domainObject &&
|
||||
self.domainObject.getCapability('composition');
|
||||
return composition && composition.add(self.selectedObject)
|
||||
.then(doPersist);
|
||||
}
|
||||
|
||||
return this.selectedId && doLink();
|
||||
return this.selectedObject && doLink();
|
||||
};
|
||||
|
||||
return LinkAction;
|
||||
|
||||
@@ -54,6 +54,9 @@ define(
|
||||
var row = Object.create(property.getDefinition());
|
||||
row.key = index;
|
||||
return row;
|
||||
}).filter(function (row) {
|
||||
// Only show properties which are editable
|
||||
return row.control;
|
||||
})
|
||||
}]
|
||||
};
|
||||
|
||||
@@ -31,7 +31,7 @@ define(
|
||||
mockDomainObject,
|
||||
mockParent,
|
||||
mockContext,
|
||||
mockMutation,
|
||||
mockComposition,
|
||||
mockPersistence,
|
||||
mockType,
|
||||
actionContext,
|
||||
@@ -67,7 +67,7 @@ define(
|
||||
}
|
||||
};
|
||||
mockContext = jasmine.createSpyObj("context", [ "getParent" ]);
|
||||
mockMutation = jasmine.createSpyObj("mutation", [ "invoke" ]);
|
||||
mockComposition = jasmine.createSpyObj("composition", [ "invoke", "add" ]);
|
||||
mockPersistence = jasmine.createSpyObj("persistence", [ "persist" ]);
|
||||
mockType = jasmine.createSpyObj("type", [ "hasFeature" ]);
|
||||
|
||||
@@ -75,11 +75,11 @@ define(
|
||||
mockDomainObject.getCapability.andReturn(mockContext);
|
||||
mockContext.getParent.andReturn(mockParent);
|
||||
mockType.hasFeature.andReturn(true);
|
||||
mockMutation.invoke.andReturn(mockPromise(true));
|
||||
|
||||
mockComposition.invoke.andReturn(mockPromise(true));
|
||||
mockComposition.add.andReturn(mockPromise(true));
|
||||
|
||||
capabilities = {
|
||||
mutation: mockMutation,
|
||||
composition: mockComposition,
|
||||
persistence: mockPersistence,
|
||||
type: mockType
|
||||
};
|
||||
@@ -96,33 +96,17 @@ define(
|
||||
});
|
||||
|
||||
|
||||
it("mutates the parent when performed", function () {
|
||||
it("adds to the parent's composition when performed", function () {
|
||||
action.perform();
|
||||
expect(mockMutation.invoke)
|
||||
.toHaveBeenCalledWith(jasmine.any(Function));
|
||||
expect(mockComposition.add)
|
||||
.toHaveBeenCalledWith(mockDomainObject);
|
||||
});
|
||||
|
||||
it("changes composition from its mutation function", function () {
|
||||
var mutator, result;
|
||||
it("persists changes afterward", function () {
|
||||
action.perform();
|
||||
mutator = mockMutation.invoke.mostRecentCall.args[0];
|
||||
result = mutator(model);
|
||||
|
||||
// Should not have cancelled the mutation
|
||||
expect(result).not.toBe(false);
|
||||
|
||||
// Simulate mutate's behavior (remove can either return a
|
||||
// new model or modify this one in-place)
|
||||
result = result || model;
|
||||
|
||||
// Should have removed "test" - that was our
|
||||
// mock domain object's id.
|
||||
expect(result.composition).toEqual(["a", "b", "c", "test"]);
|
||||
|
||||
// Finally, should have persisted
|
||||
expect(mockPersistence.persist).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -39,7 +39,7 @@ define(
|
||||
return {
|
||||
getValue: function (model) { return model[k]; },
|
||||
setValue: function (model, v) { model[k] = v; },
|
||||
getDefinition: function () { return {}; }
|
||||
getDefinition: function () { return { control: 'textfield '}; }
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user