[Tree] Don't assume context capability is present

Addresses #753 (newly-created objects may not have context,
causing errors when these are encountered by TreeNodeView)
This commit is contained in:
Victor Woeltjen 2016-03-16 14:04:03 -07:00
parent d30532a8bc
commit 73b7365ae2
2 changed files with 18 additions and 3 deletions

View File

@ -81,13 +81,13 @@ define([
}; };
function getIdPath(domainObject) { function getIdPath(domainObject) {
var context = domainObject && domainObject.getCapability('context');
function getId(domainObject) { function getId(domainObject) {
return domainObject.getId(); return domainObject.getId();
} }
return domainObject ? return context ? context.getPath().map(getId) : [];
domainObject.getCapability('context').getPath().map(getId) :
[];
} }
TreeNodeView.prototype.value = function (domainObject) { TreeNodeView.prototype.value = function (domainObject) {

View File

@ -200,6 +200,21 @@ define([
}); });
}); });
describe("when a context-less object is selected", function () {
beforeEach(function () {
var testCapabilities = makeGenericCapabilities(),
mockDomainObject =
makeMockDomainObject('xyz', {}, testCapabilities);
delete testCapabilities.context;
treeView.value(mockDomainObject);
});
it("clears all selection state", function () {
var selected = $(treeView.elements()[0]).find('.selected');
expect(selected.length).toEqual(0);
});
});
describe("when children contain children", function () { describe("when children contain children", function () {
beforeEach(function () { beforeEach(function () {
var newCapabilities = makeGenericCapabilities(), var newCapabilities = makeGenericCapabilities(),