als-document 0.1.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/document.js +489 -512
- package/package.json +6 -7
- package/parser/parser.js +287 -0
- package/parser/readme.md +121 -0
- package/parser/test.js +233 -0
- package/query/query.js +147 -0
- package/query/readme.md +131 -0
- package/query/test.js +143 -0
- package/readme.md +287 -135
- package/selector/readme.md +74 -0
- package/selector/selector.js +125 -0
- package/selector/test.js +410 -0
- package/test/html1.js +50 -0
- package/test/html2.js +1126 -0
- package/test/test.js +17 -0
package/selector/test.js
ADDED
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
let Test = require('als-test')
|
|
2
|
+
// const HtmlSelector = require('./selector')
|
|
3
|
+
const {HtmlSelector} = require('../build/document')
|
|
4
|
+
let {equal,greater,smaller,$greater, $smaller} = Test
|
|
5
|
+
|
|
6
|
+
module.exports = new Test('Selector tests',[
|
|
7
|
+
{
|
|
8
|
+
title:'Build $1 and $2',
|
|
9
|
+
result: function({html1,html2}){
|
|
10
|
+
this.vars.$1 = new HtmlSelector(html1)
|
|
11
|
+
this.vars.$2 = new HtmlSelector(html2)
|
|
12
|
+
let {$1,$2} = this.vars
|
|
13
|
+
if(typeof $1.$ == 'function' && typeof $2.$ == 'function')
|
|
14
|
+
return '$1 and $2 created'
|
|
15
|
+
else {
|
|
16
|
+
this.terminate = true
|
|
17
|
+
return 'Selector not created. Test terminated.'
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
{title:'Tests for selecting single element'},
|
|
22
|
+
{
|
|
23
|
+
title:'Get body tag from $1',
|
|
24
|
+
expected:'body',
|
|
25
|
+
result:function({$1}){
|
|
26
|
+
return $1.$('body').tag
|
|
27
|
+
},
|
|
28
|
+
action:equal
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
title:'Get body tag from $2',
|
|
32
|
+
expected:'body',
|
|
33
|
+
result:function({$2}){
|
|
34
|
+
return $2.$('body').tag
|
|
35
|
+
},
|
|
36
|
+
action:equal
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
title:'Get element by className from $1',
|
|
40
|
+
expected:true,
|
|
41
|
+
result:function({$1}){
|
|
42
|
+
return $1.$('.tabs').classList.includes('tabs')
|
|
43
|
+
},
|
|
44
|
+
action:equal
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
title:'Get element by className from $2',
|
|
48
|
+
expected:'https://www.w3schools.com',
|
|
49
|
+
result:function({$2}){
|
|
50
|
+
return $2.$('.w3-button').attribs.href
|
|
51
|
+
},
|
|
52
|
+
action:equal
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
title:'Get element by id from $1',
|
|
56
|
+
expected:'tab3',
|
|
57
|
+
result:function({$1}){
|
|
58
|
+
return $1.$('#tab3').id
|
|
59
|
+
},
|
|
60
|
+
action:equal
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
title:'Get element by id from $2',
|
|
64
|
+
expected:'runbtn',
|
|
65
|
+
result:function({$2}){
|
|
66
|
+
return $2.$('#runbtn').id
|
|
67
|
+
},
|
|
68
|
+
action:equal
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
title:'Get element by attribute from $1',
|
|
72
|
+
expected:'tab1',
|
|
73
|
+
result:function({$1}){
|
|
74
|
+
return $1.$('[name="css-tabs"][type="radio"][checked]').id
|
|
75
|
+
},
|
|
76
|
+
action:equal
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
title:'Get element by attribute from $2',
|
|
80
|
+
expected:'Save',
|
|
81
|
+
result:function({$2}){
|
|
82
|
+
return $2.$('[title="Save"]').attribs.title
|
|
83
|
+
},
|
|
84
|
+
action:equal
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
title:'Get element by attribute name $1',
|
|
88
|
+
expected:'none',
|
|
89
|
+
result:function({$1}){
|
|
90
|
+
return $1.$('[style]').style.display
|
|
91
|
+
},
|
|
92
|
+
action:equal
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
title:'Get element by attribute name $2',
|
|
96
|
+
expected:'trytopnav',
|
|
97
|
+
result:function({$2}){
|
|
98
|
+
return $2.$('[class]').attribs.class
|
|
99
|
+
},
|
|
100
|
+
action:equal
|
|
101
|
+
},
|
|
102
|
+
{title:'Check attributes for single'},
|
|
103
|
+
{
|
|
104
|
+
title:'Test includes - "*=" fro $1',
|
|
105
|
+
expected:'Tab 1',
|
|
106
|
+
result: function({$1}){
|
|
107
|
+
return $1.$('[class*="transition1"]').innerHTML
|
|
108
|
+
},
|
|
109
|
+
action:equal
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
title:'Test starts with - "^=" fro $1',
|
|
113
|
+
expected:'tab1 content',
|
|
114
|
+
result: function({$1}){
|
|
115
|
+
return $1.$('[class*="tab-content"]').innerHTML
|
|
116
|
+
},
|
|
117
|
+
action:equal
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
title:'Test ends with - "$=" fro $1',
|
|
121
|
+
expected:'tab1 content',
|
|
122
|
+
result: function({$1}){
|
|
123
|
+
return $1.$('[class*="p2 transition1"]').innerHTML
|
|
124
|
+
},
|
|
125
|
+
action:equal
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
title:'Test starts with word- "|=" fro $1',
|
|
129
|
+
expected:'css-tabs',
|
|
130
|
+
result: function({$1}){
|
|
131
|
+
return $1.$('[name|="css"]').attribs.name
|
|
132
|
+
},
|
|
133
|
+
action:equal
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
title:'Test includes word "~=" fro $1',
|
|
137
|
+
expected:true,
|
|
138
|
+
result: function({$1}){
|
|
139
|
+
return $1.$('[class~="bgc-smoke"]').classList.includes('bgc-smoke')
|
|
140
|
+
},
|
|
141
|
+
action:equal
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
title:'Test includes - "*=" fro $2',
|
|
145
|
+
expected:'w3schools.com Home',
|
|
146
|
+
result: function({$2}){
|
|
147
|
+
return $2.$('[title*=".com"]').attribs.title
|
|
148
|
+
},
|
|
149
|
+
action:equal
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
title:'Test starts with - "^=" fro $2',
|
|
153
|
+
expected:'w3-right w3-hide-small',
|
|
154
|
+
result: function({$2}){
|
|
155
|
+
return $2.$('[class^="w3-right"]').attribs.class
|
|
156
|
+
},
|
|
157
|
+
action:equal
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
title:'Test ends with - "$=" fro $2',
|
|
161
|
+
expected:'w3schools.com Home',
|
|
162
|
+
result: function({$2}){
|
|
163
|
+
return $2.$('[title$="Home"]').attribs.title
|
|
164
|
+
},
|
|
165
|
+
action:equal
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
title:'Test starts with word- "|=" fro $2',
|
|
169
|
+
expected:'en-US',
|
|
170
|
+
result: function({$2}){
|
|
171
|
+
return $2.$('[lang|="en"]').attribs.lang
|
|
172
|
+
},
|
|
173
|
+
action:equal
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
title:'Test includes word "~=" fro $2',
|
|
177
|
+
expected:'og:image:width',
|
|
178
|
+
result: function({$2}){
|
|
179
|
+
return $2.$('[property~="width"]').attribs.property
|
|
180
|
+
},
|
|
181
|
+
action:equal
|
|
182
|
+
},
|
|
183
|
+
{title:'Few selectors test for single'},
|
|
184
|
+
{
|
|
185
|
+
title:'tag and attribute $1',
|
|
186
|
+
expected:'tab1',
|
|
187
|
+
result:async function({$1}){
|
|
188
|
+
return $1.$('input[checked]').id
|
|
189
|
+
},
|
|
190
|
+
action:equal
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
title:'parent tag and attribute $1',
|
|
194
|
+
expected:'tab1',
|
|
195
|
+
result:async function({$1}){
|
|
196
|
+
return $1.$('div.tabs>input[checked]').id
|
|
197
|
+
},
|
|
198
|
+
action:equal
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
title:'parent and next $1',
|
|
202
|
+
expected:'tab2',
|
|
203
|
+
result:async function({$1}){
|
|
204
|
+
return $1.$('div.tabs>input[checked]+input').id
|
|
205
|
+
},
|
|
206
|
+
action:equal
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
title:'ancestor $1',
|
|
210
|
+
expected:true,
|
|
211
|
+
result:async function({$1}){
|
|
212
|
+
return $1.$('body [onclick*="Hello world"]').attribs.onclick.includes('this.innerHTML')
|
|
213
|
+
},
|
|
214
|
+
action:equal
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
title:'ancestor, parent and (~) $1',
|
|
218
|
+
expected:'tab3',
|
|
219
|
+
result:async function({$1}){
|
|
220
|
+
return $1.$('[checked]~#tab3').id
|
|
221
|
+
},
|
|
222
|
+
action:equal
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
title:'inner',
|
|
226
|
+
expected:'tab1 content',
|
|
227
|
+
result:async function({$1}){
|
|
228
|
+
return $1.$('[inner*="content"]').innerHTML
|
|
229
|
+
},
|
|
230
|
+
action:equal
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
title:'tag and attribute $2',
|
|
234
|
+
expected:'runbtn',
|
|
235
|
+
result:async function({$2}){
|
|
236
|
+
return $2.$('button[onclick]').id
|
|
237
|
+
},
|
|
238
|
+
action:equal
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
title:'parent tag and attribute $2',
|
|
242
|
+
expected:'×',
|
|
243
|
+
result:async function({$2}){
|
|
244
|
+
return $2.$('#container>div>span[title="Close Menu"]').innerHTML
|
|
245
|
+
},
|
|
246
|
+
action:equal
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
title:'parent and next $2',
|
|
250
|
+
expected:'w3-bar-block',
|
|
251
|
+
result:async function({$2}){
|
|
252
|
+
return $2.$('#container>div>span[title="Close Menu"]+div').attribs.class
|
|
253
|
+
},
|
|
254
|
+
action:equal
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
title:'ancestor $2',
|
|
258
|
+
expected:'Change Orientation',
|
|
259
|
+
result:async function({$2}){
|
|
260
|
+
return $2.$('#container a span').innerHTML
|
|
261
|
+
},
|
|
262
|
+
action:equal
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
title:'ancestor, parent and (~) $2',
|
|
266
|
+
expected:'Change Orientation',
|
|
267
|
+
result:async function({$2}){
|
|
268
|
+
return $2.$('#container a>i~span').innerHTML
|
|
269
|
+
},
|
|
270
|
+
action:equal
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
title:'inner',
|
|
274
|
+
expected:'Privacy policy',
|
|
275
|
+
result:async function({$2}){
|
|
276
|
+
return $2.$('[inner*="Privacy"]').innerHTML
|
|
277
|
+
},
|
|
278
|
+
action:equal
|
|
279
|
+
},
|
|
280
|
+
{title:'Select collection'},
|
|
281
|
+
{
|
|
282
|
+
title:'Select few elements (input) $1',
|
|
283
|
+
expected:3,
|
|
284
|
+
result:async function({$1}){
|
|
285
|
+
return $1.$$('input').length
|
|
286
|
+
},
|
|
287
|
+
action:equal
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
title:'Select few elements ([inner*=test]) $1',
|
|
291
|
+
expected:3,
|
|
292
|
+
result:async function({$1}){
|
|
293
|
+
return $1.$$('[inner*=test]').length
|
|
294
|
+
},
|
|
295
|
+
action:equal
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
title:'Select few elements (.transition1) $1',
|
|
299
|
+
expected:6,
|
|
300
|
+
result:async function({$1}){
|
|
301
|
+
return $1.$$('.transition1').length
|
|
302
|
+
},
|
|
303
|
+
action:equal
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
title:'Select few elements (div>.transition1) $1',
|
|
307
|
+
expected:3,
|
|
308
|
+
result:async function({$1}){
|
|
309
|
+
return $1.$$('div>.transition1').length
|
|
310
|
+
},
|
|
311
|
+
action:equal
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
title:'Select few elements (.col5>input[checked][name^=css][type]) $1',
|
|
315
|
+
expected:1,
|
|
316
|
+
result:async function({$1}){
|
|
317
|
+
return $1.$$('.col5>input[checked][name^=css][type]').length
|
|
318
|
+
},
|
|
319
|
+
action:equal
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
title:'Select few elements (.col5 label[for^="tab"]) $1',
|
|
323
|
+
expected:3,
|
|
324
|
+
result:async function({$1}){
|
|
325
|
+
return $1.$$('.col5 label[for^="tab"]').length
|
|
326
|
+
},
|
|
327
|
+
action:equal
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
title:'Select few elements (.w3-button) $2',
|
|
331
|
+
expected:12,
|
|
332
|
+
result:async function({$2}){
|
|
333
|
+
return $2.$$('.w3-button').length
|
|
334
|
+
},
|
|
335
|
+
action:equal
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
title:'Select few elements (.w3-button) $2',
|
|
339
|
+
expected:1,
|
|
340
|
+
result:async function({$2}){
|
|
341
|
+
return $2.$$('.w3-button>img').length
|
|
342
|
+
},
|
|
343
|
+
action:equal
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
title:'Select few elements (.w3-button>img+span) $2',
|
|
347
|
+
expected:'Go to Spaces',
|
|
348
|
+
result:async function({$2}){
|
|
349
|
+
return $2.$$('.w3-button>img+span')[0].innerHTML
|
|
350
|
+
},
|
|
351
|
+
action:equal
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
title:'Select few elements (#container div) $2',
|
|
355
|
+
expected:30,
|
|
356
|
+
result:async function({$2}){
|
|
357
|
+
return $2.$$('#container div').length
|
|
358
|
+
},
|
|
359
|
+
action:equal
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
title:'Select few elements (#container div) $2',
|
|
363
|
+
expected:4,
|
|
364
|
+
result:async function({$2}){
|
|
365
|
+
return $2.$$('#container>div').length
|
|
366
|
+
},
|
|
367
|
+
action:equal
|
|
368
|
+
},
|
|
369
|
+
{title:'Few selectors'},
|
|
370
|
+
{
|
|
371
|
+
title:'Select few elements (.col5 label[for^="tab"],input[checked]) $1',
|
|
372
|
+
expected:4,
|
|
373
|
+
result:async function({$1}){
|
|
374
|
+
return $1.$$('.col5 label[for^="tab"],input[checked]').length
|
|
375
|
+
},
|
|
376
|
+
action:equal
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
title:'Select few elements ([style],[onclick]) $1',
|
|
380
|
+
expected:7,
|
|
381
|
+
result:async function({$1}){
|
|
382
|
+
return $1.$$('[style],[onclick],[name]').length
|
|
383
|
+
},
|
|
384
|
+
action:equal
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
title:'Select few elements (#container a[title]) $2',
|
|
388
|
+
expected:4,
|
|
389
|
+
result:async function({$2}){
|
|
390
|
+
return $2.$$('#container a[title]').length
|
|
391
|
+
},
|
|
392
|
+
action:equal
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
title:'Select few elements (div,span) $2',
|
|
396
|
+
expected:165,
|
|
397
|
+
result:async function({$2}){
|
|
398
|
+
return $2.$$('div,span').length
|
|
399
|
+
},
|
|
400
|
+
action:equal
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
title:'Select few elements (meta[property^="og"],meta[content^="width"]) $2',
|
|
404
|
+
expected:8,
|
|
405
|
+
result:async function({$2}){
|
|
406
|
+
return $2.$$('meta[property^="og"],meta[content^="width"]').length
|
|
407
|
+
},
|
|
408
|
+
action:equal
|
|
409
|
+
},
|
|
410
|
+
])
|
package/test/html1.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
let html1 = /*html*/`
|
|
2
|
+
<!DOCTYPE html>
|
|
3
|
+
<html lang="en">
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
8
|
+
<title>Document</title>
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<script>console.log('test')</script>
|
|
12
|
+
<div onclick="console.log('hello world')"
|
|
13
|
+
style="display:none; background-color:red; border:1px sold black;border-radius:5px;">
|
|
14
|
+
Some test
|
|
15
|
+
</div>
|
|
16
|
+
<div>
|
|
17
|
+
Some test1
|
|
18
|
+
<div>
|
|
19
|
+
one more inside
|
|
20
|
+
<div onclick="this.innerHTML = '<div>Hello world</div>'"></div>
|
|
21
|
+
<!-- <div>commented element</div> -->
|
|
22
|
+
</div>
|
|
23
|
+
</div>
|
|
24
|
+
<div class="tabs col5 bgc-white b-light-dark b1" style="width:300px">
|
|
25
|
+
<input type="radio" id="tab1" name="css-tabs" checked>
|
|
26
|
+
<input type="radio" id="tab2" name="css-tabs">
|
|
27
|
+
<input type="radio" id="tab3" name="css-tabs">
|
|
28
|
+
|
|
29
|
+
<span class="headers">
|
|
30
|
+
<label class="btn p2 b-light-dark b1 transition1 bgc-smoke" for="tab1">Tab 1</label>
|
|
31
|
+
<label class="btn p2 b-light-dark b1 transition1 bgc-smoke" for="tab2">Tab 2</label>
|
|
32
|
+
<label class="btn p2 b-light-dark b1 transition1 bgc-smoke" for="tab3">Tab 3</label>
|
|
33
|
+
</span>
|
|
34
|
+
|
|
35
|
+
<div class="tab-content p2 transition1">
|
|
36
|
+
tab1 content
|
|
37
|
+
</div>
|
|
38
|
+
<div class="tab-content p2 transition1">
|
|
39
|
+
tab2 content
|
|
40
|
+
</div>
|
|
41
|
+
<div class="tab-content p2 transition1">
|
|
42
|
+
tab3 content
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
</body>
|
|
47
|
+
</html>
|
|
48
|
+
`
|
|
49
|
+
|
|
50
|
+
try {module.exports = html1} catch{}
|