1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-30 04:22:54 +02:00
TableFilter/test/test-highlight-keywords.js

66 lines
1.9 KiB
JavaScript
Raw Normal View History

2015-05-10 13:12:31 +02:00
var tf = new TableFilter('demo', {
base_path: '../dist/tablefilter/',
2015-05-10 13:12:31 +02:00
highlight_keywords: true
});
tf.init();
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');
2016-03-23 09:02:48 +01:00
deepEqual(highlightKeyword.highlightCssClass, 'keyword', 'Css class check');
2015-05-10 13:12:31 +02:00
});
2016-10-10 09:16:39 +02:00
module('Behaviour');
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();
deepEqual(tf.dom().querySelectorAll('.keyword').length, 2,
2016-01-18 07:36:10 +01:00
'Number of applied CSS classes');
2016-01-02 15:33:31 +01:00
tf.clearFilters();
2016-03-24 00:52:23 +01:00
// issue 155
deepEqual(tf.dom().querySelectorAll('.keyword').length, 0,
2016-03-23 09:02:48 +01:00
'Number of applied CSS classes');
});
2016-10-10 09:16:39 +02:00
// issue 309
test('Match same term with increasing number of chars', function() {
tf.setFilterValue(1, 'Pe');
tf.filter();
deepEqual(tf.dom().querySelectorAll('.keyword').length, 1,
2016-10-10 09:16:39 +02:00
'Search term matched');
tf.setFilterValue(1, 'Per');
tf.filter();
deepEqual(tf.dom().querySelectorAll('.keyword').length, 1,
2016-10-10 09:16:39 +02:00
'Search term matched');
tf.setFilterValue(1, 'Pert');
tf.filter();
deepEqual(tf.dom().querySelectorAll('.keyword').length, 1,
2016-10-10 09:16:39 +02:00
'Search term matched');
});
module('Reset feature');
test('can destroy and init TableFilter', function() {
tf.destroy();
tf.init();
deepEqual(typeof highlightKeyword, 'object', 'Instanciated');
2016-03-23 09:02:48 +01:00
deepEqual(highlightKeyword.highlightCssClass, 'keyword', 'Css class check');
});
module('Tear-down');
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.isInitialized(), false, 'Filters removed');
deepEqual(tf.dom().querySelectorAll('.keyword').length, 0,
2016-03-23 09:02:48 +01:00
'Number of applied CSS classes');
2016-02-22 08:14:58 +01:00
}
);