added the first two test methods that actually work!

This commit is contained in:
Manuel Friedli 2015-01-16 17:50:23 +01:00
parent 51d21d8ff6
commit 0c7aebc200
15 changed files with 248 additions and 305 deletions

View file

@ -58,7 +58,7 @@ module.exports = function (grunt) {
options: {
banner: '<%= banner %>'
},
libs:{
libs: {
src: '<%= concat.libs.dest %>',
dest: 'dist/libs.min.js'
},
@ -83,10 +83,10 @@ module.exports = function (grunt) {
dest: 'dist/jquery.<%= pkg.name %>.langs.min.js'
}
},
qunit: {
all: {
mocha_phantomjs: {
all:{
options: {
urls: ['http://localhost:9000/test/<%= pkg.name %>.html']
urls: ['http://localhost:9000/test/test.html']
}
}
},
@ -105,12 +105,9 @@ module.exports = function (grunt) {
jshintrc: '.jshintrc'
},
src: ['src/**/*.js']
// },
// test: {
// options: {
// jshintrc: 'test/.jshintrc'
// },
// src: ['test/**/*.js']
},
test: {
src: ['test/*.js']
}
},
watch: {
@ -120,11 +117,11 @@ module.exports = function (grunt) {
},
src: {
files: '<%= jshint.src.src %>',
tasks: ['jshint:src', 'qunit']
tasks: ['jshint:src', 'mocha_phantomjs']
},
test: {
files: '<%= jshint.test.src %>',
tasks: ['jshint:test', 'qunit']
files: ['test/test.html', '<%= jshint.test.src %>'],
tasks: ['jshint:test', 'mocha_phantomjs']
}
},
connect: {
@ -137,14 +134,14 @@ module.exports = function (grunt) {
}
});
grunt.loadNpmTasks('grunt-mocha-phantomjs');
// Default task.
// grunt.registerTask('default', ['jshint', 'connect', 'qunit', 'clean', 'concat', 'uglify']);
grunt.registerTask('default', ['jshint', 'connect', /*'qunit', */'clean', 'concat', 'uglify']);
grunt.registerTask('default', ['jshint', 'connect', 'mocha_phantomjs', 'clean', 'concat', 'uglify']);
grunt.registerTask('buildonly', ['clean', 'concat', 'uglify']);
grunt.registerTask('server', function () {
grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
grunt.task.run(['serve']);
});
grunt.registerTask('serve', ['connect', 'watch']);
grunt.registerTask('test', ['jshint', 'connect', 'qunit']);
grunt.registerTask('test', ['jshint', 'connect', 'mocha_phantomjs']);
};

View file

@ -1,12 +1,13 @@
{
"name": "uhr",
"version": "0.0.1",
"version": "7.0.0-next",
"dependencies": {
"jquery": "~2.1.3",
"jquery-ui": "~1.11.2",
"jquery-cookie": "~1.4.1"
},
"devDependencies": {
"qunit": "~1.12.0",
"jquery": "~2.1.3"
"mocha": "~2.1.0",
"chai": "~1.10.0"
}
}

View file

@ -333,6 +333,16 @@
}.bind(this));
}
};
var destroy = function destroy() {
this.timer = null;
$(this.element)
.removeAttr('style')
.removeAttr('class')
.empty();
$('#uhr-configlink' + this.id).remove();
$('#uhr-controlpanel' + this.id).remove();
};
var setCookie = function setCookie(cookieName, cookieValue) {
var options = {};
if (this.options.cookiePath !== undefined) {
@ -446,7 +456,9 @@
"mode": setMode,
"width": setWidth,
// constructor method
"_create": create
"_create": create,
// destructor method
"_destroy": destroy
});
$.fritteli.uhr.register = uhrGlobals.registerLanguage;
/**

File diff suppressed because one or more lines are too long

View file

@ -333,6 +333,16 @@
}.bind(this));
}
};
var destroy = function destroy() {
this.timer = null;
$(this.element)
.removeAttr('style')
.removeAttr('class')
.empty();
$('#uhr-configlink' + this.id).remove();
$('#uhr-controlpanel' + this.id).remove();
};
var setCookie = function setCookie(cookieName, cookieValue) {
var options = {};
if (this.options.cookiePath !== undefined) {
@ -446,7 +456,9 @@
"mode": setMode,
"width": setWidth,
// constructor method
"_create": create
"_create": create,
// destructor method
"_destroy": destroy
});
$.fritteli.uhr.register = uhrGlobals.registerLanguage;
/**

File diff suppressed because one or more lines are too long

View file

@ -333,6 +333,16 @@
}.bind(this));
}
};
var destroy = function destroy() {
this.timer = null;
$(this.element)
.removeAttr('style')
.removeAttr('class')
.empty();
$('#uhr-configlink' + this.id).remove();
$('#uhr-controlpanel' + this.id).remove();
};
var setCookie = function setCookie(cookieName, cookieValue) {
var options = {};
if (this.options.cookiePath !== undefined) {
@ -446,7 +456,9 @@
"mode": setMode,
"width": setWidth,
// constructor method
"_create": create
"_create": create,
// destructor method
"_destroy": destroy
});
$.fritteli.uhr.register = uhrGlobals.registerLanguage;
/**

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,117 +0,0 @@
/*!
* jQuery Cookie Plugin v1.4.0
* https://github.com/carhartl/jquery-cookie
*
* Copyright 2013 Klaus Hartl
* Released under the MIT license
*/
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as anonymous module.
define(['jquery'], factory);
} else {
// Browser globals.
factory(jQuery);
}
}(function ($) {
var pluses = /\+/g;
function encode(s) {
return config.raw ? s : encodeURIComponent(s);
}
function decode(s) {
return config.raw ? s : decodeURIComponent(s);
}
function stringifyCookieValue(value) {
return encode(config.json ? JSON.stringify(value) : String(value));
}
function parseCookieValue(s) {
if (s.indexOf('"') === 0) {
// This is a quoted cookie as according to RFC2068, unescape...
s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
}
try {
// Replace server-side written pluses with spaces.
// If we can't decode the cookie, ignore it, it's unusable.
s = decodeURIComponent(s.replace(pluses, ' '));
} catch(e) {
return;
}
try {
// If we can't parse the cookie, ignore it, it's unusable.
return config.json ? JSON.parse(s) : s;
} catch(e) {}
}
function read(s, converter) {
var value = config.raw ? s : parseCookieValue(s);
return $.isFunction(converter) ? converter(value) : value;
}
var config = $.cookie = function (key, value, options) {
// Write
if (value !== undefined && !$.isFunction(value)) {
options = $.extend({}, config.defaults, options);
if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days);
}
return (document.cookie = [
encode(key), '=', stringifyCookieValue(value),
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
options.path ? '; path=' + options.path : '',
options.domain ? '; domain=' + options.domain : '',
options.secure ? '; secure' : ''
].join(''));
}
// Read
var result = key ? undefined : {};
// To prevent the for loop in the first place assign an empty array
// in case there are no cookies at all. Also prevents odd result when
// calling $.cookie().
var cookies = document.cookie ? document.cookie.split('; ') : [];
for (var i = 0, l = cookies.length; i < l; i++) {
var parts = cookies[i].split('=');
var name = decode(parts.shift());
var cookie = parts.join('=');
if (key && key === name) {
// If second argument (value) is a function it's a converter...
result = read(cookie, value);
break;
}
// Prevent storing a cookie that we couldn't decode.
if (!key && (cookie = read(cookie)) !== undefined) {
result[name] = cookie;
}
}
return result;
};
config.defaults = {};
$.removeCookie = function (key, options) {
if ($.cookie(key) !== undefined) {
// Must not alter options, thus extending a fresh object...
$.cookie(key, '', $.extend({}, options, { expires: -1 }));
return true;
}
return false;
};
}));

