Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

Commit

Permalink
First pass at (working) fetchlink unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilto committed Dec 22, 2011
1 parent 5a7377a commit a1e6c87
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 4 deletions.
6 changes: 2 additions & 4 deletions js/jquery.mobile.fetchlinks.js
Expand Up @@ -65,12 +65,11 @@ $.widget( "mobile.fetchlink", $.mobile.widget, {
targetEl.filter( ':jqmData(role="listview")' ).length && targetEl.listview( "refresh" );

targetEl
.trigger( "create" )
.removeClass('ui-loading-inline')
.height('auto');

console.log("Plugin fired and completed");

responseEl.trigger( "create" );

}, 300);
});
}
Expand All @@ -93,7 +92,6 @@ $( document ).bind( "inlineLoader", function( e, ui ){

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

Expand Down
17 changes: 17 additions & 0 deletions tests/unit/fetchlink/ext-1.html
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery Mobile Event Test Suite</title>
</head>
<body>

<blockquote class="bq">
<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>
<address>Arthur Conan Doyle</address>
<cite>Sherlock Holmes: The Sign of the Four</cite>
</blockquote>

</body>
</html>
17 changes: 17 additions & 0 deletions tests/unit/fetchlink/ext-2.html
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery Mobile Event Test Suite</title>
</head>
<body>

<blockquote class="bq">
<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>
<address>Arthur Conan Doyle</address>
<cite>Sherlock Holmes: A Study in Scarlet</cite>
</blockquote>

</body>
</html>
43 changes: 43 additions & 0 deletions tests/unit/fetchlink/ext-3.html
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery Mobile Event Test Suite</title>

<script src="../../../js/jquery.js"></script>
<script src="../jquery.setNameSpace.js"></script>
<script src="../../../js/"></script>
<script src="../../jquery.testHelper.js"></script>
<link rel="stylesheet" href="../../../css/themes/default/" />
<link rel="stylesheet" href="../../../external/qunit.css"/>
<script src="../../../external/qunit.js"></script>

</head>
<body>

<div data-nstest-role="page" id="fetchlink-remote-page">
<div data-nstest-role="header">
<h1>Header</h1>
</div>
<div data-nstest-role="content">

<a href="ext-4.html" class="foo" data-nstest-role="button">Quote 1</a>

<label for="slider2">Flip switch:</label>
<select name="slider2" id="slider2" data-nstest-role="slider">
<option value="off">Off</option>
<option value="on">On</option>
</select>

<label for="test-slider">Slider:</label>
<input type="range" name="test-slider" id="test-slider" value="0" min="0" max="100" />

</div>
<div data-nstest-role="footer">
<h1>Footer</h1>
</div>
</div>

</body>
</html>
61 changes: 61 additions & 0 deletions tests/unit/fetchlink/fetchlink_core.js
@@ -0,0 +1,61 @@
/*
* Fetchlink unit tests
*/

(function($){

module( "Fetchlinks", {
setup: function(){
//
}
});

asyncTest( "Clicking a fetchlink loads remote content.", function(){
var targetContents = $( '.loadinto' ).html();

$.testHelper.pageSequence([
function(){
$('.foo').trigger('click');
},
function(){
ok( targetContents !== $( '.loadinto' ).html() );
start();
}
]);
});

asyncTest( "Clicking a fetchlink replaces previously loaded content with remote content.", function(){
var targetContents = $( '.loadinto' ).html();

$.testHelper.pageSequence([
function(){
$('.bar').trigger('click');
},
function(){
ok( targetContents !== $( '.loadinto' ).html() );
start();
}
]);
});

asyncTest( "Elements are properly enhanced after being fetched.", function(){
$.testHelper.pageSequence([
function(){
$('.baz').trigger('click');
},
function(){
ok( $('[data-nstest-role="header"]').hasClass( 'ui-header' ), "Page header is enhanced." );
ok( $('[data-nstest-role="content"]').hasClass( 'ui-content' ), "Page content is enhanced." );
ok( $('[data-nstest-role="footer"]').hasClass( 'ui-footer' ), "Page footer is enhanced." );
ok( $('[data-nstest-role="button"]').hasClass( 'ui-btn' ), "A link with a role of “button” is enhanced." );
ok( $('[data-nstest-role="slider"]').hasClass( 'ui-slider-switch' ), "Toggles are enhanced." );
ok( $('#test-slider').hasClass( 'ui-slider-input' ), "Slider widgets are enhanced." );

start();
}
]);
});



})(jQuery);
52 changes: 52 additions & 0 deletions tests/unit/fetchlink/index.html
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery Mobile Event Test Suite</title>

<script src="../../../js/jquery.js"></script>
<script src="../jquery.setNameSpace.js"></script>
<script src="../../../js/"></script>
<script src="../../jquery.testHelper.js"></script>
<link rel="stylesheet" href="../../../css/themes/default/" />
<link rel="stylesheet" href="../../../external/qunit.css"/>
<script src="../../../external/qunit.js"></script>

<script src="fetchlink_core.js"></script>

<script src="../swarminject.js"></script>

</head>
<body>

<h1 id="qunit-header">jQuery Mobile Event Test Suite</h1>
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests">
</ol>

<div id="qunit-fixture"></div>

<div data-nstest-role="page" id="fetchlink-test1">

<div data-nstest-role="content">
<ul data-nstest-target=".loadinto" data-nstest-fragment=".bq">
<li><a href="ext-1.html" class="foo">Quote 1</a></li>
<li><a href="ext-2.html" class="bar">Quote 2</a></li>
</ul>

<a href="ext-3.html" class="baz" data-nstest-target=".loadinto">External Page</a>

<div class="loadinto">

</div>

</div>

</div>



</body>
</html>

0 comments on commit a1e6c87

Please sign in to comment.