~bac/juju-gui/trunkcopy

« back to all changes in this revision

Viewing changes to lib/yui/tests/node/tests/node-attrs-test.js

  • Committer: kapil.foss at gmail
  • Date: 2012-07-13 18:45:59 UTC
  • Revision ID: kapil.foss@gmail.com-20120713184559-2xl7be17egsrz0c9
reshape

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
YUI.add('node-attrs-test', function(Y) {
2
 
 
3
 
    var Assert = Y.Assert,
4
 
        ArrayAssert = Y.ArrayAssert;
5
 
 
6
 
    Y.Test.Runner.add(new Y.Test.Case({
7
 
        name: 'Y.Node get() method',
8
 
 
9
 
        setUp: function() {
10
 
            this._testNode = Y.one('#test-nodes');
11
 
        },
12
 
 
13
 
        tearDown: function() {
14
 
            delete this._testNode;
15
 
        },
16
 
 
17
 
        'should return null from empty string input': function() {
18
 
            Assert.areEqual(null, this._testNode.get(''));
19
 
        },
20
 
        'should return null from unfound property': function() {
21
 
            Assert.areEqual(null, this._testNode.get('fake'));
22
 
        },
23
 
 
24
 
        'should return null nodeValue': function() {
25
 
            Assert.areEqual(null, this._testNode.get('nodeValue'));
26
 
        },
27
 
 
28
 
        'should return DIV from nodeName': function() {
29
 
            Assert.areEqual('DIV', this._testNode.get('nodeName'));
30
 
        },
31
 
 
32
 
        'should return UL from nodeName': function() {
33
 
            Assert.areEqual('UL', Y.one('#test-nodes ul').get('nodeName'));
34
 
        },
35
 
 
36
 
        'should return LI from nodeName': function() {
37
 
            Assert.areEqual('LI', Y.one('#test-nodes ul li').get('nodeName'));
38
 
        },
39
 
 
40
 
        'should return the firstChild': function() {
41
 
            var element = document.getElementById('test-nodes');
42
 
            Assert.areEqual(element.firstChild, this._testNode.get('firstChild')._node);
43
 
        },
44
 
 
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);
50
 
        },
51
 
 
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'));
57
 
 
58
 
        },
59
 
        'should return the nodeName of the of the lastChild': function() {
60
 
            var element = document.getElementById('test-nodes'),
61
 
                node = this._testNode;
62
 
 
63
 
            Assert.areEqual(element.lastChild.nodeName, node.get('lastChild').get('nodeName'));
64
 
        },
65
 
 
66
 
        'should get the document node from the ownerDocument': function() {
67
 
            Assert.areEqual(9, this._testNode.get('ownerDocument').get('nodeType'));
68
 
        },
69
 
 
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);
73
 
        },
74
 
 
75
 
        'should return the text of the new element': function() {
76
 
            Assert.areEqual('foo', Y.Node.create('<div>foo</div>').get('text'));
77
 
        },
78
 
 
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'));
83
 
        },
84
 
 
85
 
        'should return the correct number of children': function() {
86
 
            Assert.areEqual(2, this._testNode.get('children')._nodes.length);
87
 
        },
88
 
            
89
 
        'should return zero children from empty node': function() {
90
 
            Assert.areEqual(0, Y.one('#test-empty-children').get('children')._nodes.length);
91
 
        },
92
 
 
93
 
        'should return matching childNode length': function() {
94
 
            Assert.areEqual(this._testNode._node.childNodes.length,
95
 
                    this._testNode.get('childNodes').get('length').length);
96
 
        },
97
 
 
98
 
        'should return the correct tabIndex': function() {
99
 
            Assert.areEqual(document.getElementById('test-prop').tabIndex,
100
 
                    Y.one('#test-prop').get('tabIndex'));
101
 
        },
102
 
 
103
 
        'should return the correct tabIndex when not set (DIV)': function() {
104
 
            Assert.areEqual(document.getElementById('doc').tabIndex,
105
 
                    Y.one('#doc').get('tabIndex'));
106
 
        },
107
 
 
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'));
111
 
 
112
 
            Assert.areEqual(0, Y.one('#link-1').get('tabIndex'));
113
 
        },
114
 
 
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'));
118
 
 
119
 
            Assert.areEqual(-1, Y.one('#link-2').get('tabIndex'));
120
 
        },
121
 
 
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);
125
 
        },
126
 
 
127
 
        test_getters: function() {
128
 
            var id = 'test-nodes',
129
 
                element = document.getElementById(id),
130
 
                node = Y.one('#' + id),
131
 
                nodes = Y.all('#' + id + ' *');
132
 
        }
133
 
    }));
134
 
 
135
 
    Y.Test.Runner.add(new Y.Test.Case({
136
 
        name: 'Y.NodeList get() method',
137
 
 
138
 
        setUp: function() {
139
 
            this._testNodes = Y.all('#test-nodes *');
140
 
        },
141
 
 
142
 
        tearDown: function() {
143
 
            delete this._testNodes;
144
 
        },
145
 
 
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);
150
 
        },
151
 
 
152
 
        'should find the id of the first nodes\'s parentNode': function() {
153
 
            Assert.areEqual('test-nodes', this._testNodes.get('parentNode').get('id')[0]);
154
 
        },
155
 
 
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]));
158
 
        },
159
 
 
160
 
        'should convert DOM node return values to NodeList': function() {
161
 
            Assert.isTrue(Y.all('input').get('parentNode') instanceof Y.NodeList);
162
 
        }
163
 
    }));
164
 
}, '@VERSION@' ,{requires:['node-base']});