openmct/platform/entanglement/test/capabilities/LocationCapabilitySpec.js
Pete Richards 94854e5965 [Location] can retrieve contextual location
Clarify naming of method for retrieving contextual location of a domain
object.

Default behavior for objects that do not have a context is to return
undefined.  Note that default behavior is not specified and could change
if needed.
2015-08-19 11:33:45 -07:00

95 lines
3.6 KiB
JavaScript

/*global define,describe,it,expect,beforeEach,jasmine */
define(
[
'../../src/capabilities/LocationCapability',
'../DomainObjectFactory',
'../ControlledPromise'
],
function (LocationCapability, domainObjectFactory, ControlledPromise) {
describe("LocationCapability", function () {
describe("instantiated with domain object", function () {
var locationCapability,
persistencePromise,
mutationPromise,
domainObject;
beforeEach(function () {
domainObject = domainObjectFactory({
capabilities: {
context: {
getParent: function() {
return domainObjectFactory({id: 'root'});
}
},
persistence: jasmine.createSpyObj(
'persistenceCapability',
['persist']
),
mutation: jasmine.createSpyObj(
'mutationCapability',
['invoke']
)
}
});
persistencePromise = new ControlledPromise();
domainObject.capabilities.persistence.persist.andReturn(
persistencePromise
);
mutationPromise = new ControlledPromise();
domainObject.capabilities.mutation.invoke.andCallFake(
function (mutator) {
return mutationPromise.then(function () {
mutator(domainObject.model);
});
}
);
locationCapability = new LocationCapability(domainObject);
});
it("returns contextual location", function () {
expect(locationCapability.getContextualLocation())
.toBe('root');
});
it("knows when the object is an original", function () {
domainObject.model.location = 'root';
expect(locationCapability.isOriginal()).toBe(true);
expect(locationCapability.isLink()).toBe(false);
});
it("knows when the object is a link.", function () {
domainObject.model.location = 'different-root';
expect(locationCapability.isLink()).toBe(true);
expect(locationCapability.isOriginal()).toBe(false);
});
it("can persist location", function () {
var persistResult = locationCapability
.setPrimaryLocation('root'),
whenComplete = jasmine.createSpy('whenComplete');
persistResult.then(whenComplete);
expect(domainObject.model.location).not.toBeDefined();
mutationPromise.resolve();
expect(domainObject.model.location).toBe('root');
expect(whenComplete).not.toHaveBeenCalled();
expect(domainObject.capabilities.persistence.persist)
.toHaveBeenCalled();
persistencePromise.resolve();
expect(whenComplete).toHaveBeenCalled();
});
});
});
}
);