1
YUI.add('node-attrs-test', function(Y) {
4
ArrayAssert = Y.ArrayAssert;
6
Y.Test.Runner.add(new Y.Test.Case({
7
name: 'Y.Node get() method',
10
this._testNode = Y.one('#test-nodes');
13
tearDown: function() {
14
delete this._testNode;
17
'should return null from empty string input': function() {
18
Assert.areEqual(null, this._testNode.get(''));
20
'should return null from unfound property': function() {
21
Assert.areEqual(null, this._testNode.get('fake'));
24
'should return null nodeValue': function() {
25
Assert.areEqual(null, this._testNode.get('nodeValue'));
28
'should return DIV from nodeName': function() {
29
Assert.areEqual('DIV', this._testNode.get('nodeName'));
32
'should return UL from nodeName': function() {
33
Assert.areEqual('UL', Y.one('#test-nodes ul').get('nodeName'));
36
'should return LI from nodeName': function() {
37
Assert.areEqual('LI', Y.one('#test-nodes ul li').get('nodeName'));
40
'should return the firstChild': function() {
41
var element = document.getElementById('test-nodes');
42
Assert.areEqual(element.firstChild, this._testNode.get('firstChild')._node);
45
'should return the nextSibling of the firstChild': function() {
46
var element = document.getElementById('test-nodes'),
47
node = this._testNode;
48
Assert.areEqual(element.firstChild.nextSibling,
49
node.get('firstChild').get('nextSibling')._node);
52
'should return the nodeName of the nextSibling of the firstChild': function() {
53
var element = document.getElementById('test-nodes'),
54
node = this._testNode;
55
Assert.areEqual(element.firstChild.nextSibling.nodeName,
56
node.get('firstChild.nextSibling.nodeName'));
59
'should return the nodeName of the of the lastChild': function() {
60
var element = document.getElementById('test-nodes'),
61
node = this._testNode;
63
Assert.areEqual(element.lastChild.nodeName, node.get('lastChild').get('nodeName'));
66
'should get the document node from the ownerDocument': function() {
67
Assert.areEqual(9, this._testNode.get('ownerDocument').get('nodeType'));
70
'should return the OPTIONs from the SElECT': function() {
71
ArrayAssert.itemsAreEqual(document.getElementById('test-select').
72
getElementsByTagName('option'), Y.one('#test-select').get('options')._nodes);
75
'should return the text of the new element': function() {
76
Assert.areEqual('foo', Y.Node.create('<div>foo</div>').get('text'));
79
'should return the updated text': function() {
80
var node = Y.Node.create('<div>foo</div>');
81
node.set('text', 'bar');
82
Assert.areEqual('bar', node.get('text'));
85
'should return the correct number of children': function() {
86
Assert.areEqual(2, this._testNode.get('children')._nodes.length);
89
'should return zero children from empty node': function() {
90
Assert.areEqual(0, Y.one('#test-empty-children').get('children')._nodes.length);
93
'should return matching childNode length': function() {
94
Assert.areEqual(this._testNode._node.childNodes.length,
95
this._testNode.get('childNodes').get('length').length);
98
'should return the correct tabIndex': function() {
99
Assert.areEqual(document.getElementById('test-prop').tabIndex,
100
Y.one('#test-prop').get('tabIndex'));
103
'should return the correct tabIndex when not set (DIV)': function() {
104
Assert.areEqual(document.getElementById('doc').tabIndex,
105
Y.one('#doc').get('tabIndex'));
108
'should return the correct tabIndex when not set (A)': function() {
109
Assert.areEqual(document.getElementById('link-1').tabIndex,
110
Y.one('#link-1').get('tabIndex'));
112
Assert.areEqual(0, Y.one('#link-1').get('tabIndex'));
115
'should return the correct tabIndex when set to -1 (A)': function() {
116
Assert.areEqual(document.getElementById('link-2').tabIndex,
117
Y.one('#link-2').get('tabIndex'));
119
Assert.areEqual(-1, Y.one('#link-2').get('tabIndex'));
122
'should convert live list to static array': function() {
123
Assert.isUndefined(Y.one('form').get('childNodes')._nodes.item);
124
Assert.isTrue('slice' in Y.one('form').get('childNodes')._nodes);
127
test_getters: function() {
128
var id = 'test-nodes',
129
element = document.getElementById(id),
130
node = Y.one('#' + id),
131
nodes = Y.all('#' + id + ' *');
135
Y.Test.Runner.add(new Y.Test.Case({
136
name: 'Y.NodeList get() method',
139
this._testNodes = Y.all('#test-nodes *');
142
tearDown: function() {
143
delete this._testNodes;
146
'should return an array of tagNames from the nodelist': function() {
147
var node = Y.one('#test-nodes');
148
Assert.areEqual(node._node.childNodes.length,
149
node.get('childNodes').get('tagName').length);
152
'should find the id of the first nodes\'s parentNode': function() {
153
Assert.areEqual('test-nodes', this._testNodes.get('parentNode').get('id')[0]);
156
'should find the text of the first item in children collection': function() {
157
Assert.areEqual('item 1', Y.Lang.trim(this._testNodes.get('children')[0].get('text')[0]));
160
'should convert DOM node return values to NodeList': function() {
161
Assert.isTrue(Y.all('input').get('parentNode') instanceof Y.NodeList);
164
}, '@VERSION@' ,{requires:['node-base']});