2015-05-15 12:37:27 +02:00
|
|
|
var tf = new TableFilter('demo', {
|
|
|
|
base_path: '../dist/tablefilter/',
|
|
|
|
status_bar: true
|
|
|
|
});
|
|
|
|
tf.init();
|
|
|
|
|
2015-06-07 17:31:15 +02:00
|
|
|
var statusBar = tf.feature('statusBar');
|
2015-05-15 12:37:27 +02:00
|
|
|
module('Sanity checks');
|
|
|
|
test('Status bar component', function() {
|
2015-06-07 17:31:15 +02:00
|
|
|
deepEqual(typeof statusBar, 'object', 'StatusBar instantiated');
|
2016-08-06 16:48:00 +02:00
|
|
|
notEqual(statusBar.container, null, 'container property');
|
2015-02-20 14:46:57 +01:00
|
|
|
});
|
2017-03-01 12:09:20 +01:00
|
|
|
test('Should not initialize if already initialized', function() {
|
|
|
|
// setup
|
|
|
|
var hit = 0;
|
|
|
|
statusBar.initialized = true;
|
|
|
|
var initialSetToolbar = statusBar.tf.setToolbar;
|
|
|
|
statusBar.tf.setToolbar = function() {
|
|
|
|
hit++;
|
|
|
|
};
|
|
|
|
|
|
|
|
// act
|
|
|
|
statusBar.init();
|
|
|
|
|
|
|
|
// assert
|
|
|
|
deepEqual(hit, 0, 'setToolbar not called');
|
|
|
|
|
|
|
|
statusBar.tf.setToolbar = initialSetToolbar;
|
|
|
|
});
|
|
|
|
asyncTest('Can display message', function() {
|
|
|
|
// act
|
|
|
|
statusBar.message('hello world');
|
|
|
|
|
|
|
|
// assert
|
|
|
|
setTimeout(function(){
|
|
|
|
start();
|
|
|
|
deepEqual(statusBar.msgContainer.innerHTML,
|
|
|
|
'hello world', 'Message displayed');
|
2017-04-10 18:33:27 +02:00
|
|
|
statusBar.msgContainer.innerHTML = '';
|
2017-03-01 12:09:20 +01:00
|
|
|
}, 2);
|
|
|
|
});
|
2017-04-10 18:33:27 +02:00
|
|
|
asyncTest('Should not display message if not enabled', function() {
|
|
|
|
// setup
|
|
|
|
statusBar.enabled = false;
|
|
|
|
|
|
|
|
// act
|
|
|
|
statusBar.message('hello world');
|
|
|
|
|
|
|
|
// assert
|
|
|
|
setTimeout(function(){
|
|
|
|
start();
|
|
|
|
deepEqual(statusBar.msgContainer.innerHTML,
|
|
|
|
'', 'Message not displayed');
|
|
|
|
}, 2);
|
|
|
|
|
|
|
|
statusBar.enabled = true;
|
|
|
|
});
|
2015-05-15 12:37:27 +02:00
|
|
|
|
2015-11-21 06:48:03 +01:00
|
|
|
module('Feature interface');
|
|
|
|
test('Properties', function() {
|
|
|
|
deepEqual(statusBar.tf instanceof TableFilter,
|
|
|
|
true, 'TableFilter instance');
|
|
|
|
deepEqual(statusBar.feature, 'statusBar', 'Feature name');
|
|
|
|
deepEqual(statusBar.enabled, true, 'Feature enabled');
|
|
|
|
deepEqual(statusBar.initialized, true, 'Feature enabled');
|
2015-12-28 01:18:55 +01:00
|
|
|
deepEqual(typeof statusBar.emitter, 'object',
|
|
|
|
'Feature has emitter instance');
|
2015-11-21 06:48:03 +01:00
|
|
|
deepEqual(typeof statusBar.config, 'object', 'TF configuration object');
|
|
|
|
deepEqual(typeof statusBar.init, 'function', 'Feature init method');
|
|
|
|
deepEqual(typeof statusBar.destroy, 'function', 'Feature destroy method');
|
|
|
|
deepEqual(typeof statusBar.reset, 'function', 'Feature reset method');
|
|
|
|
deepEqual(typeof statusBar.enable, 'function', 'Feature enable method');
|
|
|
|
deepEqual(typeof statusBar.disable, 'function', 'Feature enable method');
|
|
|
|
deepEqual(typeof statusBar.isEnabled, 'function', 'Feature enable method');
|
|
|
|
});
|
|
|
|
test('Can destroy', function() {
|
|
|
|
statusBar.destroy();
|
2015-12-06 12:33:11 +01:00
|
|
|
deepEqual(statusBar.initialized, false, 'not initialised');
|
2015-11-21 06:48:03 +01:00
|
|
|
});
|
|
|
|
test('Can reset', function() {
|
|
|
|
statusBar.reset();
|
|
|
|
deepEqual(statusBar.enabled, true, 'enabled');
|
|
|
|
});
|
|
|
|
test('Can disable', function() {
|
|
|
|
statusBar.disable();
|
|
|
|
deepEqual(statusBar.enabled, false, 'disabled');
|
|
|
|
});
|
|
|
|
test('Can enable', function() {
|
|
|
|
statusBar.enable();
|
|
|
|
deepEqual(statusBar.enabled, true, 'enabled');
|
|
|
|
});
|
|
|
|
test('Can init', function() {
|
|
|
|
statusBar.destroy();
|
|
|
|
statusBar.enable();
|
|
|
|
statusBar.init();
|
|
|
|
deepEqual(statusBar.enabled, true, 'enabled');
|
|
|
|
});
|
|
|
|
test('Can check is enabled', function() {
|
|
|
|
statusBar.isEnabled();
|
|
|
|
deepEqual(statusBar.enabled, true, 'enabled');
|
|
|
|
});
|
|
|
|
|
2015-05-15 12:37:27 +02:00
|
|
|
module('UI elements');
|
|
|
|
test('Status bar UI elements', function() {
|
2016-08-06 16:48:00 +02:00
|
|
|
var container = statusBar.container,
|
|
|
|
label = statusBar.msgContainer;
|
2015-05-15 12:37:27 +02:00
|
|
|
deepEqual(container.nodeName, 'DIV', 'Status bar container');
|
|
|
|
deepEqual(label.nodeName, 'SPAN', 'Status bar label');
|
|
|
|
});
|
|
|
|
|
|
|
|
module('Destroy');
|
|
|
|
test('Remove UI', function() {
|
|
|
|
statusBar.destroy();
|
2016-08-06 16:48:00 +02:00
|
|
|
var container = statusBar.container,
|
|
|
|
label = statusBar.msgContainer;
|
2015-05-15 12:37:27 +02:00
|
|
|
deepEqual(container, null, 'Status bar container removed');
|
|
|
|
deepEqual(label, null, 'Status bar button removed');
|
|
|
|
});
|
|
|
|
|
2017-04-10 18:33:27 +02:00
|
|
|
module('Re-set UI');
|
|
|
|
test('Status text', function() {
|
2016-08-06 16:48:00 +02:00
|
|
|
statusBar.text = '→←';
|
2015-05-15 12:37:27 +02:00
|
|
|
statusBar.init();
|
|
|
|
|
2016-08-06 16:48:00 +02:00
|
|
|
var label = statusBar.labelContainer;
|
2015-05-15 12:37:27 +02:00
|
|
|
notEqual(
|
|
|
|
label.innerHTML.indexOf('→←'), -1, 'Status bar text');
|
|
|
|
});
|
2017-04-10 18:33:27 +02:00
|
|
|
test('Custom container', function() {
|
|
|
|
// setup
|
|
|
|
statusBar.destroy();
|
|
|
|
statusBar.targetId = 'custom-container';
|
|
|
|
|
|
|
|
// act
|
|
|
|
statusBar.init();
|
|
|
|
|
|
|
|
// assert
|
|
|
|
deepEqual(statusBar.msgContainer.nodeName,
|
|
|
|
'SPAN', 'Custom container element');
|
|
|
|
});
|
2015-05-15 12:37:27 +02:00
|
|
|
|
2015-11-21 06:48:03 +01:00
|
|
|
module('Tear-down');
|
|
|
|
test('can destroy TableFilter DOM elements', function() {
|
|
|
|
tf.destroy();
|
2016-05-27 09:40:22 +02:00
|
|
|
deepEqual(tf.isInitialized(), false, 'Filters removed');
|
2015-11-21 06:48:03 +01:00
|
|
|
});
|