Commit e2f63b29 authored by Ivan Tyagov's avatar Ivan Tyagov

Add Interaction tests.

Split tests into folders.
Clean up unused (not implemented) API.
parent b2b89799
......@@ -441,13 +441,6 @@ var RenderJs = (function () {
}
);
return result;
},
getSelf: function () {
/*
* Return Gadget's Javascript representation
*/
// XXX:
}
};
}()),
......@@ -489,8 +482,7 @@ var RenderJs = (function () {
var source, source_gadget_id, source_method_id,
source_gadget, destination, destination_gadget_id,
destination_method_id, destination_gadget,
original_source_method_id,
func_body, func;
original_source_method_id;
source = $(value).attr("source").split(".");
source_gadget_id = source[0];
source_method_id = source[1];
......
<div>A (gadget)</div>
<script type="text/javascript" language="javascript">
//<![CDATA[
$(document).ready(function() {
gadget = RenderJs.GadgetIndex.getGadgetById("A");
gadget.inc = function (){counter = counter +1;};
});
//]]>
</script>
\ No newline at end of file
<div> B (gadget) </div>
<script type="text/javascript" language="javascript">
//<![CDATA[
$(document).ready(function() {
gadget = RenderJs.GadgetIndex.getGadgetById("B");
gadget.inc = function (){counter = counter + 1};
gadget.htmlEvent1 = function (){counter = counter + 1;};
});
//]]>
</script>
\ No newline at end of file
<div id="A"
data-gadget="interactions/A.html"
data-gadget-cacheable="0"
data-gadget-cache-id="A"></div>
<div id="B"
data-gadget="interactions/B.html"
data-gadget-cacheable="0"
data-gadget-cache-id="B"></div>
<div data-gadget=""
id="main-interactor">
<connect source="A.inc"
destination="B.inc"></connect>
<connect source="A.htmlEvent1"
destination="B.htmlEvent1"></connect>
</div>
/*
* RenderJs tests
*/
counter = 0;
function cleanUp () {
/*
* Clean up namespace between tests
*/
// re-init GadgetIndex
$.each(RenderJs.GadgetIndex.getGadgetList(), function () {
RenderJs.GadgetIndex.unregisterGadget(this);
});
}
function setupRenderJSTest(){
/*
......@@ -16,12 +27,8 @@ function setupRenderJSTest(){
module("GadgetIndex");
test('GadgetIndex', function () {
// re-init GadgetIndex
$.each(RenderJs.GadgetIndex.getGadgetList(), function () {
RenderJs.GadgetIndex.unregisterGadget(this);
});
$("#qunit-fixture").append('<div data-gadget="" id="new">XXXXXXXXXXXX</div>');
cleanUp();
$("#qunit-fixture").append('<div data-gadget="" id="new">X</div>');
RenderJs.bootstrap($("#qunit-fixture"));
RenderJs.GadgetIndex.getRootGadget().getDom().one("ready", function (){
RenderJs.update($("#qunit-fixture"));
......@@ -39,31 +46,46 @@ function setupRenderJSTest(){
equal(RenderJs.GadgetIndex.getGadgetList().length, 0);
});
module("TabularGadget");
test('addNewTabGadget', function () {
RenderJs.TabbularGadget.addNewTabGadget("qunit-fixture", "test-gadget.html", "", "");
module("addGadget");
test('addGadget', function () {
cleanUp();
RenderJs.addGadget("qunit-fixture", "loading/test-gadget.html", "", "");
equal($("#qunit-fixture").children(".gadget").length, 1);
equal(RenderJs.GadgetIndex.getGadgetList().length, 1);
});
module("GadgetInitialization");
test('GadgetInitialization', function () {
// re-init GadgetIndex
$.each(RenderJs.GadgetIndex.getGadgetList(), function () {
RenderJs.GadgetIndex.unregisterGadget(this);
});
$("#qunit-fixture").append('<div data-gadget="" id="new-init" data-gadget-property="{&quot;name&quot;: &quot;Ivan&quot;, &quot;age&quot;: 33}">XXXXXXXXXXXX</div>');
cleanUp();
$("#qunit-fixture").append('<div data-gadget="" id="new-init" data-gadget-property="{&quot;name&quot;: &quot;Ivan&quot;, &quot;age&quot;: 33}">X</div>');
RenderJs.bootstrap($("#qunit-fixture"));
RenderJs.GadgetIndex.getRootGadget().getDom().one("ready", function (){
RenderJs.update($("#qunit-fixture"));
});
// test that gadget get a proper initialization from data-gadget-property
equal('Ivan', RenderJs.GadgetIndex.getGadgetById("new-init").name);
equal(33, RenderJs.GadgetIndex.getGadgetById("new-init").age);
});
// XXX: test InteractionGadget
module("InteractionGadget");
test('InteractionGadget', function () {
cleanUp();
RenderJs.addGadget("qunit-fixture", "interactions/index.html", "", "");
stop();
// we need to wait for all gadgets loading ...
window.setTimeout(function () {
RenderJs.InteractionGadget.bind($("#main-interactor"));
start();
equal(0, counter);
// A.inc will call B.inc, both will increase counter by 1
RenderJs.GadgetIndex.getGadgetById("A").inc();
equal(2, counter);
// fire pure HTML event on A and test it calls respective B method
$('#A').trigger('htmlEvent1');
equal(3, counter);
}, 500);
});
};
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