mirror of
https://github.com/nasa/openmct.git
synced 2025-05-09 12:03:21 +00:00
[Tests] Update Link Service Tests
This commit is contained in:
parent
1d162888dd
commit
197ec0eb2c
@ -28,7 +28,7 @@ define(
|
|||||||
'../DomainObjectFactory',
|
'../DomainObjectFactory',
|
||||||
'../ControlledPromise'
|
'../ControlledPromise'
|
||||||
],
|
],
|
||||||
function (LinkService, domainObjectFactory) {
|
function (LinkService, domainObjectFactory, ControlledPromise) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("LinkService", function () {
|
describe("LinkService", function () {
|
||||||
@ -51,7 +51,6 @@ define(
|
|||||||
validate;
|
validate;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
|
|
||||||
object = domainObjectFactory({
|
object = domainObjectFactory({
|
||||||
name: 'object'
|
name: 'object'
|
||||||
});
|
});
|
||||||
@ -119,20 +118,29 @@ define(
|
|||||||
describe("perform", function () {
|
describe("perform", function () {
|
||||||
|
|
||||||
var object,
|
var object,
|
||||||
|
linkedObject,
|
||||||
parentModel,
|
parentModel,
|
||||||
parentObject,
|
parentObject,
|
||||||
mutationPromise,
|
mutationPromise,
|
||||||
|
compositionPromise,
|
||||||
|
persistencePromise,
|
||||||
|
compositionCapability,
|
||||||
persistenceCapability;
|
persistenceCapability;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mutationPromise = jasmine.createSpyObj(
|
mutationPromise = new ControlledPromise();
|
||||||
'promise',
|
compositionPromise = new ControlledPromise();
|
||||||
['then']
|
persistencePromise = new ControlledPromise();
|
||||||
);
|
|
||||||
persistenceCapability = jasmine.createSpyObj(
|
persistenceCapability = jasmine.createSpyObj(
|
||||||
'persistenceCapability',
|
'persistenceCapability',
|
||||||
['persist']
|
['persist']
|
||||||
);
|
);
|
||||||
|
persistenceCapability.persist.andReturn(persistencePromise);
|
||||||
|
compositionCapability = jasmine.createSpyObj(
|
||||||
|
'compositionCapability',
|
||||||
|
['invoke']
|
||||||
|
);
|
||||||
|
compositionCapability.invoke.andReturn(compositionPromise);
|
||||||
parentModel = {
|
parentModel = {
|
||||||
composition: []
|
composition: []
|
||||||
};
|
};
|
||||||
@ -146,7 +154,8 @@ define(
|
|||||||
return mutationPromise;
|
return mutationPromise;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
persistence: persistenceCapability
|
persistence: persistenceCapability,
|
||||||
|
composition: compositionCapability
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -155,7 +164,11 @@ define(
|
|||||||
id: 'xyz'
|
id: 'xyz'
|
||||||
});
|
});
|
||||||
|
|
||||||
parentObject.getCapability.andReturn(persistenceCapability);
|
linkedObject = domainObjectFactory({
|
||||||
|
name: 'object-link',
|
||||||
|
id: 'xyz'
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -172,16 +185,22 @@ define(
|
|||||||
it("persists parent", function () {
|
it("persists parent", function () {
|
||||||
linkService.perform(object, parentObject);
|
linkService.perform(object, parentObject);
|
||||||
expect(mutationPromise.then).toHaveBeenCalled();
|
expect(mutationPromise.then).toHaveBeenCalled();
|
||||||
mutationPromise.then.calls[0].args[0]();
|
mutationPromise.resolve();
|
||||||
expect(parentObject.getCapability)
|
expect(parentObject.getCapability)
|
||||||
.toHaveBeenCalledWith('persistence');
|
.toHaveBeenCalledWith('persistence');
|
||||||
|
|
||||||
expect(persistenceCapability.persist).toHaveBeenCalled();
|
expect(persistenceCapability.persist).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns object representing new link", function () {
|
it("returns object representing new link", function () {
|
||||||
linkService.perform(object, parentObject);
|
var returnPromise, whenComplete;
|
||||||
|
returnPromise = linkService.perform(object, parentObject);
|
||||||
|
whenComplete = jasmine.createSpy('whenComplete');
|
||||||
|
returnPromise.then(whenComplete);
|
||||||
|
|
||||||
|
mutationPromise.resolve();
|
||||||
|
persistencePromise.resolve();
|
||||||
|
compositionPromise.resolve([linkedObject]);
|
||||||
|
expect(whenComplete).toHaveBeenCalledWith(linkedObject)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user