Commit 14a89b18 authored by Thibaut Frain's avatar Thibaut Frain

Jquery.sheet gadget test + functionnality refactoring

parent daf15026
/*global jQuery, window, document, jIO, confirm, alert */ /*global jQuery, window, document, jIO, confirm, alert */
/*jslint nomen: true */ /*jslint nomen: true, todo: true, unparam: true */
"use strict"; "use strict";
(function (window, document, $, jIO) { (function (window, document, $, jIO) {
...@@ -222,11 +222,11 @@ ...@@ -222,11 +222,11 @@
* @return {string} The property value * @return {string} The property value
*/ */
// NOTE: need a different way because this triggers a ton of http requests! // NOTE: need a different way because this triggers a ton of http requests!
priv.getERP5property = function (id, lookup) { // priv.getERP5property = function (id, lookup) {
var key = id + "/" + lookup; // var key = id + "/" + lookup;
// return $.ajax(priv.makeAjaxObject(key)); // // return $.ajax(priv.makeAjaxObject(key));
return {"error": "foo"}; // return {"error": "foo"};
}; // };
/** /**
...@@ -244,9 +244,9 @@ ...@@ -244,9 +244,9 @@
* Create a checkbox to select table rows * Create a checkbox to select table rows
* @method createCheckbox * @method createCheckbox
*/ */
priv.createCheckbox = function () { // priv.createCheckbox = function () {
}; // };
/** /**
* Create full table * Create full table
...@@ -273,7 +273,7 @@ ...@@ -273,7 +273,7 @@
console.log(response); console.log(response);
var i, var i,
j, j,
k, // k,
l, l,
// table setup // table setup
fragment_container, fragment_container,
...@@ -293,7 +293,7 @@ ...@@ -293,7 +293,7 @@
configure_slot, configure_slot,
pagination_elements, pagination_elements,
pagination_label, pagination_label,
pagination_number_of_items, // pagination_number_of_items,
pagination_link, pagination_link,
pagination_clone, pagination_clone,
pagination_option, pagination_option,
...@@ -301,7 +301,7 @@ ...@@ -301,7 +301,7 @@
pagination_slot, pagination_slot,
// table // table
table, table,
table_head, // table_head,
table_row, table_row,
table_body, table_body,
table_tick_label, table_tick_label,
...@@ -309,7 +309,7 @@ ...@@ -309,7 +309,7 @@
table_cell, table_cell,
table_header, table_header,
table_header_cell, table_header_cell,
fields, // fields,
property, property,
cell, cell,
row, row,
...@@ -815,31 +815,31 @@ ...@@ -815,31 +815,31 @@
* @param {string} item Element to show * @param {string} item Element to show
*/ */
// NOTE: this should be in another gadget/file // NOTE: this should be in another gadget/file
priv.generateItem = function (mode, item) { // priv.generateItem = function (mode, item) {
if (item) { // if (item) {
// fetch data // // fetch data
priv.erp5.get({"_id": item}, function (error, response) { // priv.erp5.get({"_id": item}, function (error, response) {
var property, value, abort; // var property, value, abort;
if (response) { // if (response) {
for (property in response) { // for (property in response) {
if (response.hasOwnProperty(property)) { // if (response.hasOwnProperty(property)) {
value = response[property]; // value = response[property];
priv.setValue(response.type.toLowerCase(), property, value); // priv.setValue(response.type.toLowerCase(), property, value);
} // }
} // }
} else { // } else {
abort = confirm( // abort = confirm(
"Error trying to retrieve data! Go back to overview?" // "Error trying to retrieve data! Go back to overview?"
); // );
if (abort === true) { // if (abort === true) {
$.mobile.changePage("computers.html"); // $.mobile.changePage("computers.html");
} // }
} // }
}); // });
} // }
}; // };
/** /**
* Create a serialized object from all values in the form * Create a serialized object from all values in the form
...@@ -1005,7 +1005,6 @@ ...@@ -1005,7 +1005,6 @@
return $.mobile.path.parseUrl(path).search.slice(1).split("&"); return $.mobile.path.parseUrl(path).search.slice(1).split("&");
}; };
// BINDINGS // BINDINGS
// NOTE: done in a hurry... // NOTE: done in a hurry...
$(document).on("pagebeforeshow", "#computers", function () { $(document).on("pagebeforeshow", "#computers", function () {
...@@ -1133,4 +1132,5 @@ ...@@ -1133,4 +1132,5 @@
// // select all // // select all
// .on("change", "table thead th input[type=checkbox]", function (e) { // .on("change", "table thead th input[type=checkbox]", function (e) {
}); });
}(window, document, jQuery, jIO)); }(window, document, jQuery, jIO));
/*global window, jQuery, rJS */ /*global window, jQuery, rJS */
"use strict"; "use strict";
(function (window, $, rJS, undefined) { (function (window, $, rJS) {
$.mobile.ajaxEnabled = false; $.mobile.ajaxEnabled = false;
$.mobile.linkBindingEnabled = false; $.mobile.linkBindingEnabled = false;
...@@ -15,12 +15,7 @@ ...@@ -15,12 +15,7 @@
"username": "officejs", "username": "officejs",
"application_name": "officejs" "application_name": "officejs"
}, },
jioGadget, jioGadget;
jqsGadget;
function log(x) {
console.log(x);
}
function setTitle(title) { function setTitle(title) {
g.context.find("#headergadget").find("h1").text(title); g.context.find("#headergadget").find("h1").text(title);
......
/*global window, jQuery, rJS*/ /*global window, jQuery, rJS*/
"use strict"; "use strict";
(function (window, $, rJS) {
var gk = rJS(window), (function (window, $, rJS) {
default_config = {
id: "jquerysheet-div",
style: '',
jquerySheet: true,
jquerySheetCss: true,
parser: true,
jqueryUiCss: true,
scrollTo: false,
jQueryUI: false,
raphaelJs: false,
gRaphaelJs: false,
colorPicker: false,
colorPickerCss: false,
elastic: false,
advancedMath: false,
finance: false,
editable: true,
autoFiller: true,
urlGet: '../lib/jquery.sheet-2.0.0/new_spreadsheet.html'
};
gk.declareMethod('init', function (config) { function init(config) {
rJS(this).parent = rJS(this).context.find('.jQuerySheet'); this.parent = this.context.find('.jQuerySheet');
rJS(this).parent.sheet(config); this.parent.sheet(config);
rJS(this).updateInstance(); this.instance = this.parent.getSheet();
}
var default_config = {
id: "jquerysheet-div",
style: '',
jquerySheet: true,
jquerySheetCss: true,
parser: true,
jqueryUiCss: true,
scrollTo: false,
jQueryUI: false,
raphaelJs: false,
gRaphaelJs: false,
colorPicker: false,
colorPickerCss: false,
elastic: false,
advancedMath: false,
finance: false,
editable: true,
autoFiller: true,
urlGet: '../lib/jquery.sheet-2.0.0/new_spreadsheet.html'
};
rJS(window).declareMethod('getContent', function () {
var content = JSON.stringify($.sheet.instance[0].exportSheet.json());
//console.log("getContent: " + content);
console.log("function getContent" + content);
return content;
}) })
.declareMethod('getContent', function () {
var content = JSON.stringify($.sheet.instance[0].exportSheet.json());
//console.log("getContent: " + content);
console.log("function getContent" + content);
return content;
})
.declareMethod('putContent', function (content) { .declareMethod('putContent', function (content) {
var config = $.extend({ var config = $.extend({
buildSheet: $.sheet.makeTable.json(JSON.parse(content)) buildSheet: $.sheet.makeTable.json(JSON.parse(content))
...@@ -49,16 +49,8 @@ ...@@ -49,16 +49,8 @@
rJS(this).init(default_config); rJS(this).init(default_config);
}) })
.declareMethod('updateInstance', function () {
rJS(this).instance = rJS(this).parent.getSheet();
})
.declareMethod('getParent', function () {
return rJS(this).parent;
})
.ready(function () { .ready(function () {
rJS(this).init(default_config); init.apply(rJS(this), default_config);
}); });
}(window, jQuery, rJS)); }(window, jQuery, rJS));
...@@ -18,6 +18,6 @@ ...@@ -18,6 +18,6 @@
<body> <body>
<div id="qunit"></div> <div id="qunit"></div>
<div id="qunit-fixture"></div> <div id="qunit-fixture"></div>
<div class="jqs-gadget"></div> <div class="jqs-gadget" style="display:none;"></div>
</body> </body>
</html> </html>
...@@ -2,17 +2,18 @@ ...@@ -2,17 +2,18 @@
/*jslint indent: 2, maxerr: 3, maxlen: 79 */ /*jslint indent: 2, maxerr: 3, maxlen: 79 */
"use strict"; "use strict";
QUnit.config.testTimeout = 500; QUnit.config.testTimeout = 1000;
(function (window, $, QUnit, sinon, rJS) { (function (window, $, QUnit, rJS) {
var test = QUnit.test, //var test = QUnit.test,
stop = QUnit.stop, var asyncTest = QUnit.asyncTest,
start = QUnit.start, //stop = QUnit.stop,
ok = QUnit.ok, start = QUnit.start,
equal = QUnit.equal, ok = QUnit.ok,
expect = QUnit.expect, equal = QUnit.equal,
throws = QUnit.throws, expect = QUnit.expect;
deepEqual = QUnit.deepEqual; //throws = QUnit.throws,
//deepEqual = QUnit.deepEqual;
function iframeSelector(selectorString) { function iframeSelector(selectorString) {
return $('iframe').contents().find(selectorString); return $('iframe').contents().find(selectorString);
...@@ -37,14 +38,18 @@ QUnit.config.testTimeout = 500; ...@@ -37,14 +38,18 @@ QUnit.config.testTimeout = 500;
expect(2); expect(2);
g.declareIframedGadget('../src/gadget/jqs.html', jqs_context) g.declareIframedGadget('../src/gadget/jqs.html', jqs_context)
.then(function (gadget) { .then(function (gadget) {
iframeSelector("table.jSheet td#0_table0_cell_c0_r0").html('c0r0Value'); iframeSelector("table.jSheet td#0_table0_cell_c0_r0")
iframeSelector("table.jSheet td#0_table0_cell_c1_r1").html('c1r1Value'); .html('c0r0Value');
iframeSelector("table.jSheet td#0_table0_cell_c1_r1")
.html('c1r1Value');
return gadget; return gadget;
}) })
.then(function (gadget) { .then(function (gadget) {
gadget.resetSheet().then(function () { gadget.resetSheet().then(function () {
equal(iframeSelector("table.jSheet td#0_table0_cell_c0_r0").text(),""); equal(iframeSelector(
equal(iframeSelector("table.jSheet td#0_table0_cell_c1_r1").text(),""); "table.jSheet td#0_table0_cell_c0_r0").text(),"");
equal(iframeSelector(
"table.jSheet td#0_table0_cell_c1_r1").text(),"");
start(); start();
}); });
}); });
...@@ -52,11 +57,12 @@ QUnit.config.testTimeout = 500; ...@@ -52,11 +57,12 @@ QUnit.config.testTimeout = 500;
asyncTest("get content of sheet", function () { asyncTest("get content of sheet", function () {
expect(2); expect(2);
var c0r0selector, c1r1selector;
g.declareIframedGadget('../src/gadget/jqs.html', jqs_context) g.declareIframedGadget('../src/gadget/jqs.html', jqs_context)
.then(function (gadget) { .then(function (gadget) {
iframeSelector("table.jSheet td#0_table0_cell_c0_r0").html('c0r0Value'); iframeSelector(
iframeSelector("table.jSheet td#0_table0_cell_c1_r1").html('c1r1Value'); "table.jSheet td#0_table0_cell_c0_r0").html('c0r0Value');
iframeSelector(
"table.jSheet td#0_table0_cell_c1_r1").html('c1r1Value');
return gadget; return gadget;
}) })
.then(function (gadget) { .then(function (gadget) {
...@@ -75,8 +81,10 @@ QUnit.config.testTimeout = 500; ...@@ -75,8 +81,10 @@ QUnit.config.testTimeout = 500;
g.declareIframedGadget('../src/gadget/jqs.html', jqs_context) g.declareIframedGadget('../src/gadget/jqs.html', jqs_context)
.then(function (gd) { .then(function (gd) {
iframeSelector("table.jSheet td#0_table0_cell_c0_r0").html('c0r0Value'); iframeSelector(
iframeSelector("table.jSheet td#0_table0_cell_c1_r1").html('c1r1Value'); "table.jSheet td#0_table0_cell_c0_r0").html('c0r0Value');
iframeSelector(
"table.jSheet td#0_table0_cell_c1_r1").html('c1r1Value');
gadget = gd; gadget = gd;
}) })
.always(function () { .always(function () {
...@@ -84,14 +92,20 @@ QUnit.config.testTimeout = 500; ...@@ -84,14 +92,20 @@ QUnit.config.testTimeout = 500;
.then(function (c) {content = c;}) .then(function (c) {content = c;})
.always(function () { .always(function () {
gadget.resetSheet().then(function () { gadget.resetSheet().then(function () {
equal(iframeSelector("table.jSheet td#0_table0_cell_c0_r0").text(),""); equal(iframeSelector(
equal(iframeSelector("table.jSheet td#0_table0_cell_c1_r1").text(),""); "table.jSheet td#0_table0_cell_c0_r0").text(),"");
equal(iframeSelector(
"table.jSheet td#0_table0_cell_c1_r1").text(),"");
}) })
.always(function () { .always(function () {
gadget.putContent(content) gadget.putContent(content)
.always(function () { .always(function () {
equal(iframeSelector("table.jSheet td#2_table0_cell_c0_r0").text(),"c0r0Value"); equal(iframeSelector(
equal(iframeSelector("table.jSheet td#2_table0_cell_c1_r1").text(),"c1r1Value"); "table.jSheet td#2_table0_cell_c0_r0").text(),
"c0r0Value");
equal(iframeSelector(
"table.jSheet td#2_table0_cell_c1_r1").text(),
"c1r1Value");
start(); start();
}); });
}); });
...@@ -99,5 +113,5 @@ QUnit.config.testTimeout = 500; ...@@ -99,5 +113,5 @@ QUnit.config.testTimeout = 500;
}); });
}); });
}); });
} (window, jQuery, QUnit, sinon, rJS)); } (window, jQuery, QUnit, rJS));
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