Commit 18958049 authored by Ivan Tyagov's avatar Ivan Tyagov

Use JIO's webdav storage to access GadgetCatalog index information.

Add needed basic jio libraries and adjust test accordingly.
parent f6d0d95d
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -559,15 +559,20 @@ var RenderJs = (function () { ...@@ -559,15 +559,20 @@ var RenderJs = (function () {
var cache_id = "setGadgetIndexUrlList"; var cache_id = "setGadgetIndexUrlList";
function updateGadgetIndexFromURL(url) { function updateGadgetIndexFromURL(url) {
$.ajax({url:url, // split to base and document url
async: false, // To simplify update var url_list = url.split('/'),
dataType: "json", document_url = url_list[url_list.length-1];
success: function(data) { url_list.splice($.inArray(document_url, url_list), 1);
// Store remote JSON as it is in local html5 cache var base_url = url_list.join('/'),
// as we don't need to reinvent another structure yet! web_dav = jIO.newJio({
RenderJs.Cache.set(url, data) "type": "dav",
} "username": "",
}); "password": "",
"url": base_url});
web_dav.get(document_url,
function (err, response) {
RenderJs.Cache.set(url, response);
});
}; };
return { return {
...@@ -609,7 +614,7 @@ var RenderJs = (function () { ...@@ -609,7 +614,7 @@ var RenderJs = (function () {
$.each(RenderJs.GadgetCatalog.getGadgetIndexUrlList(), $.each(RenderJs.GadgetCatalog.getGadgetIndexUrlList(),
function(index, url) { function(index, url) {
// get repos from cache // get repos from cache
var cached_repo = RenderJs.Cache.get(url) var cached_repo = RenderJs.Cache.get(url);
$.each(cached_repo['gadget_list'], $.each(cached_repo['gadget_list'],
function(index, gadget) { function(index, gadget) {
if (jQuery.inArray(service, gadget["service_list"]) > -1) { if (jQuery.inArray(service, gadget["service_list"]) > -1) {
......
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
<script src="../lib/qunit/qunit.js" type="text/javascript"></script> <script src="../lib/qunit/qunit.js" type="text/javascript"></script>
<script type="text/javascript" src="../renderjs.js"></script> <script type="text/javascript" src="../renderjs.js"></script>
<script type="text/javascript" src="renderjs_test.js"></script> <script type="text/javascript" src="renderjs_test.js"></script>
<script type="text/javascript" src="../lib/jio/md5.js"></script>
<script type="text/javascript" src="../lib/jio/jio.js"></script>
<script type="text/javascript" src="../lib/jio/davstorage.js"></script>
</head> </head>
<body> <body>
......
...@@ -175,29 +175,41 @@ function setupRenderJSTest(){ ...@@ -175,29 +175,41 @@ function setupRenderJSTest(){
module("GadgetCatalog"); module("GadgetCatalog");
test('GadgetCatalog', function () { test('GadgetCatalog', function () {
cleanUp(); cleanUp();
// allow test to be run alone (i.e. url contains arguments)
var base_url = window.location.protocol + "//" + window.location.hostname + window.location.pathname;
// generate random argument to test always with new cache id // generate random argument to test always with new cache id
var url_list = new Array('gadget_index/gadget_index.json?t='+makeid()); var url_list = new Array(base_url + '/gadget_index/gadget_index.json?t='+makeid());
RenderJs.GadgetCatalog.setGadgetIndexUrlList(url_list) RenderJs.GadgetCatalog.setGadgetIndexUrlList(url_list)
deepEqual(url_list, RenderJs.GadgetCatalog.getGadgetIndexUrlList()); deepEqual(url_list, RenderJs.GadgetCatalog.getGadgetIndexUrlList());
RenderJs.GadgetCatalog.updateGadgetIndex(); RenderJs.GadgetCatalog.updateGadgetIndex();
cached = RenderJs.Cache.get(url_list[0]); stop();
equal("HTML WYSIWYG", cached["gadget_list"][0]["title"]);
deepEqual(["edit_html", "view_html"], cached["gadget_list"][0]["service_list"]); // XXX: until we have a way to know that update which runs asynchronously is over
// we use hard coded timeouts.
// check that we can find gadgets that provide some service_list setTimeout(function(){
gadget_list = RenderJs.GadgetCatalog.getGadgetListThatProvide("edit_html"); start();
equal("HTML WYSIWYG", gadget_list[0]["title"]); cached = RenderJs.Cache.get(url_list[0]);
deepEqual(["edit_html", "view_html"], gadget_list[0]["service_list"]); equal("HTML WYSIWYG", cached["gadget_list"][0]["title"]);
gadget_list = RenderJs.GadgetCatalog.getGadgetListThatProvide("view_html"); deepEqual(["edit_html", "view_html"], cached["gadget_list"][0]["service_list"]);
equal("HTML WYSIWYG", gadget_list[0]["title"]);
deepEqual(["edit_html", "view_html"], gadget_list[0]["service_list"]); // check that we can find gadgets that provide some service_list
gadget_list = RenderJs.GadgetCatalog.getGadgetListThatProvide("edit_html");
gadget_list = RenderJs.GadgetCatalog.getGadgetListThatProvide("edit_svg"); equal("HTML WYSIWYG", gadget_list[0]["title"]);
equal("SVG WYSIWYG", gadget_list[0]["title"]); deepEqual(["edit_html", "view_html"], gadget_list[0]["service_list"]);
deepEqual(["edit_svg", "view_svg"], gadget_list[0]["service_list"]); gadget_list = RenderJs.GadgetCatalog.getGadgetListThatProvide("view_html");
equal("HTML WYSIWYG", gadget_list[0]["title"]);
// no such service is provided by gadget repos deepEqual(["edit_html", "view_html"], gadget_list[0]["service_list"]);
equal(0, RenderJs.GadgetCatalog.getGadgetListThatProvide("edit_html1"));
gadget_list = RenderJs.GadgetCatalog.getGadgetListThatProvide("edit_svg");
equal("SVG WYSIWYG", gadget_list[0]["title"]);
deepEqual(["edit_svg", "view_svg"], gadget_list[0]["service_list"]);
// no such service is provided by gadget repos
equal(0, RenderJs.GadgetCatalog.getGadgetListThatProvide("edit_html1"));
}, 1000)
}); });
......
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