UNPKG

2.04 kBJavaScriptView Raw
1
2var tf = new TableFilter('demo', {
3 base_path: '../dist/tablefilter/',
4 highlight_keywords: true
5});
6tf.init();
7
8var highlightKeyword = tf.feature('highlightKeyword');
9module('Sanity checks');
10test('HighlightKeyword component', function() {
11 deepEqual(typeof highlightKeyword, 'object', 'Instanciated');
12 deepEqual(highlightKeyword.highlightCssClass, 'keyword', 'Css class check');
13});
14
15module('Behaviour');
16test('Highlighted keywords', function() {
17 tf.setFilterValue(1, 'Perth');
18 tf.setFilterValue(3, '3.1');
19 tf.filter();
20 deepEqual(tf.dom().querySelectorAll('.keyword').length, 2,
21 'Number of applied CSS classes');
22
23 tf.clearFilters();
24 // issue 155
25 deepEqual(tf.dom().querySelectorAll('.keyword').length, 0,
26 'Number of applied CSS classes');
27});
28
29// issue 309
30test('Match same term with increasing number of chars', function() {
31 tf.setFilterValue(1, 'Pe');
32 tf.filter();
33 deepEqual(tf.dom().querySelectorAll('.keyword').length, 1,
34 'Search term matched');
35
36 tf.setFilterValue(1, 'Per');
37 tf.filter();
38 deepEqual(tf.dom().querySelectorAll('.keyword').length, 1,
39 'Search term matched');
40
41 tf.setFilterValue(1, 'Pert');
42 tf.filter();
43 deepEqual(tf.dom().querySelectorAll('.keyword').length, 1,
44 'Search term matched');
45});
46
47module('Reset feature');
48test('can destroy and init TableFilter', function() {
49 tf.destroy();
50 tf.init();
51 deepEqual(typeof highlightKeyword, 'object', 'Instanciated');
52 deepEqual(highlightKeyword.highlightCssClass, 'keyword', 'Css class check');
53});
54
55module('Tear-down');
56test('can destroy TableFilter DOM elements and clean highlighted words',
57 function() {
58 tf.setFilterValue(1, 'Perth');
59 tf.filter();
60 tf.destroy();
61 deepEqual(tf.isInitialized(), false, 'Filters removed');
62 deepEqual(tf.dom().querySelectorAll('.keyword').length, 0,
63 'Number of applied CSS classes');
64 }
65);