UNPKG

2.79 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
47// issue 628
48test('unhighlight with term', function() {
49 // setup
50 tf.clearFilters();
51 tf.setFilterValue(0, 'Sydney');
52 tf.filter();
53
54 // act
55 highlightKeyword.unhighlight('Sydney', highlightKeyword.highlightCssClass);
56
57 // assert
58 deepEqual(tf.dom().querySelectorAll('.keyword').length, 0,
59 'term unhighlighted');
60});
61test('unhighlight with null term', function() {
62 // setup
63 tf.clearFilters();
64 tf.setFilterValue(0, 'Sydney');
65 tf.setFilterValue(1, 'Canbe');
66 tf.filter();
67
68 // act
69 highlightKeyword.unhighlight(null, highlightKeyword.highlightCssClass);
70
71 // assert
72 deepEqual(tf.dom().querySelectorAll('.keyword').length, 0,
73 'all terms unhighlighted');
74});
75
76module('Reset feature');
77test('can destroy and init TableFilter', function() {
78 tf.destroy();
79 tf.init();
80 deepEqual(typeof highlightKeyword, 'object', 'Instanciated');
81 deepEqual(highlightKeyword.highlightCssClass, 'keyword', 'Css class check');
82});
83
84module('Tear-down');
85test('can destroy TableFilter DOM elements and clean highlighted words',
86 function() {
87 tf.setFilterValue(1, 'Perth');
88 tf.filter();
89 tf.destroy();
90 deepEqual(tf.isInitialized(), false, 'Filters removed');
91 deepEqual(tf.dom().querySelectorAll('.keyword').length, 0,
92 'Number of applied CSS classes');
93 }
94);