Commit db32744f authored by Thibaut Frain's avatar Thibaut Frain

Refactoring and adding some Jquery.sheet tests

parent 14a89b18
...@@ -83,6 +83,14 @@ ...@@ -83,6 +83,14 @@
<h3>Spreadsheet</h3> <h3>Spreadsheet</h3>
</a> </a>
</li> </li>
<li data-role="list-divider">New document</li>
<li class="listview_item listview_icon">
<a href="#/bootstrap-wysiwyg/">
<span class="ui-li-icon ui-li-icon-custom ui-icon-folder-open-alt ui-icon"
>&nbsp;</span>
<h3>Bootstrap-wysiwyg</h3>
</a>
</li>
<li data-role="list-divider">General</li> <li data-role="list-divider">General</li>
<li class="listview_item listview_icon"> <li class="listview_item listview_icon">
<a href="#/about/"> <a href="#/about/">
......
...@@ -44,17 +44,23 @@ ...@@ -44,17 +44,23 @@
var fileName = $("#iogadget input").val(); var fileName = $("#iogadget input").val();
jioGadget.configureIO(ioGadgetConfig, fileName) jioGadget.configureIO(ioGadgetConfig, fileName)
.then(jioGadget.getIO) .then(jioGadget.getIO)
.then(gadget.putContent); .then(gadget.setContent);
}); });
return gadget; return gadget;
} }
function registerCleanButton(gadget) { function registerClearButton(gadget) {
$("#new-doc").click(function () { $("#new-doc").click(function () {
gadget.resetSheet(); gadget.clearContent();
}); });
} }
function registerIOButtons(gadget) {
registerSaveButton(gadget);
registerLoadButton(gadget);
registerClearButton(gadget);
}
function initializeRoute() { function initializeRoute() {
body body
.route("add", "", 1) .route("add", "", 1)
...@@ -87,9 +93,14 @@ ...@@ -87,9 +93,14 @@
.route("add", "/spreadsheet/", 1) .route("add", "/spreadsheet/", 1)
.done(function () { .done(function () {
g.declareIframedGadget('./jqs.html', main_context) g.declareIframedGadget('./jqs.html', main_context)
.then(registerSaveButton) .then(registerIOButtons);
.then(registerLoadButton) });
.then(registerCleanButton);
body
.route("add", "/bootstrap-wysiwyg/", 1)
.done(function () {
g.declareIframedGadget('./bootstrap-wysiwyg.html', main_context)
.then(registerIOButtons);
}); });
} }
......
...@@ -32,25 +32,25 @@ ...@@ -32,25 +32,25 @@
rJS(window).declareMethod('getContent', function () { rJS(window).declareMethod('getContent', function () {
var content = JSON.stringify($.sheet.instance[0].exportSheet.json()); var content = JSON.stringify($.sheet.instance[0].exportSheet.json());
//console.log("getContent: " + content);
console.log("function getContent" + content); console.log("function getContent" + content);
return content; return content;
}) })
.declareMethod('putContent', function (content) { .declareMethod('setContent', function (content) {
var config = $.extend({ var config = $.extend({
buildSheet: $.sheet.makeTable.json(JSON.parse(content)) buildSheet: $.sheet.makeTable.json(JSON.parse(content))
}, default_config); }, default_config);
rJS(this).init(config); console.log(config.buildSheet);
init.apply(rJS(this), [config]);
}) })
.declareMethod('resetSheet', function () { .declareMethod('clearContent', function () {
$.sheet.killAll(); $.sheet.killAll();
rJS(this).init(default_config); init.apply(rJS(this), [default_config]);
}) })
.ready(function () { .ready(function () {
init.apply(rJS(this), default_config); init.apply(rJS(this), [default_config]);
}); });
}(window, jQuery, rJS)); }(window, jQuery, rJS));
...@@ -11,106 +11,116 @@ QUnit.config.testTimeout = 1000; ...@@ -11,106 +11,116 @@ QUnit.config.testTimeout = 1000;
start = QUnit.start, start = QUnit.start,
ok = QUnit.ok, ok = QUnit.ok,
equal = QUnit.equal, equal = QUnit.equal,
expect = QUnit.expect; expect = QUnit.expect,
//throws = QUnit.throws, //throws = QUnit.throws,
//deepEqual = QUnit.deepEqual; //deepEqual = QUnit.deepEqual;
gadgetURL = '../deploy/gadget/jqs.html';
function iframeSelector(selectorString) { function iframeSelector(selectorString) {
return $('iframe').contents().find(selectorString); return $('iframe').contents().find(selectorString);
} }
function buildSelector(n,i,j) {
var res = "table.jSheet td#";
return res+n+"_table0_cell_c"+i+"_r"+j;
}
rJS(window).ready(function () { rJS(window).ready(function () {
var g = rJS(this), var g = rJS(this),
jqs_context = g.context.find('.jqs-gadget').first(); jqs_context = g.context.find('.jqs-gadget').first();
asyncTest("jquery.sheet loading", function () { asyncTest("jquery.sheet loading : sheet loads", 2, function () {
expect(2); g.declareIframedGadget(gadgetURL, jqs_context);
g.declareIframedGadget('../src/gadget/jqs.html', jqs_context);
setTimeout(function () { setTimeout(function () {
ok(iframeSelector("table.jSheet td#0_table0_cell_c0_r0").length != 0); var c0r0 = buildSelector(0,0,0);
ok(iframeSelector("table.jSheet td#0_table0_cell_c1_r1").length != 0); var c1r1 = buildSelector(0,1,1);
ok(iframeSelector(c0r0).length != 0);
ok(iframeSelector(c1r1).length != 0);
start(); start();
},100); },100);
}); });
asyncTest("reset sheet", function () { asyncTest("jquery.sheet loading : sheet is empty", 2, function () {
expect(2); g.declareIframedGadget(gadgetURL, jqs_context);
g.declareIframedGadget('../src/gadget/jqs.html', jqs_context) var c0r0 = buildSelector(0,0,0);
var c1r1 = buildSelector(0,1,1);
setTimeout(function () {
equal(iframeSelector(c0r0).html(),"");
equal(iframeSelector(c1r1).html(),"");
start();
},100);
});
asyncTest("clear content", 2, function () {
var c0r0 = buildSelector(0,0,0);
var c1r1 = buildSelector(0,1,1);
g.declareIframedGadget(gadgetURL, jqs_context)
.then(function (gadget) { .then(function (gadget) {
iframeSelector("table.jSheet td#0_table0_cell_c0_r0") iframeSelector(c0r0).html('c0r0Value');
.html('c0r0Value'); iframeSelector(c1r1).html('c1r1Value');
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 () { return gadget.clearContent().then(function () {
equal(iframeSelector( equal(iframeSelector(c0r0).text(),"");
"table.jSheet td#0_table0_cell_c0_r0").text(),""); equal(iframeSelector(c1r1).text(),"");
equal(iframeSelector(
"table.jSheet td#0_table0_cell_c1_r1").text(),"");
start();
}); });
}); })
.always(start);
}); });
asyncTest("get content of sheet", function () { asyncTest("get content of sheet", 2, function () {
expect(2); var c0r0 = buildSelector(0,0,0);
g.declareIframedGadget('../src/gadget/jqs.html', jqs_context) var c1r1 = buildSelector(0,1,1);
g.declareIframedGadget(gadgetURL, jqs_context)
.then(function (gadget) { .then(function (gadget) {
iframeSelector( iframeSelector(c0r0).html('c0r0Value');
"table.jSheet td#0_table0_cell_c0_r0").html('c0r0Value'); iframeSelector(c1r1).html('c1r1Value');
iframeSelector(
"table.jSheet td#0_table0_cell_c1_r1").html('c1r1Value');
return gadget; return gadget;
}) })
.then(function (gadget) { .then(function (gadget) {
gadget.getContent().then(function (content) { return gadget.getContent().then(function (content) {
var json = JSON.parse(content)[0]; var json = JSON.parse(content)[0];
equal(json.data.r0.c0.value,"c0r0Value"); equal(json.data.r0.c0.value,"c0r0Value");
equal(json.data.r1.c1.value,"c1r1Value"); equal(json.data.r1.c1.value,"c1r1Value");
start();
}); });
}); })
.always(start);
}); });
asyncTest("set content of sheet", function () { asyncTest("set content of sheet", function () {
expect(4); expect(4);
var gadget, content; var gadget, content,
t0c0r0 = buildSelector(0,0,0),
t0c1r1 = buildSelector(0,1,1),
t2c0r0 = buildSelector(2,0,0),
t2c1r1 = buildSelector(2,1,1);
g.declareIframedGadget('../src/gadget/jqs.html', jqs_context) g.declareIframedGadget(gadgetURL, jqs_context)
.then(function (gd) { .then(function (gd) {
iframeSelector( iframeSelector(t0c0r0).html('c0r0Value');
"table.jSheet td#0_table0_cell_c0_r0").html('c0r0Value'); iframeSelector(t0c1r1).html('c1r1Value');
iframeSelector(
"table.jSheet td#0_table0_cell_c1_r1").html('c1r1Value');
gadget = gd; gadget = gd;
return gadget.getContent();
})
.then(function (c) {
content = c;
return gadget.clearContent();
})
.then(function () {
equal(iframeSelector(t0c0r0).text(),"");
equal(iframeSelector(t2c1r1).text(),"");
return gadget.setContent(content);
})
.then(function () {
equal(iframeSelector(t2c0r0).text(),"c0r0Value");
equal(iframeSelector(t2c1r1).text(),"c1r1Value");
}) })
.always(function () { .always(start);
gadget.getContent()
.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(),"");
})
.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");
start();
});
});
});
});
}); });
}); });
} (window, jQuery, QUnit, 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