/
test.html
220 lines (197 loc) · 8.32 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<!DOCTYPE html>
<html class lang="en-US">
<head>
<meta charset="utf-8">
<title>elo - test suite</title>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta name="author" content="Ryan Van Etten">
<meta name="description" content="JavaScript events library test suite">
<style>
html { font-family:sans-serif; color:#444; background:#fffafa; }
body { margin:1em auto; width:94%; font-size:1.1em; }
code, kbd, pre, samp { font-family:monospace; font-size:1em; }
pre { white-space:pre-wrap; }
pre, td, th { padding:1em; text-align:left; }
td { font-weight:bold; color:#2aa198 }
td:first-child { font-weight:normal; }
pre { background:#eee8d5; }
.dark pre { background:#073642; }
</style>
<script src="http://airve.github.io/js/modernizr/modernizr.js"></script>
<script src="http://airve.github.io/js/aok/aok.min.js"></script>
<script src="http://airve.github.io/js/jeesh/jeesh.min.js"></script>
<script src="http://airve.github.io/js/dj/dj.min.js"></script>
<script src="http://airve.github.io/js/vibe/vibe.min.js"></script>
<script src="elo.js"></script>
<!-- Run the tests in the head to ensure domReady works. -->
<script>
(function(window, document) {
var $ = window.elo
, elo = window.elo
, effin = elo.fn
, dj = window.dj
, bean = window.bean
, aok = window.aok
, log = aok.log
, express = aok.express
, byId = aok.id
, jQuery = window.jQuery
, ender = window.ender
, docElem = document.documentElement
, testDiv = document.createElement('div')
, readyTests = [] // tests that need to happen on *ready*
, resizeTests = [] // tests that need to happen on *resize*
, scrollTests = [] // tests that need to happen on *scroll*
, increase = (function(uid) {
return function() {
return ++uid;
};
}(0));
log(elo.fn);
function remark(item, before) {
item = '(' + item + ')';
return null == before ? item : before + ' ' + item;
}
function update(tests) {
elo.each(tests, aok);
}
update.resizeTests = function() { update(resizeTests); };
update.scrollTests = function() { update(scrollTests); };
update.readyTests = function() { update(readyTests); };
jQuery && jQuery.noConflict();
readyTests.push({id:'$.fn.empty', test:function() {
var elem = byId('empty');
effin.empty.call([elem]);
return !elem.innerHTML;
}}, {id: 'divHasEvent:blur', test: function() {
return true === ($.hasEvent('blur', testDiv) && $.hasEvent('blur', 'div'));
}});
// Make sure the $ methods tested are the elo methods:
elo && elo.bridge && elo.bridge($, $ !== elo && $ !== window.jQuery);
dj && dj.bridge(elo);
elo(function() {
var el = byId('ua');
el && (el.innerHTML = navigator.userAgent || '');
});
resizeTests['resize'] = increase;
scrollTests['scroll'] = increase
// Merge tests by event:
readyTests = readyTests.concat(scrollTests, resizeTests); // all of em
$(docElem).one('customEvent', function(o, extraParam) {
aok({id:'customEventThis', test:this === docElem});
aok({id:'customEventType', test:'customEvent' === o.type});
aok({id:'customEventArgs', test:'extraParam' === extraParam});
aok({id:'customEventTrig', test:true === o.isTrigger});
}).trigger('customEvent', ['extraParam']);
elo(function(_elo) {
aok({id:'readyParam', test:_elo === elo});
aok({id:'readyScope', test:this === document});
aok({id:'instanceof', test:function() {
var $group = elo([elo(), elo(''), elo('div')]);
return $group instanceof elo && $group.each(function() {
return this instanceof elo;
});
}});
aok({id:'effinSynced', test:function() {
var key, bool = elo.prototype === elo.fn;
if (bool) {
elo.fn[key = 'checkSync'] = 1;
bool = 1 === elo.prototype[key];
delete elo.prototype[key];
bool = bool && !elo.fn.hasOwnProperty(key);
}
return bool;
}});
aok({id:'inheritsConstructor', test:function() {
return !!elo.fn.constructor && elo.fn.constructor === elo().constructor;
}});
aok({id:'countDivs', test:function() {
var $div = elo('div'), a = $div.length, b = document.getElementsByTagName('div').length;
this.pass += remark(a + ' === ' + b);
this.fail += remark(a + ' !== ' + b);
return typeof a == 'number' && a === b;
}});
aok({id:'selectorProp', test:function() {
var $div = elo('div'), prop = 'selector';
return 'div' === $div[prop] && $div.hasOwnProperty(prop) && void 0 === elo()[prop];
}});
aok({id:'dataSingle', test:function() {
var el = testDiv, key = 'k', value = $.data(el, key, 1);
if (1 !== value || $.data(el, key) !== value) return false;
$.removeData(el, key);
return void 0 === $.data(el, key);
}});
aok({id:'cleanData', test:function() {
var ran = 0, key = 'a', type = 'kustom', subjects = [testDiv, {}];
$.fn.data.call(subjects, key, 1);
$.fn.on.call(subjects, type, function() { ran++; });
$.data(subjects, key, 1);
$.cleanData(subjects);
$.fn.trigger.call(subjects, type);
return !ran && !$.data(subjects, key) && !$.data(subjects[0], key) && !$.data(subjects[1], key);
}});
});
// Print test outputs:
$.domReady(function(){
var i = 0;
$('tr').on('click', function(){
log(i++);
});
var b = $('body')[0];
$.hasEvent('blur') && update(readyTests);
//$(window).trigger('resize', );
//$.on(byId('ua'), 'click', f);
//$.trigger(byId('ua'), 'click');
$.data(docElem, {who: 2, what: 3, why: 4});
elo.noConflict();
//log(elo.eventMap);
//log(elo.dataMap);
});
$(window).on('scroll', update.scrollTests);
$(window).on('resize', update.resizeTests);
$(docElem).on('click', function() {
var $$ = ender || jQuery;
$$ && $$(this).toggleClass('dark');
});
function testInterop(eventData, a, b) {
aok({
id: 'interopEventData'
, pass: remark(eventData, aok.prototype.pass)
, test: eventData instanceof Object
});
aok({
id: 'interopArgs'
, pass: remark(arguments, aok.prototype.pass)
, test: true
});
}
if (bean) {
//bean.on($('html')[0], 'lick', testInterop, {foo: 'bar'});
bean.on(docElem, 'click', testInterop, 2, 3);
bean.fire(docElem, 'click', 5);
}
if (jQuery) {
//jQuery('html').on('click', 7, testInterop);
//jQuery('html').trigger('click', 5, 6);
}
}(this, this.document));
</script>
</head>
<body>
<header>
<h1><a href="http://github.com/ryanve/elo">elo</a> Test Suite</h1>
</header>
<pre id="ua"></pre>
<!--[if IE]>
<strong>[!] Tests in <abbr class=red>IE</abbr> may not work locally.</strong>
<![endif]-->
<div id="a">
<pre><code>div#a</code></pre>
</div>
<p>Open the console to view tests.</p>
<div id="empty">
<p>This text in <code>div#empty</code> gets emptied by <code>elo.fn.empty()</code>
and therefore should <strong>not</strong> appear on the page.</p>
</div>
</body>
</html>