Merge branch 'feature/update-toolchain' into feature/unify-versioninfo

This commit is contained in:
Manuel Friedli 2015-01-18 22:39:58 +01:00
commit 959e4a41aa
5 changed files with 199 additions and 25 deletions

View file

@ -9,14 +9,6 @@
"node" : true,
"jquery" : true,
"predef" : [
"suite",
"test",
"define",
"require"
],
// Development.
"debug" : false, // Allow debugger statements e.g. browser breakpoints.
"devel" : true, // Allow developments statements e.g. `console.log();`.
@ -55,6 +47,6 @@
"plusplus" : false, // Prohibit use of `++` & `--`.
"sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
"trailing" : true, // Prohibit trailing whitespaces.
"white" : false, // Check against strict whitespace and indentation rules.
"white" : true, // Check against strict whitespace and indentation rules.
"indent" : 0 // Specify indentation spacing
}

View file

@ -107,6 +107,9 @@ module.exports = function (grunt) {
src: ['src/**/*.js']
},
test: {
options: {
jshintrc: 'test/.jshintrc'
},
src: ['test/*.js']
}
},

60
test/.jshintrc Normal file
View file

@ -0,0 +1,60 @@
{
// Settings
"passfail" : false, // Stop on first error.
"maxerr" : 100, // Maximum error before stopping.
// Predefined globals whom JSHint will ignore.
"browser" : true, // Standard browser globals e.g. `window`, `document`.
"node" : true,
"jquery" : true,
"predef" : [
"suite",
"chai",
"setup",
"teardown",
"test"
],
// Development.
"debug" : false, // Allow debugger statements e.g. browser breakpoints.
"devel" : true, // Allow developments statements e.g. `console.log();`.
"strict" : true, // Require `use strict` pragma in every file.
"globalstrict" : false, // Allow global "use strict" (also enables 'strict').
// The Good Parts.
"asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons).
"laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
"bitwise" : true, // Prohibit bitwise operators (&, |, ^, etc.).
"boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
"curly" : true, // Require {} for every new block or scope.
"eqeqeq" : true, // Require triple equals i.e. `===`.
"eqnull" : false, // Tolerate use of `== null`.
"evil" : false, // Tolerate use of `eval`.
"expr" : false, // Tolerate `ExpressionStatement` as Programs.
"forin" : false, // Tolerate `for in` loops without `hasOwnPrototype`.
"immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
"latedef" : true, // Prohipit variable use before definition.
"loopfunc" : false, // Allow functions to be defined within loops.
"noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`.
"scripturl" : true, // Tolerate script-targeted URLs.
"shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
"supernew" : false, // Tolerate `new function () { ... };` and `new Object;`.
"undef" : true, // Require all non-global variables be declared before they are used.
// Personal styling preferences.
"newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`.
"noempty" : true, // Prohibit use of empty blocks.
"nonew" : true, // Prohibit use of constructors for side-effects.
"nomen" : true, // Prohibit use of initial or trailing underbars in names.
"onevar" : false, // Allow only one `var` statement per function.
"plusplus" : false, // Prohibit use of `++` & `--`.
"sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
"trailing" : true, // Prohibit trailing whitespaces.
"white" : true, // Check against strict whitespace and indentation rules.
"indent" : 0 // Specify indentation spacing
}

View file

@ -2,11 +2,12 @@
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Test</title>
<title>Test bärneruhr.ch</title>
<link rel="stylesheet" type="text/css" href="css/mocha.css"/>
<link rel="stylesheet" type="text/css" href="../css/uhr.css"/>
<link rel="stylesheet" type="text/css" href="../css/uhr-black.css" data-class="black"/>
<link rel="stylesheet" type="text/css" href="../css/uhr-red.css" data-class="red"/>
<link rel="stylesheet" type="text/css" href="../css/uhr-pink.css" data-class="pink"/>
</head>
<body>
<div id="u"></div>
@ -20,8 +21,8 @@
</script>
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript">
mocha.checkLeaks();
mocha.globals(['jQuery*']);
// mocha.checkLeaks();
// mocha.globals(['jQuery*']);
if (window.mochaPhantomJS) {
mochaPhantomJS.run();
}

