Skip to content

Commit a1e6c87

Browse files
committed
First pass at (working) fetchlink unit tests.
1 parent 5a7377a commit a1e6c87

File tree

6 files changed

+192
-4
lines changed

6 files changed

+192
-4
lines changed

js/jquery.mobile.fetchlinks.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,11 @@ $.widget( "mobile.fetchlink", $.mobile.widget, {
6565
targetEl.filter( ':jqmData(role="listview")' ).length && targetEl.listview( "refresh" );
6666

6767
targetEl
68-
.trigger( "create" )
6968
.removeClass('ui-loading-inline')
7069
.height('auto');
71-
72-
console.log("Plugin fired and completed");
7370

71+
responseEl.trigger( "create" );
72+
7473
}, 300);
7574
});
7675
}
@@ -93,7 +92,6 @@ $( document ).bind( "inlineLoader", function( e, ui ){
9392

9493
//auto self-init widgets
9594
$( document ).bind( "pagecreate create", function( e ){
96-
console.log("Create called");
9795
$( $.mobile.fetchlink.prototype.options.initSelector, e.target ).fetchlink();
9896
});
9997

tests/unit/fetchlink/ext-1.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>jQuery Mobile Event Test Suite</title>
7+
</head>
8+
<body>
9+
10+
<blockquote class="bq">
11+
<p>“You will not apply my precept,” he said, shaking his head. “How often have I said to you that when you have eliminated the impossible, whatever remains, however improbable, must be the truth?”</p>
12+
<address>Arthur Conan Doyle</address>
13+
<cite>Sherlock Holmes: The Sign of the Four</cite>
14+
</blockquote>
15+
16+
</body>
17+
</html>

tests/unit/fetchlink/ext-2.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>jQuery Mobile Event Test Suite</title>
7+
</head>
8+
<body>
9+
10+
<blockquote class="bq">
11+
<p>“What the deuce is it to me?” he interrupted impatiently; “you say that we go ’round the sun. If we went ’round the moon it would not make a pennyworth of difference to me or to my work.”</p>
12+
<address>Arthur Conan Doyle</address>
13+
<cite>Sherlock Holmes: A Study in Scarlet</cite>
14+
</blockquote>
15+
16+
</body>
17+
</html>

tests/unit/fetchlink/ext-3.html

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>jQuery Mobile Event Test Suite</title>
7+
8+
<script src="../../../js/jquery.js"></script>
9+
<script src="../jquery.setNameSpace.js"></script>
10+
<script src="../../../js/"></script>
11+
<script src="../../jquery.testHelper.js"></script>
12+
<link rel="stylesheet" href="../../../css/themes/default/" />
13+
<link rel="stylesheet" href="../../../external/qunit.css"/>
14+
<script src="../../../external/qunit.js"></script>
15+
16+
</head>
17+
<body>
18+
19+
<div data-nstest-role="page" id="fetchlink-remote-page">
20+
<div data-nstest-role="header">
21+
<h1>Header</h1>
22+
</div>
23+
<div data-nstest-role="content">
24+
25+
<a href="ext-4.html" class="foo" data-nstest-role="button">Quote 1</a>
26+
27+
<label for="slider2">Flip switch:</label>
28+
<select name="slider2" id="slider2" data-nstest-role="slider">
29+
<option value="off">Off</option>
30+
<option value="on">On</option>
31+
</select>
32+
33+
<label for="test-slider">Slider:</label>
34+
<input type="range" name="test-slider" id="test-slider" value="0" min="0" max="100" />
35+
36+
</div>
37+
<div data-nstest-role="footer">
38+
<h1>Footer</h1>
39+
</div>
40+
</div>
41+
42+
</body>
43+
</html>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Fetchlink unit tests
3+
*/
4+
5+
(function($){
6+
7+
module( "Fetchlinks", {
8+
setup: function(){
9+
//
10+
}
11+
});
12+
13+
asyncTest( "Clicking a fetchlink loads remote content.", function(){
14+
var targetContents = $( '.loadinto' ).html();
15+
16+
$.testHelper.pageSequence([
17+
function(){
18+
$('.foo').trigger('click');
19+
},
20+
function(){
21+
ok( targetContents !== $( '.loadinto' ).html() );
22+
start();
23+
}
24+
]);
25+
});
26+
27+
asyncTest( "Clicking a fetchlink replaces previously loaded content with remote content.", function(){
28+
var targetContents = $( '.loadinto' ).html();
29+
30+
$.testHelper.pageSequence([
31+
function(){
32+
$('.bar').trigger('click');
33+
},
34+
function(){
35+
ok( targetContents !== $( '.loadinto' ).html() );
36+
start();
37+
}
38+
]);
39+
});
40+
41+
asyncTest( "Elements are properly enhanced after being fetched.", function(){
42+
$.testHelper.pageSequence([
43+
function(){
44+
$('.baz').trigger('click');
45+
},
46+
function(){
47+
ok( $('[data-nstest-role="header"]').hasClass( 'ui-header' ), "Page header is enhanced." );
48+
ok( $('[data-nstest-role="content"]').hasClass( 'ui-content' ), "Page content is enhanced." );
49+
ok( $('[data-nstest-role="footer"]').hasClass( 'ui-footer' ), "Page footer is enhanced." );
50+
ok( $('[data-nstest-role="button"]').hasClass( 'ui-btn' ), "A link with a role of “button” is enhanced." );
51+
ok( $('[data-nstest-role="slider"]').hasClass( 'ui-slider-switch' ), "Toggles are enhanced." );
52+
ok( $('#test-slider').hasClass( 'ui-slider-input' ), "Slider widgets are enhanced." );
53+
54+
start();
55+
}
56+
]);
57+
});
58+
59+
60+
61+
})(jQuery);

tests/unit/fetchlink/index.html

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>jQuery Mobile Event Test Suite</title>
7+
8+
<script src="../../../js/jquery.js"></script>
9+
<script src="../jquery.setNameSpace.js"></script>
10+
<script src="../../../js/"></script>
11+
<script src="../../jquery.testHelper.js"></script>
12+
<link rel="stylesheet" href="../../../css/themes/default/" />
13+
<link rel="stylesheet" href="../../../external/qunit.css"/>
14+
<script src="../../../external/qunit.js"></script>
15+
16+
<script src="fetchlink_core.js"></script>
17+
18+
<script src="../swarminject.js"></script>
19+
20+
</head>
21+
<body>
22+
23+
<h1 id="qunit-header">jQuery Mobile Event Test Suite</h1>
24+
<h2 id="qunit-banner"></h2>
25+
<h2 id="qunit-userAgent"></h2>
26+
<ol id="qunit-tests">
27+
</ol>
28+
29+
<div id="qunit-fixture"></div>
30+
31+
<div data-nstest-role="page" id="fetchlink-test1">
32+
33+
<div data-nstest-role="content">
34+
<ul data-nstest-target=".loadinto" data-nstest-fragment=".bq">
35+
<li><a href="ext-1.html" class="foo">Quote 1</a></li>
36+
<li><a href="ext-2.html" class="bar">Quote 2</a></li>
37+
</ul>
38+
39+
<a href="ext-3.html" class="baz" data-nstest-target=".loadinto">External Page</a>
40+
41+
<div class="loadinto">
42+
43+
</div>
44+
45+
</div>
46+
47+
</div>
48+
49+
50+
51+
</body>
52+
</html>

0 commit comments

Comments
 (0)