mirror of
https://github.com/nasa/openmct.git
synced 2025-05-04 09:42:57 +00:00
[Core] Add specs for contextual objects
Add specs for the context capability, and the domain object wrapper which introduces it. Ongoing transition work for platform/core, WTD-573.
This commit is contained in:
parent
e18b4f234f
commit
2b82262775
@ -8,7 +8,53 @@ define(
|
|||||||
function (ContextCapability) {
|
function (ContextCapability) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var DOMAIN_OBJECT_METHODS = [
|
||||||
|
"getId",
|
||||||
|
"getModel",
|
||||||
|
"getCapability",
|
||||||
|
"hasCapability",
|
||||||
|
"useCapability"
|
||||||
|
];
|
||||||
|
|
||||||
describe("The context capability", function () {
|
describe("The context capability", function () {
|
||||||
|
var mockDomainObject,
|
||||||
|
mockParent,
|
||||||
|
mockGrandparent,
|
||||||
|
mockContext,
|
||||||
|
context;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS);
|
||||||
|
mockParent = jasmine.createSpyObj("parent", DOMAIN_OBJECT_METHODS);
|
||||||
|
mockGrandparent = jasmine.createSpyObj("grandparent", DOMAIN_OBJECT_METHODS);
|
||||||
|
mockContext = jasmine.createSpyObj("context", [ "getParent", "getRoot", "getPath" ]);
|
||||||
|
|
||||||
|
mockParent.getCapability.andReturn(mockContext);
|
||||||
|
mockContext.getParent.andReturn(mockGrandparent);
|
||||||
|
mockContext.getRoot.andReturn(mockGrandparent);
|
||||||
|
mockContext.getPath.andReturn([mockGrandparent, mockParent]);
|
||||||
|
|
||||||
|
context = new ContextCapability(mockParent, mockDomainObject);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("allows an object's parent to be retrieved", function () {
|
||||||
|
expect(context.getParent()).toEqual(mockParent);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("allows an object's full ancestry to be retrieved", function () {
|
||||||
|
expect(context.getPath()).toEqual([mockGrandparent, mockParent, mockDomainObject]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("allows the deepest ancestor of an object to be retrieved", function () {
|
||||||
|
expect(context.getRoot()).toEqual(mockGrandparent);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("treats ancestors with no context capability as deepest ancestors", function () {
|
||||||
|
mockParent.getCapability.andReturn(undefined);
|
||||||
|
expect(context.getPath()).toEqual([mockParent, mockDomainObject]);
|
||||||
|
expect(context.getRoot()).toEqual(mockParent);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,55 @@ define(
|
|||||||
function (ContextualDomainObject) {
|
function (ContextualDomainObject) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
|
||||||
|
var DOMAIN_OBJECT_METHODS = [
|
||||||
|
"getId",
|
||||||
|
"getModel",
|
||||||
|
"getCapability",
|
||||||
|
"hasCapability",
|
||||||
|
"useCapability"
|
||||||
|
];
|
||||||
|
|
||||||
describe("A contextual domain object", function () {
|
describe("A contextual domain object", function () {
|
||||||
|
var mockParent,
|
||||||
|
mockDomainObject,
|
||||||
|
model,
|
||||||
|
contextualDomainObject;
|
||||||
|
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
mockParent = jasmine.createSpyObj("parent", DOMAIN_OBJECT_METHODS);
|
||||||
|
mockDomainObject = jasmine.createSpyObj("parent", DOMAIN_OBJECT_METHODS);
|
||||||
|
|
||||||
|
model = { someKey: "some value" };
|
||||||
|
|
||||||
|
mockDomainObject.getCapability.andReturn("some capability");
|
||||||
|
mockDomainObject.getModel.andReturn(model);
|
||||||
|
|
||||||
|
contextualDomainObject = new ContextualDomainObject(
|
||||||
|
mockDomainObject,
|
||||||
|
mockParent
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it("adds a context capability to a domain object", function () {
|
||||||
|
var context = contextualDomainObject.getCapability('context');
|
||||||
|
|
||||||
|
// Expect something that looks like a context capability
|
||||||
|
expect(context).toBeDefined();
|
||||||
|
expect(context.getPath).toBeDefined();
|
||||||
|
expect(context.getRoot).toBeDefined();
|
||||||
|
expect(context.getParent()).toEqual(mockParent);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it("does not shadow other domain object methods", function () {
|
||||||
|
expect(contextualDomainObject.getModel())
|
||||||
|
.toEqual(model);
|
||||||
|
expect(contextualDomainObject.getCapability("other"))
|
||||||
|
.toEqual("some capability");
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user