2015-01-16 17:50:23 +01:00
|
|
|
suite('Bärneruhr', function () {
|
|
|
|
'use strict';
|
|
|
|
var assert = chai.assert;
|
2015-01-18 21:36:55 +01:00
|
|
|
var $ = jQuery;
|
2015-01-18 21:40:36 +01:00
|
|
|
var elem;
|
2015-01-18 21:36:55 +01:00
|
|
|
|
|
|
|
setup(function () {
|
2015-01-18 21:40:36 +01:00
|
|
|
elem = $('#u');
|
2015-01-18 21:36:55 +01:00
|
|
|
});
|
|
|
|
|
2019-05-03 22:27:16 +02:00
|
|
|
function cleanupCookies(id) {
|
|
|
|
$.removeCookie('uhr-language' + id);
|
|
|
|
$.removeCookie('uhr-mode' + id);
|
|
|
|
$.removeCookie('uhr-status' + id);
|
|
|
|
$.removeCookie('uhr-theme' + id);
|
|
|
|
}
|
|
|
|
|
2015-01-18 21:36:55 +01:00
|
|
|
teardown(function () {
|
2015-01-18 21:40:36 +01:00
|
|
|
var uhr = elem.uhr('instance');
|
2015-01-18 21:36:55 +01:00
|
|
|
if (uhr !== undefined) {
|
|
|
|
cleanupCookies(uhr.id);
|
|
|
|
}
|
|
|
|
try {
|
2015-01-18 21:40:36 +01:00
|
|
|
elem.uhr('destroy');
|
2015-01-18 21:36:55 +01:00
|
|
|
} catch (e) {
|
|
|
|
// just TRY to clean up, but don't DIE trying.
|
|
|
|
}
|
|
|
|
window.location.hash = '';
|
2014-07-04 01:08:39 +02:00
|
|
|
});
|
2015-01-18 21:36:55 +01:00
|
|
|
|
|
|
|
test('create and destroy widget', function () {
|
2015-01-18 21:40:36 +01:00
|
|
|
var uhr = elem.uhr('instance');
|
2015-01-18 21:36:55 +01:00
|
|
|
var id;
|
|
|
|
assert.isUndefined(uhr);
|
2015-01-18 21:40:36 +01:00
|
|
|
elem.uhr();
|
|
|
|
uhr = elem.uhr('instance');
|
2015-01-16 17:50:23 +01:00
|
|
|
assert.isNotNull(uhr);
|
|
|
|
assert.isDefined(uhr);
|
2015-01-18 21:36:55 +01:00
|
|
|
id = uhr.id;
|
2015-01-18 21:40:36 +01:00
|
|
|
elem.uhr('destroy');
|
|
|
|
uhr = elem.uhr('instance');
|
2015-01-16 17:50:23 +01:00
|
|
|
assert.isUndefined(uhr);
|
2015-01-18 21:36:55 +01:00
|
|
|
// 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;
|
2015-01-18 21:40:36 +01:00
|
|
|
elem.uhr();
|
|
|
|
options = elem.uhr('instance').options;
|
2015-01-18 21:36:55 +01:00
|
|
|
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'
|
|
|
|
};
|
2015-01-18 21:40:36 +01:00
|
|
|
elem.uhr(myOptions);
|
|
|
|
options = elem.uhr('instance').options;
|
2015-01-18 21:36:55 +01:00
|
|
|
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);
|
|
|
|
|
2015-01-18 21:40:36 +01:00
|
|
|
realWidth = elem.width();
|
2015-01-18 21:36:55 +01:00
|
|
|
assert.equal(myWidth, realWidth);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('unknown language', function () {
|
|
|
|
var uhr;
|
2015-01-18 21:40:36 +01:00
|
|
|
elem.uhr({
|
2015-01-18 21:36:55 +01:00
|
|
|
language: 'klingon'
|
|
|
|
});
|
2015-01-18 21:40:36 +01:00
|
|
|
uhr = elem.uhr('instance');
|
2015-01-18 21:36:55 +01:00
|
|
|
// NB: 'de' is just the first language that is included in the page. that may change!
|
2019-05-03 23:54:30 +02:00
|
|
|
assert.equal(uhr.options.language, 'de');
|
2015-01-18 21:36:55 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('unknown theme', function () {
|
|
|
|
var uhr;
|
2015-01-18 21:40:36 +01:00
|
|
|
elem.uhr({
|
2015-01-18 21:36:55 +01:00
|
|
|
theme: 'klingon'
|
|
|
|
});
|
2015-01-18 21:40:36 +01:00
|
|
|
uhr = elem.uhr('instance');
|
2015-01-18 21:36:55 +01:00
|
|
|
// 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';
|
|
|
|
|
2015-01-18 21:40:36 +01:00
|
|
|
elem.uhr();
|
|
|
|
options = elem.uhr('instance').options;
|
2015-01-18 21:36:55 +01:00
|
|
|
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';
|
|
|
|
|
2015-01-18 21:40:36 +01:00
|
|
|
elem.uhr();
|
|
|
|
options = elem.uhr('instance').options;
|
2015-01-18 21:36:55 +01:00
|
|
|
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');
|
2015-01-16 17:50:23 +01:00
|
|
|
});
|
|
|
|
});
|