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
|
/*
Unit test for count
*/
assert = chai.assert;
describe('Microformat.count', function() {
it('count', function(){
var doc,
node,
result;
var html = '<a class="h-card" href="http://glennjones.net"><span class="p-name">Glenn</span></a><a class="h-card" href="http://janedoe.net"><span class="p-name">Jane</span></a><a class="h-event" href="http://janedoe.net"><span class="p-name">Event</span><span class="dt-start">2015-07-01</span></a>';
doc = document.implementation.createHTMLDocument('New Document');
node = document.createElement('div');
node.innerHTML = html;
doc.body.appendChild(node);
options ={
'node': node,
};
result = Microformats.count(options);
assert.deepEqual( result, {'h-event': 1,'h-card': 2} );
});
it('count rels', function(){
var doc,
node,
result;
var html = '<link href="http://glennjones.net/notes/atom" rel="notes alternate" title="Notes" type="application/atom+xml" /><a class="h-card" href="http://glennjones.net"><span class="p-name">Glenn</span></a><a class="h-card" href="http://janedoe.net"><span class="p-name">Jane</span></a><a class="h-event" href="http://janedoe.net"><span class="p-name">Event</span><span class="dt-start">2015-07-01</span></a>';
doc = document.implementation.createHTMLDocument('New Document');
node = document.createElement('div');
node.innerHTML = html;
doc.body.appendChild(node);
options ={
'node': node,
};
result = Microformats.count(options);
assert.deepEqual( result, {'h-event': 1,'h-card': 2, 'rels': 1} );
});
it('count - no results', function(){
var doc,
node,
result;
var html = '<span class="p-name">Jane</span>';
doc = document.implementation.createHTMLDocument('New Document');
node = document.createElement('div');
node.innerHTML = html;
doc.body.appendChild(node);
options ={
'node': node,
};
result = Microformats.count(options);
assert.deepEqual( result, {} );
});
it('count - no options', function(){
var result;
result = Microformats.count({});
assert.deepEqual( result, {} );
});
it('count - options.html', function(){
var options = {},
result;
options.html = '<a class="h-card" href="http://glennjones.net"><span class="p-name">Glenn</span></a><a class="h-card" href="http://janedoe.net"><span class="p-name">Jane</span></a><a class="h-event" href="http://janedoe.net"><span class="p-name">Event</span><span class="dt-start">2015-07-01</span></a>';
result = Microformats.count(options);
assert.deepEqual( result, {'h-event': 1,'h-card': 2} );
});
});
|