2015-05-10 13:12:31 +02:00
|
|
|
(function(win, TableFilter) {
|
2014-11-08 13:37:24 +01:00
|
|
|
|
2015-05-15 12:37:27 +02:00
|
|
|
var tf = new TableFilter('demo', {
|
|
|
|
base_path: '../dist/tablefilter/'
|
|
|
|
});
|
2014-11-08 13:37:24 +01:00
|
|
|
tf.init();
|
|
|
|
|
2015-11-14 16:14:13 +01:00
|
|
|
module('Table 1: sanity checks');
|
|
|
|
test('TableFilter object', function() {
|
|
|
|
deepEqual(tf instanceof TableFilter, true, 'TableFilter instanciated');
|
|
|
|
deepEqual(tf.id, 'demo', 'id check');
|
|
|
|
deepEqual(tf.filtersRowIndex, 0, 'Filters row index');
|
2015-06-05 15:10:25 +02:00
|
|
|
deepEqual(tf.getCellsNb(), 5, 'filters type collection length');
|
2014-11-08 13:37:24 +01:00
|
|
|
});
|
|
|
|
|
2015-10-31 09:00:28 +01:00
|
|
|
module('Table 1: DOM tests');
|
2014-11-08 13:37:24 +01:00
|
|
|
test('Filters row', function() {
|
2017-04-14 11:30:58 +02:00
|
|
|
equal(
|
|
|
|
tf.dom().rows[0].className,
|
|
|
|
'fltrow',
|
|
|
|
'Filters row CSS class name'
|
|
|
|
);
|
2015-02-21 04:39:09 +01:00
|
|
|
equal(tf.getFilterElement(0).nodeName, 'INPUT', 'Filter DOM element');
|
2016-04-04 11:08:57 +02:00
|
|
|
deepEqual(
|
2017-04-14 11:30:58 +02:00
|
|
|
tf.dom().scrollWidth === tf.dom().clientWidth,
|
2016-04-04 11:08:57 +02:00
|
|
|
true,
|
|
|
|
'Horizontal scrollbar is not displayed'
|
|
|
|
);
|
2014-11-08 13:37:24 +01:00
|
|
|
});
|
|
|
|
|
2015-10-31 09:00:28 +01:00
|
|
|
var tf1 = new TableFilter(
|
|
|
|
document.querySelector('.test'),
|
|
|
|
{
|
|
|
|
base_path: '../dist/tablefilter/',
|
2016-04-04 11:08:57 +02:00
|
|
|
responsive: true,
|
2015-11-29 01:46:20 +01:00
|
|
|
filters_row_index: 1,
|
|
|
|
btn: true
|
2015-10-31 09:00:28 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
tf1.init();
|
2016-11-10 04:16:57 +01:00
|
|
|
|
|
|
|
var btn = document.querySelector('.' + tf1.btnCssClass);
|
2015-10-31 09:00:28 +01:00
|
|
|
|
2015-11-29 01:46:20 +01:00
|
|
|
module('Table 2: sanity checks');
|
2016-04-04 11:08:57 +02:00
|
|
|
test('TableFilter instance', function() {
|
2015-10-31 09:00:28 +01:00
|
|
|
notEqual(tf1.id, null, 'id check');
|
2017-04-14 11:30:58 +02:00
|
|
|
deepEqual(tf1.dom().classList.contains(tf1.prfxResponsive), true,
|
2016-04-04 11:08:57 +02:00
|
|
|
'Responsive CSS class');
|
2015-10-31 09:00:28 +01:00
|
|
|
equal(tf1.filtersRowIndex, 1, 'Filters row index');
|
|
|
|
deepEqual(tf1.getCellsNb(), 5, 'filters type collection length');
|
|
|
|
});
|
|
|
|
|
|
|
|
module('Table 2: DOM tests');
|
|
|
|
test('Filters row', function() {
|
|
|
|
equal(
|
2017-04-14 11:30:58 +02:00
|
|
|
tf1.dom().rows[1].className,
|
2015-10-31 09:00:28 +01:00
|
|
|
'fltrow',
|
|
|
|
'Filters row CSS class name'
|
|
|
|
);
|
|
|
|
equal(tf1.getFilterElement(0).nodeName, 'INPUT', 'Filter DOM element');
|
2016-04-04 11:08:57 +02:00
|
|
|
deepEqual(
|
2017-04-14 11:30:58 +02:00
|
|
|
tf1.dom().scrollWidth > tf1.dom().clientWidth,
|
2016-04-04 11:08:57 +02:00
|
|
|
true,
|
|
|
|
'Horizontal scrollbar is displayed'
|
|
|
|
);
|
2015-10-31 09:00:28 +01:00
|
|
|
});
|
2015-11-29 01:46:20 +01:00
|
|
|
test('Filter button', function(){
|
|
|
|
notEqual(btn, null, 'Button exists');
|
|
|
|
deepEqual(btn.nodeName, 'INPUT', 'Expected element');
|
|
|
|
});
|
|
|
|
test('Filter button click event', function(){
|
|
|
|
tf1.setFilterValue(4, '>30');
|
|
|
|
btn.click();
|
|
|
|
deepEqual(tf1.getValidRows().length, 2, 'Filter button event result');
|
|
|
|
});
|
2015-10-31 09:00:28 +01:00
|
|
|
|
2016-12-09 13:25:42 +01:00
|
|
|
test('Cannot init if initialised', function() {
|
|
|
|
// setup
|
|
|
|
var importFile = tf1.import;
|
|
|
|
var hit = 0;
|
2017-05-25 05:51:44 +02:00
|
|
|
tf1.import = function() { hit++; };
|
2016-12-09 13:25:42 +01:00
|
|
|
tf1.initialized = true;
|
|
|
|
|
|
|
|
// act
|
|
|
|
tf1.init();
|
|
|
|
|
|
|
|
// assert
|
|
|
|
deepEqual(hit, 0, 'import not called');
|
|
|
|
|
|
|
|
tf1.import = importFile;
|
|
|
|
});
|
|
|
|
|
2016-12-08 04:21:39 +01:00
|
|
|
module('Tear-down');
|
|
|
|
test('can destroy TableFilter DOM elements', function() {
|
|
|
|
tf.destroy();
|
|
|
|
tf1.destroy();
|
|
|
|
|
|
|
|
deepEqual(tf.isInitialized(), false, 'Instance no longer initialised');
|
|
|
|
deepEqual(tf1.getFilterElement(0), null, 'Filter 0 removed');
|
|
|
|
});
|
|
|
|
|
2016-12-08 12:16:47 +01:00
|
|
|
module('Edge cases');
|
2016-12-08 04:21:39 +01:00
|
|
|
test('throws when no working DOM element', function() {
|
|
|
|
throws(
|
|
|
|
function() { new TableFilter('xyz'); },
|
|
|
|
Error,
|
|
|
|
'Throws Error when no DOM table'
|
|
|
|
);
|
|
|
|
});
|
2016-12-08 12:16:47 +01:00
|
|
|
test('Can instantiate with wrong refRow', function() {
|
|
|
|
var tf2 = new TableFilter('demo', -9);
|
2017-01-04 04:09:18 +01:00
|
|
|
tf2.init();
|
2016-12-08 12:16:47 +01:00
|
|
|
deepEqual(tf2.nbCells, 5, 'Expected number of columns');
|
|
|
|
});
|
2016-12-08 04:21:39 +01:00
|
|
|
|
2015-05-10 13:12:31 +02:00
|
|
|
})(window, TableFilter);
|