This repository was archived by the owner on Mar 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathqunit.html
More file actions
279 lines (213 loc) · 6.57 KB
/
qunit.html
File metadata and controls
279 lines (213 loc) · 6.57 KB
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge;chrome=1" />
<title>QUnit tests // jQuery Slideshow</title>
<link rel="stylesheet" href="../css/example.css" />
<link rel="stylesheet" href="../css/slideshow.css" />
<link rel="stylesheet" href="qunit-1.10.0.css" />
<!--
jQuery Slideshow by Matt Hinchliffe <http://www.maketea.co.uk>
Find out more at GitHub <http://github.com/i-like-robots/jQuery-Slideshow>
-->
</head>
<body>
<div id="container">
<section id="introduction">
<h1>QUnit tests</h1>
<div id="example">
<div class="slideshow" data-auto="0">
<ul class="carousel">
<li class="slide">
<img src="http://placebox.es/440/200/d97ef2/f5f5f5" alt="" width="440" height="200" />
</li>
<li class="slide">
<img src="http://placebox.es/440/200/50ac3d/f5f5f5" alt="" width="440" height="200" />
</li>
<li class="slide">
<img src="http://placebox.es/440/200/0a77bb/f5f5f5" alt="" width="440" height="200" />
</li>
<li class="slide">
<img src="http://placebox.es/440/200/d97ef2/f5f5f5" alt="" width="440" height="200" />
</li>
<li class="slide">
<img src="http://placebox.es/440/200/50ac3d/f5f5f5" alt="" width="440" height="200" />
</li>
<li class="slide">
<img src="http://placebox.es/440/200/0a77bb/f5f5f5" alt="" width="440" height="200" />
</li>
</ul>
</div>
</div>
</section>
</div>
<section id="tests" style="margin: 20px;">
<h2>Tests</h2>
<div id="qunit"></div>
</section>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="../src/slideshow.js"></script>
<script src="qunit-1.10.0.js"></script>
<script>
$(function()
{
var $s, api;
$.fx.off = true;
QUnit.config.reorder = false;
var lifecycle = {
setup: function()
{
if ( ! api )
{
$s = $('.slideshow').slides();
api = $s.eq(0).data('slides');
}
}
};
module("Setup", lifecycle);
test("$(collection).slides()", function()
{
ok(api.count > 0, "Check slides are found");
ok(api.$pagination.length > 0, "Check pagination created");
ok(api.$next.length > 0, "Check next skip link created");
ok(api.$prev.length > 0, "Check previous skip link created");
});
test("API", function()
{
equal((typeof api).toLowerCase() == "object" && ! $.isEmptyObject(api), true, "API returned");
});
//
// API tests
//
module("Public API", lifecycle);
test(".hasNext()", function()
{
api.to(0);
equal(api.hasNext(), true, "First slide");
api.to( api.count -1 );
equal(api.hasNext(), false, "Last slide");
});
test(".hasPrevious()", function()
{
api.to(0);
equal(api.hasPrevious(), false, "First slide");
api.to( api.count - 1 );
equal(api.hasPrevious(), true, "Last slide");
});
test(".next()", function()
{
api.to(0);
var prev = api.current;
api.next();
equal(prev + 1, api.current, "Current slide equals last slide + 1");
});
test(".previous()", function()
{
api.to( api.count - 1 );
var prev = api.current;
api.previous();
equal(prev - 1, api.current, "Current slide equals last slide - 1");
});
test(".to()", function()
{
api.to(0);
equal(api.current, 0, "Go-to first slide");
api.to( api.count - 1 );
equal(api.current, api.count - 1, "Go-to last slide");
// loop
$.extend(api.opts, { loop: true });
api.to(0);
api.to( api.current - 1 );
equal(api.current, api.count - 1, "Out of bounds (0 - 1) - looping enabled");
api.to( api.count - 1 );
api.to( api.current + 1 );
equal(api.current, 0, "Out of bounds (total + 1) - looping enabled");
// no loop
$.extend(api.opts, { loop: false });
api.to(0);
api.to( api.current - 1 );
equal(api.current, 0, "Out of bounds (0 - 1) - looping disabled");
api.to( api.count - 1 );
api.to( api.current + 1 );
equal(api.current, api.count - 1, "Out of bounds (total + 1) - looping disabled");
});
test(".redraw()", function()
{
api.redraw("crossfade");
equal(api.opts.transition, "crossfade", "Test crossfade registered");
api.redraw("scroll");
equal(api.opts.transition, "scroll", "Test scroll registered");
});
//
// callbacks
//
test("Callbacks", function()
{
var oncomplete = false;
var onupdate = false;
api.to(0);
api.opts.oncomplete = function() {
equal(arguments[0], 1, "oncomplete callback receives current slide index");
equal(arguments[1], 0, "oncomplete callback receives previous slide index");
oncomplete = true;
};
api.opts.onupdate = "onupdate";
window.onupdate = function() {
equal(arguments[0], 1, "onupdate callback receives next slide index");
onupdate = true;
};
api.to(1);
equal(oncomplete, true, "oncomplete callback called");
equal(onupdate, true, "onupdate callback called");
api.opts.oncomplete = null;
api.opts.onupdate = null;
});
//
// user controls
//
module("User controls", lifecycle);
test("Next skip link (looping)", function()
{
api.to(0);
api.$next.trigger('click');
equal(api.current, 1, "From first to second slide");
// loop
$.extend(api.opts, { loop: true });
api.to( api.count - 1 );
api.$next.trigger('click');
equal(api.current, 0, "Attempt to go to from last to first slide - looping enabled");
// no loop
$.extend(api.opts, { loop: false });
api.to( api.count - 1 );
api.$next.trigger('click');
equal(api.current, api.count - 1, "Attempt to go to from last to first slide - looping disabled");
});
test("Previous skip link", function()
{
api.to( api.count - 1 );
api.$prev.trigger('click');
equal(api.current, api.count - 2, "From last to preceding slide");
// loop
$.extend(api.opts, { loop: true });
api.to(0);
api.$prev.trigger('click');
equal(api.current, api.count - 1, "Attempt to go to from first to last slide - looping enabled");
// no loop
$.extend(api.opts, { loop: false });
api.to(0);
api.$prev.trigger('click');
equal(api.current, 0, "Attempt to go to from first to last slide - looping disabled");
});
test("Pagination", function()
{
var $links = api.$pagination.find('a');
$links.eq(0).trigger('click');
equal(api.current, 0, "Go to first slide");
$links.eq( api.count - 1 ).trigger('click');
equal(api.current, api.count - 1, "Go to last slide");
});
});
</script>
</body>
</html>