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 () { ...@@ -441,13 +441,6 @@ var RenderJs = (function () {
} }
); );
return result; return result;
},
getSelf: function () {
/*
* Return Gadget's Javascript representation
*/
// XXX:
} }
}; };
}()), }()),
...@@ -489,8 +482,7 @@ var RenderJs = (function () { ...@@ -489,8 +482,7 @@ var RenderJs = (function () {
var source, source_gadget_id, source_method_id, var source, source_gadget_id, source_method_id,
source_gadget, destination, destination_gadget_id, source_gadget, destination, destination_gadget_id,
destination_method_id, destination_gadget, destination_method_id, destination_gadget,
original_source_method_id, original_source_method_id;
func_body, func;
source = $(value).attr("source").split("."); source = $(value).attr("source").split(".");
source_gadget_id = source[0]; source_gadget_id = source[0];
source_method_id = source[1]; 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 * 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(){ function setupRenderJSTest(){
/* /*
...@@ -8,62 +19,73 @@ function setupRenderJSTest(){ ...@@ -8,62 +19,73 @@ function setupRenderJSTest(){
*/ */
module("Cache"); module("Cache");
test('Cache', function () { test('Cache', function () {
cache_id = 'my_test'; cache_id = 'my_test';
data = {'gg':1}; data = {'gg':1};
RenderJs.Cache.set(cache_id, data); RenderJs.Cache.set(cache_id, data);
deepEqual(data, RenderJs.Cache.get(cache_id)); deepEqual(data, RenderJs.Cache.get(cache_id));
}); });
module("GadgetIndex"); module("GadgetIndex");
test('GadgetIndex', function () { test('GadgetIndex', function () {
// re-init GadgetIndex cleanUp();
$.each(RenderJs.GadgetIndex.getGadgetList(), function () { $("#qunit-fixture").append('<div data-gadget="" id="new">X</div>');
RenderJs.GadgetIndex.unregisterGadget(this); RenderJs.bootstrap($("#qunit-fixture"));
}); RenderJs.GadgetIndex.getRootGadget().getDom().one("ready", function (){
RenderJs.update($("#qunit-fixture"));
$("#qunit-fixture").append('<div data-gadget="" id="new">XXXXXXXXXXXX</div>'); });
RenderJs.bootstrap($("#qunit-fixture")); equal(RenderJs.GadgetIndex.getGadgetList().length, 2);
RenderJs.GadgetIndex.getRootGadget().getDom().one("ready", function (){ equal(true, RenderJs.GadgetIndex.isGadgetListLoaded());
RenderJs.update($("#qunit-fixture")); equal($("#qunit-fixture").attr("id"), RenderJs.GadgetIndex.getRootGadget().getDom().attr("id"));
}); equal(RenderJs.GadgetIndex.getGadgetById("qunit-fixture"), RenderJs.GadgetIndex.getRootGadget());
equal(RenderJs.GadgetIndex.getGadgetList().length, 2);
equal(true, RenderJs.GadgetIndex.isGadgetListLoaded());
equal($("#qunit-fixture").attr("id"), RenderJs.GadgetIndex.getRootGadget().getDom().attr("id"));
equal(RenderJs.GadgetIndex.getGadgetById("qunit-fixture"), RenderJs.GadgetIndex.getRootGadget());
// unregister gadget all gadgets from this test not to mess with rest of tests // unregister gadget all gadgets from this test not to mess with rest of tests
RenderJs.GadgetIndex.unregisterGadget(RenderJs.GadgetIndex.getGadgetById("qunit-fixture")); RenderJs.GadgetIndex.unregisterGadget(RenderJs.GadgetIndex.getGadgetById("qunit-fixture"));
equal(RenderJs.GadgetIndex.getGadgetList().length, 1); equal(RenderJs.GadgetIndex.getGadgetList().length, 1);
equal(RenderJs.GadgetIndex.getGadgetById("new"), RenderJs.GadgetIndex.getRootGadget()); equal(RenderJs.GadgetIndex.getGadgetById("new"), RenderJs.GadgetIndex.getRootGadget());
RenderJs.GadgetIndex.unregisterGadget(RenderJs.GadgetIndex.getGadgetById("new")); RenderJs.GadgetIndex.unregisterGadget(RenderJs.GadgetIndex.getGadgetById("new"));
equal(RenderJs.GadgetIndex.getGadgetList().length, 0); equal(RenderJs.GadgetIndex.getGadgetList().length, 0);
}); });
module("TabularGadget"); module("addGadget");
test('addNewTabGadget', function () { test('addGadget', function () {
RenderJs.TabbularGadget.addNewTabGadget("qunit-fixture", "test-gadget.html", "", ""); cleanUp();
equal($("#qunit-fixture").children(".gadget").length, 1); RenderJs.addGadget("qunit-fixture", "loading/test-gadget.html", "", "");
equal(RenderJs.GadgetIndex.getGadgetList().length, 1); equal($("#qunit-fixture").children(".gadget").length, 1);
equal(RenderJs.GadgetIndex.getGadgetList().length, 1);
}); });
module("GadgetInitialization"); module("GadgetInitialization");
test('GadgetInitialization', function () { test('GadgetInitialization', function () {
// re-init GadgetIndex cleanUp();
$.each(RenderJs.GadgetIndex.getGadgetList(), function () { $("#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.GadgetIndex.unregisterGadget(this); RenderJs.bootstrap($("#qunit-fixture"));
}); RenderJs.GadgetIndex.getRootGadget().getDom().one("ready", function (){
RenderJs.update($("#qunit-fixture"));
});
$("#qunit-fixture").append('<div data-gadget="" id="new-init" data-gadget-property="{&quot;name&quot;: &quot;Ivan&quot;, &quot;age&quot;: 33}">XXXXXXXXXXXX</div>'); // test that gadget get a proper initialization from data-gadget-property
RenderJs.bootstrap($("#qunit-fixture")); equal('Ivan', RenderJs.GadgetIndex.getGadgetById("new-init").name);
RenderJs.GadgetIndex.getRootGadget().getDom().one("ready", function (){ equal(33, RenderJs.GadgetIndex.getGadgetById("new-init").age);
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