View file

@ -1,21 +1,139 @@
suite('Bärneruhr', function () {
'use strict';
var assert = chai.assert;
test('create widget', function () {
var e = jQuery('#u');
var uhr = e.uhr('instance');
assert.isUndefined(uhr);
uhr = e.uhr();
assert.isNotNull(uhr);
assert.isDefined(uhr);
var $ = jQuery;
var elem;
setup(function () {
elem = $('#u');
});
test('destroy widget', function() {
var e = jQuery('#u');
var uhr = e.uhr('instance');
teardown(function () {
var uhr = elem.uhr('instance');
if (uhr !== undefined) {
cleanupCookies(uhr.id);
}
try {
elem.uhr('destroy');
} catch (e) {
// just TRY to clean up, but don't DIE trying.
}
window.location.hash = '';
});
function cleanupCookies(id) {
$.removeCookie('uhr-language' + id);
$.removeCookie('uhr-mode' + id);
$.removeCookie('uhr-status' + id);
$.removeCookie('uhr-theme' + id);
}
test('create and destroy widget', function () {
var uhr = elem.uhr('instance');
var id;
assert.isUndefined(uhr);
elem.uhr();
uhr = elem.uhr('instance');
assert.isNotNull(uhr);
assert.isDefined(uhr);
e.uhr('destroy');
uhr = e.uhr('instance');
id = uhr.id;
elem.uhr('destroy');
uhr = elem.uhr('instance');
assert.isUndefined(uhr);
// cookies need to be cleaned up separately in this case, because in teardown(), the uhr widget doesn't exist anymore
cleanupCookies(id);
});
test('default config', function () {
var options;
elem.uhr();
options = elem.uhr('instance').options;
assert.isTrue(options.autoresize);
assert.isTrue(options.controls);
assert.isUndefined(options.cookiePath);
assert.isFalse(options.force);
assert.equal(options.language, 'de_CH');
assert.equal(options.mode, 'normal');
assert.equal(options.status, 'on');
assert.equal(options.theme, 'black');
});
test('custom config', function () {
var options;
var realWidth;
var myWidth = 100;
var myOptions = {
autoresize: false,
controls: false,
cookiePath: '/foo/bar',
force: true,
language: 'de',
mode: 'seconds',
status: 'off',
theme: 'red',
width: myWidth + 'px'
};
elem.uhr(myOptions);
options = elem.uhr('instance').options;
assert.equal(options.autoresize, myOptions.autoresize);
assert.equal(options.controls, myOptions.controls);
assert.equal(options.cookiePath, myOptions.cookiePath);
assert.equal(options.force, myOptions.force);
assert.equal(options.language, myOptions.language);
assert.equal(options.mode, myOptions.mode);
assert.equal(options.status, myOptions.status);
assert.equal(options.theme, myOptions.theme);
assert.equal(options.width, myOptions.width);
realWidth = elem.width();
assert.equal(myWidth, realWidth);
});
test('unknown language', function () {
var uhr;
elem.uhr({
language: 'klingon'
});
uhr = elem.uhr('instance');
// NB: 'de' is just the first language that is included in the page. that may change!
assert.equal(uhr.options.language, 'de');
});
test('unknown theme', function () {
var uhr;
elem.uhr({
theme: 'klingon'
});
uhr = elem.uhr('instance');
// NB: 'black' is the first theme that is included in the test page.
assert.equal(uhr.options.theme, 'black');
});
test('URL params, short', function () {
var options;
window.location.hash = '#t=red&l=dk&m=seconds&s=on';
elem.uhr();
options = elem.uhr('instance').options;
assert.isTrue(options.force);
assert.equal(options.language, 'dk');
assert.equal(options.mode, 'seconds');
assert.equal(options.status, 'on');
assert.equal(options.theme, 'red');
});
test('URL params, long', function () {
var options;
window.location.hash = '#theme=pink&language=de_CH&mode=normal&status=off';
elem.uhr();
options = elem.uhr('instance').options;
assert.isTrue(options.force);
assert.equal(options.language, 'de_CH');
assert.equal(options.mode, 'normal');
assert.equal(options.status, 'off');
assert.equal(options.theme, 'pink');
});
});