This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
test.html
201 lines (174 loc) · 7.47 KB
/
test.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Jirafy Tests</title>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.11.0.css">
<script src="http://code.jquery.com/qunit/qunit-1.11.0.js"></script>
<script>
// Stub out chrome extension call.
var chrome = {
extension: {
sendRequest: function() {}
}
}
</script>
<script src="ext/jirafy.js"></script>
<script>
function assertNodes() {
var nodes = arguments[0];
for (var i = 1, len = arguments.length; i < len; i++) {
if (i - 1 < nodes.length) {
equal(nodes[i - 1].nodeValue, arguments[i], 'Node: ' + arguments[i]);
} else {
ok(false, 'No node for ' + arguments[i]);
}
}
}
function id(value) {
return document.getElementById(value);
}
var regexFoo = getRegex(['FOO']),
regexFooBar = getRegex(['FOO', 'BAR']),
ignore = ['a', 'textarea', 'pre', 'code'];
test('Multiple JIRA issues in a row', function() {
var node = id('multiple-in-a-row');
getMatches(node, regexFoo, function(node, ticket, offset) {
if(['FOO-4', 'FOO-8', 'FOO-15'].indexOf(ticket) > -1) {
equal(ticket, ticket, 'Node: ' + node);
}else {
ok(false, 'No node for ' + node);
}
}, ignore);
});
test('No matches inside <a>', function() {
var node = id('no-matches-in-anchor');
getMatches(node, regexFoo, function(node, ticket, offset) {
ok(false, 'Node found: ' + node);
}, ignore);
equal(true, true, 'No nodes found');
});
test('No matches inside <textarea>', function() {
var node = id('no-matches-in-textarea');
getMatches(node, regexFoo, function(node, ticket, offset) {
ok(false, 'Node found: ' + node);
}, ignore);
equal(true, true, 'No nodes found');
});
test('Multiple project keys', function() {
var node = id('multiple-project-keys');
getMatches(node, regexFooBar, function(node, ticket, offset) {
if(['FOO-4', 'BAR-8'].indexOf(ticket) > -1) {
equal(ticket, ticket, 'Node: ' + node);
}else {
ok(false, 'No node for ' + node);
}
}, ignore);
});
test('No match across elements', function() {
var node = id('no-match-across-elements');
getMatches(node, regexFoo, function(node, ticket, offset) {
ok(false, 'Node found: ' + node);
}, ignore);
equal(true, true, 'No nodes found');
});
test('Simple anchor insertion', function() {
var node = id('simple-insertion');
equal(node.innerHTML, 'FOO-4', 'Ticket without link');
replaceTicketNumbersWithLinks(['FOO'], 'http://example.com', 'false', [], node)
equal(node.innerHTML, '<a href="http://example.com/browse/FOO-4">FOO-4</a>');
});
test('Simple anchor insertion open in new window', function() {
var node = id('simple-insertion');
equal(node.innerHTML, 'FOO-4', 'Ticket without link');
replaceTicketNumbersWithLinks(['FOO'], 'http://example.com', 'true', [], node)
equal(node.innerHTML, '<a href="http://example.com/browse/FOO-4" target="_blank">FOO-4</a>');
});
test('Multiple anchor insertion', function() {
var node = id('multiple-insertion');
equal(node.innerHTML, 'Beer me FOO-23 and BAR-42 issues.', 'Tickets without links');
replaceTicketNumbersWithLinks(['FOO', ['BAR']], 'http://example.com', 'false', [], node)
equal(node.innerHTML, 'Beer me <a href=\"http://example.com/browse/FOO-23\">FOO-23</a> and <a href=\"http://example.com/browse/BAR-42\">BAR-42</a> issues.');
});
test('Match only given projects', function() {
var node = id('match-only-foo');
getMatches(node, regexFoo, function(node, ticket, offset) {
equal(ticket, 'FOO-15', 'Found only FOO-15');
}, ignore);
});
test('Do not link a full link', function() {
var node = id('do-not-link-full-link');
equal(node.innerHTML, 'http://example.com/jira/browse/FOO-108');
getMatches(node, regexFoo, function(node, ticket, offset) {
ok(false, 'Node found: ' + node);
}, ignore);
equal(node.innerHTML, 'http://example.com/jira/browse/FOO-108');
});
asyncTest('Capture new AJAX link', function () {
var node = id('capture-new-ajax-link'), elem;
expect( 3 );
zGlb_ignoreElements = [];
zGlb_projectKeys = ['FOO'];
zGlb_jiraServer = 'http://example.com';
zGlb_targetWindow = 'false';
equal(node.innerHTML, 'FOO-18', 'Ticket without link');
handlePageChange();
equal(node.innerHTML, '<a href="http://example.com/browse/FOO-18">FOO-18</a>');
loadAJAXPage();
node = id('qunit-fixture');
elem = document.createElement('p');
elem.id = 'a-new-ajax-link';
elem.innerHTML = 'FOO-76';
node.appendChild(elem);
setTimeout(function() {
equal(elem.innerHTML, '<a href="http://example.com/browse/FOO-76">FOO-76</a>');
start();
}, 2000); //debounce is 1sec (consolidate number of DOM updates) PLUS 500ms timeout before processing
});
asyncTest('Capture multiple AJAX link', function () {
var node = id('capture-multiple-ajax-links'), elem;
expect( 3 );
zGlb_ignoreElements = [];
zGlb_projectKeys = ['FOO'];
zGlb_jiraServer = 'http://example.com';
zGlb_targetWindow = 'false';
loadAJAXPage();
node = id('qunit-fixture');
elem76 = document.createElement('p');
elem76.id = 'a-new-ajax-link-76';
elem76.innerHTML = 'FOO-76';
node.appendChild(elem76);
elem77 = document.createElement('p');
elem77.id = 'a-new-ajax-link-77';
elem77.innerHTML = 'FOO-77';
node.appendChild(elem77);
elem78 = document.createElement('p');
elem78.id = 'a-new-ajax-link-78';
elem78.innerHTML = 'FOO-78';
node.appendChild(elem78);
setTimeout(function() {
equal(elem76.innerHTML, '<a href="http://example.com/browse/FOO-76">FOO-76</a>');
equal(elem77.innerHTML, '<a href="http://example.com/browse/FOO-77">FOO-77</a>');
equal(elem78.innerHTML, '<a href="http://example.com/browse/FOO-78">FOO-78</a>');
start();
}, 2000);
});
</script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">
<p id="multiple-in-a-row">FOO-4<br>FOO-8<br>FOO-15</p>
<p id="no-matches-in-anchor"><a href="http://example.com/jira/browse/FOO-108">FOO-108</a></p>
<p id="no-matches-in-textarea"><textarea>FOO-108</textarea></p>
<div id="multiple-project-keys"><p>FOO-4</p><p>BAR-8</p></div>
<p id="no-match-across-elements"><span>FO</span>O-108</p>
<p id="simple-insertion">FOO-4</p>
<p id="multiple-insertion">Beer me FOO-23 and BAR-42 issues.</p>
<p id="match-only-foo">FOO-15<br>BAR-16<br>PING-23<br>PONG-42</p>
<p id="do-not-link-full-link">http://example.com/jira/browse/FOO-108</p>
<p id="capture-new-ajax-link">FOO-18</p>
<p id="capture-multiple-ajax-links">FOO-76 and FOO-77 and FOO-78</p>
</div>
</body>
</html>