source: Dev/branches/rest-dojo-ui/client/dojox/data/tests/dom.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 5.5 KB
Line 
1dojo.provide("dojox.data.tests.dom");
2dojo.require("dojox.data.dom");
3
4tests.register("dojox.data.tests.dom",
5        [
6                function testCreateDocument(t){
7                        var document = dojox.data.dom.createDocument();
8                        t.assertTrue(document !== null);
9                },
10                function testCreateDocumentFromText(t){
11                        var simpleXml = "<parentNode><childNode><grandchildNode/></childNode><childNode/></parentNode>";
12                        var document = dojox.data.dom.createDocument(simpleXml, "text/xml");
13                       
14                        var parent = document.firstChild;
15                        t.assertTrue(parent !== null);
16                        t.assertTrue(parent.tagName === "parentNode");
17                        t.assertTrue(parent.childNodes.length == 2);
18                       
19                        var firstChild = parent.firstChild;
20                        t.assertTrue(firstChild !== null);
21                        t.assertTrue(firstChild.tagName === "childNode");
22                        t.assertTrue(firstChild.childNodes.length == 1);
23                       
24                        var secondChild = firstChild.nextSibling;
25                        t.assertTrue(secondChild !== null);
26                        t.assertTrue(secondChild.tagName === "childNode");
27
28                        var grandChild = firstChild.firstChild;
29                        t.assertTrue(grandChild !== null);
30                        t.assertTrue(grandChild.tagName === "grandchildNode");
31
32                },
33                function testCreateDocumentEmptyString(t){
34                        var simpleXml = "";
35                        var document = dojox.data.dom.createDocument(simpleXml, "text/xml");
36                       
37                        t.assertTrue(typeof document != "undefined");
38
39                        var parent = document.firstChild;
40                        t.assertTrue(parent === null);
41                },
42                function testCreateDocumentEmpty(t){
43                        var simpleXml;
44                        var document = dojox.data.dom.createDocument();
45                       
46                        t.assertTrue(typeof document != "undefined");
47
48                        var parent = document.firstChild;
49                        t.assertTrue(parent === null);
50                },
51                function testReadTextContent(t){
52                        var text = "This is a bunch of child text on the node";
53                        var simpleXml = "<parentNode>" + text + "</parentNode>";
54                        var document = dojox.data.dom.createDocument(simpleXml, "text/xml");
55           
56                        var topNode = document.firstChild;
57                        t.assertTrue(topNode !== null);
58                        t.assertTrue(topNode.tagName === "parentNode");
59                        t.assertTrue(text === dojox.data.dom.textContent(topNode));
60                        dojo.destroy(topNode);
61                        t.assertTrue(document.firstChild === null);
62                },
63                function testSetTextContent(t){
64                        var text = "This is a bunch of child text on the node";
65                        var text2 = "This is the new text";
66                        var simpleXml = "<parentNode>" + text + "</parentNode>";
67                        var document = dojox.data.dom.createDocument(simpleXml, "text/xml");
68           
69                        var topNode = document.firstChild;
70                        t.assertTrue(topNode !== null);
71                        t.assertTrue(topNode.tagName === "parentNode");
72                        t.assertTrue(text === dojox.data.dom.textContent(topNode));
73                        dojox.data.dom.textContent(topNode, text2);
74                        t.assertTrue(text2 === dojox.data.dom.textContent(topNode));
75                        dojo.destroy(topNode);
76                        t.assertTrue(document.firstChild === null);
77
78                },
79                function testReplaceChildrenArray(t){
80                        var simpleXml1 = "<parentNode><child1/><child2/><child3/></parentNode>";
81                        var simpleXml2 = "<parentNode><child4/><child5/><child6/><child7/></parentNode>";
82                        var doc1 = dojox.data.dom.createDocument(simpleXml1, "text/xml");
83                        var doc2 = dojox.data.dom.createDocument(simpleXml2, "text/xml");
84           
85                        var topNode1 = doc1.firstChild;
86                        var topNode2 = doc2.firstChild;
87                        t.assertTrue(topNode1 !== null);
88                        t.assertTrue(topNode1.tagName === "parentNode");
89                        t.assertTrue(topNode2 !== null);
90                        t.assertTrue(topNode2.tagName === "parentNode");
91                        dojox.data.dom.removeChildren(topNode1);
92                        var newChildren=[];
93                        for(var i=0;i<topNode2.childNodes.length;i++){
94                                newChildren.push(topNode2.childNodes[i]);
95                        }
96                        dojox.data.dom.removeChildren(topNode2);
97                        dojox.data.dom.replaceChildren(topNode1,newChildren);
98                        t.assertTrue(topNode1.childNodes.length === 4);
99                        t.assertTrue(topNode1.firstChild.tagName === "child4");
100                        t.assertTrue(topNode1.lastChild.tagName === "child7");
101
102                },
103                function testReplaceChildrenSingle(t){
104                        var simpleXml1 = "<parentNode><child1/><child2/><child3/></parentNode>";
105                        var simpleXml2 = "<parentNode><child4/></parentNode>";
106                        var doc1 = dojox.data.dom.createDocument(simpleXml1, "text/xml");
107                        var doc2 = dojox.data.dom.createDocument(simpleXml2, "text/xml");
108           
109                        var topNode1 = doc1.firstChild;
110                        var topNode2 = doc2.firstChild;
111                        t.assertTrue(topNode1 !== null);
112                        t.assertTrue(topNode1.tagName === "parentNode");
113                        t.assertTrue(topNode2 !== null);
114                        t.assertTrue(topNode2.tagName === "parentNode");
115                        dojox.data.dom.removeChildren(topNode1);
116                       
117                        var newChildren = topNode2.firstChild;
118                        dojox.data.dom.removeChildren(topNode2);
119                        dojox.data.dom.replaceChildren(topNode1,newChildren);
120                        t.assertTrue(topNode1.childNodes.length === 1);
121                        t.assertTrue(topNode1.firstChild.tagName === "child4");
122                        t.assertTrue(topNode1.lastChild.tagName === "child4");
123                },
124                function testRemoveChildren(t){
125                        var simpleXml1 = "<parentNode><child1/><child2/><child3/></parentNode>";
126                        var doc1 = dojox.data.dom.createDocument(simpleXml1, "text/xml");
127           
128                        var topNode1 = doc1.firstChild;
129                        t.assertTrue(topNode1 !== null);
130                        t.assertTrue(topNode1.tagName === "parentNode");
131                        dojox.data.dom.removeChildren(topNode1);
132                        t.assertTrue(topNode1.childNodes.length === 0);
133                        t.assertTrue(topNode1.firstChild === null);
134                },
135                function testInnerXML(t){
136                        var simpleXml1 = "<parentNode><child1/><child2/><child3/></parentNode>";
137                        var doc1 = dojox.data.dom.createDocument(simpleXml1, "text/xml");
138           
139                        var topNode1 = doc1.firstChild;
140                        t.assertTrue(topNode1 !== null);
141                        t.assertTrue(topNode1.tagName === "parentNode");
142
143                        var innerXml = dojox.data.dom.innerXML(topNode1);
144                        t.assertTrue(simpleXml1 === innerXml);
145                }
146        ]
147);
Note: See TracBrowser for help on using the repository browser.