2015-02-20 05:03:57 +01:00
|
|
|
|
2015-05-10 13:12:31 +02:00
|
|
|
var tf = new TableFilter('demo', {
|
2015-05-15 12:37:27 +02:00
|
|
|
base_path: '../dist/tablefilter/',
|
2015-05-10 13:12:31 +02:00
|
|
|
help_instructions: true
|
|
|
|
});
|
|
|
|
tf.init();
|
2015-02-20 05:03:57 +01:00
|
|
|
|
2015-06-07 17:31:15 +02:00
|
|
|
var help = tf.feature('help');
|
2015-05-10 13:12:31 +02:00
|
|
|
module('Sanity checks');
|
2017-01-01 12:14:27 +01:00
|
|
|
test('Button element', function() {
|
2015-05-10 13:12:31 +02:00
|
|
|
deepEqual(typeof help, 'object', 'Help instanciated');
|
2015-06-08 12:21:50 +02:00
|
|
|
notEqual(help.btn, null, 'btn property');
|
2015-05-10 13:12:31 +02:00
|
|
|
});
|
2015-02-20 05:03:57 +01:00
|
|
|
|
2015-11-21 04:41:40 +01:00
|
|
|
module('Feature interface');
|
|
|
|
test('Properties', function() {
|
|
|
|
deepEqual(help.tf instanceof TableFilter, true, 'TableFilter instance');
|
|
|
|
deepEqual(help.feature, 'help', 'Feature name');
|
|
|
|
deepEqual(help.enabled, true, 'Feature enabled');
|
|
|
|
deepEqual(help.initialized, true, 'Feature enabled');
|
2015-12-28 01:18:55 +01:00
|
|
|
deepEqual(typeof help.emitter, 'object', 'Feature has emitter instance');
|
2015-11-21 04:41:40 +01:00
|
|
|
deepEqual(typeof help.config, 'object', 'TF configuration object');
|
|
|
|
deepEqual(typeof help.init, 'function', 'Feature init method');
|
|
|
|
deepEqual(typeof help.destroy, 'function', 'Feature destroy method');
|
|
|
|
deepEqual(typeof help.reset, 'function', 'Feature reset method');
|
|
|
|
deepEqual(typeof help.enable, 'function', 'Feature enable method');
|
|
|
|
deepEqual(typeof help.disable, 'function', 'Feature enable method');
|
|
|
|
deepEqual(typeof help.isEnabled, 'function', 'Feature enable method');
|
|
|
|
});
|
|
|
|
test('Can destroy', function() {
|
|
|
|
help.destroy();
|
2015-12-06 12:33:11 +01:00
|
|
|
deepEqual(help.initialized, false, 'not initialised');
|
2015-11-21 04:41:40 +01:00
|
|
|
});
|
|
|
|
test('Can reset', function() {
|
|
|
|
help.reset();
|
|
|
|
deepEqual(help.enabled, true, 'enabled');
|
|
|
|
});
|
|
|
|
test('Can disable', function() {
|
|
|
|
help.disable();
|
|
|
|
deepEqual(help.enabled, false, 'disabled');
|
|
|
|
});
|
|
|
|
test('Can enable', function() {
|
|
|
|
help.enable();
|
|
|
|
deepEqual(help.enabled, true, 'enabled');
|
|
|
|
});
|
|
|
|
test('Can init', function() {
|
|
|
|
help.destroy();
|
|
|
|
help.enable();
|
|
|
|
help.init();
|
|
|
|
deepEqual(help.enabled, true, 'enabled');
|
|
|
|
});
|
|
|
|
test('Can check is enabled', function() {
|
|
|
|
help.isEnabled();
|
|
|
|
deepEqual(help.enabled, true, 'enabled');
|
|
|
|
});
|
|
|
|
|
2015-05-10 13:12:31 +02:00
|
|
|
module('UI elements');
|
|
|
|
test('Help UI elements', function() {
|
2015-06-08 12:21:50 +02:00
|
|
|
var container = help.cont,
|
|
|
|
helpBtn = help.btn;
|
2015-05-10 13:12:31 +02:00
|
|
|
deepEqual(container.nodeName, 'DIV', 'Help container');
|
|
|
|
deepEqual(helpBtn.nodeName, 'SPAN', 'Help button');
|
|
|
|
});
|
2015-02-20 05:03:57 +01:00
|
|
|
|
2016-12-27 11:20:16 +01:00
|
|
|
test('Help container auto-closes when user clicks away', function() {
|
|
|
|
// setup
|
|
|
|
help.toggle();
|
|
|
|
|
|
|
|
// act
|
|
|
|
var evObj = document.createEvent('HTMLEvents');
|
|
|
|
evObj.initEvent('mouseup', true, true);
|
|
|
|
// mouseup fired from a table cell
|
2017-04-14 11:30:58 +02:00
|
|
|
tf.dom().rows[3].cells[2].dispatchEvent(evObj);
|
2016-12-27 11:20:16 +01:00
|
|
|
|
|
|
|
// assert
|
|
|
|
deepEqual(help.cont.style.display, 'none',
|
|
|
|
'Help container closed after user clicks away'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2017-01-01 12:14:27 +01:00
|
|
|
// 376 issue: ensure close button closes popup
|
|
|
|
test('Close button closes popup', function() {
|
|
|
|
// setup
|
|
|
|
help.toggle();
|
|
|
|
|
|
|
|
// act
|
|
|
|
var evObj = document.createEvent('HTMLEvents');
|
|
|
|
evObj.initEvent('click', true, true);
|
|
|
|
help.cont.querySelector('.close').dispatchEvent(evObj);
|
|
|
|
|
|
|
|
// assert
|
|
|
|
deepEqual(help.cont.style.display, 'none',
|
|
|
|
'Close button closes popup'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
test('Help button closes popup when already open', function() {
|
|
|
|
// setup
|
|
|
|
help.toggle();
|
|
|
|
|
|
|
|
// act
|
|
|
|
var evObj = document.createEvent('HTMLEvents');
|
|
|
|
evObj.initEvent('click', true, true);
|
|
|
|
help.btn.querySelector('.helpBtn').dispatchEvent(evObj);
|
|
|
|
|
|
|
|
// assert
|
|
|
|
deepEqual(help.cont.style.display, 'none',
|
|
|
|
'Close button closes popup'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2015-05-10 13:12:31 +02:00
|
|
|
module('Destroy and re-init');
|
|
|
|
test('Remove UI', function() {
|
|
|
|
help.destroy();
|
2015-06-08 12:21:50 +02:00
|
|
|
var container = help.cont,
|
|
|
|
helpBtn = help.btn;
|
2015-05-10 13:12:31 +02:00
|
|
|
deepEqual(container, null, 'Help container removed');
|
|
|
|
deepEqual(helpBtn, null, 'Help button removed');
|
|
|
|
});
|
2015-02-20 05:03:57 +01:00
|
|
|
|
2015-05-10 13:12:31 +02:00
|
|
|
test('Re-set UI', function() {
|
2015-06-07 17:31:15 +02:00
|
|
|
var help = tf.feature('help');
|
|
|
|
help.destroy();
|
2015-06-08 12:21:50 +02:00
|
|
|
help.btnText = '→Help←';
|
|
|
|
help.instrText = 'Hello world!';
|
2015-06-07 17:31:15 +02:00
|
|
|
help.init();
|
2015-05-10 13:12:31 +02:00
|
|
|
|
2015-06-08 12:21:50 +02:00
|
|
|
var container = help.cont,
|
|
|
|
helpBtn = help.btn;
|
2015-05-10 13:12:31 +02:00
|
|
|
notEqual(
|
|
|
|
container.innerHTML.indexOf('Hello world!'),
|
|
|
|
-1,
|
|
|
|
'Help pop-up text'
|
|
|
|
);
|
|
|
|
notEqual(helpBtn.innerHTML.indexOf('→Help←'), -1, 'Help button text');
|
2015-02-20 05:03:57 +01:00
|
|
|
});
|
2015-11-21 04:41:40 +01:00
|
|
|
|
2016-01-19 13:13:34 +01:00
|
|
|
|
2017-05-23 05:49:21 +02:00
|
|
|
module('Destroy and re-init');
|
2016-03-24 00:52:23 +01:00
|
|
|
test('Can init help when property is undefined and toolbar is set',
|
|
|
|
function() {
|
|
|
|
tf.destroy();
|
2017-05-13 12:51:10 +02:00
|
|
|
tf = new TableFilter('demo', {
|
|
|
|
base_path: '../dist/tablefilter/',
|
|
|
|
help_instructions: undefined,
|
|
|
|
// creates toolbar
|
|
|
|
rows_counter: true
|
|
|
|
});
|
2016-03-24 00:52:23 +01:00
|
|
|
tf.init();
|
2017-05-13 12:51:10 +02:00
|
|
|
var help = tf.feature('help');
|
2016-01-19 13:13:34 +01:00
|
|
|
|
2016-03-24 00:52:23 +01:00
|
|
|
notEqual(help.btn, null, 'btn property');
|
2017-05-23 05:49:21 +02:00
|
|
|
deepEqual(help.btn.childNodes[1].innerHTML, '?', 'Button text');
|
2017-05-13 12:51:10 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2017-06-28 12:47:32 +02:00
|
|
|
test('Does not init help when property is undefined and toolbar is not set ' +
|
2017-05-13 12:51:10 +02:00
|
|
|
'by other feature(s)',
|
2017-06-28 12:47:32 +02:00
|
|
|
function() {
|
|
|
|
tf.destroy();
|
|
|
|
tf = new TableFilter('demo', {
|
|
|
|
base_path: '../dist/tablefilter/'
|
|
|
|
});
|
|
|
|
tf.init();
|
|
|
|
var help = tf.feature('help');
|
2017-05-13 12:51:10 +02:00
|
|
|
|
2017-06-28 12:47:32 +02:00
|
|
|
deepEqual(help.initialized, false, 'feature not initialized');
|
|
|
|
deepEqual(help.btn, null, 'btn property not set');
|
|
|
|
deepEqual(help.cont, null, 'cont property not set');
|
|
|
|
});
|
2016-03-24 00:52:23 +01:00
|
|
|
|
2017-05-23 05:49:21 +02:00
|
|
|
test('Can init help when property is defined with a literal object ' +
|
|
|
|
'and toolbar is set',
|
2017-06-28 12:47:32 +02:00
|
|
|
function() {
|
|
|
|
tf.destroy();
|
|
|
|
tf = new TableFilter('demo', {
|
|
|
|
base_path: '../dist/tablefilter/',
|
|
|
|
help_instructions: {
|
|
|
|
btn_text: '??',
|
|
|
|
text: 'hello world'
|
|
|
|
},
|
|
|
|
// creates toolbar
|
|
|
|
rows_counter: true
|
|
|
|
});
|
|
|
|
tf.init();
|
|
|
|
var help = tf.feature('help');
|
2017-05-23 05:49:21 +02:00
|
|
|
|
2017-06-28 12:47:32 +02:00
|
|
|
notEqual(help.btn, null, 'btn property');
|
|
|
|
deepEqual(help.btn.childNodes[1].innerHTML, '??', 'Button text');
|
|
|
|
deepEqual(help.instrText, 'hello world', 'Text property');
|
|
|
|
deepEqual(help.cont.innerHTML.indexOf('hello world') !== -1, true,
|
|
|
|
'Text in DOM element');
|
|
|
|
});
|
2017-05-23 05:49:21 +02:00
|
|
|
|
2016-03-24 00:52:23 +01:00
|
|
|
test('Can toggle help when property is undefined and toolbar is set',
|
|
|
|
function() {
|
|
|
|
tf.destroy();
|
|
|
|
tf = new TableFilter('demo', {
|
|
|
|
base_path: '../dist/tablefilter/',
|
|
|
|
// creates toolbar
|
|
|
|
rows_counter: true
|
|
|
|
});
|
|
|
|
tf.init();
|
|
|
|
var help = tf.feature('help');
|
|
|
|
|
|
|
|
// Pull 157, help button regression when setting is undefined
|
|
|
|
help.toggle();
|
|
|
|
|
|
|
|
notEqual(help, null, 'help instantiated');
|
|
|
|
deepEqual(help.enabled, true, 'help enabled');
|
|
|
|
deepEqual(help.cont.style.display, 'inline', 'Container is open');
|
2017-06-28 12:47:32 +02:00
|
|
|
});
|
2016-01-19 13:13:34 +01:00
|
|
|
|
2015-11-21 04:41:40 +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 04:41:40 +01:00
|
|
|
});
|