diff --git a/platform/commonUI/general/src/ui/TreeNodeView.js b/platform/commonUI/general/src/ui/TreeNodeView.js index 3dfef187e7..14ff0f3233 100644 --- a/platform/commonUI/general/src/ui/TreeNodeView.js +++ b/platform/commonUI/general/src/ui/TreeNodeView.js @@ -105,13 +105,13 @@ define([ }; function getIdPath(domainObject) { + var context = domainObject && domainObject.getCapability('context'); + function getId(domainObject) { return domainObject.getId(); } - return domainObject ? - domainObject.getCapability('context').getPath().map(getId) : - []; + return context ? context.getPath().map(getId) : []; } TreeNodeView.prototype.value = function (domainObject) { diff --git a/platform/commonUI/general/test/ui/TreeViewSpec.js b/platform/commonUI/general/test/ui/TreeViewSpec.js index c196890782..f4339e2b31 100644 --- a/platform/commonUI/general/test/ui/TreeViewSpec.js +++ b/platform/commonUI/general/test/ui/TreeViewSpec.js @@ -206,6 +206,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 () { beforeEach(function () { var newCapabilities = makeGenericCapabilities(),