File diff suppressed because one or more lines are too long

View file

@ -3,7 +3,8 @@
"version": "7.0.0-next",
"description": "jQuery QLOCKTWO plugin",
"keywords": [
"jquery-plugin", "qlocktwo"
"jquery-plugin",
"qlocktwo"
],
"homepage": "http://bärneruhr.ch/",
"author": {
@ -31,8 +32,10 @@
"grunt-contrib-qunit": "~0.5.1",
"grunt-contrib-uglify": "~0.5.0",
"grunt-contrib-watch": "~0.6.1",
"grunt-mocha-phantomjs": "^0.6.0",
"jshint-stylish": "~0.2.0",
"load-grunt-tasks": "~0.6.0",
"phantomjs": "^1.9.13",
"time-grunt": "~0.3.2"
}
}

View file

@ -344,6 +344,16 @@
}.bind(this));
}
};
var destroy = function destroy() {
this.timer = null;
$(this.element)
.removeAttr('style')
.removeAttr('class')
.empty();
$('#uhr-configlink' + this.id).remove();
$('#uhr-controlpanel' + this.id).remove();
};
var setCookie = function setCookie(cookieName, cookieValue) {
var options = {};
if (this.options.cookiePath !== undefined) {
@ -457,7 +467,9 @@
"mode": setMode,
"width": setWidth,
// constructor method
"_create": create
"_create": create,
// destructor method
"_destroy": destroy
});
$.fritteli.uhr.register = uhrGlobals.registerLanguage;
/**

View file

@ -6,23 +6,28 @@
<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"/>
</head>
<body>
<div id="mocha"></div>
<script src="lib/mocha.js"></script>
<script src="lib/chai.js"></script>
<script>mocha.setup('tdd');</script>
<script src="../lib/jquery-2.1.0.min.js"></script>
<script src="../lib/jquery-ui-1.10.4.custom.min.js"></script>
<script src="../lib/jquery-cookie-1.4.0.js"></script>
<script src="../src/uhr.js"></script>
<script src="../src/uhr-de_CH.js"></script>
<script src="test.js"></script>
<div id="u"></div>
<script>
<div id="mocha"></div>
<script type="text/javascript" src="lib/mocha.js"></script>
<script type="text/javascript" src="lib/chai.js"></script>
<script type="text/javascript" src="../dist/libs.js"></script>
<script type="text/javascript" src="../dist/jquery.uhr.complete.js"></script>
<script type="text/javascript">
mocha.setup('tdd');
</script>
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript">
mocha.checkLeaks();
mocha.globals(['jQuery*']);
if (window.mochaPhantomJS) {
mochaPhantomJS.run();
}
else {
mocha.run();
// $('#u').uhr({'width':'200px'});
}
</script>
</body>
</html>

View file

@ -1,5 +1,21 @@
suite('Bärneruhr', function() {
"use strict";
test('dummy', function() {
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);
});
test('destroy widget', function() {
var e = jQuery('#u');
var uhr = e.uhr('instance');
assert.isNotNull(uhr);
assert.isDefined(uhr);
e.uhr('destroy');
uhr = e.uhr('instance');
assert.isUndefined(uhr);
});
});