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,14 +559,19 @@ var RenderJs = (function () { ...@@ -559,14 +559,19 @@ 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);
}); });
}; };
...@@ -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,11 +175,20 @@ function setupRenderJSTest(){ ...@@ -175,11 +175,20 @@ 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();
stop();
// XXX: until we have a way to know that update which runs asynchronously is over
// we use hard coded timeouts.
setTimeout(function(){
start();
cached = RenderJs.Cache.get(url_list[0]); cached = RenderJs.Cache.get(url_list[0]);
equal("HTML WYSIWYG", cached["gadget_list"][0]["title"]); equal("HTML WYSIWYG", cached["gadget_list"][0]["title"]);
deepEqual(["edit_html", "view_html"], cached["gadget_list"][0]["service_list"]); deepEqual(["edit_html", "view_html"], cached["gadget_list"][0]["service_list"]);
...@@ -199,6 +208,9 @@ function setupRenderJSTest(){ ...@@ -199,6 +208,9 @@ function setupRenderJSTest(){
// no such service is provided by gadget repos // no such service is provided by gadget repos
equal(0, RenderJs.GadgetCatalog.getGadgetListThatProvide("edit_html1")); 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