2014-12-14 05:55:01 +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
|
|
|
highlight_keywords: true
|
|
|
|
});
|
|
|
|
tf.init();
|
2014-12-14 05:55:01 +01:00
|
|
|
|
2015-06-07 17:31:15 +02:00
|
|
|
var highlightKeyword = tf.feature('highlightKeyword');
|
2015-05-10 13:12:31 +02:00
|
|
|
module('Sanity checks');
|
|
|
|
test('HighlightKeyword component', function() {
|
|
|
|
deepEqual(typeof highlightKeyword, 'object', 'Instanciated');
|
2015-11-21 04:41:40 +01:00
|
|
|
deepEqual(highlightKeyword.highlightedNodes instanceof Array,
|
|
|
|
true, 'Property check');
|
2015-05-10 13:12:31 +02:00
|
|
|
});
|
2014-12-14 05:55:01 +01:00
|
|
|
|
2015-05-10 13:12:31 +02:00
|
|
|
test('Highlighted keywords', function() {
|
|
|
|
tf.setFilterValue(1, 'Perth');
|
|
|
|
tf.setFilterValue(3, '3.1');
|
2016-01-02 15:33:31 +01:00
|
|
|
tf.filter();
|
2015-11-21 04:41:40 +01:00
|
|
|
deepEqual(highlightKeyword.highlightedNodes.length,
|
|
|
|
2, 'Number of highlighted words');
|
2016-01-18 07:36:10 +01:00
|
|
|
deepEqual(tf.tbl.querySelectorAll('.keyword').length, 2,
|
|
|
|
'Number of applied CSS classes');
|
2014-12-14 05:55:01 +01:00
|
|
|
|
2016-01-02 15:33:31 +01:00
|
|
|
tf.clearFilters();
|
2015-11-21 04:41:40 +01:00
|
|
|
deepEqual(highlightKeyword.highlightedNodes.length,
|
|
|
|
0, 'Number of highlighted words');
|
2016-01-18 07:36:10 +01:00
|
|
|
// TODO: uncomment when fixed
|
|
|
|
// deepEqual(tf.tbl.querySelectorAll('.keyword').length, 0,
|
|
|
|
// 'Number of applied CSS classes');
|
2015-11-21 04:41:40 +01:00
|
|
|
});
|
|
|
|
|
2016-01-14 11:13:19 +01:00
|
|
|
module('Reset feature');
|
|
|
|
test('can destroy and init TableFilter', function() {
|
|
|
|
tf.destroy();
|
|
|
|
tf.init();
|
|
|
|
deepEqual(typeof highlightKeyword, 'object', 'Instanciated');
|
|
|
|
deepEqual(highlightKeyword.highlightedNodes instanceof Array,
|
|
|
|
true, 'Property check');
|
|
|
|
});
|
|
|
|
|
2015-11-21 04:41:40 +01:00
|
|
|
module('Tear-down');
|
2016-01-14 11:13:19 +01:00
|
|
|
test('can destroy TableFilter DOM elements and clean highlighted words',
|
|
|
|
function() {
|
2016-02-22 08:14:58 +01:00
|
|
|
tf.setFilterValue(1, 'Perth');
|
|
|
|
tf.filter();
|
|
|
|
tf.destroy();
|
|
|
|
deepEqual(tf.hasGrid(), false, 'Filters removed');
|
|
|
|
deepEqual(highlightKeyword.highlightedNodes.length,
|
|
|
|
0, 'Number of highlighted words');
|
|
|
|
}
|
|
|
|
);
|