Add the tests from the blog article
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/ff55cb8f Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/ff55cb8f Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/ff55cb8f Branch: refs/heads/master Commit: ff55cb8f56755100a8300c92b1046d832fc8a32b Parents: 9c8f658 Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Thu Jun 13 10:55:47 2013 +0300 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Thu Jun 13 10:55:47 2013 +0300 ---------------------------------------------------------------------- .../src/main/webapp/js-test/all.html | 46 + .../src/main/webapp/js-test/lib/gym.js | 106 + .../src/main/webapp/js-test/lib/jquery.min.js | 6 + .../src/main/webapp/js-test/lib/qunit.css | 244 ++ .../src/main/webapp/js-test/lib/qunit.js | 2152 ++++++++++++++++++ .../src/main/webapp/js-test/tests/ajax/form.js | 40 + .../src/main/webapp/js-test/tests/echo.js | 26 + .../src/main/webapp/js-test/tests/forminput.js | 46 + .../src/main/webapp/js-test/tests/helloworld.js | 19 + 9 files changed, 2685 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/ff55cb8f/wicket-examples/src/main/webapp/js-test/all.html ---------------------------------------------------------------------- diff --git a/wicket-examples/src/main/webapp/js-test/all.html b/wicket-examples/src/main/webapp/js-test/all.html new file mode 100644 index 0000000..6325b25 --- /dev/null +++ b/wicket-examples/src/main/webapp/js-test/all.html @@ -0,0 +1,46 @@ +<!DOCTYPE html> +<html> + +<head> + <title>QUnit tests</title> + <meta http-equiv="content-type" content="text/html; charset=UTF-8"> + <link rel="stylesheet" href="lib/qunit.css" type="text/css" media="screen" /> + <script type="text/javascript" src="lib/jquery.min.js"></script> + <script type="text/javascript" charset="utf-8"> + $q = jQuery.noConflict(true), + $ = null, + jQuery = null; + </script> + <script type="text/javascript" src="lib/qunit.js"></script> + + <!-- common helpers --> + <!--<script type="text/javascript" src="lib/when.js"></script>--> + <script type="text/javascript" src="lib/gym.js"></script> + + <!-- the modules under test --> + <script type="text/javascript" src="tests/helloworld.js"></script> + <script type="text/javascript" src="tests/echo.js"></script> + <script type="text/javascript" src="tests/forminput.js"></script> + + <script type="text/javascript" src="tests/ajax/form.js"></script> +</head> + +<body> + <h1 id="qunit-header">Wicket Examples's JS tests</h1> + + <h2 id="qunit-banner"></h2> + + <div id="qunit-testrunner-toolbar"></div> + + <h2 id="qunit-userAgent"></h2> + + <!-- Show the iframe to see how the tests run --> + <iframe id="applicationFrame" width="100%" height="500px" src="../"></iframe> + + <ol id="qunit-tests"></ol> + + <div id="qunit-fixture"> + + </div> +</body> +</html> http://git-wip-us.apache.org/repos/asf/wicket/blob/ff55cb8f/wicket-examples/src/main/webapp/js-test/lib/gym.js ---------------------------------------------------------------------- diff --git a/wicket-examples/src/main/webapp/js-test/lib/gym.js b/wicket-examples/src/main/webapp/js-test/lib/gym.js new file mode 100644 index 0000000..57aaf3c --- /dev/null +++ b/wicket-examples/src/main/webapp/js-test/lib/gym.js @@ -0,0 +1,106 @@ + +var load = function(url) { + var deferred = $q.Deferred(); + onPageLoad(function(iframe, $) { + deferred.resolve(iframe, $); + }); + getIframe().attr('src', url); + + return deferred; +} + +var click = function($btn) { + var deferred = $q.Deferred(); + onPageLoad(function(iframe, $$) { + deferred.resolve(iframe, $$); + }); + + $btn.click(); + + return deferred; +} + +// private +var getIframe = function() { + return $q('#applicationFrame'); +} + +// private +var onPageLoad = function(toExecute) { + + getIframe() + .off('load') + .on('load', function() { + $q(this).off('load'); + + var newIframe, $; + + newIframe = window.frames[0]; + $ = newIframe.jQuery || jQueryWithContext; + + //debug(newIframe); + + toExecute.call(newIframe, $); + }); +}; + +/** + * Non-Ajax pages do not have jQuery so we use + * $q with context to simulate it + */ +// private +var jQueryWithContext = function(selector) { + return $q(selector, $q(getIframe()).contents()); +}; + +var ajaxClick = function($btn) { + var deferred = $q.Deferred(); + var iframeWindow = getIframe()[0].contentWindow; + + onAjaxComplete(iframeWindow, function($$) { + deferred.resolve($$); + }); + + $btn.click(); + + return deferred; +} + +/** + * Registers a callback when Wicket Ajax call is completed + */ +// private +var onAjaxComplete = function(iframe, toExecute) { + + // unregister any leaked subscriber + iframe.jQuery(iframe.document).off('/ajax/call/complete'); + + // register the requested subscriber + iframe.Wicket.Event.subscribe('/ajax/call/complete', function(jqEvent, attributes, jqXHR, textStatus) { + // immediately unregister this subscriber + iframe.jQuery(iframe.document).off('/ajax/call/complete'); + + // call back + var $$ = iframe.jQuery || jQueryWithContext; + toExecute($$); + }); +}; + +// unused +var followHref = function(iframe, $, $link) { + var loc = iframe.document.location; +// console.log('Current url', loc.href); +// console.log('Link', $link.selector); + + if ($link.length) { + var newUrl = $link.attr('href'); +// console.log('Following href: ', newUrl); + loc.replace(newUrl); + } +} + +var debug = function(iframe) { + "use strict"; + + console.log('Current url: ', iframe.window.location.href); +}
