mirror of
https://github.com/nasa/openmct.git
synced 2025-06-19 15:43:48 +00:00
Migrated to using notifications and fixed tests
This commit is contained in:
@ -95,7 +95,6 @@ define(
|
|||||||
persistenceSpace: originalParent.getCapability('persistence')
|
persistenceSpace: originalParent.getCapability('persistence')
|
||||||
}
|
}
|
||||||
delete modelClone.model.composition;
|
delete modelClone.model.composition;
|
||||||
delete modelClone.model.location;
|
|
||||||
delete modelClone.model.persisted;
|
delete modelClone.model.persisted;
|
||||||
delete modelClone.model.modified;
|
delete modelClone.model.modified;
|
||||||
return $q.when(originalObject.useCapability('composition')).then(function(composees){
|
return $q.when(originalObject.useCapability('composition')).then(function(composees){
|
||||||
@ -108,7 +107,11 @@ define(
|
|||||||
return copy(composee, originalObject).then(function(composeeClone){
|
return copy(composee, originalObject).then(function(composeeClone){
|
||||||
//Once copied, associate each cloned
|
//Once copied, associate each cloned
|
||||||
// composee with its parent clone
|
// composee with its parent clone
|
||||||
composeeClone.model.location = modelClone.id;
|
if ( !(composee.hasCapability("location") && composee.getCapability("location").isLink())) {
|
||||||
|
//If the object is not a link,
|
||||||
|
// locate it within its parent
|
||||||
|
composeeClone.model.location = modelClone.id;
|
||||||
|
}
|
||||||
modelClone.model.composition = modelClone.model.composition || [];
|
modelClone.model.composition = modelClone.model.composition || [];
|
||||||
return modelClone.model.composition.push(composeeClone.id);
|
return modelClone.model.composition.push(composeeClone.id);
|
||||||
});
|
});
|
||||||
@ -122,7 +125,12 @@ define(
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return copy(domainObject, parent).then(function(){
|
return copy(domainObject, parent).then(function(domainObjectClone){
|
||||||
|
//If the domain object being cloned is not a link, set its
|
||||||
|
// location to the new parent
|
||||||
|
if ( !(domainObject.hasCapability("location") && domainObject.getCapability("location").isLink())) {
|
||||||
|
domainObjectClone.model.location = parent.getId();
|
||||||
|
}
|
||||||
return clones;
|
return clones;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -166,7 +174,6 @@ define(
|
|||||||
if (!parent.hasCapability('composition')){
|
if (!parent.hasCapability('composition')){
|
||||||
return self.$q.reject();
|
return self.$q.reject();
|
||||||
}
|
}
|
||||||
parentClone.model.location = parent.getId();
|
|
||||||
|
|
||||||
return self.persistenceService
|
return self.persistenceService
|
||||||
.updateObject(parentClone.persistenceSpace, parentClone.id, parentClone.model)
|
.updateObject(parentClone.persistenceSpace, parentClone.id, parentClone.model)
|
||||||
|
@ -140,7 +140,7 @@ define(
|
|||||||
.args[0](newParent);
|
.args[0](newParent);
|
||||||
|
|
||||||
expect(composeService.perform)
|
expect(composeService.perform)
|
||||||
.toHaveBeenCalledWith(selectedObject, newParent, undefined);
|
.toHaveBeenCalledWith(selectedObject, newParent);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -126,6 +126,7 @@ define(
|
|||||||
describe("perform", function () {
|
describe("perform", function () {
|
||||||
|
|
||||||
var mockQ,
|
var mockQ,
|
||||||
|
mockDeferred,
|
||||||
creationService,
|
creationService,
|
||||||
createObjectPromise,
|
createObjectPromise,
|
||||||
copyService,
|
copyService,
|
||||||
@ -168,18 +169,32 @@ define(
|
|||||||
return 1234;
|
return 1234;
|
||||||
})
|
})
|
||||||
|
|
||||||
|
var resolvedValue;
|
||||||
|
|
||||||
|
mockDeferred = jasmine.createSpyObj('mockDeferred', ['notify', 'resolve']);
|
||||||
|
mockDeferred.notify.andCallFake(function(notification){});
|
||||||
|
mockDeferred.resolve.andCallFake(function(value){resolvedValue = value})
|
||||||
|
mockDeferred.promise = {
|
||||||
|
then: function(callback){
|
||||||
|
return synchronousPromise(callback(resolvedValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mockQ = jasmine.createSpyObj('mockQ', ['when', 'all', 'reject', 'defer']);
|
||||||
|
mockQ.when.andCallFake(synchronousPromise);
|
||||||
|
mockQ.all.andCallFake(function (promises) {
|
||||||
|
var result = {};
|
||||||
|
Object.keys(promises).forEach(function (k) {
|
||||||
|
promises[k].then(function (v) { result[k] = v; });
|
||||||
|
});
|
||||||
|
return synchronousPromise(result);
|
||||||
|
});
|
||||||
|
mockQ.defer.andReturn(mockDeferred);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("on domain object without composition", function () {
|
describe("on domain object without composition", function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
object = domainObjectFactory({
|
|
||||||
name: 'object',
|
|
||||||
id: 'abc',
|
|
||||||
model: {
|
|
||||||
name: 'some object',
|
|
||||||
persisted: mockNow.now()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
newParent = domainObjectFactory({
|
newParent = domainObjectFactory({
|
||||||
name: 'newParent',
|
name: 'newParent',
|
||||||
id: '456',
|
id: '456',
|
||||||
@ -190,14 +205,15 @@ define(
|
|||||||
persistence: parentPersistenceCapability
|
persistence: parentPersistenceCapability
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mockQ = jasmine.createSpyObj('mockQ', ['when', 'all', 'reject']);
|
|
||||||
mockQ.when.andCallFake(synchronousPromise);
|
object = domainObjectFactory({
|
||||||
mockQ.all.andCallFake(function (promises) {
|
name: 'object',
|
||||||
var result = {};
|
id: 'abc',
|
||||||
Object.keys(promises).forEach(function (k) {
|
model: {
|
||||||
promises[k].then(function (v) { result[k] = v; });
|
name: 'some object',
|
||||||
});
|
location: newParent.id,
|
||||||
return synchronousPromise(result);
|
persisted: mockNow.now()
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
copyService = new CopyService(mockQ, creationService, policyService, mockPersistenceService, mockNow.now);
|
copyService = new CopyService(mockQ, creationService, policyService, mockPersistenceService, mockNow.now);
|
||||||
@ -235,18 +251,14 @@ define(
|
|||||||
var newObject,
|
var newObject,
|
||||||
childObject,
|
childObject,
|
||||||
compositionCapability,
|
compositionCapability,
|
||||||
|
locationCapability,
|
||||||
compositionPromise;
|
compositionPromise;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockQ = jasmine.createSpyObj('mockQ', ['when', 'all', 'reject']);
|
|
||||||
mockQ.when.andCallFake(synchronousPromise);
|
|
||||||
mockQ.all.andCallFake(function (promises) {
|
locationCapability = jasmine.createSpyObj('locationCapability', ['isLink']);
|
||||||
var result = {};
|
locationCapability.isLink.andReturn(true);
|
||||||
Object.keys(promises).forEach(function (k) {
|
|
||||||
promises[k].then(function (v) { result[k] = v; });
|
|
||||||
});
|
|
||||||
return synchronousPromise(result);
|
|
||||||
});
|
|
||||||
|
|
||||||
childObject = domainObjectFactory({
|
childObject = domainObjectFactory({
|
||||||
name: 'childObject',
|
name: 'childObject',
|
||||||
@ -264,8 +276,6 @@ define(
|
|||||||
['then']
|
['then']
|
||||||
);
|
);
|
||||||
|
|
||||||
//compositionPromise.then.andCallFake(synchronousPromise);
|
|
||||||
|
|
||||||
compositionCapability
|
compositionCapability
|
||||||
.invoke
|
.invoke
|
||||||
.andReturn(synchronousPromise([childObject]));
|
.andReturn(synchronousPromise([childObject]));
|
||||||
@ -275,10 +285,12 @@ define(
|
|||||||
id: 'abc',
|
id: 'abc',
|
||||||
model: {
|
model: {
|
||||||
name: 'some object',
|
name: 'some object',
|
||||||
composition: ['def']
|
composition: ['def'],
|
||||||
|
location: 'testLocation'
|
||||||
},
|
},
|
||||||
capabilities: {
|
capabilities: {
|
||||||
composition: compositionCapability
|
composition: compositionCapability,
|
||||||
|
location: locationCapability
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
newObject = domainObjectFactory({
|
newObject = domainObjectFactory({
|
||||||
@ -315,16 +327,6 @@ define(
|
|||||||
copyFinished = jasmine.createSpy('copyFinished');
|
copyFinished = jasmine.createSpy('copyFinished');
|
||||||
copyResult.then(copyFinished);
|
copyResult.then(copyFinished);
|
||||||
});
|
});
|
||||||
/**
|
|
||||||
* This is testing that the number of calls to the
|
|
||||||
* backend is kept to a minimum
|
|
||||||
*/
|
|
||||||
it("makes only n+2 persistence calls for n copied" +
|
|
||||||
" objects", function () {
|
|
||||||
expect(mockPersistenceService.createObject.calls.length).toEqual(2);
|
|
||||||
expect(mockPersistenceService.updateObject.calls.length).toEqual(1);
|
|
||||||
expect(parentPersistenceCapability.persist).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("copies object and children in a bottom-up" +
|
it("copies object and children in a bottom-up" +
|
||||||
" fashion", function () {
|
" fashion", function () {
|
||||||
@ -342,6 +344,20 @@ define(
|
|||||||
expect(copyFinished.mostRecentCall.args[0].model.persisted).toBe(mockNow.now());
|
expect(copyFinished.mostRecentCall.args[0].model.persisted).toBe(mockNow.now());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
Preserves links
|
||||||
|
*/
|
||||||
|
it ("preserves links", function() {
|
||||||
|
expect(copyFinished.mostRecentCall.args[0].model.location).toBe("testLocation");
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
Preserves links
|
||||||
|
*/
|
||||||
|
it ("correctly locates cloned objects", function() {
|
||||||
|
expect(mockPersistenceService.createObject.calls[0].args[2].location).toEqual(mockPersistenceService.createObject.calls[1].args[1])
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user