Merge remote-tracking branch 'github-open/open97' into open-master
This commit is contained in:
@@ -86,37 +86,18 @@ define(
|
||||
// composition, so that it will subsequently appear
|
||||
// as a child contained by that parent.
|
||||
function addToComposition(id, parent, parentPersistence) {
|
||||
var mutatationResult = parent.useCapability("mutation", function (model) {
|
||||
if (Array.isArray(model.composition)) {
|
||||
// Don't add if the id is already there
|
||||
if (model.composition.indexOf(id) === -1) {
|
||||
model.composition.push(id);
|
||||
}
|
||||
} else {
|
||||
// This is abnormal; composition should be an array
|
||||
self.$log.warn(NO_COMPOSITION_WARNING + parent.getId());
|
||||
return false; // Cancel mutation
|
||||
}
|
||||
});
|
||||
var compositionCapability = parent.getCapability('composition'),
|
||||
addResult = compositionCapability &&
|
||||
compositionCapability.add(id);
|
||||
|
||||
return self.$q.when(mutatationResult).then(function (result) {
|
||||
return self.$q.when(addResult).then(function (result) {
|
||||
if (!result) {
|
||||
self.$log.error("Could not mutate " + parent.getId());
|
||||
self.$log.error("Could not modify " + parent.getId());
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return parentPersistence.persist().then(function () {
|
||||
// Locate and return new Object in context of parent.
|
||||
return parent
|
||||
.useCapability('composition')
|
||||
.then(function (children) {
|
||||
var i;
|
||||
for (i = 0; i < children.length; i += 1) {
|
||||
if (children[i].getId() === id) {
|
||||
return children[i];
|
||||
}
|
||||
}
|
||||
});
|
||||
return result;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ define(
|
||||
);
|
||||
mockCompositionCapability = jasmine.createSpyObj(
|
||||
"composition",
|
||||
["invoke"]
|
||||
["invoke", "add"]
|
||||
);
|
||||
mockContextCapability = jasmine.createSpyObj(
|
||||
"context",
|
||||
@@ -120,6 +120,7 @@ define(
|
||||
mockCompositionCapability.invoke.andReturn(
|
||||
mockPromise([mockNewObject])
|
||||
);
|
||||
mockCompositionCapability.add.andReturn(mockPromise(true));
|
||||
|
||||
creationService = new CreationService(
|
||||
mockPersistenceService,
|
||||
@@ -143,33 +144,34 @@ define(
|
||||
parentModel = { composition: ["notAnyUUID"] };
|
||||
creationService.createObject(model, mockParentObject);
|
||||
|
||||
// Invoke the mutation callback
|
||||
expect(mockMutationCapability.invoke).toHaveBeenCalled();
|
||||
mockMutationCapability.invoke.mostRecentCall.args[0](parentModel);
|
||||
|
||||
// Should have a longer composition now, with the new UUID
|
||||
expect(parentModel.composition.length).toEqual(2);
|
||||
// Verify that a new ID was added
|
||||
expect(mockCompositionCapability.add)
|
||||
.toHaveBeenCalledWith(jasmine.any(String));
|
||||
});
|
||||
|
||||
it("warns if parent has no composition", function () {
|
||||
var model = { someKey: "some value" },
|
||||
parentModel = { };
|
||||
creationService.createObject(model, mockParentObject);
|
||||
it("provides the newly-created object", function () {
|
||||
var mockDomainObject = jasmine.createSpyObj(
|
||||
'newDomainObject',
|
||||
['getId', 'getModel', 'getCapability']
|
||||
),
|
||||
mockCallback = jasmine.createSpy('callback');
|
||||
|
||||
// Verify precondition; no prior warnings
|
||||
expect(mockLog.warn).not.toHaveBeenCalled();
|
||||
// Act as if the object had been created
|
||||
mockCompositionCapability.add.andCallFake(function (id) {
|
||||
mockDomainObject.getId.andReturn(id);
|
||||
mockCompositionCapability.invoke
|
||||
.andReturn(mockPromise([mockDomainObject]));
|
||||
return mockPromise(mockDomainObject);
|
||||
});
|
||||
|
||||
// Invoke the mutation callback
|
||||
expect(mockMutationCapability.invoke).toHaveBeenCalled();
|
||||
mockMutationCapability.invoke.mostRecentCall.args[0](parentModel);
|
||||
// Should find it in the composition
|
||||
creationService.createObject({}, mockParentObject)
|
||||
.then(mockCallback);
|
||||
|
||||
expect(mockCallback).toHaveBeenCalledWith(mockDomainObject);
|
||||
|
||||
// Should have a longer composition now, with the new UUID
|
||||
expect(mockLog.warn).toHaveBeenCalled();
|
||||
// Composition should still be undefined
|
||||
expect(parentModel.composition).toBeUndefined();
|
||||
});
|
||||
|
||||
|
||||
it("warns if parent has no persistence capability", function () {
|
||||
// Callbacks
|
||||
var success = jasmine.createSpy("success"),
|
||||
@@ -185,7 +187,6 @@ define(
|
||||
expect(mockLog.warn).toHaveBeenCalled();
|
||||
expect(success).not.toHaveBeenCalled();
|
||||
expect(failure).toHaveBeenCalled();
|
||||
|
||||
});
|
||||
|
||||
it("logs an error when mutaton fails", function () {
|
||||
@@ -194,7 +195,7 @@ define(
|
||||
var model = { someKey: "some value" },
|
||||
parentModel = { composition: ["notAnyUUID"] };
|
||||
|
||||
mockMutationCapability.invoke.andReturn(mockPromise(false));
|
||||
mockCompositionCapability.add.andReturn(mockPromise(false));
|
||||
|
||||
creationService.createObject(model, mockParentObject);
|
||||
|
||||
|
||||
@@ -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