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 () {
var cache_id = "setGadgetIndexUrlList";
function updateGadgetIndexFromURL(url) {
$.ajax({url:url,
async: false, // To simplify update
dataType: "json",
success: function(data) {
// Store remote JSON as it is in local html5 cache
// as we don't need to reinvent another structure yet!
RenderJs.Cache.set(url, data)
}
});
// split to base and document url
var url_list = url.split('/'),
document_url = url_list[url_list.length-1];
url_list.splice($.inArray(document_url, url_list), 1);
var base_url = url_list.join('/'),
web_dav = jIO.newJio({
"type": "dav",
"username": "",
"password": "",
"url": base_url});
web_dav.get(document_url,
function (err, response) {
RenderJs.Cache.set(url, response);
});
};
return {
......@@ -609,7 +614,7 @@ var RenderJs = (function () {
$.each(RenderJs.GadgetCatalog.getGadgetIndexUrlList(),
function(index, url) {
// get repos from cache
var cached_repo = RenderJs.Cache.get(url)
var cached_repo = RenderJs.Cache.get(url);
$.each(cached_repo['gadget_list'],
function(index, gadget) {
if (jQuery.inArray(service, gadget["service_list"]) > -1) {
......
......@@ -7,6 +7,9 @@
<script src="../lib/qunit/qunit.js" type="text/javascript"></script>
<script type="text/javascript" src="../renderjs.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>
<body>
......
......@@ -175,29 +175,41 @@ function setupRenderJSTest(){
module("GadgetCatalog");
test('GadgetCatalog', function () {
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
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)
deepEqual(url_list, RenderJs.GadgetCatalog.getGadgetIndexUrlList());
RenderJs.GadgetCatalog.updateGadgetIndex();
cached = RenderJs.Cache.get(url_list[0]);
equal("HTML WYSIWYG", cached["gadget_list"][0]["title"]);
deepEqual(["edit_html", "view_html"], cached["gadget_list"][0]["service_list"]);
// check that we can find gadgets that provide some service_list
gadget_list = RenderJs.GadgetCatalog.getGadgetListThatProvide("edit_html");
equal("HTML WYSIWYG", gadget_list[0]["title"]);
deepEqual(["edit_html", "view_html"], gadget_list[0]["service_list"]);
gadget_list = RenderJs.GadgetCatalog.getGadgetListThatProvide("view_html");
equal("HTML WYSIWYG", gadget_list[0]["title"]);
deepEqual(["edit_html", "view_html"], gadget_list[0]["service_list"]);
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"));
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]);
equal("HTML WYSIWYG", cached["gadget_list"][0]["title"]);
deepEqual(["edit_html", "view_html"], cached["gadget_list"][0]["service_list"]);
// check that we can find gadgets that provide some service_list
gadget_list = RenderJs.GadgetCatalog.getGadgetListThatProvide("edit_html");
equal("HTML WYSIWYG", gadget_list[0]["title"]);
deepEqual(["edit_html", "view_html"], gadget_list[0]["service_list"]);
gadget_list = RenderJs.GadgetCatalog.getGadgetListThatProvide("view_html");
equal("HTML WYSIWYG", gadget_list[0]["title"]);
deepEqual(["edit_html", "view_html"], gadget_list[0]["service_list"]);
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