-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.js
211 lines (183 loc) · 6.09 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
define([
'./browser'
], function(browser){
function byId(id){
return document.getElementById(id);
}
var
suiteName = 'Headless Browser';
function dumbSimpleNode(t){
// simple node:
document.body.innerHTML = '<div>dumb simple</div>';
document.body.log();
t.assert(document.body.children.length === 1);
}
function simpleNode(t){
// simple node:
document.body.innerHTML = '<div class="test" id="test">inner text</div>';
document.body.log();
t.assert(byId('test'));
}
function overWriteHtml(t){
// simple node:
document.body.innerHTML = '<div class="test" id="test">inner text</div>';
document.body.innerHTML = '<div class="test" id="test">New inner text</div>';
document.body.log();
t.assert(byId('test').textContent === 'New inner text');
}
function singleChild(t){
// single child:
document.body.innerHTML = "<div id='p1'><div class='c'>child text</chld></prnt>";
document.body.log();
t.assert(byId('p1').firstChild.textContent === 'child text');
}
function childrenTwoLevels(t){
// two levels deep:
document.body.innerHTML = "<div id='p1'><div class='c1'><div class='c2'>baby text</chld2></chld1></prnt>";
document.body.log();
t.assert(byId('p1').firstChild.firstChild.textContent === 'baby text');
}
function siblings(t){
// two siblings:
document.body.innerHTML = "<div><div id='p1'><div class='c1'>text 1</chld1><div class='c2'>text 2</chld2></prnt></div>";
document.body.log();
t.assert(byId('p1').firstChild.textContent === 'text 1' && byId('p1').firstChild.nextSibling.textContent === 'text 2');
}
function overwriteSiblings(t){
// two siblings:
document.body.innerHTML = "<div id='p1'><div class='c1'>text 1</chld1><div class='c2'>text 2</chld2></prnt>";
document.body.innerHTML = "<div id='p1'><div class='c2'>text 3</chld1><div class='c4'>text 4</chld2></prnt>";
document.body.log();
var node = byId('p1').firstChild;
t.assert(node.textContent === 'text 3' && node.nextSibling.textContent === 'text 4');
}
function classNameTest(t){
// one node, attributes
document.body.innerHTML = "<div id='p1' class='p1 dark mode'></div>";
document.body.log();
var node = byId('p1');
t.assert(node.className === 'p1 dark mode');
}
function styleTest(t){
// one node, attributes
document.body.innerHTML = "<div id='p1' style='display:block;'></div>";
document.body.log();
var node = byId('p1');
t.assert(node.style.display === 'block');
}
function cssTextTest(t){
// one node, attributes
document.body.innerHTML = "<div id='p1' style='display:block;color:#0000ff;'></div>";
document.body.log();
var node = byId('p1');
t.assert(node.cssText === 'display:block;color:#0000ff;');
}
function simpleAttributesTest(t){
// one node, attributes
document.body.innerHTML = "<div id='p1' disabled=true width=400 title='The Title'></div>";
document.body.log();
var node = byId('p1');
t.assert(node.getAttribute('disabled') === true);
t.assert(node.getAttribute('width') === 400);
t.assert(node.getAttribute('title') === 'The Title');
}
function siblingsAttributes(t){
// two siblings, attributes:
document.body.innerHTML = "<div id='p1'><div class='c1' title='Child One'>text 1</chld1><div class='c2' title='Child Two'>text2</chld2></prnt>";
document.body.log();
var node = byId('p1').firstChild;
t.assert(node.getAttribute('title') === 'Child One' && node.nextSibling.getAttribute('title') === 'Child Two');
}
function dataAttributes(t){
// two siblings, attributes:
document.body.innerHTML = "<div id='widget01' data-widget='ParentWidget'>" +
"<div data-widget='ChildWidget'>" +
"<div data-widget='GrandChildWidget' data-props='displayText:Grand Child Widget!'></div>" +
"</div>" +
"</div>";
document.body.log();
console.log('chillen', document.body.firstChild.firstChild.firstChild.log());
//var node = byId('p1').firstChild;
//t.assert(node.getAttribute('title') === 'Child One' && node.nextSibling.getAttribute('title') === 'Child Two');
}
function doubleQuotes(t){
// one node, attributes, double-quotes and an apostrophe
document.body.innerHTML = '<div id="p1" class="p1 dark mode\'s" width=400 disabled=true style="display:block;"></div>';
document.body.log();
var node = byId('p1');
t.assert(node.className === "p1 dark mode\'s");
t.assert(node.style.display === 'block');
}
function textOnly(t){
// simple text
document.body.innerHTML = 'There is only text';
document.body.log();
t.assert(document.body.innerHTML === 'There is only text');
}
//function loadHtml(t){
// // from execution dir in command line
// var snippet = browser.loadFile('base/rtests/HeadlessBrowser/domTest.html');
// //console.log('snippet', snippet);
// document.body.innerHTML = snippet;
// document.body.log();
//
// t.assert(byId('widget01').style.color === '#ff0000');
// t.assert(byId('wrapper').className === 'child');
// t.assert(byId('wrapper').firstChild.textContent === 'span text');
//}
return {
suiteName: suiteName,
tests:[
{
title:'Dumb Simple Node',
run: dumbSimpleNode
},{
title:'Simple Node',
run: simpleNode
},{
title:'Overwrite innerHTML',
run: overWriteHtml
},{
title:'Single Child',
run: singleChild
},{
title:'Children Two Levels Deep',
run: childrenTwoLevels
},{
title:'Siblings',
run: siblings
},{
title:'Overwrite Siblings',
run: overwriteSiblings
},{
title:'Class Name Test',
run: classNameTest
},{
title:'Style Test',
run: styleTest
},{
title:'cssText Test',
run: cssTextTest
},{
title:'Simple Attributes',
run: simpleAttributesTest
},{
title:'Siblings Attributes',
run: siblingsAttributes
},{
title:'Double Quotes Attributes Test',
run: doubleQuotes
},{
title:'Data Attributes Test',
run: dataAttributes
},
{
title:'Text Only',
run: textOnly
}/*,{
title:'Load External HTML',
run: loadHtml
}*/
]
};
});