diff --git a/platform/commonUI/edit/src/capabilities/EditableContextCapability.js b/platform/commonUI/edit/src/capabilities/EditableContextCapability.js index b8658aa19a..a21dc9ba31 100644 --- a/platform/commonUI/edit/src/capabilities/EditableContextCapability.js +++ b/platform/commonUI/edit/src/capabilities/EditableContextCapability.js @@ -28,7 +28,7 @@ define( editableObject, domainObject, cache, - true // Not idempotent + true // Idempotent ); }; } diff --git a/platform/commonUI/edit/src/capabilities/EditableRelationshipCapability.js b/platform/commonUI/edit/src/capabilities/EditableRelationshipCapability.js new file mode 100644 index 0000000000..cc0082757a --- /dev/null +++ b/platform/commonUI/edit/src/capabilities/EditableRelationshipCapability.js @@ -0,0 +1,36 @@ +/*global define*/ + + +define( + ['./EditableLookupCapability'], + function (EditableLookupCapability) { + 'use strict'; + + /** + * Wrapper for the "relationship" capability; + * ensures that any domain objects reachable in Edit mode + * are also wrapped as EditableDomainObjects. + * + * Meant specifically for use by EditableDomainObject and the + * associated cache; the constructor signature is particular + * to a pattern used there and may contain unused arguments. + */ + return function EditableRelationshipCapability( + relationshipCapability, + editableObject, + domainObject, + cache + ) { + // This is a "lookup" style capability (it looks up other + // domain objects), but we do not want to return the same + // specific value every time (composition may change) + return new EditableLookupCapability( + relationshipCapability, + editableObject, + domainObject, + cache, + false // Not idempotent + ); + }; + } +); \ No newline at end of file diff --git a/platform/commonUI/edit/src/objects/EditableDomainObject.js b/platform/commonUI/edit/src/objects/EditableDomainObject.js index a6b3d503d7..4e3363c8e9 100644 --- a/platform/commonUI/edit/src/objects/EditableDomainObject.js +++ b/platform/commonUI/edit/src/objects/EditableDomainObject.js @@ -14,6 +14,7 @@ define( '../capabilities/EditablePersistenceCapability', '../capabilities/EditableContextCapability', '../capabilities/EditableCompositionCapability', + '../capabilities/EditableRelationshipCapability', '../capabilities/EditorCapability', './EditableDomainObjectCache' ], @@ -21,6 +22,7 @@ define( EditablePersistenceCapability, EditableContextCapability, EditableCompositionCapability, + EditableRelationshipCapability, EditorCapability, EditableDomainObjectCache ) { @@ -30,6 +32,7 @@ define( persistence: EditablePersistenceCapability, context: EditableContextCapability, composition: EditableCompositionCapability, + relationship: EditableRelationshipCapability, editor: EditorCapability }; @@ -64,7 +67,10 @@ define( // Override certain capabilities editableObject.getCapability = function (name) { var delegateArguments = getDelegateArguments(name, arguments), - capability = domainObject.getCapability.apply(this, delegateArguments), + capability = domainObject.getCapability.apply( + this, + delegateArguments + ), factory = capabilityFactories[name]; return (factory && capability) ? diff --git a/platform/commonUI/edit/test/capabilities/EditableRelationshipCapabilitySpec.js b/platform/commonUI/edit/test/capabilities/EditableRelationshipCapabilitySpec.js new file mode 100644 index 0000000000..65d044d7c8 --- /dev/null +++ b/platform/commonUI/edit/test/capabilities/EditableRelationshipCapabilitySpec.js @@ -0,0 +1,54 @@ +/*global define,describe,it,expect,beforeEach,jasmine*/ + +define( + ["../../src/capabilities/EditableRelationshipCapability"], + function (EditableRelationshipCapability) { + "use strict"; + + describe("An editable relationship capability", function () { + var mockContext, + mockEditableObject, + mockDomainObject, + mockTestObject, + someValue, + mockFactory, + capability; + + beforeEach(function () { + // EditableContextCapability should watch ALL + // methods for domain objects, so give it an + // arbitrary interface to wrap. + mockContext = + jasmine.createSpyObj("context", [ "getDomainObject" ]); + mockTestObject = jasmine.createSpyObj( + "domainObject", + [ "getId", "getModel", "getCapability" ] + ); + mockFactory = + jasmine.createSpyObj("factory", ["getEditableObject"]); + + someValue = { x: 42 }; + + mockContext.getDomainObject.andReturn(mockTestObject); + mockFactory.getEditableObject.andReturn(someValue); + + capability = new EditableRelationshipCapability( + mockContext, + mockEditableObject, + mockDomainObject, + mockFactory + ); + + }); + + // Most behavior is tested for EditableLookupCapability, + // so just verify that this isse + it("presumes non-idempotence of its wrapped capability", function () { + expect(capability.getDomainObject()) + .toEqual(capability.getDomainObject()); + expect(mockContext.getDomainObject.calls.length).toEqual(2); + }); + + }); + } +); \ No newline at end of file diff --git a/platform/commonUI/edit/test/suite.json b/platform/commonUI/edit/test/suite.json index 5744ff8ea8..da4fbb899e 100644 --- a/platform/commonUI/edit/test/suite.json +++ b/platform/commonUI/edit/test/suite.json @@ -12,6 +12,7 @@ "capabilities/EditableContextCapability", "capabilities/EditableLookupCapability", "capabilities/EditablePersistenceCapability", + "capabilities/EditableRelationshipCapability", "capabilities/EditorCapability", "objects/EditableDomainObject", "objects/EditableDomainObjectCache",