From a1e6c874a1755223b1a86a02b2a64a35a6e97d26 Mon Sep 17 00:00:00 2001 From: Mat Marquis Date: Thu, 22 Dec 2011 18:06:36 -0500 Subject: [PATCH] First pass at (working) fetchlink unit tests. --- js/jquery.mobile.fetchlinks.js | 6 +-- tests/unit/fetchlink/ext-1.html | 17 +++++++ tests/unit/fetchlink/ext-2.html | 17 +++++++ tests/unit/fetchlink/ext-3.html | 43 ++++++++++++++++++ tests/unit/fetchlink/fetchlink_core.js | 61 ++++++++++++++++++++++++++ tests/unit/fetchlink/index.html | 52 ++++++++++++++++++++++ 6 files changed, 192 insertions(+), 4 deletions(-) create mode 100644 tests/unit/fetchlink/ext-1.html create mode 100644 tests/unit/fetchlink/ext-2.html create mode 100644 tests/unit/fetchlink/ext-3.html create mode 100644 tests/unit/fetchlink/fetchlink_core.js create mode 100644 tests/unit/fetchlink/index.html diff --git a/js/jquery.mobile.fetchlinks.js b/js/jquery.mobile.fetchlinks.js index 6fff520a..c80dcae4 100644 --- a/js/jquery.mobile.fetchlinks.js +++ b/js/jquery.mobile.fetchlinks.js @@ -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); }); } @@ -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(); }); diff --git a/tests/unit/fetchlink/ext-1.html b/tests/unit/fetchlink/ext-1.html new file mode 100644 index 00000000..b5d27d7a --- /dev/null +++ b/tests/unit/fetchlink/ext-1.html @@ -0,0 +1,17 @@ + + + + + + jQuery Mobile Event Test Suite + + + +
+

“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?”

+
Arthur Conan Doyle
+ Sherlock Holmes: The Sign of the Four +
+ + + diff --git a/tests/unit/fetchlink/ext-2.html b/tests/unit/fetchlink/ext-2.html new file mode 100644 index 00000000..9dfa2ac0 --- /dev/null +++ b/tests/unit/fetchlink/ext-2.html @@ -0,0 +1,17 @@ + + + + + + jQuery Mobile Event Test Suite + + + +
+

“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.”

+
Arthur Conan Doyle
+ Sherlock Holmes: A Study in Scarlet +
+ + + diff --git a/tests/unit/fetchlink/ext-3.html b/tests/unit/fetchlink/ext-3.html new file mode 100644 index 00000000..7f38b4a5 --- /dev/null +++ b/tests/unit/fetchlink/ext-3.html @@ -0,0 +1,43 @@ + + + + + + jQuery Mobile Event Test Suite + + + + + + + + + + + + + + + + diff --git a/tests/unit/fetchlink/fetchlink_core.js b/tests/unit/fetchlink/fetchlink_core.js new file mode 100644 index 00000000..788432e2 --- /dev/null +++ b/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); \ No newline at end of file diff --git a/tests/unit/fetchlink/index.html b/tests/unit/fetchlink/index.html new file mode 100644 index 00000000..9397ddd6 --- /dev/null +++ b/tests/unit/fetchlink/index.html @@ -0,0 +1,52 @@ + + + + + + jQuery Mobile Event Test Suite + + + + + + + + + + + + + + + + +

jQuery Mobile Event Test Suite

+

+

+
    +
+ +
+ + + + + + +