Merge branch 'master' into persist-on-mutation-825
Conflicts: platform/commonUI/edit/src/actions/RemoveAction.js platform/commonUI/edit/test/actions/EditAndComposeActionSpec.js platform/commonUI/edit/test/actions/RemoveActionSpec.js platform/entanglement/src/services/LinkService.js platform/features/timeline/src/controllers/drag/TimelineDragHandler.js platform/features/timeline/src/controllers/swimlane/TimelineSwimlaneDecorator.js platform/features/timeline/test/controllers/drag/TimelineDragHandlerSpec.js platform/features/timeline/test/controllers/swimlane/TimelineSwimlaneDropHandlerSpec.js
This commit is contained in:
@@ -81,8 +81,8 @@ define(
|
||||
// additionally fills in the action's getMetadata method
|
||||
// with the extension definition (if no getMetadata
|
||||
// method was supplied.)
|
||||
function instantiateAction(Action, context) {
|
||||
var action = new Action(context),
|
||||
function instantiateAction(Action, ctxt) {
|
||||
var action = new Action(ctxt),
|
||||
metadata;
|
||||
|
||||
// Provide a getMetadata method that echos
|
||||
@@ -90,7 +90,7 @@ define(
|
||||
// unless the action has defined its own.
|
||||
if (!action.getMetadata) {
|
||||
metadata = Object.create(Action.definition || {});
|
||||
metadata.context = context;
|
||||
metadata.context = ctxt;
|
||||
action.getMetadata = function () {
|
||||
return metadata;
|
||||
};
|
||||
@@ -103,14 +103,14 @@ define(
|
||||
// applicable in a given context, according to the static
|
||||
// appliesTo method of given actions (if defined), and
|
||||
// instantiate those applicable actions.
|
||||
function createIfApplicable(actions, context) {
|
||||
function createIfApplicable(actions, ctxt) {
|
||||
function isApplicable(Action) {
|
||||
return Action.appliesTo ? Action.appliesTo(context) : true;
|
||||
return Action.appliesTo ? Action.appliesTo(ctxt) : true;
|
||||
}
|
||||
|
||||
function instantiate(Action) {
|
||||
try {
|
||||
return instantiateAction(Action, context);
|
||||
return instantiateAction(Action, ctxt);
|
||||
} catch (e) {
|
||||
$log.error([
|
||||
"Could not instantiate action",
|
||||
|
||||
@@ -81,7 +81,7 @@ define(
|
||||
return mutationResult && self.invoke().then(findObject);
|
||||
}
|
||||
|
||||
function addIdToModel(model) {
|
||||
function addIdToModel(objModel) {
|
||||
// Pick a specific index if needed.
|
||||
index = isNaN(index) ? composition.length : index;
|
||||
// Also, don't put past the end of the array
|
||||
@@ -89,11 +89,11 @@ define(
|
||||
|
||||
// Remove the existing instance of the id
|
||||
if (oldIndex !== -1) {
|
||||
model.composition.splice(oldIndex, 1);
|
||||
objModel.composition.splice(oldIndex, 1);
|
||||
}
|
||||
|
||||
// ...and add it back at the appropriate index.
|
||||
model.composition.splice(index, 0, id);
|
||||
objModel.composition.splice(index, 0, id);
|
||||
}
|
||||
|
||||
// If no index has been specified already and the id is already
|
||||
|
||||
@@ -82,7 +82,7 @@ define(
|
||||
parentContext =
|
||||
parentObject && parentObject.getCapability('context'),
|
||||
parentPath = parentContext ?
|
||||
parentContext.getPath() : [ this.parentObject ];
|
||||
parentContext.getPath() : [this.parentObject];
|
||||
|
||||
return parentPath.concat([this.domainObject]);
|
||||
};
|
||||
|
||||
@@ -62,9 +62,9 @@ define(
|
||||
}
|
||||
|
||||
// Package capabilities as key-value pairs
|
||||
function packageCapabilities(capabilities) {
|
||||
function packageCapabilities(caps) {
|
||||
var result = {};
|
||||
capabilities.forEach(function (capability) {
|
||||
caps.forEach(function (capability) {
|
||||
if (capability.key) {
|
||||
result[capability.key] =
|
||||
result[capability.key] || capability;
|
||||
|
||||
@@ -124,9 +124,9 @@ define(
|
||||
clone = JSON.parse(JSON.stringify(model)),
|
||||
useTimestamp = arguments.length > 1;
|
||||
|
||||
function notifyListeners(model) {
|
||||
function notifyListeners(newModel) {
|
||||
generalTopic.notify(domainObject);
|
||||
specificTopic.notify(model);
|
||||
specificTopic.notify(newModel);
|
||||
}
|
||||
|
||||
// Function to handle copying values to the actual
|
||||
|
||||
@@ -69,18 +69,18 @@ define(
|
||||
* Checks if the value returned is falsey, and if so returns a
|
||||
* rejected promise
|
||||
*/
|
||||
function rejectIfFalsey(value, $q){
|
||||
if (!value){
|
||||
function rejectIfFalsey(value, $q) {
|
||||
if (!value) {
|
||||
return $q.reject("Error persisting object");
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
function formatError(error){
|
||||
function formatError(error) {
|
||||
if (error && error.message) {
|
||||
return error.message;
|
||||
} else if (error && typeof error === "string"){
|
||||
} else if (error && typeof error === "string") {
|
||||
return error;
|
||||
} else {
|
||||
return "unknown error";
|
||||
@@ -91,7 +91,7 @@ define(
|
||||
* Display a notification message if an error has occurred during
|
||||
* persistence.
|
||||
*/
|
||||
function notifyOnError(error, domainObject, notificationService, $q){
|
||||
function notifyOnError(error, domainObject, notificationService, $q) {
|
||||
var errorMessage = "Unable to persist " + domainObject.getModel().name;
|
||||
if (error) {
|
||||
errorMessage += ": " + formatError(error);
|
||||
@@ -129,8 +129,8 @@ define(
|
||||
}
|
||||
|
||||
// Update persistence timestamp...
|
||||
domainObject.useCapability("mutation", function (model) {
|
||||
model.persisted = modified;
|
||||
domainObject.useCapability("mutation", function (m) {
|
||||
m.persisted = modified;
|
||||
}, modified);
|
||||
|
||||
// ...and persist
|
||||
@@ -138,9 +138,9 @@ define(
|
||||
this.getSpace(),
|
||||
getKey(domainObject.getId()),
|
||||
domainObject.getModel()
|
||||
]).then(function(result){
|
||||
]).then(function (result) {
|
||||
return rejectIfFalsey(result, self.$q);
|
||||
}).catch(function(error){
|
||||
}).catch(function (error) {
|
||||
return notifyOnError(error, domainObject, self.notificationService, self.$q);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -82,9 +82,9 @@ define(
|
||||
}
|
||||
|
||||
// Package the result as id->model
|
||||
function packageResult(parsedIds, models) {
|
||||
function packageResult(parsedIdsToPackage, models) {
|
||||
var result = {};
|
||||
parsedIds.forEach(function (parsedId, index) {
|
||||
parsedIdsToPackage.forEach(function (parsedId, index) {
|
||||
var id = parsedId.id;
|
||||
if (models[index]) {
|
||||
result[id] = models[index];
|
||||
@@ -93,11 +93,11 @@ define(
|
||||
return result;
|
||||
}
|
||||
|
||||
function loadModels(parsedIds) {
|
||||
return $q.all(parsedIds.map(loadModel))
|
||||
function loadModels(parsedIdsToLoad) {
|
||||
return $q.all(parsedIdsToLoad.map(loadModel))
|
||||
.then(function (models) {
|
||||
return packageResult(
|
||||
parsedIds,
|
||||
parsedIdsToLoad,
|
||||
models.map(addPersistedTimestamp)
|
||||
);
|
||||
});
|
||||
|
||||
@@ -46,7 +46,9 @@ define(
|
||||
*/
|
||||
function RootModelProvider(roots, $q, $log) {
|
||||
// Pull out identifiers to used as ROOT's
|
||||
var ids = roots.map(function (root) { return root.id; });
|
||||
var ids = roots.map(function (root) {
|
||||
return root.id;
|
||||
});
|
||||
|
||||
// Assign an initial location to root models
|
||||
roots.forEach(function (root) {
|
||||
|
||||
@@ -58,14 +58,14 @@ define(
|
||||
* corresponding keys in the recursive step.
|
||||
*
|
||||
*
|
||||
* @param a the first object to be merged
|
||||
* @param b the second object to be merged
|
||||
* @param modelA the first object to be merged
|
||||
* @param modelB the second object to be merged
|
||||
* @param merger the merger, as described above
|
||||
* @returns {*} the result of merging `a` and `b`
|
||||
* @returns {*} the result of merging `modelA` and `modelB`
|
||||
* @constructor
|
||||
* @memberof platform/core
|
||||
*/
|
||||
function mergeModels(a, b, merger) {
|
||||
function mergeModels(modelA, modelB, merger) {
|
||||
var mergeFunction;
|
||||
|
||||
function mergeArrays(a, b) {
|
||||
@@ -93,11 +93,11 @@ define(
|
||||
}
|
||||
|
||||
mergeFunction = (merger && Function.isFunction(merger)) ? merger :
|
||||
(Array.isArray(a) && Array.isArray(b)) ? mergeArrays :
|
||||
(a instanceof Object && b instanceof Object) ? mergeObjects :
|
||||
(Array.isArray(modelA) && Array.isArray(modelB)) ? mergeArrays :
|
||||
(modelA instanceof Object && modelB instanceof Object) ? mergeObjects :
|
||||
mergeOther;
|
||||
|
||||
return mergeFunction(a, b);
|
||||
return mergeFunction(modelA, modelB);
|
||||
}
|
||||
|
||||
return mergeModels;
|
||||
|
||||
@@ -33,8 +33,12 @@ define(
|
||||
}
|
||||
},
|
||||
identity: {
|
||||
toModelValue: function (v) { return v; },
|
||||
toFormValue: function (v) { return v; }
|
||||
toModelValue: function (v) {
|
||||
return v;
|
||||
},
|
||||
toFormValue: function (v) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
},
|
||||
ARRAY_SUFFIX = '[]';
|
||||
|
||||
@@ -159,8 +159,8 @@ define(
|
||||
}
|
||||
|
||||
function lookupTypeDef(typeKey) {
|
||||
function buildTypeDef(typeKey) {
|
||||
var typeDefs = typeDefinitions[typeKey] || [],
|
||||
function buildTypeDef(typeKeyToBuild) {
|
||||
var typeDefs = typeDefinitions[typeKeyToBuild] || [],
|
||||
inherits = typeDefs.map(function (typeDef) {
|
||||
return asArray(typeDef.inherits || []);
|
||||
}).reduce(function (a, b) {
|
||||
@@ -175,11 +175,11 @@ define(
|
||||
// Always provide a default name
|
||||
def.model = def.model || {};
|
||||
def.model.name = def.model.name ||
|
||||
("Unnamed " + (def.name || "Object"));
|
||||
("Unnamed " + (def.name || "Object"));
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
return (self.typeMap[typeKey] =
|
||||
self.typeMap[typeKey] || buildTypeDef(typeKey));
|
||||
}
|
||||
|
||||
@@ -105,15 +105,15 @@ define(
|
||||
// Check if an object has all capabilities designated as `needs`
|
||||
// for a view. Exposing a capability via delegation is taken to
|
||||
// satisfy this filter if `allowDelegation` is true.
|
||||
function capabilitiesMatch(domainObject, capabilities, allowDelegation) {
|
||||
var delegation = domainObject.getCapability("delegation");
|
||||
function capabilitiesMatch(domainObj, capabilities, allowDelegation) {
|
||||
var delegation = domainObj.getCapability("delegation");
|
||||
|
||||
allowDelegation = allowDelegation && (delegation !== undefined);
|
||||
|
||||
// Check if an object has (or delegates, if allowed) a
|
||||
// capability.
|
||||
function hasCapability(c) {
|
||||
return domainObject.hasCapability(c) ||
|
||||
return domainObj.hasCapability(c) ||
|
||||
(allowDelegation && delegation.doesDelegateCapability(c));
|
||||
}
|
||||
|
||||
@@ -128,13 +128,13 @@ define(
|
||||
|
||||
// Check if a view and domain object type can be paired;
|
||||
// both can restrict the others they accept.
|
||||
function viewMatchesType(view, type) {
|
||||
var views = type && (type.getDefinition() || {}).views,
|
||||
function viewMatchesType(view, objType) {
|
||||
var views = objType && (objType.getDefinition() || {}).views,
|
||||
matches = true;
|
||||
|
||||
// View is restricted to a certain type
|
||||
if (view.type) {
|
||||
matches = matches && type && type.instanceOf(view.type);
|
||||
matches = matches && objType && objType.instanceOf(view.type);
|
||||
}
|
||||
|
||||
// Type wishes to restrict its specific views
|
||||
|
||||
@@ -32,7 +32,7 @@ define(
|
||||
aggregator;
|
||||
|
||||
function createMockActionProvider(actions, i) {
|
||||
var spy = jasmine.createSpyObj("agg" + i, [ "getActions" ]);
|
||||
var spy = jasmine.createSpyObj("agg" + i, ["getActions"]);
|
||||
spy.getActions.andReturn(actions);
|
||||
return spy;
|
||||
}
|
||||
@@ -69,4 +69,4 @@ define(
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -37,19 +37,19 @@ define(
|
||||
beforeEach(function () {
|
||||
mockAction = jasmine.createSpyObj(
|
||||
"action",
|
||||
[ "perform", "getMetadata" ]
|
||||
["perform", "getMetadata"]
|
||||
);
|
||||
mockActionService = jasmine.createSpyObj(
|
||||
"actionService",
|
||||
[ "getActions" ]
|
||||
["getActions"]
|
||||
);
|
||||
mockQ = jasmine.createSpyObj(
|
||||
"$q",
|
||||
[ "when" ]
|
||||
["when"]
|
||||
);
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId", "getModel", "getCapability", "hasCapability", "useCapability" ]
|
||||
["getId", "getModel", "getCapability", "hasCapability", "useCapability"]
|
||||
);
|
||||
|
||||
mockActionService.getActions.andReturn([mockAction, {}]);
|
||||
@@ -76,7 +76,7 @@ define(
|
||||
});
|
||||
|
||||
it("promises the result of performed actions", function () {
|
||||
var mockPromise = jasmine.createSpyObj("promise", [ "then" ]);
|
||||
var mockPromise = jasmine.createSpyObj("promise", ["then"]);
|
||||
mockQ.when.andReturn(mockPromise);
|
||||
mockAction.perform.andReturn("the action's result");
|
||||
|
||||
|
||||
@@ -33,29 +33,41 @@ define(
|
||||
actionProvider;
|
||||
|
||||
function SimpleAction() {
|
||||
return { perform: function () { return "simple"; } };
|
||||
return { perform: function () {
|
||||
return "simple";
|
||||
} };
|
||||
}
|
||||
|
||||
function CategorizedAction() {
|
||||
return { perform: function () { return "categorized"; } };
|
||||
return { perform: function () {
|
||||
return "categorized";
|
||||
} };
|
||||
}
|
||||
CategorizedAction.category = "someCategory";
|
||||
|
||||
function KeyedAction() {
|
||||
return { perform: function () { return "keyed"; } };
|
||||
return { perform: function () {
|
||||
return "keyed";
|
||||
} };
|
||||
}
|
||||
KeyedAction.key = "someKey";
|
||||
|
||||
function CategorizedKeyedAction() {
|
||||
return { perform: function () { return "both"; } };
|
||||
return { perform: function () {
|
||||
return "both";
|
||||
} };
|
||||
}
|
||||
CategorizedKeyedAction.key = "someKey";
|
||||
CategorizedKeyedAction.category = "someCategory";
|
||||
|
||||
function MetadataAction() {
|
||||
return {
|
||||
perform: function () { return "metadata"; },
|
||||
getMetadata: function () { return "custom metadata"; }
|
||||
perform: function () {
|
||||
return "metadata";
|
||||
},
|
||||
getMetadata: function () {
|
||||
return "custom metadata";
|
||||
}
|
||||
};
|
||||
}
|
||||
MetadataAction.key = "metadata";
|
||||
@@ -152,7 +164,7 @@ define(
|
||||
}
|
||||
|
||||
provided = new ActionProvider(
|
||||
[ SimpleAction, BadAction ],
|
||||
[SimpleAction, BadAction],
|
||||
mockLog
|
||||
).getActions();
|
||||
});
|
||||
|
||||
@@ -36,15 +36,15 @@ define(
|
||||
beforeEach(function () {
|
||||
mockAction = jasmine.createSpyObj(
|
||||
"action",
|
||||
[ "perform", "getMetadata" ]
|
||||
["perform", "getMetadata"]
|
||||
);
|
||||
mockActionService = jasmine.createSpyObj(
|
||||
"actionService",
|
||||
[ "getActions" ]
|
||||
["getActions"]
|
||||
);
|
||||
mockLog = jasmine.createSpyObj(
|
||||
"$log",
|
||||
[ "error", "warn", "info", "debug" ]
|
||||
["error", "warn", "info", "debug"]
|
||||
);
|
||||
|
||||
mockActionService.getActions.andReturn([mockAction]);
|
||||
@@ -70,4 +70,4 @@ define(
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -64,7 +64,7 @@ define(
|
||||
|
||||
mockObjectService = jasmine.createSpyObj(
|
||||
"objectService",
|
||||
[ "getObjects" ]
|
||||
["getObjects"]
|
||||
);
|
||||
|
||||
mockInjector = {
|
||||
@@ -97,7 +97,7 @@ define(
|
||||
});
|
||||
|
||||
it("requests ids found in model's composition from the object service", function () {
|
||||
var ids = [ "a", "b", "c", "xyz" ];
|
||||
var ids = ["a", "b", "c", "xyz"];
|
||||
|
||||
mockDomainObject.getModel.andReturn({ composition: ids });
|
||||
|
||||
@@ -114,7 +114,9 @@ define(
|
||||
mockObjectService.getObjects.andReturn(mockPromise({x: mockChild}));
|
||||
mockChild.getCapability.andReturn(undefined);
|
||||
|
||||
composition.invoke().then(function (c) { result = c; });
|
||||
composition.invoke().then(function (c) {
|
||||
result = c;
|
||||
});
|
||||
|
||||
// Should have been added by a wrapper
|
||||
expect(result[0].getCapability('context')).toBeDefined();
|
||||
@@ -153,7 +155,7 @@ define(
|
||||
|
||||
it("does not re-add IDs which are already present", function () {
|
||||
var result,
|
||||
testModel = { composition: [ 'a' ] },
|
||||
testModel = { composition: ['a'] },
|
||||
mockChild = jasmine.createSpyObj("child", DOMAIN_OBJECT_METHODS);
|
||||
|
||||
mockDomainObject.getModel.andReturn(testModel);
|
||||
@@ -184,7 +186,7 @@ define(
|
||||
|
||||
it("can add objects at a specified index", function () {
|
||||
var result,
|
||||
testModel = { composition: [ 'a', 'b', 'c' ] },
|
||||
testModel = { composition: ['a', 'b', 'c'] },
|
||||
mockChild = jasmine.createSpyObj("child", DOMAIN_OBJECT_METHODS);
|
||||
|
||||
mockDomainObject.getModel.andReturn(testModel);
|
||||
|
||||
@@ -46,7 +46,7 @@ define(
|
||||
mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS);
|
||||
mockParent = jasmine.createSpyObj("parent", DOMAIN_OBJECT_METHODS);
|
||||
mockGrandparent = jasmine.createSpyObj("grandparent", DOMAIN_OBJECT_METHODS);
|
||||
mockContext = jasmine.createSpyObj("context", [ "getParent", "getRoot", "getPath" ]);
|
||||
mockContext = jasmine.createSpyObj("context", ["getParent", "getRoot", "getPath"]);
|
||||
|
||||
mockParent.getCapability.andReturn(mockContext);
|
||||
mockContext.getParent.andReturn(mockGrandparent);
|
||||
@@ -77,4 +77,4 @@ define(
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -79,4 +79,4 @@ define(
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -31,16 +31,22 @@ define(
|
||||
var mockLog,
|
||||
provider;
|
||||
|
||||
function BasicCapability() { return; }
|
||||
function BasicCapability() {
|
||||
return;
|
||||
}
|
||||
BasicCapability.key = "basic";
|
||||
|
||||
function ApplicableCapability() { return; }
|
||||
function ApplicableCapability() {
|
||||
return;
|
||||
}
|
||||
ApplicableCapability.key = "applicable";
|
||||
ApplicableCapability.appliesTo = function (model) {
|
||||
return !model.isNotApplicable;
|
||||
};
|
||||
|
||||
function KeylessCapability() { return; }
|
||||
function KeylessCapability() {
|
||||
return;
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
mockLog = jasmine.createSpyObj(
|
||||
|
||||
@@ -36,7 +36,11 @@ define(
|
||||
object = {},
|
||||
delegation;
|
||||
|
||||
function capture(k) { return function (v) { captured[k] = v; }; }
|
||||
function capture(k) {
|
||||
return function (v) {
|
||||
captured[k] = v;
|
||||
};
|
||||
}
|
||||
function TestDomainObject(caps, id) {
|
||||
return {
|
||||
getId: function () {
|
||||
@@ -67,12 +71,16 @@ define(
|
||||
beforeEach(function () {
|
||||
captured = {};
|
||||
typeDef = {};
|
||||
typeDef.delegates = [ "foo" ];
|
||||
type = { getDefinition: function () { return typeDef; } };
|
||||
typeDef.delegates = ["foo"];
|
||||
type = { getDefinition: function () {
|
||||
return typeDef;
|
||||
} };
|
||||
children = [];
|
||||
capabilities = {
|
||||
type: type,
|
||||
composition: { invoke: function () { return mockPromise(children); } }
|
||||
composition: { invoke: function () {
|
||||
return mockPromise(children);
|
||||
} }
|
||||
};
|
||||
object = new TestDomainObject(capabilities);
|
||||
|
||||
@@ -95,4 +103,4 @@ define(
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -38,15 +38,15 @@ define(
|
||||
mockInstantiate = jasmine.createSpy("instantiate");
|
||||
mockIdentifierService = jasmine.createSpyObj(
|
||||
'identifierService',
|
||||
[ 'parse', 'generate' ]
|
||||
['parse', 'generate']
|
||||
);
|
||||
mockIdentifier = jasmine.createSpyObj(
|
||||
'identifier',
|
||||
[ 'getSpace', 'getKey', 'getDefinedSpace' ]
|
||||
['getSpace', 'getKey', 'getDefinedSpace']
|
||||
);
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
'domainObject',
|
||||
[ 'getId', 'getCapability', 'getModel' ]
|
||||
['getId', 'getCapability', 'getModel']
|
||||
);
|
||||
|
||||
mockInjector.get.andCallFake(function (key) {
|
||||
@@ -73,16 +73,16 @@ define(
|
||||
});
|
||||
|
||||
it("uses the instantiate service to create domain objects", function () {
|
||||
var mockDomainObject = jasmine.createSpyObj('domainObject', [
|
||||
var mockDomainObj = jasmine.createSpyObj('domainObject', [
|
||||
'getId',
|
||||
'getModel',
|
||||
'getCapability',
|
||||
'useCapability',
|
||||
'hasCapability'
|
||||
]), testModel = { someKey: "some value" };
|
||||
mockInstantiate.andReturn(mockDomainObject);
|
||||
mockInstantiate.andReturn(mockDomainObj);
|
||||
expect(instantiation.instantiate(testModel))
|
||||
.toBe(mockDomainObject);
|
||||
.toBe(mockDomainObj);
|
||||
expect(mockInstantiate)
|
||||
.toHaveBeenCalledWith({
|
||||
someKey: "some value",
|
||||
|
||||
@@ -35,8 +35,12 @@ define(
|
||||
topic,
|
||||
mockNow,
|
||||
domainObject = {
|
||||
getId: function () { return "test-id"; },
|
||||
getModel: function () { return testModel; }
|
||||
getId: function () {
|
||||
return "test-id";
|
||||
},
|
||||
getModel: function () {
|
||||
return testModel;
|
||||
}
|
||||
},
|
||||
mutation;
|
||||
|
||||
|
||||
@@ -46,10 +46,10 @@ define(
|
||||
then: function (callback) {
|
||||
return asPromise(callback(value));
|
||||
},
|
||||
catch: function(callback) {
|
||||
catch: function (callback) {
|
||||
//Define a default 'happy' catch, that skips over the
|
||||
// catch callback
|
||||
return doCatch ? asPromise(callback(value)): asPromise(value);
|
||||
return doCatch ? asPromise(callback(value)) : asPromise(value);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -60,16 +60,16 @@ define(
|
||||
|
||||
mockPersistenceService = jasmine.createSpyObj(
|
||||
"persistenceService",
|
||||
[ "updateObject", "readObject", "createObject", "deleteObject" ]
|
||||
["updateObject", "readObject", "createObject", "deleteObject"]
|
||||
);
|
||||
|
||||
mockIdentifierService = jasmine.createSpyObj(
|
||||
'identifierService',
|
||||
[ 'parse', 'generate' ]
|
||||
['parse', 'generate']
|
||||
);
|
||||
mockIdentifier = jasmine.createSpyObj(
|
||||
'identifier',
|
||||
[ 'getSpace', 'getKey', 'getDefinedSpace' ]
|
||||
['getSpace', 'getKey', 'getDefinedSpace']
|
||||
);
|
||||
mockQ = jasmine.createSpyObj(
|
||||
"$q",
|
||||
@@ -81,12 +81,16 @@ define(
|
||||
);
|
||||
mockCacheService = jasmine.createSpyObj(
|
||||
"cacheService",
|
||||
[ "get", "put", "remove", "all" ]
|
||||
["get", "put", "remove", "all"]
|
||||
);
|
||||
|
||||
mockDomainObject = {
|
||||
getId: function () { return id; },
|
||||
getModel: function () { return model; },
|
||||
getId: function () {
|
||||
return id;
|
||||
},
|
||||
getModel: function () {
|
||||
return model;
|
||||
},
|
||||
useCapability: jasmine.createSpy()
|
||||
};
|
||||
// Simulate mutation capability
|
||||
@@ -107,7 +111,7 @@ define(
|
||||
);
|
||||
});
|
||||
|
||||
describe("successful persistence", function() {
|
||||
describe("successful persistence", function () {
|
||||
beforeEach(function () {
|
||||
mockPersistenceService.updateObject.andReturn(happyPromise);
|
||||
mockPersistenceService.createObject.andReturn(happyPromise);
|
||||
@@ -163,9 +167,9 @@ define(
|
||||
});
|
||||
});
|
||||
|
||||
describe("unsuccessful persistence", function() {
|
||||
describe("unsuccessful persistence", function () {
|
||||
var sadPromise = {
|
||||
then: function(callback){
|
||||
then: function (callback) {
|
||||
return asPromise(callback(0), true);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -60,7 +60,7 @@ define(
|
||||
|
||||
mockObjectService = jasmine.createSpyObj(
|
||||
"objectService",
|
||||
[ "getObjects" ]
|
||||
["getObjects"]
|
||||
);
|
||||
|
||||
mockInjector = {
|
||||
@@ -85,7 +85,7 @@ define(
|
||||
});
|
||||
|
||||
it("requests ids found in model's composition from the object service", function () {
|
||||
var ids = [ "a", "b", "c", "xyz" ];
|
||||
var ids = ["a", "b", "c", "xyz"];
|
||||
|
||||
mockDomainObject.getModel.andReturn({ relationships: { xyz: ids } });
|
||||
|
||||
@@ -96,7 +96,7 @@ define(
|
||||
|
||||
it("provides a list of relationship types", function () {
|
||||
mockDomainObject.getModel.andReturn({ relationships: {
|
||||
abc: [ 'a', 'b' ],
|
||||
abc: ['a', 'b'],
|
||||
def: "not an array, should be ignored",
|
||||
xyz: []
|
||||
} });
|
||||
@@ -139,4 +139,4 @@ define(
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -99,7 +99,7 @@ define(
|
||||
});
|
||||
|
||||
it("ensures a single object instance, even for multiple concurrent calls", function () {
|
||||
var promiseA, promiseB, mockCallback = jasmine.createSpy();
|
||||
var promiseA, promiseB;
|
||||
|
||||
promiseA = fakePromise();
|
||||
promiseB = fakePromise();
|
||||
@@ -126,7 +126,7 @@ define(
|
||||
});
|
||||
|
||||
it("is robust against updating with undefined values", function () {
|
||||
var promiseA, promiseB, mockCallback = jasmine.createSpy();
|
||||
var promiseA, promiseB;
|
||||
|
||||
promiseA = fakePromise();
|
||||
promiseB = fakePromise();
|
||||
|
||||
@@ -40,7 +40,7 @@ define(
|
||||
beforeEach(function () {
|
||||
mockModelService = jasmine.createSpyObj(
|
||||
"modelService",
|
||||
[ "getModels" ]
|
||||
["getModels"]
|
||||
);
|
||||
|
||||
testModels = {
|
||||
@@ -61,14 +61,18 @@ define(
|
||||
it("provides models for any IDs which are missing", function () {
|
||||
var models;
|
||||
decorator.getModels(['testId', 'otherId'])
|
||||
.then(function (m) { models = m; });
|
||||
.then(function (m) {
|
||||
models = m;
|
||||
});
|
||||
expect(models.otherId).toBeDefined();
|
||||
});
|
||||
|
||||
it("does not overwrite existing models", function () {
|
||||
var models;
|
||||
decorator.getModels(['testId', 'otherId'])
|
||||
.then(function (m) { models = m; });
|
||||
.then(function (m) {
|
||||
models = m;
|
||||
});
|
||||
expect(models.testId).toEqual({ someKey: "some value" });
|
||||
});
|
||||
|
||||
|
||||
@@ -37,18 +37,20 @@ define(
|
||||
aggregator;
|
||||
|
||||
beforeEach(function () {
|
||||
mockQ = jasmine.createSpyObj("$q", [ "all" ]);
|
||||
mockQ = jasmine.createSpyObj("$q", ["all"]);
|
||||
mockProviders = modelList.map(function (models, i) {
|
||||
var mockProvider = jasmine.createSpyObj(
|
||||
"mockProvider" + i,
|
||||
[ "getModels" ]
|
||||
["getModels"]
|
||||
);
|
||||
mockProvider.getModels.andReturn(models);
|
||||
return mockProvider;
|
||||
});
|
||||
|
||||
mockQ.all.andReturn({
|
||||
then: function (c) { return c(modelList); }
|
||||
then: function (c) {
|
||||
return c(modelList);
|
||||
}
|
||||
});
|
||||
|
||||
aggregator = new ModelAggregator(mockQ, mockProviders);
|
||||
@@ -72,4 +74,4 @@ define(
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -27,7 +27,7 @@ define(['../../src/models/ModelCacheService'], function (ModelCacheService) {
|
||||
cacheService;
|
||||
|
||||
beforeEach(function () {
|
||||
testIds = [ 'a', 'b', 'c', 'd' ];
|
||||
testIds = ['a', 'b', 'c', 'd'];
|
||||
testModels = testIds.reduce(function (models, id) {
|
||||
models[id] = { someKey: "some value for " + id };
|
||||
return models;
|
||||
|
||||
@@ -57,7 +57,9 @@ define(
|
||||
};
|
||||
}
|
||||
|
||||
function capture(value) { captured = value; }
|
||||
function capture(value) {
|
||||
captured = value;
|
||||
}
|
||||
|
||||
|
||||
beforeEach(function () {
|
||||
|
||||
@@ -55,7 +55,9 @@ define(
|
||||
});
|
||||
|
||||
it("provides models from extension declarations", function () {
|
||||
var mockPromise = { then: function () { return; } };
|
||||
var mockPromise = { then: function () {
|
||||
return;
|
||||
} };
|
||||
mockQ.when.andReturn(mockPromise);
|
||||
|
||||
// Verify that we got the promise as the return value
|
||||
@@ -97,4 +99,4 @@ define(
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -49,7 +49,7 @@ define(
|
||||
beforeEach(function () {
|
||||
mockModelService = jasmine.createSpyObj(
|
||||
"modelService",
|
||||
[ "getModels" ]
|
||||
["getModels"]
|
||||
);
|
||||
mockInstantiate = jasmine.createSpy("instantiate");
|
||||
|
||||
@@ -64,7 +64,7 @@ define(
|
||||
});
|
||||
|
||||
it("requests models from the model service", function () {
|
||||
var ids = [ "a", "b", "c" ];
|
||||
var ids = ["a", "b", "c"];
|
||||
mockModelService.getModels.andReturn(mockPromise({}));
|
||||
provider.getObjects(ids);
|
||||
expect(mockModelService.getModels).toHaveBeenCalledWith(ids);
|
||||
@@ -72,7 +72,7 @@ define(
|
||||
|
||||
|
||||
it("instantiates objects with provided models", function () {
|
||||
var ids = [ "a", "b", "c"],
|
||||
var ids = ["a", "b", "c"],
|
||||
model = { someKey: "some value"},
|
||||
result;
|
||||
mockModelService.getModels.andReturn(mockPromise({ a: model }));
|
||||
|
||||
@@ -84,4 +84,4 @@ define(
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -44,7 +44,7 @@ define(
|
||||
|
||||
mockLog = jasmine.createSpyObj(
|
||||
"$log",
|
||||
[ "error", "warn", "info", "debug" ]
|
||||
["error", "warn", "info", "debug"]
|
||||
);
|
||||
|
||||
mockDomainObject =
|
||||
|
||||
@@ -45,7 +45,7 @@ define(
|
||||
);
|
||||
mockIdentifierService = jasmine.createSpyObj(
|
||||
'identifierService',
|
||||
[ 'parse', 'generate' ]
|
||||
['parse', 'generate']
|
||||
);
|
||||
mockCapabilityConstructor = jasmine.createSpy('capability');
|
||||
mockCapabilityInstance = {};
|
||||
@@ -61,7 +61,7 @@ define(
|
||||
|
||||
mockCacheService = jasmine.createSpyObj(
|
||||
'cacheService',
|
||||
[ 'get', 'put', 'remove', 'all' ]
|
||||
['get', 'put', 'remove', 'all']
|
||||
);
|
||||
|
||||
testModel = { someKey: "some value" };
|
||||
|
||||
@@ -44,4 +44,4 @@ define(
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -34,7 +34,7 @@ define(
|
||||
testMessage = { someKey: "some value"};
|
||||
mockLog = jasmine.createSpyObj(
|
||||
'$log',
|
||||
[ 'error', 'warn', 'info', 'debug' ]
|
||||
['error', 'warn', 'info', 'debug']
|
||||
);
|
||||
mockCallback = jasmine.createSpy('callback');
|
||||
topic = new Topic(mockLog);
|
||||
|
||||
@@ -32,32 +32,32 @@ define(
|
||||
expect(mergeModels(
|
||||
{
|
||||
"a": "property a",
|
||||
"b": [ 1, 2, 3 ],
|
||||
"b": [1, 2, 3],
|
||||
"c": {
|
||||
x: 42,
|
||||
z: [ 0 ]
|
||||
z: [0]
|
||||
},
|
||||
"d": "should be ignored"
|
||||
},
|
||||
{
|
||||
"b": [ 4 ],
|
||||
"b": [4],
|
||||
"c": {
|
||||
y: "property y",
|
||||
z: [ "h" ]
|
||||
z: ["h"]
|
||||
},
|
||||
"d": "property d"
|
||||
}
|
||||
)).toEqual({
|
||||
"a": "property a",
|
||||
"b": [ 1, 2, 3, 4 ],
|
||||
"b": [1, 2, 3, 4],
|
||||
"c": {
|
||||
x: 42,
|
||||
y: "property y",
|
||||
z: [ 0, "h" ]
|
||||
z: [0, "h"]
|
||||
},
|
||||
"d": "property d"
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -36,11 +36,11 @@ define(
|
||||
beforeEach(function () {
|
||||
mockTypeService = jasmine.createSpyObj(
|
||||
"typeService",
|
||||
[ "getType" ]
|
||||
["getType"]
|
||||
);
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId", "getModel", "getCapability" ]
|
||||
["getId", "getModel", "getCapability"]
|
||||
);
|
||||
mockType = { someKey: "some value" };
|
||||
|
||||
@@ -57,4 +57,4 @@ define(
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -36,7 +36,7 @@ define(
|
||||
glyph: 't',
|
||||
inherits: ['test-parent-1', 'test-parent-2'],
|
||||
features: ['test-feature-1'],
|
||||
properties: [ {} ],
|
||||
properties: [{}],
|
||||
model: {someKey: "some value"}
|
||||
};
|
||||
type = new TypeImpl(testTypeDef);
|
||||
@@ -74,10 +74,14 @@ define(
|
||||
|
||||
it("supports instance-of checks by type object", function () {
|
||||
expect(type.instanceOf({
|
||||
getKey: function () { return 'test-parent-1'; }
|
||||
getKey: function () {
|
||||
return 'test-parent-1';
|
||||
}
|
||||
})).toBeTruthy();
|
||||
expect(type.instanceOf({
|
||||
getKey: function () { return 'some-other-type'; }
|
||||
getKey: function () {
|
||||
return 'some-other-type';
|
||||
}
|
||||
})).toBeFalsy();
|
||||
});
|
||||
|
||||
@@ -110,4 +114,4 @@ define(
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -28,7 +28,7 @@ define(
|
||||
|
||||
it("allows non-conversion when parameter is 'identity'", function () {
|
||||
var conversion = new TypePropertyConversion("identity");
|
||||
[ 42, "42", { a: 42 } ].forEach(function (v) {
|
||||
[42, "42", { a: 42 }].forEach(function (v) {
|
||||
expect(conversion.toFormValue(v)).toBe(v);
|
||||
expect(conversion.toModelValue(v)).toBe(v);
|
||||
});
|
||||
@@ -61,4 +61,4 @@ define(
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -57,7 +57,7 @@ define(
|
||||
it("sets properties by path", function () {
|
||||
var definition = {
|
||||
key: "someKey",
|
||||
property: [ "some", "property" ]
|
||||
property: ["some", "property"]
|
||||
},
|
||||
model = {},
|
||||
property = new TypeProperty(definition);
|
||||
@@ -68,7 +68,7 @@ define(
|
||||
it("gets properties by path", function () {
|
||||
var definition = {
|
||||
key: "someKey",
|
||||
property: [ "some", "property" ]
|
||||
property: ["some", "property"]
|
||||
},
|
||||
model = { some: { property: "some value" } },
|
||||
property = new TypeProperty(definition);
|
||||
@@ -78,7 +78,7 @@ define(
|
||||
it("stops looking for properties when a path is invalid", function () {
|
||||
var definition = {
|
||||
key: "someKey",
|
||||
property: [ "some", "property" ]
|
||||
property: ["some", "property"]
|
||||
},
|
||||
property = new TypeProperty(definition);
|
||||
expect(property.getValue(undefined)).toBeUndefined();
|
||||
@@ -97,7 +97,7 @@ define(
|
||||
it("provides empty arrays for values that are array-like", function () {
|
||||
var definition = {
|
||||
property: "someProperty",
|
||||
items: [ {}, {}, {} ]
|
||||
items: [{}, {}, {}]
|
||||
},
|
||||
model = {},
|
||||
property = new TypeProperty(definition);
|
||||
@@ -108,7 +108,7 @@ define(
|
||||
it("detects and ignores empty arrays on setValue", function () {
|
||||
var definition = {
|
||||
property: "someProperty",
|
||||
items: [ {}, {}, {} ]
|
||||
items: [{}, {}, {}]
|
||||
},
|
||||
model = {},
|
||||
property = new TypeProperty(definition);
|
||||
@@ -123,4 +123,4 @@ define(
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -146,4 +146,4 @@ define(
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -30,17 +30,17 @@ define(
|
||||
describe("A view capability", function () {
|
||||
var mockViewService,
|
||||
mockDomainObject,
|
||||
views = [ {key: "someView"} ],
|
||||
views = [{key: "someView"}],
|
||||
view;
|
||||
|
||||
beforeEach(function () {
|
||||
mockViewService = jasmine.createSpyObj(
|
||||
"viewService",
|
||||
[ "getViews" ]
|
||||
["getViews"]
|
||||
);
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId", "getModel", "getCapability" ]
|
||||
["getId", "getModel", "getCapability"]
|
||||
);
|
||||
mockViewService.getViews.andReturn(views);
|
||||
view = new ViewCapability(mockViewService, mockDomainObject);
|
||||
@@ -55,4 +55,4 @@ define(
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -33,11 +33,11 @@ define(
|
||||
},
|
||||
viewB = {
|
||||
key: "b",
|
||||
needs: [ "someCapability" ]
|
||||
needs: ["someCapability"]
|
||||
},
|
||||
viewC = {
|
||||
key: "c",
|
||||
needs: [ "someCapability" ],
|
||||
needs: ["someCapability"],
|
||||
delegation: true
|
||||
},
|
||||
capabilities = {},
|
||||
@@ -109,7 +109,7 @@ define(
|
||||
it("restricts typed views to matching types", function () {
|
||||
var testType = "testType",
|
||||
testView = { key: "x", type: testType },
|
||||
provider = new ViewProvider([testView], mockLog);
|
||||
viewProvider = new ViewProvider([testView], mockLog);
|
||||
|
||||
// Include a "type" capability
|
||||
capabilities.type = jasmine.createSpyObj(
|
||||
@@ -120,21 +120,21 @@ define(
|
||||
|
||||
// Should be included when types match
|
||||
capabilities.type.instanceOf.andReturn(true);
|
||||
expect(provider.getViews(mockDomainObject))
|
||||
expect(viewProvider.getViews(mockDomainObject))
|
||||
.toEqual([testView]);
|
||||
expect(capabilities.type.instanceOf)
|
||||
.toHaveBeenCalledWith(testType);
|
||||
|
||||
// ...but not when they don't
|
||||
capabilities.type.instanceOf.andReturn(false);
|
||||
expect(provider.getViews(mockDomainObject))
|
||||
expect(viewProvider.getViews(mockDomainObject))
|
||||
.toEqual([]);
|
||||
|
||||
});
|
||||
|
||||
it("enforces view restrictions from types", function () {
|
||||
var testView = { key: "x" },
|
||||
provider = new ViewProvider([testView], mockLog);
|
||||
viewProvider = new ViewProvider([testView], mockLog);
|
||||
|
||||
// Include a "type" capability
|
||||
capabilities.type = jasmine.createSpyObj(
|
||||
@@ -146,16 +146,16 @@ define(
|
||||
// Should be included when view keys match
|
||||
capabilities.type.getDefinition
|
||||
.andReturn({ views: [testView.key]});
|
||||
expect(provider.getViews(mockDomainObject))
|
||||
expect(viewProvider.getViews(mockDomainObject))
|
||||
.toEqual([testView]);
|
||||
|
||||
// ...but not when they don't
|
||||
capabilities.type.getDefinition
|
||||
.andReturn({ views: ["somethingElse"]});
|
||||
expect(provider.getViews(mockDomainObject))
|
||||
expect(viewProvider.getViews(mockDomainObject))
|
||||
.toEqual([]);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user