From 73b7365ae23ebf57929ac1c567ac63c895693eb9 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 16 Mar 2016 14:04:03 -0700 Subject: [PATCH] [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) --- platform/commonUI/general/src/ui/TreeNodeView.js | 6 +++--- platform/commonUI/general/test/ui/TreeViewSpec.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/platform/commonUI/general/src/ui/TreeNodeView.js b/platform/commonUI/general/src/ui/TreeNodeView.js index 2b02a2c1f9..5f3fc277af 100644 --- a/platform/commonUI/general/src/ui/TreeNodeView.js +++ b/platform/commonUI/general/src/ui/TreeNodeView.js @@ -81,13 +81,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 370e5c8e10..18a1b86770 100644 --- a/platform/commonUI/general/test/ui/TreeViewSpec.js +++ b/platform/commonUI/general/test/ui/TreeViewSpec.js @@ -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 () { beforeEach(function () { var newCapabilities = makeGenericCapabilities(),