Commit fa9b2fa9 authored by Ivan Tyagov's avatar Ivan Tyagov

Add basic testing for RouteGadget.

parent a4bdbf28
...@@ -19,6 +19,8 @@ function cleanUp () { ...@@ -19,6 +19,8 @@ function cleanUp () {
counter = 0; counter = 0;
first_name='' first_name=''
last_name='' last_name=''
route_changed=0
function parseJSONAndUpdateNameSpace(result) { function parseJSONAndUpdateNameSpace(result) {
first_name=result['first_name']; first_name=result['first_name'];
last_name=result['last_name']; last_name=result['last_name'];
...@@ -232,5 +234,39 @@ function setupRenderJSTest(){ ...@@ -232,5 +234,39 @@ function setupRenderJSTest(){
}); });
module("RouteGadget");
test('RouteGadget', function () {
cleanUp();
RenderJs.addGadget("qunit-fixture", "new_route_add", "route/index.html", "", "");
equal(0, route_changed);
stop();
// we need to wait for all gadgets loading ...
RenderJs.bindReady(function () {
start();
// initialize route gadget as it's loaded asynchronously
RenderJs.RouteGadget.route($("#main-router"));
// listen to event and do actual routing
$.url.onhashchange(function () {
var body = $("body");
body
.route("go", $.url.getPath())
.fail(function () {
alert("no route");
});
});
$.url.go('/gadget-one/');
// give some time so .render finishes, most likely we need some event like .bindReady
// to indicate that respective .render method finishes in generic RenderJs ?
stop();
setTimeout( function () {
start();
// respective gadget .render method must be called and global var changed
equal(1, route_changed);
}, 1000);
});
});
}; };
// JavaScript file that is used to load RenderJs depenencies // JavaScript file that is used to load RenderJs depenencies
require.config({ require.config({
baseUrl: "..", baseUrl: "..",
paths: {
route: "lib/route/route",
url: "lib/route/url",
jquery: "lib/jquery/jquery",
renderjs: "renderjs",
},
shim: { shim: {
"test/renderjs_test": [ "renderjs" ] "test/renderjs_test": [ "renderjs" ],
"url": ["renderjs"],
"route": ["url"]
} }
}); });
require([ "require-renderjs", "test/renderjs_test" ], function(domReady) { require([ "require-renderjs", "test/renderjs_test", "url", "route" ], function(domReady) {
setupRenderJSTest(); setupRenderJSTest();
}); });
<html>
<head></head>
<body>
<script type="text/javascript" language="javascript">
//<![CDATA[
$(document).ready(function() {
gadget = RenderJs.GadgetIndex.getGadgetById("gadget-one");
gadget.render = function (){
route_changed=1; // so we can test this method was actually called from qunit
};
});
//]]>
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div data-gadget=""
id="main-router"
data-gadget-route="[
{&quot;source&quot;: &quot;/gadget-one/&quot;, &quot;destination&quot;: &quot;gadget-one&quot;}]">
</div>
<div id="gadget-one"
data-gadget="route/gadget-one.html"></div>
</body>
</html>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment