mirror of
https://github.com/nasa/openmct.git
synced 2025-01-26 22:29:34 +00:00
[Core] Edit-wrap relationship capability
Wrap objects retrieved via the relationship capability with Edit mode caching etc, for WTD-1007.
This commit is contained in:
parent
97fe378751
commit
bbe26cd06c
@ -28,7 +28,7 @@ define(
|
||||
editableObject,
|
||||
domainObject,
|
||||
cache,
|
||||
true // Not idempotent
|
||||
true // Idempotent
|
||||
);
|
||||
};
|
||||
}
|
||||
|
@ -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
|
||||
);
|
||||
};
|
||||
}
|
||||
);
|
@ -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) ?
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
@ -12,6 +12,7 @@
|
||||
"capabilities/EditableContextCapability",
|
||||
"capabilities/EditableLookupCapability",
|
||||
"capabilities/EditablePersistenceCapability",
|
||||
"capabilities/EditableRelationshipCapability",
|
||||
"capabilities/EditorCapability",
|
||||
"objects/EditableDomainObject",
|
||||
"objects/EditableDomainObjectCache",
|
||||
|
Loading…
x
Reference in New Issue
Block a user