2015-06-10 12:53:20 +02:00
|
|
|
(function(win, TableFilter){
|
2015-10-18 10:58:08 +02:00
|
|
|
|
2015-06-14 04:23:27 +02:00
|
|
|
var id = function (id){ return document.getElementById(id); };
|
2015-06-10 12:53:20 +02:00
|
|
|
|
|
|
|
var tf = new TableFilter('demo', {
|
|
|
|
base_path: '../dist/tablefilter/',
|
|
|
|
linked_filters: true,
|
2016-02-20 08:00:03 +01:00
|
|
|
col_0: 'checklist',
|
2015-06-10 12:53:20 +02:00
|
|
|
col_1: 'checklist',
|
2015-10-18 10:58:08 +02:00
|
|
|
on_after_reset: testClearFilters
|
2015-06-10 12:53:20 +02:00
|
|
|
});
|
|
|
|
tf.init();
|
2015-10-18 10:58:08 +02:00
|
|
|
tf.setFilterValue(0, 'Sydney');
|
|
|
|
tf.getFilterElement(0).focus();
|
2016-01-02 15:33:31 +01:00
|
|
|
tf.filter();
|
2015-06-10 12:53:20 +02:00
|
|
|
|
|
|
|
module('Sanity checks');
|
|
|
|
test('Linked filters feature', function() {
|
2015-06-13 13:23:33 +02:00
|
|
|
deepEqual(tf instanceof TableFilter, true, 'TableFilter instantiated');
|
2015-06-10 12:53:20 +02:00
|
|
|
deepEqual(tf.linkedFilters, true, 'Linked filters enabled');
|
|
|
|
|
2016-01-02 15:33:31 +01:00
|
|
|
tf.clearFilters();
|
2015-10-18 10:58:08 +02:00
|
|
|
tf.onAfterFilter = null;
|
2015-06-10 12:53:20 +02:00
|
|
|
tf.destroy();
|
2015-06-13 13:23:33 +02:00
|
|
|
tf = null;
|
2016-02-20 08:00:03 +01:00
|
|
|
setWithChecklistFilters();
|
2015-10-18 10:58:08 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// function testLinked(tf) {
|
|
|
|
// test('Check filters are linked', function() {
|
|
|
|
// // var filter0 = tf.getFilterElement(0);
|
|
|
|
// deepEqual(tf.activeFilterId, 'flt1_demo_1', 'Active filter');
|
|
|
|
// // deepEqual(filter0.options.length, 2,
|
|
|
|
// // 'Linked filter expected options number'
|
|
|
|
// // );
|
|
|
|
// });
|
|
|
|
// tf._clearFilters();
|
|
|
|
// tf.onAfterFilter = null;
|
|
|
|
// tf.destroy();
|
|
|
|
// tf = null;
|
|
|
|
// setExcludedOptions();
|
|
|
|
// }
|
2015-06-13 13:23:33 +02:00
|
|
|
|
|
|
|
function setExcludedOptions(){
|
|
|
|
tf = new TableFilter('demo', {
|
|
|
|
base_path: '../dist/tablefilter/',
|
|
|
|
linked_filters: true,
|
|
|
|
disable_excluded_options: true,
|
|
|
|
col_0: 'multiple',
|
|
|
|
col_1: 'checklist',
|
2015-10-18 10:58:08 +02:00
|
|
|
on_after_filter: testExcludedOptions,
|
|
|
|
on_after_reset: testClearFilters
|
2015-06-13 13:23:33 +02:00
|
|
|
});
|
|
|
|
tf.init();
|
2015-06-14 04:23:27 +02:00
|
|
|
tf.setFilterValue(0, 'Sydney');
|
|
|
|
tf.getFilterElement(0).focus();
|
2016-01-02 15:33:31 +01:00
|
|
|
tf.filter();
|
2015-06-13 13:23:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function testExcludedOptions(tf){
|
2015-06-14 04:23:27 +02:00
|
|
|
var flt0 = tf.getFilterElement(0);
|
2015-06-13 13:23:33 +02:00
|
|
|
|
2015-06-14 04:23:27 +02:00
|
|
|
test('Check filters are linked', function() {
|
|
|
|
deepEqual(tf.activeFilterId, 'flt0_demo', 'Active filter');
|
|
|
|
deepEqual(
|
|
|
|
flt0.options[1].disabled,
|
|
|
|
true,
|
|
|
|
'Expected disabled option in master filter'
|
|
|
|
);
|
|
|
|
deepEqual(
|
|
|
|
id('flt1_'+tf.id+'_2').disabled,
|
|
|
|
true,
|
|
|
|
'Expected disabled option in slave filter'
|
|
|
|
);
|
|
|
|
});
|
2015-10-18 10:58:08 +02:00
|
|
|
|
|
|
|
tf.onAfterFilter = null;
|
2016-01-02 15:33:31 +01:00
|
|
|
setTimeout(tf.clearFilters, 0);
|
2015-10-18 10:58:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tests for https://github.com/koalyptus/TableFilter/pull/42 issue
|
|
|
|
function testClearFilters() {
|
|
|
|
test('Check clear filters functionality', function() {
|
|
|
|
deepEqual(tf.getFilterableRowsNb(), 7,
|
|
|
|
'Nb of valid rows after filters are cleared');
|
|
|
|
});
|
2016-02-20 08:00:03 +01:00
|
|
|
|
|
|
|
tf.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
function setWithChecklistFilters() {
|
|
|
|
tf = new TableFilter('demo', {
|
|
|
|
base_path: '../dist/tablefilter/',
|
|
|
|
linked_filters: true,
|
|
|
|
col_0: 'checklist',
|
|
|
|
col_1: 'checklist'
|
|
|
|
});
|
|
|
|
tf.init();
|
|
|
|
|
2016-07-02 06:06:12 +02:00
|
|
|
var flt0 = tf.getFilterElement(0);
|
|
|
|
var flt1 = tf.getFilterElement(1);
|
|
|
|
|
2016-02-20 08:00:03 +01:00
|
|
|
var evObj = document.createEvent('HTMLEvents');
|
2016-07-02 06:06:12 +02:00
|
|
|
evObj.initEvent('click', true, true);
|
2016-02-20 08:00:03 +01:00
|
|
|
|
|
|
|
tf.setFilterValue(0, 'Sydney');
|
2016-07-02 06:06:12 +02:00
|
|
|
flt0.querySelectorAll('input')[1].dispatchEvent(evObj);
|
2016-02-20 08:00:03 +01:00
|
|
|
tf.setFilterValue(1, 'Adelaide');
|
2016-07-02 06:06:12 +02:00
|
|
|
flt1.querySelectorAll('input')[0].dispatchEvent(evObj);
|
|
|
|
|
2016-02-20 08:00:03 +01:00
|
|
|
setTimeout(testWithChecklistFilters.call(null, tf), 50);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests for issue 113
|
|
|
|
function testWithChecklistFilters(tf){
|
|
|
|
var flt0 = id(tf.fltIds[0]);
|
|
|
|
var flt1 = id(tf.fltIds[1]);
|
|
|
|
|
|
|
|
deepEqual(flt0.getElementsByTagName('li').length, 2, 'Nb of options');
|
|
|
|
deepEqual(flt1.getElementsByTagName('li').length, 2, 'Nb of options');
|
|
|
|
tf.destroy();
|
|
|
|
tf = null;
|
|
|
|
setExcludedOptions();
|
2015-06-10 12:53:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
})(window, TableFilter);
|