Commit fe765144 authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

Adding Indexed storage + qunit tests.

parent 10a18668
/*! JIO - v0.1.0 - 2012-05-29
/*! JIO - v0.1.0 - 2012-06-01
* Copyright (c) 2012 Nexedi; Licensed */
var JIO =
(function () { var jio_loader_function = function ( localOrCookieStorage, $ ) {
......@@ -169,13 +168,6 @@ var JIO =
////////////////////////////////////////////////////////////////////////////
// Tools
extend = function (o1,o2) {
var key;
for (key in o2) {
o1[key] = o2[key];
}
return o1;
},
// end Tools
////////////////////////////////////////////////////////////////////////////
......@@ -229,7 +221,7 @@ var JIO =
newJob = function ( spec, my ) {
// Job constructor
var job = extend({},spec);
var job = $.extend(true,{},spec);
job['id']=0;
job['status']='initial';
job['date']=Date.now();
......@@ -441,8 +433,8 @@ var JIO =
// options.job = the job object containing at least {id:..}.
// options.where = remove values where options.where(job) === true
var settings = extend ({where:function (job) {return true;}},
options),andwhere,found=false,k='key';
var settings = $.extend ({where:function (job) {return true;}},
options),andwhere,found=false,k='key';
//// modify the job list
if (settings.job) {
......@@ -556,7 +548,7 @@ var JIO =
// It is a callback function called just before user callback.
// It is called to manage job_object according to the ended job.
var job = extend({},endedjob); // copy
var job = $.extend(true,{},endedjob); // copy
// This job is supposed terminated, we can remove it from queue.
that.removeJob ({'job':job});
......@@ -800,7 +792,7 @@ var JIO =
//// Getters Setters
that.cloneJob = function () {
return extend({},priv.job);
return $.extend(true,{},priv.job);
};
that.getUserName = function () {
return priv.job.userName || '';
......@@ -817,6 +809,9 @@ var JIO =
that.getStorageLocation = function () {
return priv.job.storage.location || '';
};
that.getSecondStorage = function () {
return priv.job.storage.storage || {};
};
that.getStorageArray = function () {
return priv.job.storage.storageArray || [];
};
......@@ -827,7 +822,7 @@ var JIO =
return priv.job.fileContent || '';
};
that.cloneOptionObject = function () {
return extend({},priv.job.options);
return $.extend(true,{},priv.job.options);
};
that.getMaxTries = function () {
return priv.job.maxtries;
......@@ -1146,7 +1141,7 @@ var JIO =
// } else { } // Error
// }});
var settings = extend ({
var settings = $.extend (true,{
'userName': priv.storage.userName,
'storage': priv.storage,
'applicant': priv.applicant,
......@@ -1179,7 +1174,7 @@ var JIO =
// } else { } // Error
// }});
var settings = extend({
var settings = $.extend(true,{
'storage': priv.storage,
'applicant': priv.applicant,
'fileContent': '',
......@@ -1217,7 +1212,7 @@ var JIO =
// fileName:'string',fileContent:'string',
// creationDate:123,lastModified:456 }
var settings = extend ({
var settings = $.extend (true,{
'storage': priv.storage,
'applicant': priv.applicant,
'method':'loadDocument',
......@@ -1251,7 +1246,7 @@ var JIO =
// result.return_value is an Array that contains documents objects.
var settings = extend ({
var settings = $.extend (true,{
'storage': priv.storage,
'applicant': priv.applicant,
'method':'getDocumentList',
......@@ -1281,7 +1276,7 @@ var JIO =
// } else { } // Not Removed
// }});
var settings = extend ({
var settings = $.extend (true,{
'storage': priv.storage,
'applicant': priv.applicant,
'method':'removeDocument',
......@@ -1296,7 +1291,7 @@ var JIO =
//// end Methods
//// Initialize
var settings = extend({'use_local_storage':true},spec.options);
var settings = $.extend(true,{'use_local_storage':true},spec.options);
// objectify storage and applicant
if(typeof spec.storage === 'string') {
......@@ -1349,7 +1344,7 @@ var JIO =
// applicant: the applicant object or json string
// options.useLocalStorage: if true, save job queue on localStorage.
var settings = extend({'use_local_storage':true},options);
var settings = $.extend(true,{'use_local_storage':true},options);
return newJioConstructor({storage:storage,
applicant:applicant,
......@@ -1380,7 +1375,7 @@ var JIO =
};
that.getConstObject = function () {
// Returns a copy of the constants
return extend({},jio_const_obj);
return $.extend(true,{},jio_const_obj);
};
return that;
};
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -871,6 +871,136 @@ test ('Remove document', function () {
mytest('DummyStorageAllOK,3tries: remove document.','done');
o.jio.stop();
});
module ('Jio IndexedStorage');
test ('Check name availability', function () {
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (message,value) {
o.f = function (result) {
deepEqual (result.return_value,value,message);};
t.spy(o,'f');
o.jio.checkNameAvailability({userName:'MrIndexedCheck',
callback:o.f,maxtries:3});
clock.tick(100000);
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
}
};
o.jio=JIO.createNew({type:'indexed',
storage:{type:'dummyall3tries',
userName:'indexedcheck'}},
{ID:'jiotests'});
mytest('dummy ok : name must be available', true);
o.jio.stop();
});
test ('Document load', function () {
var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.createNew({type:'indexed',
storage:{type:'dummyall3tries',
userName:'indexedload'}},
{ID:'jiotests'});
// loading must take long time with dummyall3tries
o.f = function () {};
this.spy(o,'f');
o.jio.loadDocument({fileName:'memo',maxtries:3,callback:o.f,
options:{metadata_only:true}});
clock.tick(500);
ok(!o.f.calledOnce,'Callback must not be called');
// wait long time too retreive list
clock.tick(100000);
// now we can test if the document metadata are loaded faster.
o.doc = {fileName:'memo',lastModified:25000,creationDate:20000};
o.f2 = function (result) {
deepEqual (result.return_value,o.doc,'Document metadata retrieved');
};
this.spy(o,'f2');
o.jio.loadDocument({fileName:'memo',maxtries:3,callback:o.f2,
options:{metadata_only:true}});
clock.tick(500);
if (!o.f2.calledOnce) {
ok (false, 'no response / too much results');
}
// test a simple document loading
o.doc2 = {fileName:'file',lastModified:17000,
creationDate:11000,fileContent:'content2'};
o.f3 = function (result) {
deepEqual (result.return_value,o.doc2,'Simple document loading');
};
this.spy(o,'f3');
o.jio.loadDocument({fileName:'file',maxtries:3,callback:o.f3});
clock.tick(100000);
if (!o.f3.calledOnce) {
ok (false, 'no response / too much results');
}
o.jio.stop();
});
test ('Document save', function () {
var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.createNew({type:'indexed',
storage:{type:'dummyall3tries',
userName:'indexedsave'}},
{ID:'jiotests'});
o.f = function (result) {
deepEqual (result.status,'done','document save');
};
this.spy(o,'f');
o.jio.saveDocument({fileName:'file',maxtries:3,callback:o.f});
clock.tick(100000);
if (!o.f.calledOnce){
ok (false, 'no response / too much results');
}
o.jio.stop();
});
test ('Get document list', function () {
var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.createNew({type:'indexed',
storage:{type:'dummyall3tries',
userName:'indexedgetlist'}},
{ID:'jiotests'});
o.doc1 = {fileName:'file',lastModified:15000,creationDate:10000};
o.doc2 = {fileName:'memo',lastModified:25000,creationDate:20000};
// getting list must take long time with dummyall3tries
o.f = function () {};
this.spy(o,'f');
o.jio.getDocumentList({maxtries:3,callback:o.f});
clock.tick(500);
ok(!o.f.calledOnce,'Callback must not be called');
// wail long time too retreive list
clock.tick(100000);
// now we can test if the document list is loaded faster
o.f2 = function (result) {
deepEqual (result.return_value,[o.doc1,o.doc2],'get document list');
};
this.spy(o,'f2');
o.jio.getDocumentList({maxtries:3,callback:o.f2});
clock.tick(500);
if (!o.f2.calledOnce) {
ok (false, 'no response / too much results');
}
});
test ('Remove document', function () {
var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.createNew({type:'indexed',
storage:{type:'dummyall3tries',
userName:'indexedsave'}},
{ID:'jiotests'});
o.f = function (result) {
deepEqual (result.status,'done','document remove');
};
this.spy(o,'f');
o.jio.removeDocument({fileName:'file',maxtries:3,callback:o.f});
clock.tick(100000);
if (!o.f.calledOnce){
ok (false, 'no response / too much results');
}
o.jio.stop();
});
// end require
}; // end thisfun
......
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