openmct/platform/entanglement/test/capabilities/LocationCapabilitySpec.js
larkin 9ea1d24121 [Entanglement] Add LocationCapability
DomainObjects with a context capability also gain a LocationCapability.

This capability allows you to determine the location of the current
instance of a domain object, and also provides methods for determining
if the current instance of a domain object is a link, or if it is an
original.
2015-08-04 11:24:50 -07:00

82 lines
3.1 KiB
JavaScript

/*global define,describe,it,expect,beforeEach */
define(
[
'../../src/capabilities/LocationCapability',
'../DomainObjectFactory'
],
function (LocationCapability, domainObjectFactory) {
describe("LocationCapability", function () {
it("applies to objects with a context capability", function () {
var domainObject = domainObjectFactory({
capabilities: {
context: true
}
});
expect(LocationCapability.appliesTo(domainObject)).toBe(true);
});
it("does not apply to objects without context capability", function () {
var domainObject = domainObjectFactory();
expect(LocationCapability.appliesTo(domainObject)).toBe(false);
});
describe("instantiated with domain object", function () {
var locationCapability,
domainObject;
beforeEach(function () {
domainObject = domainObjectFactory({
capabilities: {
context: {
getPath: function() {
return [
{
getId: function () {
return 'root';
}
},
{
getId: function () {
return 'parent';
}
},
{
getId: function () {
return 'me';
}
}
];
}
}
}
});
locationCapability = new LocationCapability(domainObject);
});
it("returns location", function () {
expect(locationCapability.getLocation())
.toBe('root/parent/me');
});
it("knows when the object is an original", function () {
domainObject.model.location = 'root/parent/me';
expect(locationCapability.isOriginal()).toBe(true);
expect(locationCapability.isLink()).toBe(false);
});
it("knows when the object is a link.", function () {
domainObject.model.location = 'root/another/location/me';
expect(locationCapability.isLink()).toBe(true);
expect(locationCapability.isOriginal()).toBe(false);
});
});
});
}
);