Commit 5ab6b025 authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

QUnit&Sinon.js localStorage complete (todo simplify tests).

Local storage save document bugs fixed.
parent f32b249f
......@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<title>JIO QUnit Test</title>
<title>JIO QUnit/Sinon Test</title>
<link rel="stylesheet" href="qunit/qunit-1.5.0.css" />
</head>
<body>
......@@ -12,6 +12,8 @@
<script type="text/javascript" src="unhosted/jio.js"></script>
<script type="text/javascript" src="unhosted/base64.js"></script>
<script type="text/javascript" src="unhosted/jio.storage.js"></script>
<script type="text/javascript" src="sinon/sinon-1.3.4.js"></script>
<script type="text/javascript" src="sinon/sinon-qunit-1.0.0.js"></script>
<script type="text/javascript" src="jiotests.js"></script>
</body>
</html>
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
/**
* sinon-qunit 1.0.0, 2010/12/09
*
* @author Christian Johansen (christian@cjohansen.no)
*
* (The BSD License)
*
* Copyright (c) 2010-2011, Christian Johansen, christian@cjohansen.no
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Christian Johansen nor the names of his contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*global sinon, QUnit, test*/
sinon.assert.fail = function (msg) {
QUnit.ok(false, msg);
};
sinon.assert.pass = function (assertion) {
QUnit.ok(true, assertion);
};
sinon.config = {
injectIntoThis: true,
injectInto: null,
properties: ["spy", "stub", "mock", "clock", "sandbox"],
useFakeTimers: true,
useFakeServer: false
};
(function (global) {
var qTest = QUnit.test;
QUnit.test = global.test = function (testName, expected, callback, async) {
if (arguments.length === 2) {
callback = expected;
expected = null;
}
return qTest(testName, expected, sinon.test(callback), async);
};
}(this));
This diff is collapsed.
......@@ -25,6 +25,10 @@
'start_event':'start_loading',
'stop_event':'stop_loading',
'retvalue':'fileContent' }, // returns the file content 'string'
'getDocument': {
'start_event':'start_gettingDocument',
'stop_event':'stop_gettingDocument',
'retvalue':'document' }, // returns the document object
'getDocumentList': {
'start_event':'start_gettingList',
'stop_event':'stop_gettingList',
......@@ -600,7 +604,7 @@
// or in the storage set at init. At the end of the job,
// 'job_done' will be sent with this job and its 'isAvailable'
// return value.
// options.storage : the storage where to remove (optional)
// options.storage : the storage where to check (optional)
// options.applicant : the applicant (optional)
// options.callback(result) : called to get the result.
......@@ -628,7 +632,7 @@
// Load a document in the storage set in [options]
// or in the storage set at init. At the end of the job,
// 'job_done' will be sent with this job.
// options.storage : the storage where to remove (optional)
// options.storage : the storage where to save (optional)
// options.applicant : the applicant (optional)
// options.callback(result) : called to get the result.
......@@ -658,13 +662,14 @@
// or in the storage set at init. At the end of the job,
// 'job_done' will be sent with this job and its 'fileContent'
// return value.
// options.storage : the storage where to remove (optional)
// options.storage : the storage where to load (optional)
// options.applicant : the applicant (optional)
// options.callback(result) : called to get the result.
// jio.loadDocument({'fileName':'file','callback':
// function (result) { alert('content: '+
// result.fileContent); }});
// result.doc.fileContent + ' creation date: ' +
// result.doc.creationDate); }});
console.log ('load');
if (!this.isReady()) return null;
......@@ -676,19 +681,15 @@
},options);
// check dependencies
if ( settings.fileName && settings.storage && settings.applicant) {
return jioGlobalObj.queue.addJob ( new Job ( settings ) );
return this.queue.addJob ( new Job ( settings ) );
}
return null;
},
getDocument: function ( options ) {
// TODO (don't forgot to add this method to constants)
},
getDocumentList: function ( options ) {
// Get a document list of the user in the storage set in [options]
// or in the storage set at init.
// options.storage : the storage where to remove (optional)
// options.storage : the storage where to get the list (optional)
// options.applicant : the applicant (optional)
// options.callback(result) : called to get the result.
......
......@@ -34,6 +34,10 @@
// if the name already exists, it is not available.
// job: the job object
// job.userName: the name we want to check.
// jobendcallback : the function called at the end of the job.
// returns {'status':string,'message':string,'isAvailable':boolean}
// in the jobendcallback arguments.
// wait a little in order to simulate asynchronous operation
setTimeout(function () {
......@@ -73,6 +77,10 @@
// job.options.overwrite : true -> overwrite
// job.options.force : true -> save even if jobdate < existingdate
// or overwrite: false
// jobendcallback : the function called at the end of the job.
// returns {'status':string,'message':string,'isSaved':boolean}
// in the jobendcallback arguments.
var settings = $.extend({'overwrite':true,
'force':false},job.options);
......@@ -88,8 +96,8 @@
doc = {
'fileName': job.fileName,
'fileContent': job.fileContent,
'creationDate': Date.now (),
'lastModified': Date.now ()
'creationDate': job.lastModified,
'lastModified': job.lastModified
}
// writing
jioGlobalObj.localStorage.setItem(
......@@ -119,7 +127,7 @@
return;
}
// overwriting
doc.lastModified = Date.now();
doc.lastModified = job.lastModified;
doc.fileContent = job.fileContent;
// writing
jioGlobalObj.localStorage.setItem(
......@@ -145,8 +153,16 @@
}, // end saveDocument
loadDocument: function ( job, jobendcallback ) {
// load a document in the storage, copy the content into the job
// job : the job
// Load a document from the storage. It returns a document object
// containing all information of the document and its content.
// job : the job object
// job.fileName : the document name we want to load.
// jobendcallback : the function called at the end of the job.
// returns {'status':string,'message':string,'document':object}
// in the jobendcallback arguments.
// document object is {'fileName':string,'fileContent':string,
// 'creationDate':date,'lastModified':date}
var t = this;
// wait a little in order to simulate asynchronous operation
......@@ -164,7 +180,11 @@
} else {
res.status = job.status = 'done';
res.message = 'Document loaded.';
res.fileContent = doc.fileContent;
res.document = {
'fileContent': doc.fileContent,
'fileName': doc.fileName,
'creationDate': doc.creationDate,
'lastModified': doc.lastModified};
jobendcallback(job);
job.callback(res);
}
......@@ -172,6 +192,17 @@
}, // end loadDocument
getDocumentList: function ( job, jobendcallback) {
// Get a document list from the storage. It returns a document
// array containing all the user documents informations, but not
// their content.
// job : the job object
// jobendcallback : the function called at the end of the job.
// returns {'status':string,'message':string,'list':array}
// in the jobendcallback arguments.
// the list is [object,object] -> object = {'fileName':string,
// 'lastModified':date,'creationDate':date}
var t = this;
setTimeout(function () {
var res = {};
......@@ -198,6 +229,13 @@
}, // end getDocumentList
removeDocument: function ( job, jobendcallback ) {
// Remove a document from the storage.
// job : the job object
// jobendcallback : the function called at the end of the job.
// returns {'status':string,'message':string,'isRemoved':boolean}
// in the jobendcallback arguments.
var t = this;
setTimeout (function () {
var res = {};
......@@ -228,7 +266,7 @@
}
};
// add key to storageObject
// add key to storageObjectType of global jio
Jio.addStorageType('local', function (options) {
return new LocalStorage(options);
});
......
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