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