mirror of
https://github.com/nasa/openmct.git
synced 2025-06-09 19:01:40 +00:00
[Entanglement] MoveService updates the location of moved objects
The move service updates the location of moved objects when those objects are originals.
This commit is contained in:
parent
3fb4296d23
commit
10ec30ba76
@ -77,13 +77,20 @@ define(
|
|||||||
return objectInNewContext;
|
return objectInNewContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: recursively map new objects to old objects, use old object to determine if object was originally a link, and update new object if it was not.
|
||||||
|
|
||||||
return objectInNewContext.useCapability(
|
return objectInNewContext.useCapability(
|
||||||
'mutation',
|
'mutation',
|
||||||
function (model) {
|
function (model) {
|
||||||
model.location =
|
model.location = objectInNewContext
|
||||||
locationCapability.getLocation();
|
.getCapability('location')
|
||||||
|
.getLocation();
|
||||||
}
|
}
|
||||||
);
|
).then(function() {
|
||||||
|
return objectInNewContext
|
||||||
|
.getCapability('persistence')
|
||||||
|
.persist();
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return object
|
return object
|
||||||
|
@ -28,7 +28,12 @@ define(
|
|||||||
'../DomainObjectFactory',
|
'../DomainObjectFactory',
|
||||||
'../ControlledPromise'
|
'../ControlledPromise'
|
||||||
],
|
],
|
||||||
function (MoveService, MockLinkService, domainObjectFactory) {
|
function (
|
||||||
|
MoveService,
|
||||||
|
MockLinkService,
|
||||||
|
domainObjectFactory,
|
||||||
|
ControlledPromise
|
||||||
|
) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("MoveService", function () {
|
describe("MoveService", function () {
|
||||||
@ -141,9 +146,13 @@ define(
|
|||||||
describe("perform", function () {
|
describe("perform", function () {
|
||||||
|
|
||||||
var object,
|
var object,
|
||||||
parentObject,
|
newParent,
|
||||||
actionCapability,
|
actionCapability,
|
||||||
locationCapability;
|
locationCapability,
|
||||||
|
persistenceCapability,
|
||||||
|
persistencePromise,
|
||||||
|
mutationPromise,
|
||||||
|
moveResult;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
actionCapability = jasmine.createSpyObj(
|
actionCapability = jasmine.createSpyObj(
|
||||||
@ -153,28 +162,47 @@ define(
|
|||||||
|
|
||||||
locationCapability = jasmine.createSpyObj(
|
locationCapability = jasmine.createSpyObj(
|
||||||
'locationCapability',
|
'locationCapability',
|
||||||
['isOriginal']
|
[
|
||||||
|
'isOriginal',
|
||||||
|
'getLocation'
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
persistenceCapability = jasmine.createSpyObj(
|
||||||
|
'persistenceCapability',
|
||||||
|
['persist']
|
||||||
|
);
|
||||||
|
|
||||||
|
persistencePromise = new ControlledPromise();
|
||||||
|
persistenceCapability.persist.andReturn(persistencePromise);
|
||||||
|
|
||||||
|
mutationPromise = new ControlledPromise();
|
||||||
|
|
||||||
object = domainObjectFactory({
|
object = domainObjectFactory({
|
||||||
name: 'object',
|
name: 'object',
|
||||||
capabilities: {
|
capabilities: {
|
||||||
action: actionCapability,
|
action: actionCapability,
|
||||||
|
mutation: {
|
||||||
|
invoke: function (mutator) {
|
||||||
|
mutator(object.model);
|
||||||
|
return mutationPromise;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
persistence: persistenceCapability,
|
||||||
location: locationCapability
|
location: locationCapability
|
||||||
|
},
|
||||||
|
model: {
|
||||||
|
location: 'otherThing'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
parentObject = domainObjectFactory({
|
moveResult = moveService.perform(object, newParent);
|
||||||
name: 'parentObject'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
moveService.perform(object, parentObject);
|
it("links object to newParent", function () {
|
||||||
});
|
|
||||||
|
|
||||||
it("links object to parentObject", function () {
|
|
||||||
expect(linkService.perform).toHaveBeenCalledWith(
|
expect(linkService.perform).toHaveBeenCalledWith(
|
||||||
object,
|
object,
|
||||||
parentObject
|
newParent
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -183,17 +211,135 @@ define(
|
|||||||
.toHaveBeenCalledWith(jasmine.any(Function));
|
.toHaveBeenCalledWith(jasmine.any(Function));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it("removes object when link is completed", function () {
|
it("removes object when link is completed", function () {
|
||||||
linkService.perform.mostRecentCall.promise.resolve()
|
linkService.perform.mostRecentCall.promise.resolve();
|
||||||
expect(object.getCapability)
|
expect(object.getCapability)
|
||||||
.toHaveBeenCalledWith('action');
|
.toHaveBeenCalledWith('action');
|
||||||
expect(actionCapability.perform)
|
expect(actionCapability.perform)
|
||||||
.toHaveBeenCalledWith('remove');
|
.toHaveBeenCalledWith('remove');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("when moving an original", function() {
|
||||||
|
beforeEach(function () {
|
||||||
|
locationCapability.isOriginal.andReturn(true);
|
||||||
|
locationCapability.getLocation.andReturn('newParent');
|
||||||
|
linkService.perform.mostRecentCall.promise.resolve();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("updates location", function() {
|
||||||
|
expect(object.model.location).toBe('newParent');
|
||||||
|
});
|
||||||
|
it("persists new model when mutation completes", function() {
|
||||||
|
mutationPromise.resolve();
|
||||||
|
expect(persistenceCapability.persist)
|
||||||
|
.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("when moving a link", function() {
|
||||||
|
beforeEach(function () {
|
||||||
|
locationCapability.isOriginal.andReturn(false);
|
||||||
|
locationCapability.getLocation.andReturn('newParent');
|
||||||
|
linkService.perform.mostRecentCall.promise.resolve();
|
||||||
|
});
|
||||||
|
it("does not modify location", function() {
|
||||||
|
expect(object.model.location).toBe('otherThing');
|
||||||
|
});
|
||||||
|
it("does not call persistence", function() {
|
||||||
|
expect(persistenceCapability.persist)
|
||||||
|
.not
|
||||||
|
.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when moving an object with children", function() {
|
||||||
|
|
||||||
|
var children;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
|
||||||
|
var instantMutator = function (index) {
|
||||||
|
return {
|
||||||
|
invoke: function (mutator) {
|
||||||
|
mutator(children[index].model);
|
||||||
|
return {
|
||||||
|
then: function(callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
children = [
|
||||||
|
domainObjectFactory({
|
||||||
|
id: 'childa',
|
||||||
|
capabilities: {
|
||||||
|
location: jasmine.createSpyObj(
|
||||||
|
'childalocation',
|
||||||
|
['isOriginal', 'getLocation']
|
||||||
|
),
|
||||||
|
mutation: instantMutator(0)
|
||||||
|
},
|
||||||
|
model: {
|
||||||
|
location: 'childa-old-location'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
domainObjectFactory({
|
||||||
|
id: 'childb',
|
||||||
|
capabilities: {
|
||||||
|
location: jasmine.createSpyObj(
|
||||||
|
'childblocation',
|
||||||
|
['isOriginal', 'getLocation']
|
||||||
|
),
|
||||||
|
mutation: instantMutator(1)
|
||||||
|
},
|
||||||
|
model: {
|
||||||
|
location: 'childb-old-location'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
domainObjectFactory({
|
||||||
|
id: 'childc',
|
||||||
|
capabilities: {
|
||||||
|
location: jasmine.createSpyObj(
|
||||||
|
'childclocation',
|
||||||
|
['isOriginal', 'getLocation']
|
||||||
|
),
|
||||||
|
mutation: instantMutator(2)
|
||||||
|
},
|
||||||
|
model: {
|
||||||
|
location: 'childc-old-location'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
|
children[0].capabilities.location.isOriginal.andReturn(true);
|
||||||
|
children[0].capabilities.location.getLocation.andReturn('childalocation');
|
||||||
|
children[1].capabilities.location.isOriginal.andReturn(true);
|
||||||
|
children[1].capabilities.location.getLocation.andReturn('childblocation');
|
||||||
|
children[2].capabilities.location.isOriginal.andReturn(false);
|
||||||
|
children[2].capabilities.location.getLocation.andReturn('childclocation');
|
||||||
|
|
||||||
|
object.capabilities.composition = {
|
||||||
|
invoke: function () {
|
||||||
|
return {
|
||||||
|
then: function (callback) {
|
||||||
|
callback(children);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
linkService.perform.mostRecentCall.promise.resolve();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it("recursively updates the location of originals", function () {
|
||||||
|
expect(children[0].model.location).toBe('childalocation');
|
||||||
|
expect(children[1].model.location).toBe('childblocation');
|
||||||
|
expect(children[2].model.location).toBe('childc-old-location');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user