Skip to content
This repository has been archived by the owner on Dec 21, 2021. It is now read-only.

Commit

Permalink
AUI-1156 - Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ipeychev authored and Jonathan Mak committed Feb 28, 2014
1 parent f7c2ab7 commit de89766
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 50 deletions.
18 changes: 7 additions & 11 deletions demos/tree/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,9 @@ <h2>TreeView with Tree Paginator</h2>

var treeViewPaginator = new Y.TreeView({
boundingBox: '#treepaginator',
}).render();

var rootTreeNodePaginator = new Y.TreeNode(
{
children: [
children: [
{
children: [
{
id: 'child-one',
io: 'assets/pages.html',
Expand All @@ -234,12 +232,10 @@ <h2>TreeView with Tree Paginator</h2>
{ label: 'child-three' },
{ label: 'child-four' }
],
label: 'root-one',
id: 'root-one'
}
);

treeViewPaginator.appendChild(rootTreeNodePaginator);
id: 'root-one',
label: 'root-one'
}]
}).render();
});
</script>
</body>
Expand Down
99 changes: 60 additions & 39 deletions src/aui-tree/tests/unit/js/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ YUI.add('module-tests', function(Y) {
var suite = new Y.Test.Suite('aui-tree');

var createNewTreeView = function() {

return new Y.TreeView({
children: [
{
Expand Down Expand Up @@ -98,13 +97,13 @@ YUI.add('module-tests', function(Y) {

Y.Assert.isTrue(
treeViewIndex.hasOwnProperty('root'),
'treeViewIndex object should have a "root" property');
'treeViewIndex object should have a \'root\' property');
Y.Assert.isTrue(
treeViewIndex.hasOwnProperty('child'),
'treeViewIndex object should have a "child" property');
'treeViewIndex object should have a \'child\' property');
Y.Assert.isTrue(
rootTreeNodeIndex.hasOwnProperty('child'),
'rootTreeNodeIndex object should have a "child" property');
'rootTreeNodeIndex object should have a \'child\' property');
},

'removeChild() should remove child TreeNode': function() {
Expand Down Expand Up @@ -249,12 +248,15 @@ YUI.add('module-tests', function(Y) {
/**
* @tests AUI-1156
*/
'Display "Load More Results" link for TreeNodes': function() {
'Display \'Load More Results\' link for TreeNodes': function() {
var childTreeNode,
hitAreaNodeList,
rootHitArea,
rootTreeNode,
rootTreeNodeBB,
treeView;

treeView = new Y.TreeView();
treeView = new Y.TreeView();

childTreeNode = [
{
Expand All @@ -269,50 +271,69 @@ YUI.add('module-tests', function(Y) {
},
type: 'io'
},
{ label: 'child-two' },
{ label: 'child-three' },
{ label: 'child-four' }
];

rootTreeNode = new Y.TreeNode(
{
children: childTreeNode,
id: 'root-one',
label: 'root-one',
label: 'child-two'
},
{
label: 'child-three'
},
{
label: 'child-four'
}
);

treeView.appendChild(rootTreeNode);

var rootTreeNodeCB = rootTreeNode.get('contentBox');
];

var allTreeHitareas = rootTreeNodeCB.all('.tree-container .tree-hitarea');
var treeHitareasArray = [];
rootTreeNode = new Y.TreeNode({
children: childTreeNode,
id: 'root-one',
label: 'root-one'
});

Y.each(
allTreeHitareas,
function(hitarea) {
treeHitareasArray.push(hitarea);
}
);
treeView.appendChild(rootTreeNode);

setTimeout(function() {
for (var i = treeHitareasArray.length; i--;) {
treeHitareasArray[i].simulate('click');
}
treeView.render();

rootTreeNodeBB = rootTreeNode.get('boundingBox');

debugger;

rootHitArea = rootTreeNodeBB.one('.tree-hitarea');

rootHitArea.simulate('click');

hitAreaNodeList = rootTreeNodeBB.all('.tree-hitarea');

Y.Assert.areEqual(2, hitAreaNodeList.size(), 'There must be two hit-area elements');

/*
* We can Mock the AJAX request here, but this is not we want to test. We want to test
* if paginator link will appear, so we will invoke the success handler directly here,
* assumming that server returned correct response. Clicking on hit area was proved to work above.
*/
rootTreeNode.get('children')[0].ioSuccessHandler(null, null, {
responseText: '[ \
{ \
"label": "subchild-one", \
"leaf": true, \
"type": "node" \
}, \
{ \
"label": "subchild-two", \
"leaf": true, \
"type": "node" \
}, \
{ \
"label": "subchild-three", \
"leaf": true, \
"type": "node" \
} \
]'
});

var paginatorLink = allTreeHitareas.one('a');
var paginatorLink = rootTreeNodeBB.one('a');

Y.Assert.isTrue(
paginatorLink.hasClass('tree-node-paginator'),
'childTreeNode has a paginator link');

paginatorLink.simulate('click');

var childTreeNodes = rootTreeNodeCB.all('.tree-container .tree-container li');

Y.Assert.areSame(6, childTreeNodes.size(), 'childTreeNodes should have 6 children');
}
}));

Expand Down

0 comments on commit de89766

Please sign in to comment.