From 70971545a36a71f573028761003d5824fce2740b Mon Sep 17 00:00:00 2001 From: tomkp Date: Thu, 9 Jul 2015 17:28:45 +0100 Subject: [PATCH] test framework --- test/TreePane-test.js | 60 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/test/TreePane-test.js b/test/TreePane-test.js index 5e8b6bc..a8689ad 100644 --- a/test/TreePane-test.js +++ b/test/TreePane-test.js @@ -7,20 +7,45 @@ import TreePane from '../src/TreePane'; describe('TreePane', function () { + const model = { - name: 'Tom', + name: 'Default', children: [ - { name: 'Alice'}, { name: 'Jacob'} + { name: 'react-tree-pane', children:[ + {name: 'demo', children: [ + {name: 'bundle.js'}, + {name: 'Example.js'} + ]}, + {name: 'src', children: [ + {name: 'TreePane.js'} + ]}, + {name: 'test', children: [ + {name: 'TreePane-test.js'} + ]}, + {name: 'package.json'} + ]} ] }; + const treePane = TestUtils.renderIntoDocument( ); it('should render the tree pane', function () { - new Asserter(treePane); + new TreePaneAsserter(treePane); + }); + + + it('should render the whole tree expanded', function () { + new TreePaneAsserter(treePane) + .findNode().assertValue('Default').assertIsExpanded().assertNumberOfChildren(1) + .findChildNode('react-tree-pane').assertIsExpanded().assertNumberOfChildren(3) + .findChildNode('demo').assertIsExpanded().assertNumberOfChildren(2).end() + .findChildNode('src').assertIsExpanded().assertNumberOfChildren(1).end() + .findChildNode('test').assertIsExpanded().assertNumberOfChildren(1).end() + ; }); }); @@ -28,22 +53,37 @@ describe('TreePane', function () { -class Asserter { +class TreePaneAsserter { constructor(treePane) { - this.component = TestUtils.findRenderedDOMComponentWithClass(treePane, 'TreePane'); this.treePane = treePane; } - - assertNumberOfChildren() { - //expect(this.component.props.children.length).to.equal(3); + findNode() { + return new NodeAsserter(this); } +} - findChildren() { - //return TestUtils.scryRenderedDOMComponentsWithClass(this.component, 'Node'); +class NodeAsserter { + constructor(parent) { + this.parent = parent; } + findCell() {return new CellAsserter(this) } + assertValue() { return this; } + assertIsExpanded() { return this; } + assertIsCollapsed() { return this; } + assertNumberOfChildren(expected) { return this; } + findChildNode(value) { return new NodeAsserter(this) } + end() { return this.parent; } +} + +class CellAsserter { + constructor(parent) { + this.parent = parent; + } + assertValue() { return this; } + end() { return this.parent; } }