From d72aaf54ca93e72d9f8f5b2752303bf9da131cee Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 14 Mar 2016 14:40:46 -0700 Subject: [PATCH] [Tree] Test inner tree creation --- .../commonUI/general/test/ui/TreeViewSpec.js | 87 +++++++++++++++---- 1 file changed, 70 insertions(+), 17 deletions(-) diff --git a/platform/commonUI/general/test/ui/TreeViewSpec.js b/platform/commonUI/general/test/ui/TreeViewSpec.js index 8b67248c2a..370e5c8e10 100644 --- a/platform/commonUI/general/test/ui/TreeViewSpec.js +++ b/platform/commonUI/general/test/ui/TreeViewSpec.js @@ -99,9 +99,25 @@ define([ describe("model", function () { var mockComposition; + function makeGenericCapabilities() { + var mockContext = + jasmine.createSpyObj('context', [ 'getPath' ]), + mockType = + jasmine.createSpyObj('type', [ 'getGlyph' ]), + mockLocation = + jasmine.createSpyObj('location', [ 'isLink' ]), + mockMutation = + jasmine.createSpyObj('mutation', [ 'listen' ]); + return { + context: mockContext, + type: mockType, + mutation: mockMutation, + location: mockLocation + }; + } + function waitForCompositionCallback() { - var calledBack = false, - n = Math.random(); + var calledBack = false; testCapabilities.composition.invoke().then(function (c) { calledBack = true; }); @@ -112,22 +128,11 @@ define([ beforeEach(function () { mockComposition = ['a', 'b', 'c'].map(function (id) { - var mockContext = - jasmine.createSpyObj('context', [ 'getPath' ]), - mockType = - jasmine.createSpyObj('type', [ 'getGlyph' ]), - mockLocation = - jasmine.createSpyObj('location', [ 'isLink' ]), - mockMutation = - jasmine.createSpyObj('mutation', [ 'listen' ]), - mockChild = makeMockDomainObject(id, {}, { - context: mockContext, - type: mockType, - mutation: mockMutation, - location: mockLocation - }); + var testCapabilities = makeGenericCapabilities(), + mockChild = + makeMockDomainObject(id, {}, testCapabilities); - mockContext.getPath + testCapabilities.context.getPath .andReturn([mockDomainObject, mockChild]); return mockChild; @@ -194,6 +199,54 @@ define([ expect(selected.length).toEqual(1); }); }); + + describe("when children contain children", function () { + beforeEach(function () { + var newCapabilities = makeGenericCapabilities(), + gcCapabilities = makeGenericCapabilities(), + mockNewChild = + makeMockDomainObject('d', {}, newCapabilities), + mockGrandchild = + makeMockDomainObject('gc', {}, gcCapabilities), + calledBackInner = false; + + newCapabilities.composition = + jasmine.createSpyObj('composition', [ 'invoke' ]); + newCapabilities.composition.invoke + .andReturn(Promise.resolve([mockGrandchild])); + mockComposition.push(mockNewChild); + + newCapabilities.context.getPath.andReturn([ + mockDomainObject, + mockNewChild + ]); + gcCapabilities.context.getPath.andReturn([ + mockDomainObject, + mockNewChild, + mockGrandchild + ]); + + testCapabilities.mutation.listen + .mostRecentCall.args[0](mockDomainObject); + waitForCompositionCallback(); + runs(function () { + // Select the innermost object to force expansion, + // such that we can verify the subtree is present. + treeView.value(mockGrandchild); + newCapabilities.composition.invoke().then(function () { + calledBackInner = true; + }); + }); + waitsFor(function () { + return calledBackInner; + }); + }); + + it("creates inner trees", function () { + expect($(treeView.elements()[0]).find('ul').length) + .toEqual(1); + }); + }); }); describe("observe", function () {