Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Increase variations in single select tree tests
Browse files Browse the repository at this point in the history
Many problems with this unit test:
- Mouse clicks were not being tested, only API methods
- Folder selectable tree needs to test items also.
- Folder selectable tree needs to test items with folders previously selected, and folders with items previously selected
- Markup for folder selectable tree did not include a `tree-item` template and therefore created only folders and did not create any items (hence 4 folders/items are returned instead of the folders/correct 8 items).
- The selectItem method was being used to select folders.
  • Loading branch information
interactivellama authored and swilliams committed May 21, 2015
1 parent f32e292 commit 028e161
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
7 changes: 7 additions & 0 deletions test/markup/tree-markup.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@
<ul class="tree-branch-children"></ul>
<div class="tree-loader" role="alert">Loading...</div>
</li>
<!-- item template -->
<li class="tree-item hidden" data-template="treeitem" role="treeitem">
<button class="tree-item-name">
<span class="glyphicon icon-item fueluxicon-bullet"></span>
<span class="tree-label">Example Item</span>
</button>
</li>
</ul>

</div>
Expand Down
25 changes: 20 additions & 5 deletions test/tree-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,13 @@ define(function (require) {

$selNode = $tree.find('.tree-branch:eq(1)');
$tree.tree('discloseFolder', $selNode.find('.tree-branch-header'));
equal($selNode.find('.tree-branch-children > li').length, 4, 'Folder has been populated with sub-folders');
equal($selNode.find('.tree-branch-children > li').length, 8, 'Folder has been populated with sub-folders and items');
});

test("Single item/folder selection works as designed", function () {
var $tree = $(html).find('#MyTree');

// multiSelect: false is the default
$tree.tree({
dataSource: this.dataSource
});
Expand All @@ -204,10 +205,24 @@ define(function (require) {
folderSelect: true
});

$tree.tree('selectItem', $tree.find('.tree-branch-name:eq(1)'));
equal($tree.tree('selectedItems').length, 1, 'Return single selected value');
$tree.tree('selectItem', $tree.find('.tree-branch-name:eq(2)'));
equal($tree.tree('selectedItems').length, 1, 'Return new single selected value');
$tree.tree('selectItem', $tree.find('.tree-item:eq(1)'));
equal($tree.tree('selectedItems').length, 1, 'Return single selected item (none previously selected, 1st programatic selection)');

$tree.tree('selectFolder', $tree.find('.tree-branch-name:eq(1)'));
equal($tree.tree('selectedItems').length, 1, 'Return single selected folder (item previously selected, 2nd programatic selection)');

$tree.tree('selectItem', $tree.find('.tree-item:eq(2)'));
equal($tree.tree('selectedItems').length, 1, 'Return single selected item (folder previously selected, 3rd programatic selection)');

$tree.find('.tree-item:eq(1)').click();
equal($tree.tree('selectedItems').length, 1, 'Return single selected item (item previously selected, 1st click selection)');

$tree.find('.tree-branch-name:eq(1)').click();
equal($tree.tree('selectedItems').length, 1, 'Return single selected folder (item previously selected, 2nd click selection)');

$tree.find('.tree-item:eq(2)').click();
equal($tree.tree('selectedItems').length, 1, 'Return single selected item (folder previously selected, 3rd click selection)');

});

test("Multiple item/folder selection works as designed", function () {
Expand Down

0 comments on commit 028e161

Please sign in to comment.