You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2013/04/29 14:27:42 UTC
git commit: Add JavaScript unit test demonstrating usage of Wicket
JavaScript files in AMD (RequireJS)
Updated Branches:
refs/heads/master cebf00849 -> 72ae10987
Add JavaScript unit test demonstrating usage of Wicket JavaScript files in AMD (RequireJS)
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/72ae1098
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/72ae1098
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/72ae1098
Branch: refs/heads/master
Commit: 72ae109875f4f5d4529c02db8e2ab75519cbb96f
Parents: cebf008
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Mon Apr 29 14:26:59 2013 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon Apr 29 14:26:59 2013 +0200
----------------------------------------------------------------------
grunt.js | 8 ++-
.../wicket/ajax/res/js/wicket-ajax-jquery-debug.js | 3 +-
wicket-core/src/test/js/amd.html | 68 +++++++++++++++
wicket-core/src/test/js/amd.js | 58 ++++++++++++
4 files changed, 135 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/72ae1098/grunt.js
----------------------------------------------------------------------
diff --git a/grunt.js b/grunt.js
index 2b24be1..e76e409 100644
--- a/grunt.js
+++ b/grunt.js
@@ -46,7 +46,8 @@ module.exports = function(grunt) {
"./wicket-core/src/test/js/form.js",
"./wicket-core/src/test/js/dom.js",
"./wicket-core/src/test/js/channels.js",
- "./wicket-core/src/test/js/event.js"
+ "./wicket-core/src/test/js/event.js",
+ "./wicket-core/src/test/js/amd.js"
],
gruntJs = [
"grunt.js"
@@ -94,6 +95,11 @@ module.exports = function(grunt) {
*/
index: ['http://localhost/ajax-tests/test/js/all.html'],
+ /**
+ * Run Asynchronous module definition tests
+ */
+ amd: ['http://localhost/ajax-tests/test/js/amd.html'],
+
/*
* Runs only local tests (w/o ajax ones).
*/
http://git-wip-us.apache.org/repos/asf/wicket/blob/72ae1098/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery-debug.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery-debug.js b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery-debug.js
index d979c97..d9089d1 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery-debug.js
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery-debug.js
@@ -28,7 +28,7 @@
'use strict';
if (typeof(Wicket) === 'undefined') {
- Wicket = {};
+ window.Wicket = {};
}
if (typeof(Wicket.Ajax) === 'undefined') {
@@ -265,4 +265,5 @@
};
jQuery(window).on('load', Wicket.Ajax.DebugWindow.init);
+
})();
http://git-wip-us.apache.org/repos/asf/wicket/blob/72ae1098/wicket-core/src/test/js/amd.html
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/js/amd.html b/wicket-core/src/test/js/amd.html
new file mode 100644
index 0000000..42c5852
--- /dev/null
+++ b/wicket-core/src/test/js/amd.html
@@ -0,0 +1,68 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <title id="titleId">Asynchronous module tests</title>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <link rel="stylesheet" href="qunit/qunit.css" type="text/css" media="screen" />
+ <script type="text/javascript" src="qunit/qunit.js"></script>
+ <script type="text/javascript">
+ var require = {
+ paths: {
+ 'jquery': '../../main/java/org/apache/wicket/resource/jquery/jquery', // no .js extension
+ 'wicket-event': '../../main/java/org/apache/wicket/ajax/res/js/wicket-event-jquery',
+ 'Wicket': '../../main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery',
+ 'WicketDebugWindow': '../../main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery-debug'
+ },
+ shim: {
+ 'wicket-event': {
+ deps: ['jquery']
+ },
+ 'Wicket': {
+ deps: ['wicket-event'],
+ exports: 'Wicket'
+ },
+ 'WicketDebugWindow': {
+ deps: ['Wicket'],
+ exports: 'WicketDebugWindow'
+ }
+ }
+ };
+ </script>
+ <script src="amd/require.js" type="text/javascript"></script>
+
+ <!-- the module under test -->
+ <script>
+ var oldAutoStart = QUnit.config.autostart;
+ // do not start the tests before they are loaded via AMD
+ QUnit.config.autostart = false;
+
+ require(["amd"], function (amdModule) {
+ QUnit.start();
+
+ amdModule.runTests();
+
+ QUnit.config.autostart = oldAutoStart;
+ }
+ );
+ </script>
+</head>
+
+<body>
+ <h1 id="qunit-header">Wicket AMD tests</h1>
+
+ <h2 id="qunit-banner"></h2>
+
+ <div id="qunit-testrunner-toolbar"></div>
+
+ <h2 id="qunit-userAgent"></h2>
+
+ <ol id="qunit-tests"></ol>
+
+ <div id="qunit-fixture">
+
+ <div id="amdElement"></div>
+
+ </div>
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/wicket/blob/72ae1098/wicket-core/src/test/js/amd.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/js/amd.js b/wicket-core/src/test/js/amd.js
new file mode 100644
index 0000000..f6ef1c1
--- /dev/null
+++ b/wicket-core/src/test/js/amd.js
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*global ok: true, start: true, test: true, equal: true, deepEqual: true,
+ QUnit: true, module: true, expect: true, define: true */
+
+define(
+ [
+ "jquery",
+ "Wicket",
+ "WicketDebugWindow"
+ ],
+ function ($, w) {
+ "use strict";
+
+ return {
+ runTests: function () {
+ test("Wicket object is successfully loaded via RequireJs", function () {
+
+ expect(15);
+
+ // test for one member for each Wicket.** module
+ ok($.isFunction(w.Browser.isChrome), "Wicket Browser (from wicket-event-jquery.js) is imported");
+ ok($.isFunction(w.Event.fix), "Wicket Event (from wicket-event-jquery.js) is imported");
+ ok($.isFunction(w.Ajax.ajax), "Wicket Ajax (from wicket-ajax-jquery.js) is imported");
+ ok($.isFunction(w.DOM.get), "Wicket DOM (from wicket-ajax-jquery.js) is imported");
+ ok($.isFunction(w.Form.serialize), "Wicket Form (from wicket-ajax-jquery.js) is imported");
+ ok($.isFunction(new w.Channel("blah|s").done), "Wicket Channel (from wicket-ajax-jquery.js) is imported");
+ ok($.isFunction(new w.ChannelManager().done), "Wicket ChannelManager (from wicket-ajax-jquery.js) is imported");
+ ok($.isFunction(w.Class.create), "Wicket Class (from wicket-ajax-jquery.js) is imported");
+ ok($.isFunction(w.Head.addElement), "Wicket Head (from wicket-ajax-jquery.js) is imported");
+ ok($.isFunction(w.Focus.attachFocusEvent), "Wicket Focus (from wicket-ajax-jquery.js) is imported");
+ ok($.isFunction(w.Log.error), "Wicket Log (from wicket-ajax-jquery.js) is imported");
+ ok($.isFunction(new w.Throttler().throttle), "Wicket Throttler (from wicket-ajax-jquery.js) is imported");
+ ok($.isFunction(new w.ThrottlerEntry().getFunc), "Wicket ThrottlerEntry (from wicket-ajax-jquery.js) is imported");
+
+ equal('div', w.DOM.get('amdElement').tagName.toLowerCase(), "Wicket.DOM.get() works");
+
+ ok($.isFunction(w.Ajax.DebugWindow.logError), "Wicket Ajax.DebugWindow (from wicket-ajax-jquery-debug.js) is imported");
+ });
+ }
+ };
+ }
+);
\ No newline at end of file