Commit 99599cba authored by Thibaut Frain's avatar Thibaut Frain

Added jslint tests and qunit tests

parent 403dada0
module.exports = function(grunt) {
"use strict";
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jslint: {
client: {
src: [
'lib/presentation-editor.js'
],
directives: {
browser: true,
maxlen: 100,
indent: 2,
maxerr: 3,
unparam: true,
plusplus: true,
predef: [
'window',
'document',
'$',
'html_beautify'
]
}
}
}
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-jslint');
// Default task(s).
grunt.registerTask('default', ['jslint']);
};
......@@ -18,5 +18,8 @@
"jquery-mobile": "1.4.0",
"jquery-ui": "1.10.3",
"js-beautify": "1.4.2"
},
"devDependencies": {
"qunit": "1.14.0"
}
}
......@@ -7,5 +7,10 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
"license": "ISC",
"devDependencies": {
"grunt": "0.4.2",
"grunt-jslint": "1.1.2",
"grunt-contrib-qunit": "0.4.0"
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test Presentation Gadget</title>
<link rel="stylesheet" href="../bower_components/qunit/qunit/qunit.css">
<!-- Jquery -->
<script src="../lib/jquery.min.js"></script>
<!-- Renderjs -->
<script src="../lib/rsvp.min.js"></script>
<script src="../lib/jschannel.js"></script>
<script src="../lib/renderjs.js"></script>
<!-- Qunit tests -->
<script src="../bower_components/qunit/qunit/qunit.js"></script>
<script src="presentation-editor-test.js"></script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<div id="test-jqs"></div>
</body>
</html>
/*global window, document, QUnit, jQuery, RenderJSGadget*/
(function ($, QUnit, RenderJSGadget) {
"use strict";
QUnit.config.testTimeout = 10000;
var asyncTest = QUnit.asyncTest,
start = QUnit.start,
equal = QUnit.equal,
presentationEditorURL = '../index.html';
function ifr$(selector) {
return $('iframe').contents().find(selector);
}
asyncTest("[Presentation editor] set title slide (iframed)", 1, function () {
var g = new RenderJSGadget(),
gadgetContext = document.getElementById('qunit-fixture');
g.declareGadget(presentationEditorURL,
{sandbox: "iframe", element: gadgetContext})
.then(function (gadget){
var content = "<section><h1>TestTitle</h1></section>";
return gadget.setContent(content);
})
.then(function (){
var expected = ifr$("#slide-list section h1")[0].textContent;
equal(expected, "TestTitle");
})
.always(start);
});
}(jQuery, QUnit, RenderJSGadget));
/*jslint indent: 2, maxlen: 80 */
/*global require, phantom, document, setInterval, clearInterval, console */
(function () {
"use strict";
var system = require('system'), page;
/**
* Wait until the test condition is true or a timeout occurs. Useful for
* waiting on a server response or for a ui change (fadeIn, etc.) to occur.
*
* @method waitFor
* @param {Function} testFx Condition that evaluates to a boolean
* @param {Function} onReady What to do when testFx condition is fulfilled
* @param {Number} time_out_millis The max amount of time to wait.
* If not specified, 10 sec is used.
*/
function waitFor(testFx, onReady, time_out_millis) {
var maxtime_out_millis, start, condition, interval;
maxtime_out_millis = time_out_millis || 300000;
start = new Date().getTime();
condition = false;
interval = setInterval(function () {
if ((new Date().getTime() - start < maxtime_out_millis) && !condition) {
// If not time-out yet and condition not yet fulfilled
condition = testFx();
} else {
if (!condition) {
// If condition still not fulfilled (timeout but condition is 'false')
console.log("'waitFor()' timeout");
phantom.exit(1);
} else {
// Condition fulfilled (timeout and/or condition is 'true')
console.log("'waitFor()' finished in " +
(new Date().getTime() - start) + "ms.");
onReady();
clearInterval(interval); //< Stop this interval
}
}
}, 100); //< repeat check every 100ms
}
if (system.args.length !== 2) {
console.log('Usage: run-qunit.js URL');
phantom.exit(1);
}
page = require('webpage').create();
// Route "console.log()" calls from within the Page context to the main
// Phantom context (i.e. current "this")
page.onConsoleMessage = function (msg) {
console.log(msg);
};
page.open(system.args[1], function (status) {
if (status !== "success") {
console.log("Unable to access network");
phantom.exit(1);
}
waitFor(function () {
return page.evaluate(function () {
var el = document.getElementById('qunit-testresult');
if (el && el.innerText.match('completed')) {
return true;
}
return false;
});
}, function () {
var failedNum = page.evaluate(function () {
console.log("========================================================");
console.log(document.documentElement.innerHTML);
console.log("========================================================");
var el = document.getElementById('qunit-testresult');
console.log(el.innerText);
try {
return el.getElementsByClassName('failed')[0].innerHTML;
} catch (ignore) { }
return 10000;
});
phantom.exit((parseInt(failedNum, 10) > 0) ? 1 : 0);
});
});
}());
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