Skip to content

Commit

Permalink
Added tests and doc #63
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmiles committed Apr 13, 2015
1 parent 17ddaa0 commit 2d081c7
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,21 @@ $('#tree').treeview('expandNode', [ nodeId, { levels: 2, silent: true } ]);

Triggers `nodeExpanded` event; pass silent to suppress events.

#### getCollapsed()

Returns an array of collapsed nodes e.g. state.expanded = false.

```javascript
$('#tree').treeview('getCollapsed', nodeId);
```
#### getExpanded()

Returns an array of expanded nodes e.g. state.expanded = true.

```javascript
$('#tree').treeview('getExpanded', nodeId);
```

#### getNode(nodeId)

Returns a single node object that matches the given node id.
Expand All @@ -429,6 +444,14 @@ Returns the parent node of a given node, if valid otherwise returns undefined.
$('#tree').treeview('getParent', node);
```

#### getSelected()

Returns an array of selected nodes e.g. state.selected = true.

```javascript
$('#tree').treeview('getSelected', nodeId);
```

#### getSiblings(node | nodeId)

Returns an array of sibling nodes for a given node, if valid otherwise returns undefined.
Expand All @@ -437,6 +460,14 @@ Returns an array of sibling nodes for a given node, if valid otherwise returns u
$('#tree').treeview('getSiblings', node);
```

#### getUnselected()

Returns an array of unselected nodes e.g. state.selected = false.

```javascript
$('#tree').treeview('getUnselected', nodeId);
```

#### remove()

Removes the tree view component. Removing attached events, internal attached objects, and added HTML elements.
Expand Down
43 changes: 42 additions & 1 deletion tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@
test('getNode', function () {
var $tree = init({ data: data });
var nodeParent1 = $tree.treeview('getNode', 0);
equal(nodeParent1.text, 'Parent 1', 'Correct node returned : requested "Parent 1", for "Parent 1"');
equal(nodeParent1.text, 'Parent 1', 'Correct node returned : requested "Parent 1", got "Parent 1"');
});

test('getParent', function () {
Expand Down Expand Up @@ -412,6 +412,47 @@
ok(results, 'Correct siblings for "Child 1" [non root] : results OK');
});

test('getSelected', function () {
var $tree = init({ data: data })
.treeview('selectNode', 0);

var selectedNodes = $tree.treeview('getSelected');
ok((selectedNodes instanceof Array), 'Result is an array');
equal(selectedNodes.length, 1, 'Correct number of nodes returned');
equal(selectedNodes[0].text, 'Parent 1', 'Correct node returned');
});

test('getUnselected', function () {
var $tree = init({ data: data })
.treeview('selectNode', 0);

var unselectedNodes = $tree.treeview('getUnselected');
ok((unselectedNodes instanceof Array), 'Result is an array');
equal(unselectedNodes.length, 8, 'Correct number of nodes returned');
});

// Assumptions:
// Default tree + expanded to 2 levels,
// means 1 node 'Parent 1' should be expanded and therefore returned
test('getExpanded', function () {
var $tree = init({ data: data });
var expandedNodes = $tree.treeview('getExpanded');
ok((expandedNodes instanceof Array), 'Result is an array');
equal(expandedNodes.length, 1, 'Correct number of nodes returned');
equal(expandedNodes[0].text, 'Parent 1', 'Correct node returned');
});

// Assumptions:
// Default tree + expanded to 2 levels, means only 'Parent 1' should be expanded
// as all other parent nodes have no children their state will be collapsed
// which means 8 of the 9 nodes should be returned
test('getCollapsed', function () {
var $tree = init({ data: data });
var collapsedNodes = $tree.treeview('getCollapsed');
ok((collapsedNodes instanceof Array), 'Result is an array');
equal(collapsedNodes.length, 8, 'Correct number of nodes returned');
});

test('selectNode / unselectNode', function () {
var $tree = init({ data: data });
var el;
Expand Down

0 comments on commit 2d081c7

Please sign in to comment.